comparison ltc_prng.c @ 755:b07eb3dc23ec ecc

refactor kexdh code a bit, start working on ecdh etc
author Matt Johnston <matt@ucc.asn.au>
date Tue, 26 Mar 2013 01:35:22 +0800
parents
children 76fba0856749
comparison
equal deleted inserted replaced
725:49f68a7b7a55 755:b07eb3dc23ec
1 /* Copied from libtomcrypt/src/prngs/sprng.c and modified to
2 * use Dropbear's genrandom(). */
3
4 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
5 *
6 * LibTomCrypt is a library that provides various cryptographic
7 * algorithms in a highly modular and flexible manner.
8 *
9 * The library is free for all purposes without any express
10 * guarantee it works.
11 *
12 * Tom St Denis, [email protected], http://libtomcrypt.com
13 */
14 #include "options.h"
15 #include "includes.h"
16 #include "random.h"
17
18 /**
19 @file sprng.c
20 Secure PRNG, Tom St Denis
21 */
22
23 /* A secure PRNG using the RNG functions. Basically this is a
24 * wrapper that allows you to use a secure RNG as a PRNG
25 * in the various other functions.
26 */
27
28 #ifdef DROPBEAR_LTC_PRNG
29
30 /**
31 Start the PRNG
32 @param prng [out] The PRNG state to initialize
33 @return CRYPT_OK if successful
34 */
35 int dropbear_prng_start(prng_state *prng)
36 {
37 return CRYPT_OK;
38 }
39
40 /**
41 Add entropy to the PRNG state
42 @param in The data to add
43 @param inlen Length of the data to add
44 @param prng PRNG state to update
45 @return CRYPT_OK if successful
46 */
47 int dropbear_prng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
48 {
49 return CRYPT_OK;
50 }
51
52 /**
53 Make the PRNG ready to read from
54 @param prng The PRNG to make active
55 @return CRYPT_OK if successful
56 */
57 int dropbear_prng_ready(prng_state *prng)
58 {
59 return CRYPT_OK;
60 }
61
62 /**
63 Read from the PRNG
64 @param out Destination
65 @param outlen Length of output
66 @param prng The active PRNG to read from
67 @return Number of octets read
68 */
69 unsigned long dropbear_prng_read(unsigned char *out, unsigned long outlen, prng_state *prng)
70 {
71 LTC_ARGCHK(out != NULL);
72 genrandom(out, outlen);
73 return CRYPT_OK;
74 }
75
76 /**
77 Terminate the PRNG
78 @param prng The PRNG to terminate
79 @return CRYPT_OK if successful
80 */
81 int dropbear_prng_done(prng_state *prng)
82 {
83 return CRYPT_OK;
84 }
85
86 /**
87 Export the PRNG state
88 @param out [out] Destination
89 @param outlen [in/out] Max size and resulting size of the state
90 @param prng The PRNG to export
91 @return CRYPT_OK if successful
92 */
93 int dropbear_prng_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
94 {
95 LTC_ARGCHK(outlen != NULL);
96
97 *outlen = 0;
98 return CRYPT_OK;
99 }
100
101 /**
102 Import a PRNG state
103 @param in The PRNG state
104 @param inlen Size of the state
105 @param prng The PRNG to import
106 @return CRYPT_OK if successful
107 */
108 int dropbear_prng_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
109 {
110 return CRYPT_OK;
111 }
112
113 /**
114 PRNG self-test
115 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
116 */
117 int dropbear_prng_test(void)
118 {
119 return CRYPT_OK;
120 }
121
122 const struct ltc_prng_descriptor dropbear_prng_desc =
123 {
124 "dropbear_prng", 0,
125 &dropbear_prng_start,
126 &dropbear_prng_add_entropy,
127 &dropbear_prng_ready,
128 &dropbear_prng_read,
129 &dropbear_prng_done,
130 &dropbear_prng_export,
131 &dropbear_prng_import,
132 &dropbear_prng_test
133 };
134
135
136 #endif // DROPBEAR_LTC_PRNG