comparison libtomcrypt/src/prngs/sprng.c @ 1478:3a933956437e coverity

update coverity
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 23:49:22 +0800
parents 6dba84798cd5
children
comparison
equal deleted inserted replaced
1439:8d24733026c5 1478:3a933956437e
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file sprng.c 12 @file sprng.c
15 Secure PRNG, Tom St Denis 13 Secure PRNG, Tom St Denis
16 */ 14 */
17 15
18 /* A secure PRNG using the RNG functions. Basically this is a 16 /* A secure PRNG using the RNG functions. Basically this is a
19 * wrapper that allows you to use a secure RNG as a PRNG 17 * wrapper that allows you to use a secure RNG as a PRNG
20 * in the various other functions. 18 * in the various other functions.
21 */ 19 */
22 20
37 35
38 /** 36 /**
39 Start the PRNG 37 Start the PRNG
40 @param prng [out] The PRNG state to initialize 38 @param prng [out] The PRNG state to initialize
41 @return CRYPT_OK if successful 39 @return CRYPT_OK if successful
42 */ 40 */
43 int sprng_start(prng_state *prng) 41 int sprng_start(prng_state *prng)
44 { 42 {
45 return CRYPT_OK; 43 LTC_UNUSED_PARAM(prng);
44 return CRYPT_OK;
46 } 45 }
47 46
48 /** 47 /**
49 Add entropy to the PRNG state 48 Add entropy to the PRNG state
50 @param in The data to add 49 @param in The data to add
51 @param inlen Length of the data to add 50 @param inlen Length of the data to add
52 @param prng PRNG state to update 51 @param prng PRNG state to update
53 @return CRYPT_OK if successful 52 @return CRYPT_OK if successful
54 */ 53 */
55 int sprng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng) 54 int sprng_add_entropy(const unsigned char *in, unsigned long inlen, prng_state *prng)
56 { 55 {
56 LTC_UNUSED_PARAM(in);
57 LTC_UNUSED_PARAM(inlen);
58 LTC_UNUSED_PARAM(prng);
57 return CRYPT_OK; 59 return CRYPT_OK;
58 } 60 }
59 61
60 /** 62 /**
61 Make the PRNG ready to read from 63 Make the PRNG ready to read from
62 @param prng The PRNG to make active 64 @param prng The PRNG to make active
63 @return CRYPT_OK if successful 65 @return CRYPT_OK if successful
64 */ 66 */
65 int sprng_ready(prng_state *prng) 67 int sprng_ready(prng_state *prng)
66 { 68 {
69 LTC_UNUSED_PARAM(prng);
67 return CRYPT_OK; 70 return CRYPT_OK;
68 } 71 }
69 72
70 /** 73 /**
71 Read from the PRNG 74 Read from the PRNG
72 @param out Destination 75 @param out Destination
73 @param outlen Length of output 76 @param outlen Length of output
74 @param prng The active PRNG to read from 77 @param prng The active PRNG to read from
75 @return Number of octets read 78 @return Number of octets read
76 */ 79 */
77 unsigned long sprng_read(unsigned char *out, unsigned long outlen, prng_state *prng) 80 unsigned long sprng_read(unsigned char *out, unsigned long outlen, prng_state *prng)
78 { 81 {
79 LTC_ARGCHK(out != NULL); 82 LTC_ARGCHK(out != NULL);
83 LTC_UNUSED_PARAM(prng);
80 return rng_get_bytes(out, outlen, NULL); 84 return rng_get_bytes(out, outlen, NULL);
81 } 85 }
82 86
83 /** 87 /**
84 Terminate the PRNG 88 Terminate the PRNG
85 @param prng The PRNG to terminate 89 @param prng The PRNG to terminate
86 @return CRYPT_OK if successful 90 @return CRYPT_OK if successful
87 */ 91 */
88 int sprng_done(prng_state *prng) 92 int sprng_done(prng_state *prng)
89 { 93 {
94 LTC_UNUSED_PARAM(prng);
90 return CRYPT_OK; 95 return CRYPT_OK;
91 } 96 }
92 97
93 /** 98 /**
94 Export the PRNG state 99 Export the PRNG state
95 @param out [out] Destination 100 @param out [out] Destination
96 @param outlen [in/out] Max size and resulting size of the state 101 @param outlen [in/out] Max size and resulting size of the state
97 @param prng The PRNG to export 102 @param prng The PRNG to export
98 @return CRYPT_OK if successful 103 @return CRYPT_OK if successful
99 */ 104 */
100 int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng) 105 int sprng_export(unsigned char *out, unsigned long *outlen, prng_state *prng)
101 { 106 {
102 LTC_ARGCHK(outlen != NULL); 107 LTC_ARGCHK(outlen != NULL);
108 LTC_UNUSED_PARAM(out);
109 LTC_UNUSED_PARAM(prng);
103 110
104 *outlen = 0; 111 *outlen = 0;
105 return CRYPT_OK; 112 return CRYPT_OK;
106 } 113 }
107 114
108 /** 115 /**
109 Import a PRNG state 116 Import a PRNG state
110 @param in The PRNG state 117 @param in The PRNG state
111 @param inlen Size of the state 118 @param inlen Size of the state
112 @param prng The PRNG to import 119 @param prng The PRNG to import
113 @return CRYPT_OK if successful 120 @return CRYPT_OK if successful
114 */ 121 */
115 int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng) 122 int sprng_import(const unsigned char *in, unsigned long inlen, prng_state *prng)
116 { 123 {
124 LTC_UNUSED_PARAM(in);
125 LTC_UNUSED_PARAM(inlen);
126 LTC_UNUSED_PARAM(prng);
117 return CRYPT_OK; 127 return CRYPT_OK;
118 } 128 }
119 129
120 /** 130 /**
121 PRNG self-test 131 PRNG self-test
122 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled 132 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled
123 */ 133 */
124 int sprng_test(void) 134 int sprng_test(void)
125 { 135 {
136 #ifndef LTC_TEST
137 return CRYPT_NOP;
138 #else
139 prng_state st;
140 unsigned char en[] = { 0x01, 0x02, 0x03, 0x04 };
141 unsigned char out[1000];
142 int err;
143
144 if ((err = sprng_start(&st)) != CRYPT_OK) return err;
145 if ((err = sprng_add_entropy(en, sizeof(en), &st)) != CRYPT_OK) return err;
146 if ((err = sprng_ready(&st)) != CRYPT_OK) return err;
147 if (sprng_read(out, 500, &st) != 500) return CRYPT_ERROR_READPRNG; /* skip 500 bytes */
148 if ((err = sprng_done(&st)) != CRYPT_OK) return err;
149
126 return CRYPT_OK; 150 return CRYPT_OK;
151 #endif
127 } 152 }
128 153
129 #endif 154 #endif
130 155
131 156
132
133 157
134 /* $Source$ */ 158
135 /* $Revision$ */ 159 /* ref: $Format:%D$ */
136 /* $Date$ */ 160 /* git commit: $Format:%H$ */
161 /* commit time: $Format:%ai$ */