1 /* Copied from libtomcrypt/src/prngs/sprng.c and modified to
2 * use Dropbear's genrandom(). */
4 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
6 * LibTomCrypt is a library that provides various cryptographic
7 * algorithms in a highly modular and flexible manner.
9 * The library is free for all purposes without any express
12 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
21 Secure PRNG, Tom St Denis
24 /* A secure PRNG using the RNG functions. Basically this is a
25 * wrapper that allows you to use a secure RNG as a PRNG
26 * in the various other functions.
29 #ifdef DROPBEAR_LTC_PRNG
33 @param prng [out] The PRNG state to initialize
34 @return CRYPT_OK if successful
36 int dropbear_prng_start(prng_state
* UNUSED(prng
))
42 Add entropy to the PRNG state
43 @param in The data to add
44 @param inlen Length of the data to add
45 @param prng PRNG state to update
46 @return CRYPT_OK if successful
48 int dropbear_prng_add_entropy(const unsigned char* UNUSED(in
), unsigned long UNUSED(inlen
), prng_state
* UNUSED(prng
))
54 Make the PRNG ready to read from
55 @param prng The PRNG to make active
56 @return CRYPT_OK if successful
58 int dropbear_prng_ready(prng_state
* UNUSED(prng
))
65 @param out Destination
66 @param outlen Length of output
67 @param prng The active PRNG to read from
68 @return Number of octets read
70 unsigned long dropbear_prng_read(unsigned char* out
, unsigned long outlen
, prng_state
* UNUSED(prng
))
72 LTC_ARGCHK(out
!= NULL
);
73 genrandom(out
, outlen
);
79 @param prng The PRNG to terminate
80 @return CRYPT_OK if successful
82 int dropbear_prng_done(prng_state
* UNUSED(prng
))
89 @param out [out] Destination
90 @param outlen [in/out] Max size and resulting size of the state
91 @param prng The PRNG to export
92 @return CRYPT_OK if successful
94 int dropbear_prng_export(unsigned char* UNUSED(out
), unsigned long* outlen
, prng_state
* UNUSED(prng
))
96 LTC_ARGCHK(outlen
!= NULL
);
104 @param in The PRNG state
105 @param inlen Size of the state
106 @param prng The PRNG to import
107 @return CRYPT_OK if successful
109 int dropbear_prng_import(const unsigned char* UNUSED(in
), unsigned long UNUSED(inlen
), prng_state
* UNUSED(prng
))
116 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
118 int dropbear_prng_test(void)
123 const struct ltc_prng_descriptor dropbear_prng_desc
=
127 dropbear_prng_add_entropy
,
131 dropbear_prng_export
,
132 dropbear_prng_import
,
137 #endif /* DROPBEAR_LTC_PRNG */