dropbear 2016.73
[tomato.git] / release / src / router / dropbear / ltc_prng.c
blobaa68cce19fd001d4256d7326166aadc999f909e5
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
10 * guarantee it works.
12 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
14 #include "options.h"
15 #include "includes.h"
16 #include "dbrandom.h"
17 #include "ltc_prng.h"
19 /**
20 @file sprng.c
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
31 /**
32 Start the PRNG
33 @param prng [out] The PRNG state to initialize
34 @return CRYPT_OK if successful
35 */
36 int dropbear_prng_start(prng_state* UNUSED(prng))
38 return CRYPT_OK;
41 /**
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
47 */
48 int dropbear_prng_add_entropy(const unsigned char* UNUSED(in), unsigned long UNUSED(inlen), prng_state* UNUSED(prng))
50 return CRYPT_OK;
53 /**
54 Make the PRNG ready to read from
55 @param prng The PRNG to make active
56 @return CRYPT_OK if successful
57 */
58 int dropbear_prng_ready(prng_state* UNUSED(prng))
60 return CRYPT_OK;
63 /**
64 Read from the 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
69 */
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);
74 return outlen;
77 /**
78 Terminate the PRNG
79 @param prng The PRNG to terminate
80 @return CRYPT_OK if successful
81 */
82 int dropbear_prng_done(prng_state* UNUSED(prng))
84 return CRYPT_OK;
87 /**
88 Export the PRNG state
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
93 */
94 int dropbear_prng_export(unsigned char* UNUSED(out), unsigned long* outlen, prng_state* UNUSED(prng))
96 LTC_ARGCHK(outlen != NULL);
98 *outlen = 0;
99 return CRYPT_OK;
103 Import a PRNG state
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))
111 return CRYPT_OK;
115 PRNG self-test
116 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
118 int dropbear_prng_test(void)
120 return CRYPT_OK;
123 const struct ltc_prng_descriptor dropbear_prng_desc =
125 "dropbear_prng", 0,
126 dropbear_prng_start,
127 dropbear_prng_add_entropy,
128 dropbear_prng_ready,
129 dropbear_prng_read,
130 dropbear_prng_done,
131 dropbear_prng_export,
132 dropbear_prng_import,
133 dropbear_prng_test
137 #endif /* DROPBEAR_LTC_PRNG */