Skip to content

Commit d9c4e20

Browse files
committed
put PRNG descriptor into state
1 parent 0c30412 commit d9c4e20

16 files changed

+49
-313
lines changed

helper.pl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ sub check_descriptors {
127127
my $fails = 0;
128128
$fails = $fails + check_descriptor("ciphers", "cipher");
129129
$fails = $fails + check_descriptor("hashes", "hash");
130-
$fails = $fails + check_descriptor("prngs", "prng");
131130
return $fails;
132131
}
133132

src/headers/tomcrypt_prng.h

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,10 @@ struct sober128_prng {
5454
};
5555
#endif
5656

57-
typedef struct {
58-
union {
59-
char dummy[1];
60-
#ifdef LTC_YARROW
61-
struct yarrow_prng yarrow;
62-
#endif
63-
#ifdef LTC_RC4
64-
struct rc4_prng rc4;
65-
#endif
66-
#ifdef LTC_CHACHA20_PRNG
67-
struct chacha20_prng chacha;
68-
#endif
69-
#ifdef LTC_FORTUNA
70-
struct fortuna_prng fortuna;
71-
#endif
72-
#ifdef LTC_SOBER128
73-
struct sober128_prng sober128;
74-
#endif
75-
} u;
76-
short ready; /* ready flag 0-1 */
77-
LTC_MUTEX_TYPE(lock) /* lock */
78-
} prng_state;
57+
typedef struct ltc_prng_state prng_state;
7958

8059
/** PRNG descriptor */
81-
extern struct ltc_prng_descriptor {
60+
struct ltc_prng_descriptor {
8261
/** Name of the PRNG */
8362
const char *name;
8463
/** size in bytes of exported state */
@@ -130,7 +109,31 @@ extern struct ltc_prng_descriptor {
130109
@return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
131110
*/
132111
int (*test)(void);
133-
} prng_descriptor[];
112+
};
113+
114+
struct ltc_prng_state {
115+
union {
116+
char dummy[1];
117+
#ifdef LTC_YARROW
118+
struct yarrow_prng yarrow;
119+
#endif
120+
#ifdef LTC_RC4
121+
struct rc4_prng rc4;
122+
#endif
123+
#ifdef LTC_CHACHA20_PRNG
124+
struct chacha20_prng chacha;
125+
#endif
126+
#ifdef LTC_FORTUNA
127+
struct fortuna_prng fortuna;
128+
#endif
129+
#ifdef LTC_SOBER128
130+
struct sober128_prng sober128;
131+
#endif
132+
} u;
133+
short ready; /* ready flag 0-1 */
134+
struct ltc_prng_descriptor desc;
135+
LTC_MUTEX_TYPE(lock) /* lock */
136+
};
134137

135138
#ifdef LTC_YARROW
136139
int yarrow_start(prng_state *prng);
@@ -141,7 +144,6 @@ int yarrow_done(prng_state *prng);
141144
int yarrow_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
142145
int yarrow_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
143146
int yarrow_test(void);
144-
extern const struct ltc_prng_descriptor yarrow_desc;
145147
#endif
146148

147149
#ifdef LTC_FORTUNA
@@ -155,7 +157,6 @@ int fortuna_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
155157
int fortuna_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
156158
int fortuna_update_seed(const unsigned char *in, unsigned long inlen, prng_state *prng);
157159
int fortuna_test(void);
158-
extern const struct ltc_prng_descriptor fortuna_desc;
159160
#endif
160161

161162
#ifdef LTC_RC4
@@ -167,7 +168,6 @@ int rc4_done(prng_state *prng);
167168
int rc4_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
168169
int rc4_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
169170
int rc4_test(void);
170-
extern const struct ltc_prng_descriptor rc4_desc;
171171
#endif
172172

173173
#ifdef LTC_CHACHA20_PRNG
@@ -179,7 +179,6 @@ int chacha20_prng_done(prng_state *prng);
179179
int chacha20_prng_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
180180
int chacha20_prng_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
181181
int chacha20_prng_test(void);
182-
extern const struct ltc_prng_descriptor chacha20_prng_desc;
183182
#endif
184183

185184
#ifdef LTC_SPRNG
@@ -191,7 +190,6 @@ int sprng_done(prng_state *prng);
191190
int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
192191
int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
193192
int sprng_test(void);
194-
extern const struct ltc_prng_descriptor sprng_desc;
195193
#endif
196194

197195
#ifdef LTC_SOBER128
@@ -203,24 +201,16 @@ int sober128_done(prng_state *prng);
203201
int sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
204202
int sober128_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
205203
int sober128_test(void);
206-
extern const struct ltc_prng_descriptor sober128_desc;
207204
#endif
208205

209-
int find_prng(const char *name);
210-
int register_prng(const struct ltc_prng_descriptor *prng);
211-
int unregister_prng(const struct ltc_prng_descriptor *prng);
212-
int register_all_prngs(void);
213-
int prng_is_valid(int idx);
214-
LTC_MUTEX_PROTO(ltc_prng_mutex)
215-
216206
/* Slow RNG you **might** be able to use to seed a PRNG with. Be careful as this
217207
* might not work on all platforms as planned
218208
*/
219209
unsigned long rng_get_bytes(unsigned char *out,
220210
unsigned long outlen,
221211
void (*callback)(void));
222212

223-
int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));
213+
int rng_make_prng(int bits, prng_state *prng, void (*callback)(void));
224214

225215
#ifdef LTC_PRNG_ENABLE_LTC_RNG
226216
extern unsigned long (*ltc_rng)(unsigned char *out, unsigned long outlen,

src/misc/crypt/crypt_find_prng.c

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/misc/crypt/crypt_prng_descriptor.c

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/misc/crypt/crypt_prng_is_valid.c

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/misc/crypt/crypt_prng_rng_descriptor.c

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/misc/crypt/crypt_register_all_prngs.c

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/misc/crypt/crypt_register_prng.c

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)