comparison ltc_prng.c @ 910:89555751c489 asm

merge up to 2013.63, improve ASM makefile rules a bit
author Matt Johnston <matt@ucc.asn.au>
date Thu, 27 Feb 2014 21:35:58 +0800
parents 220f55d540ae
children 210f6b49df89
comparison
equal deleted inserted replaced
909:e4b75744acab 910:89555751c489
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 "dbrandom.h"
17 #include "ltc_prng.h"
18
19 /**
20 @file sprng.c
21 Secure PRNG, Tom St Denis
22 */
23
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.
27 */
28
29 #ifdef DROPBEAR_LTC_PRNG
30
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))
37 {
38 return CRYPT_OK;
39 }
40
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))
49 {
50 return CRYPT_OK;
51 }
52
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))
59 {
60 return CRYPT_OK;
61 }
62
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))
71 {
72 LTC_ARGCHK(out != NULL);
73 genrandom(out, outlen);
74 return outlen;
75 }
76
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))
83 {
84 return CRYPT_OK;
85 }
86
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))
95 {
96 LTC_ARGCHK(outlen != NULL);
97
98 *outlen = 0;
99 return CRYPT_OK;
100 }
101
102 /**
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
108 */
109 int dropbear_prng_import(const unsigned char* UNUSED(in), unsigned long UNUSED(inlen), prng_state* UNUSED(prng))
110 {
111 return CRYPT_OK;
112 }
113
114 /**
115 PRNG self-test
116 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
117 */
118 int dropbear_prng_test(void)
119 {
120 return CRYPT_OK;
121 }
122
123 const struct ltc_prng_descriptor dropbear_prng_desc =
124 {
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
134 };
135
136
137 #endif /* DROPBEAR_LTC_PRNG */