cordova-plugin-mserviceinterface-2.0 1.0.21 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -28
- package/plugin.xml +153 -153
- package/src/android/CallbackProgressDialog.java +53 -53
- package/src/android/FileProvider.java +7 -7
- package/src/android/backgroundNotification.java +120 -120
- package/src/android/doubleogradle.gradle +5 -5
- package/src/android/mInterface.java +2087 -2066
- package/src/android/mInterfaceReceiver.java +59 -59
- package/src/android/mInterfaceService.java +749 -749
- package/src/android/mInterfaceUtil.java +1686 -1688
- package/src/android/res/xml/network_security_config.xml +8 -8
- package/src/android/res/xml/opener_paths.xml +16 -16
- package/src/ios/InternetConnection.h +64 -64
- package/src/ios/InternetConnection.m +242 -242
- package/src/ios/SSZipArchive.h +146 -146
- package/src/ios/SSZipArchive.m +1180 -1180
- package/src/ios/SSZipCommon.h +66 -66
- package/src/ios/UICKeyChainStore.h +64 -64
- package/src/ios/UICKeyChainStore.m +434 -434
- package/src/ios/XMLConverter.h +61 -61
- package/src/ios/XMLConverter.m +243 -243
- package/src/ios/ZipArchive.h +19 -19
- package/src/ios/aes/aes.h +270 -270
- package/src/ios/aes/aes_ni.c +687 -687
- package/src/ios/aes/aes_ni.h +59 -59
- package/src/ios/aes/aescrypt.c +301 -301
- package/src/ios/aes/aeskey.c +554 -554
- package/src/ios/aes/aesopt.h +776 -776
- package/src/ios/aes/aestab.c +418 -418
- package/src/ios/aes/aestab.h +173 -173
- package/src/ios/aes/brg_endian.h +127 -127
- package/src/ios/aes/brg_types.h +191 -191
- package/src/ios/aes/fileenc.c +145 -145
- package/src/ios/aes/fileenc.h +121 -121
- package/src/ios/aes/hmac.c +209 -209
- package/src/ios/aes/hmac.h +119 -119
- package/src/ios/aes/prng.c +155 -155
- package/src/ios/aes/prng.h +82 -82
- package/src/ios/aes/pwd2key.c +181 -181
- package/src/ios/aes/pwd2key.h +45 -45
- package/src/ios/aes/sha1.c +283 -283
- package/src/ios/aes/sha1.h +72 -72
- package/src/ios/mInterface.h +2 -0
- package/src/ios/mInterface.m +18 -1
- package/src/ios/minizip/crypt.c +146 -146
- package/src/ios/minizip/crypt.h +66 -66
- package/src/ios/minizip/ioapi.c +353 -353
- package/src/ios/minizip/ioapi.h +154 -154
- package/src/ios/minizip/ioapi_buf.c +452 -452
- package/src/ios/minizip/ioapi_buf.h +52 -52
- package/src/ios/minizip/ioapi_mem.c +167 -167
- package/src/ios/minizip/ioapi_mem.h +52 -52
- package/src/ios/minizip/minishared.c +292 -292
- package/src/ios/minizip/minishared.h +50 -50
- package/src/ios/minizip/unzip.c +2007 -2007
- package/src/ios/minizip/unzip.h +254 -254
- package/src/ios/minizip/zip.c +2007 -2007
- package/src/ios/minizip/zip.h +215 -215
- package/www/mInterface.js +3 -3
package/src/ios/aes/prng.c
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
/*
|
|
2
|
-
---------------------------------------------------------------------------
|
|
3
|
-
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
LICENSE TERMS
|
|
7
|
-
|
|
8
|
-
The free distribution and use of this software in both source and binary
|
|
9
|
-
form is allowed (with or without changes) provided that:
|
|
10
|
-
|
|
11
|
-
1. distributions of this source code include the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer;
|
|
13
|
-
|
|
14
|
-
2. distributions in binary form include the above copyright
|
|
15
|
-
notice, this list of conditions and the following disclaimer
|
|
16
|
-
in the documentation and/or other associated materials;
|
|
17
|
-
|
|
18
|
-
3. the copyright holder's name is not used to endorse products
|
|
19
|
-
built using this software without specific written permission.
|
|
20
|
-
|
|
21
|
-
ALTERNATIVELY, provided that this notice is retained in full, this product
|
|
22
|
-
may be distributed under the terms of the GNU General Public License (GPL),
|
|
23
|
-
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
|
24
|
-
|
|
25
|
-
DISCLAIMER
|
|
26
|
-
|
|
27
|
-
This software is provided 'as is' with no explicit or implied warranties
|
|
28
|
-
in respect of its properties, including, but not limited to, correctness
|
|
29
|
-
and/or fitness for purpose.
|
|
30
|
-
---------------------------------------------------------------------------
|
|
31
|
-
Issue Date: 24/01/2003
|
|
32
|
-
|
|
33
|
-
This file implements a random data pool based on the use of an external
|
|
34
|
-
entropy function. It is based on the ideas advocated by Peter Gutmann in
|
|
35
|
-
his work on pseudo random sequence generators. It is not a 'paranoid'
|
|
36
|
-
random sequence generator and no attempt is made to protect the pool
|
|
37
|
-
from prying eyes either by memory locking or by techniques to obscure
|
|
38
|
-
its location in memory.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
#include <string.h>
|
|
42
|
-
#include "prng.h"
|
|
43
|
-
|
|
44
|
-
#if defined(__cplusplus)
|
|
45
|
-
extern "C"
|
|
46
|
-
{
|
|
47
|
-
#endif
|
|
48
|
-
|
|
49
|
-
/* mix a random data pool using the SHA1 compression function (as */
|
|
50
|
-
/* suggested by Peter Gutmann in his paper on random pools) */
|
|
51
|
-
|
|
52
|
-
static void prng_mix(unsigned char buf[])
|
|
53
|
-
{ unsigned int i, len;
|
|
54
|
-
sha1_ctx ctx[1];
|
|
55
|
-
|
|
56
|
-
/*lint -e{663} unusual array to pointer conversion */
|
|
57
|
-
for(i = 0; i < PRNG_POOL_SIZE; i += SHA1_DIGEST_SIZE)
|
|
58
|
-
{
|
|
59
|
-
/* copy digest size pool block into SHA1 hash block */
|
|
60
|
-
memcpy(ctx->hash, buf + (i ? i : PRNG_POOL_SIZE)
|
|
61
|
-
- SHA1_DIGEST_SIZE, SHA1_DIGEST_SIZE);
|
|
62
|
-
|
|
63
|
-
/* copy data from pool into the SHA1 data buffer */
|
|
64
|
-
len = PRNG_POOL_SIZE - i;
|
|
65
|
-
memcpy(ctx->wbuf, buf + i, (len > SHA1_BLOCK_SIZE ? SHA1_BLOCK_SIZE : len));
|
|
66
|
-
|
|
67
|
-
if(len < SHA1_BLOCK_SIZE)
|
|
68
|
-
memcpy(((char*)ctx->wbuf) + len, buf, SHA1_BLOCK_SIZE - len);
|
|
69
|
-
|
|
70
|
-
/* compress using the SHA1 compression function */
|
|
71
|
-
sha1_compile(ctx);
|
|
72
|
-
|
|
73
|
-
/* put digest size block back into the random pool */
|
|
74
|
-
memcpy(buf + i, ctx->hash, SHA1_DIGEST_SIZE);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/* refresh the output buffer and update the random pool by adding */
|
|
79
|
-
/* entropy and remixing */
|
|
80
|
-
|
|
81
|
-
static void update_pool(prng_ctx ctx[1])
|
|
82
|
-
{ unsigned int i = 0;
|
|
83
|
-
|
|
84
|
-
/* transfer random pool data to the output buffer */
|
|
85
|
-
memcpy(ctx->obuf, ctx->rbuf, PRNG_POOL_SIZE);
|
|
86
|
-
|
|
87
|
-
/* enter entropy data into the pool */
|
|
88
|
-
while(i < PRNG_POOL_SIZE)
|
|
89
|
-
i += ctx->entropy(ctx->rbuf + i, PRNG_POOL_SIZE - i);
|
|
90
|
-
|
|
91
|
-
/* invert and xor the original pool data into the pool */
|
|
92
|
-
for(i = 0; i < PRNG_POOL_SIZE; ++i)
|
|
93
|
-
ctx->rbuf[i] ^= ~ctx->obuf[i];
|
|
94
|
-
|
|
95
|
-
/* mix the pool and the output buffer */
|
|
96
|
-
prng_mix(ctx->rbuf);
|
|
97
|
-
prng_mix(ctx->obuf);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
void prng_init(prng_entropy_fn fun, prng_ctx ctx[1])
|
|
101
|
-
{ int i;
|
|
102
|
-
|
|
103
|
-
/* clear the buffers and the counter in the context */
|
|
104
|
-
memset(ctx, 0, sizeof(prng_ctx));
|
|
105
|
-
|
|
106
|
-
/* set the pointer to the entropy collection function */
|
|
107
|
-
ctx->entropy = fun;
|
|
108
|
-
|
|
109
|
-
/* initialise the random data pool */
|
|
110
|
-
update_pool(ctx);
|
|
111
|
-
|
|
112
|
-
/* mix the pool a minimum number of times */
|
|
113
|
-
for(i = 0; i < PRNG_MIN_MIX; ++i)
|
|
114
|
-
prng_mix(ctx->rbuf);
|
|
115
|
-
|
|
116
|
-
/* update the pool to prime the pool output buffer */
|
|
117
|
-
update_pool(ctx);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/* provide random bytes from the random data pool */
|
|
121
|
-
|
|
122
|
-
void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1])
|
|
123
|
-
{ unsigned char *rp = data;
|
|
124
|
-
unsigned int len, pos = ctx->pos;
|
|
125
|
-
|
|
126
|
-
while(data_len)
|
|
127
|
-
{
|
|
128
|
-
/* transfer 'data_len' bytes (or the number of bytes remaining */
|
|
129
|
-
/* the pool output buffer if less) into the output */
|
|
130
|
-
len = (data_len < PRNG_POOL_SIZE - pos ? data_len : PRNG_POOL_SIZE - pos);
|
|
131
|
-
memcpy(rp, ctx->obuf + pos, len);
|
|
132
|
-
rp += len; /* update ouput buffer position pointer */
|
|
133
|
-
pos += len; /* update pool output buffer pointer */
|
|
134
|
-
data_len -= len; /* update the remaining data count */
|
|
135
|
-
|
|
136
|
-
/* refresh the random pool if necessary */
|
|
137
|
-
if(pos == PRNG_POOL_SIZE)
|
|
138
|
-
{
|
|
139
|
-
update_pool(ctx); pos = 0;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
ctx->pos = pos;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
void prng_end(prng_ctx ctx[1])
|
|
147
|
-
{
|
|
148
|
-
/* ensure the data in the context is destroyed */
|
|
149
|
-
memset(ctx, 0, sizeof(prng_ctx));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
#if defined(__cplusplus)
|
|
153
|
-
}
|
|
154
|
-
#endif
|
|
155
|
-
|
|
1
|
+
/*
|
|
2
|
+
---------------------------------------------------------------------------
|
|
3
|
+
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
LICENSE TERMS
|
|
7
|
+
|
|
8
|
+
The free distribution and use of this software in both source and binary
|
|
9
|
+
form is allowed (with or without changes) provided that:
|
|
10
|
+
|
|
11
|
+
1. distributions of this source code include the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer;
|
|
13
|
+
|
|
14
|
+
2. distributions in binary form include the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer
|
|
16
|
+
in the documentation and/or other associated materials;
|
|
17
|
+
|
|
18
|
+
3. the copyright holder's name is not used to endorse products
|
|
19
|
+
built using this software without specific written permission.
|
|
20
|
+
|
|
21
|
+
ALTERNATIVELY, provided that this notice is retained in full, this product
|
|
22
|
+
may be distributed under the terms of the GNU General Public License (GPL),
|
|
23
|
+
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
|
24
|
+
|
|
25
|
+
DISCLAIMER
|
|
26
|
+
|
|
27
|
+
This software is provided 'as is' with no explicit or implied warranties
|
|
28
|
+
in respect of its properties, including, but not limited to, correctness
|
|
29
|
+
and/or fitness for purpose.
|
|
30
|
+
---------------------------------------------------------------------------
|
|
31
|
+
Issue Date: 24/01/2003
|
|
32
|
+
|
|
33
|
+
This file implements a random data pool based on the use of an external
|
|
34
|
+
entropy function. It is based on the ideas advocated by Peter Gutmann in
|
|
35
|
+
his work on pseudo random sequence generators. It is not a 'paranoid'
|
|
36
|
+
random sequence generator and no attempt is made to protect the pool
|
|
37
|
+
from prying eyes either by memory locking or by techniques to obscure
|
|
38
|
+
its location in memory.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
#include <string.h>
|
|
42
|
+
#include "prng.h"
|
|
43
|
+
|
|
44
|
+
#if defined(__cplusplus)
|
|
45
|
+
extern "C"
|
|
46
|
+
{
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
/* mix a random data pool using the SHA1 compression function (as */
|
|
50
|
+
/* suggested by Peter Gutmann in his paper on random pools) */
|
|
51
|
+
|
|
52
|
+
static void prng_mix(unsigned char buf[])
|
|
53
|
+
{ unsigned int i, len;
|
|
54
|
+
sha1_ctx ctx[1];
|
|
55
|
+
|
|
56
|
+
/*lint -e{663} unusual array to pointer conversion */
|
|
57
|
+
for(i = 0; i < PRNG_POOL_SIZE; i += SHA1_DIGEST_SIZE)
|
|
58
|
+
{
|
|
59
|
+
/* copy digest size pool block into SHA1 hash block */
|
|
60
|
+
memcpy(ctx->hash, buf + (i ? i : PRNG_POOL_SIZE)
|
|
61
|
+
- SHA1_DIGEST_SIZE, SHA1_DIGEST_SIZE);
|
|
62
|
+
|
|
63
|
+
/* copy data from pool into the SHA1 data buffer */
|
|
64
|
+
len = PRNG_POOL_SIZE - i;
|
|
65
|
+
memcpy(ctx->wbuf, buf + i, (len > SHA1_BLOCK_SIZE ? SHA1_BLOCK_SIZE : len));
|
|
66
|
+
|
|
67
|
+
if(len < SHA1_BLOCK_SIZE)
|
|
68
|
+
memcpy(((char*)ctx->wbuf) + len, buf, SHA1_BLOCK_SIZE - len);
|
|
69
|
+
|
|
70
|
+
/* compress using the SHA1 compression function */
|
|
71
|
+
sha1_compile(ctx);
|
|
72
|
+
|
|
73
|
+
/* put digest size block back into the random pool */
|
|
74
|
+
memcpy(buf + i, ctx->hash, SHA1_DIGEST_SIZE);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* refresh the output buffer and update the random pool by adding */
|
|
79
|
+
/* entropy and remixing */
|
|
80
|
+
|
|
81
|
+
static void update_pool(prng_ctx ctx[1])
|
|
82
|
+
{ unsigned int i = 0;
|
|
83
|
+
|
|
84
|
+
/* transfer random pool data to the output buffer */
|
|
85
|
+
memcpy(ctx->obuf, ctx->rbuf, PRNG_POOL_SIZE);
|
|
86
|
+
|
|
87
|
+
/* enter entropy data into the pool */
|
|
88
|
+
while(i < PRNG_POOL_SIZE)
|
|
89
|
+
i += ctx->entropy(ctx->rbuf + i, PRNG_POOL_SIZE - i);
|
|
90
|
+
|
|
91
|
+
/* invert and xor the original pool data into the pool */
|
|
92
|
+
for(i = 0; i < PRNG_POOL_SIZE; ++i)
|
|
93
|
+
ctx->rbuf[i] ^= ~ctx->obuf[i];
|
|
94
|
+
|
|
95
|
+
/* mix the pool and the output buffer */
|
|
96
|
+
prng_mix(ctx->rbuf);
|
|
97
|
+
prng_mix(ctx->obuf);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void prng_init(prng_entropy_fn fun, prng_ctx ctx[1])
|
|
101
|
+
{ int i;
|
|
102
|
+
|
|
103
|
+
/* clear the buffers and the counter in the context */
|
|
104
|
+
memset(ctx, 0, sizeof(prng_ctx));
|
|
105
|
+
|
|
106
|
+
/* set the pointer to the entropy collection function */
|
|
107
|
+
ctx->entropy = fun;
|
|
108
|
+
|
|
109
|
+
/* initialise the random data pool */
|
|
110
|
+
update_pool(ctx);
|
|
111
|
+
|
|
112
|
+
/* mix the pool a minimum number of times */
|
|
113
|
+
for(i = 0; i < PRNG_MIN_MIX; ++i)
|
|
114
|
+
prng_mix(ctx->rbuf);
|
|
115
|
+
|
|
116
|
+
/* update the pool to prime the pool output buffer */
|
|
117
|
+
update_pool(ctx);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* provide random bytes from the random data pool */
|
|
121
|
+
|
|
122
|
+
void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1])
|
|
123
|
+
{ unsigned char *rp = data;
|
|
124
|
+
unsigned int len, pos = ctx->pos;
|
|
125
|
+
|
|
126
|
+
while(data_len)
|
|
127
|
+
{
|
|
128
|
+
/* transfer 'data_len' bytes (or the number of bytes remaining */
|
|
129
|
+
/* the pool output buffer if less) into the output */
|
|
130
|
+
len = (data_len < PRNG_POOL_SIZE - pos ? data_len : PRNG_POOL_SIZE - pos);
|
|
131
|
+
memcpy(rp, ctx->obuf + pos, len);
|
|
132
|
+
rp += len; /* update ouput buffer position pointer */
|
|
133
|
+
pos += len; /* update pool output buffer pointer */
|
|
134
|
+
data_len -= len; /* update the remaining data count */
|
|
135
|
+
|
|
136
|
+
/* refresh the random pool if necessary */
|
|
137
|
+
if(pos == PRNG_POOL_SIZE)
|
|
138
|
+
{
|
|
139
|
+
update_pool(ctx); pos = 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
ctx->pos = pos;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
void prng_end(prng_ctx ctx[1])
|
|
147
|
+
{
|
|
148
|
+
/* ensure the data in the context is destroyed */
|
|
149
|
+
memset(ctx, 0, sizeof(prng_ctx));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#if defined(__cplusplus)
|
|
153
|
+
}
|
|
154
|
+
#endif
|
|
155
|
+
|
package/src/ios/aes/prng.h
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/*
|
|
2
|
-
---------------------------------------------------------------------------
|
|
3
|
-
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
LICENSE TERMS
|
|
7
|
-
|
|
8
|
-
The free distribution and use of this software in both source and binary
|
|
9
|
-
form is allowed (with or without changes) provided that:
|
|
10
|
-
|
|
11
|
-
1. distributions of this source code include the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer;
|
|
13
|
-
|
|
14
|
-
2. distributions in binary form include the above copyright
|
|
15
|
-
notice, this list of conditions and the following disclaimer
|
|
16
|
-
in the documentation and/or other associated materials;
|
|
17
|
-
|
|
18
|
-
3. the copyright holder's name is not used to endorse products
|
|
19
|
-
built using this software without specific written permission.
|
|
20
|
-
|
|
21
|
-
ALTERNATIVELY, provided that this notice is retained in full, this product
|
|
22
|
-
may be distributed under the terms of the GNU General Public License (GPL),
|
|
23
|
-
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
|
24
|
-
|
|
25
|
-
DISCLAIMER
|
|
26
|
-
|
|
27
|
-
This software is provided 'as is' with no explicit or implied warranties
|
|
28
|
-
in respect of its properties, including, but not limited to, correctness
|
|
29
|
-
and/or fitness for purpose.
|
|
30
|
-
---------------------------------------------------------------------------
|
|
31
|
-
Issue Date: 24/01/2003
|
|
32
|
-
|
|
33
|
-
This is the header file for an implementation of a random data pool based on
|
|
34
|
-
the use of an external entropy function (inspired by Peter Gutmann's work).
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
#ifndef _PRNG_H
|
|
38
|
-
#define _PRNG_H
|
|
39
|
-
|
|
40
|
-
#include "sha1.h"
|
|
41
|
-
|
|
42
|
-
#define PRNG_POOL_LEN 256 /* minimum random pool size */
|
|
43
|
-
#define PRNG_MIN_MIX 20 /* min initial pool mixing iterations */
|
|
44
|
-
|
|
45
|
-
/* ensure that pool length is a multiple of the SHA1 digest size */
|
|
46
|
-
|
|
47
|
-
#define PRNG_POOL_SIZE (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE))
|
|
48
|
-
|
|
49
|
-
#if defined(__cplusplus)
|
|
50
|
-
extern "C"
|
|
51
|
-
{
|
|
52
|
-
#endif
|
|
53
|
-
|
|
54
|
-
/* A function for providing entropy is a parameter in the prng_init() */
|
|
55
|
-
/* call. This function has the following form and returns a maximum */
|
|
56
|
-
/* of 'len' bytes of pseudo random data in the buffer 'buf'. It can */
|
|
57
|
-
/* return less than 'len' bytes but will be repeatedly called for more */
|
|
58
|
-
/* data in this case. */
|
|
59
|
-
|
|
60
|
-
typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len);
|
|
61
|
-
|
|
62
|
-
typedef struct
|
|
63
|
-
{ unsigned char rbuf[PRNG_POOL_SIZE]; /* the random pool */
|
|
64
|
-
unsigned char obuf[PRNG_POOL_SIZE]; /* pool output buffer */
|
|
65
|
-
unsigned int pos; /* output buffer position */
|
|
66
|
-
prng_entropy_fn entropy; /* entropy function pointer */
|
|
67
|
-
} prng_ctx;
|
|
68
|
-
|
|
69
|
-
/* initialise the random stream generator */
|
|
70
|
-
void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]);
|
|
71
|
-
|
|
72
|
-
/* obtain random bytes from the generator */
|
|
73
|
-
void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]);
|
|
74
|
-
|
|
75
|
-
/* close the random stream generator */
|
|
76
|
-
void prng_end(prng_ctx ctx[1]);
|
|
77
|
-
|
|
78
|
-
#if defined(__cplusplus)
|
|
79
|
-
}
|
|
80
|
-
#endif
|
|
81
|
-
|
|
82
|
-
#endif
|
|
1
|
+
/*
|
|
2
|
+
---------------------------------------------------------------------------
|
|
3
|
+
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
LICENSE TERMS
|
|
7
|
+
|
|
8
|
+
The free distribution and use of this software in both source and binary
|
|
9
|
+
form is allowed (with or without changes) provided that:
|
|
10
|
+
|
|
11
|
+
1. distributions of this source code include the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer;
|
|
13
|
+
|
|
14
|
+
2. distributions in binary form include the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer
|
|
16
|
+
in the documentation and/or other associated materials;
|
|
17
|
+
|
|
18
|
+
3. the copyright holder's name is not used to endorse products
|
|
19
|
+
built using this software without specific written permission.
|
|
20
|
+
|
|
21
|
+
ALTERNATIVELY, provided that this notice is retained in full, this product
|
|
22
|
+
may be distributed under the terms of the GNU General Public License (GPL),
|
|
23
|
+
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
|
24
|
+
|
|
25
|
+
DISCLAIMER
|
|
26
|
+
|
|
27
|
+
This software is provided 'as is' with no explicit or implied warranties
|
|
28
|
+
in respect of its properties, including, but not limited to, correctness
|
|
29
|
+
and/or fitness for purpose.
|
|
30
|
+
---------------------------------------------------------------------------
|
|
31
|
+
Issue Date: 24/01/2003
|
|
32
|
+
|
|
33
|
+
This is the header file for an implementation of a random data pool based on
|
|
34
|
+
the use of an external entropy function (inspired by Peter Gutmann's work).
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
#ifndef _PRNG_H
|
|
38
|
+
#define _PRNG_H
|
|
39
|
+
|
|
40
|
+
#include "sha1.h"
|
|
41
|
+
|
|
42
|
+
#define PRNG_POOL_LEN 256 /* minimum random pool size */
|
|
43
|
+
#define PRNG_MIN_MIX 20 /* min initial pool mixing iterations */
|
|
44
|
+
|
|
45
|
+
/* ensure that pool length is a multiple of the SHA1 digest size */
|
|
46
|
+
|
|
47
|
+
#define PRNG_POOL_SIZE (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE))
|
|
48
|
+
|
|
49
|
+
#if defined(__cplusplus)
|
|
50
|
+
extern "C"
|
|
51
|
+
{
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
/* A function for providing entropy is a parameter in the prng_init() */
|
|
55
|
+
/* call. This function has the following form and returns a maximum */
|
|
56
|
+
/* of 'len' bytes of pseudo random data in the buffer 'buf'. It can */
|
|
57
|
+
/* return less than 'len' bytes but will be repeatedly called for more */
|
|
58
|
+
/* data in this case. */
|
|
59
|
+
|
|
60
|
+
typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len);
|
|
61
|
+
|
|
62
|
+
typedef struct
|
|
63
|
+
{ unsigned char rbuf[PRNG_POOL_SIZE]; /* the random pool */
|
|
64
|
+
unsigned char obuf[PRNG_POOL_SIZE]; /* pool output buffer */
|
|
65
|
+
unsigned int pos; /* output buffer position */
|
|
66
|
+
prng_entropy_fn entropy; /* entropy function pointer */
|
|
67
|
+
} prng_ctx;
|
|
68
|
+
|
|
69
|
+
/* initialise the random stream generator */
|
|
70
|
+
void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]);
|
|
71
|
+
|
|
72
|
+
/* obtain random bytes from the generator */
|
|
73
|
+
void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]);
|
|
74
|
+
|
|
75
|
+
/* close the random stream generator */
|
|
76
|
+
void prng_end(prng_ctx ctx[1]);
|
|
77
|
+
|
|
78
|
+
#if defined(__cplusplus)
|
|
79
|
+
}
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
#endif
|