blob: a46f21c1f256babcc4e70b0ebf56d4286548a16f [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Gilles Peskineef0624f2018-08-03 20:23:09 +02002#include "mbedtls/entropy.h"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00003#include "mbedtls/ctr_drbg.h"
Mohammad Azim Khan67735d52017-04-06 11:55:43 +01004#include "string.h"
Rich Evans00ab4702015-02-06 13:43:58 +00005
Gilles Peskine5ef5a9a2018-08-03 20:27:50 +02006/* Modes for ctr_drbg_validate */
7enum reseed_mode
8{
9 RESEED_NEVER, /* never reseed */
10 RESEED_FIRST, /* instantiate, reseed, generate, generate */
11 RESEED_SECOND, /* instantiate, generate, reseed, generate */
12 RESEED_ALWAYS /* prediction resistance, no explicit reseed */
13};
14
Nir Sonnenschein85fcb582018-08-29 23:38:57 +030015static size_t test_offset_idx = 0;
16static size_t test_max_idx = 0;
Reut Caspie278b362017-10-19 08:49:19 +010017static int mbedtls_test_entropy_func( void *data, unsigned char *buf, size_t len )
Paul Bakker0e04d0e2011-11-27 14:46:59 +000018{
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +010019 const unsigned char *p = (unsigned char *) data;
Gilles Peskineef0624f2018-08-03 20:23:09 +020020 if( test_offset_idx + len > test_max_idx )
21 return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
Paul Bakker3ddfa662013-11-26 17:45:20 +010022 memcpy( buf, p + test_offset_idx, len );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +010023 test_offset_idx += len;
Paul Bakker0e04d0e2011-11-27 14:46:59 +000024 return( 0 );
25}
Nir Sonnenschein6275be32018-08-29 10:25:30 +030026
Nir Sonnenschein85fcb582018-08-29 23:38:57 +030027static void ctr_drbg_validate_internal( int reseed_mode, data_t * nonce,
Nir Sonnenschein6275be32018-08-29 10:25:30 +030028 int entropy_len_arg, data_t * entropy,
29 data_t * reseed,
30 data_t * add1, data_t * add2,
31 data_t * result )
32{
33 mbedtls_ctr_drbg_context ctx;
34 unsigned char buf[64];
35
36 size_t entropy_chunk_len = (size_t) entropy_len_arg;
37
Nir Sonnenschein85fcb582018-08-29 23:38:57 +030038 TEST_ASSERT( entropy_chunk_len <= sizeof( buf ) );
39
Nir Sonnenschein6275be32018-08-29 10:25:30 +030040 test_offset_idx = 0;
41 mbedtls_ctr_drbg_init( &ctx );
42
43 test_max_idx = entropy->len;
44
Nir Sonnenschein85fcb582018-08-29 23:38:57 +030045 /* CTR_DRBG_Instantiate(entropy[:entropy->len], nonce, perso, <ignored>)
46 * where nonce||perso = nonce[nonce->len] */
Gilles Peskine50ed86b2019-10-04 12:15:55 +020047 mbedtls_ctr_drbg_set_entropy_len( &ctx, entropy_chunk_len );
Gilles Peskine0ed378a2019-10-22 20:33:56 +020048 mbedtls_ctr_drbg_set_nonce_len( &ctx, 0 );
Gilles Peskine50ed86b2019-10-04 12:15:55 +020049 TEST_ASSERT( mbedtls_ctr_drbg_seed(
Nir Sonnenschein6275be32018-08-29 10:25:30 +030050 &ctx,
51 mbedtls_test_entropy_func, entropy->x,
Gilles Peskine50ed86b2019-10-04 12:15:55 +020052 nonce->x, nonce->len ) == 0 );
Nir Sonnenschein6275be32018-08-29 10:25:30 +030053 if( reseed_mode == RESEED_ALWAYS )
54 mbedtls_ctr_drbg_set_prediction_resistance(
55 &ctx,
56 MBEDTLS_CTR_DRBG_PR_ON );
57
58 if( reseed_mode == RESEED_FIRST )
59 {
Nir Sonnenschein85fcb582018-08-29 23:38:57 +030060 /* CTR_DRBG_Reseed(entropy[idx:idx+entropy->len],
61 * reseed[:reseed->len]) */
Nir Sonnenschein6275be32018-08-29 10:25:30 +030062 TEST_ASSERT( mbedtls_ctr_drbg_reseed(
63 &ctx,
64 reseed->x, reseed->len ) == 0 );
65 }
66
Nir Sonnenschein85fcb582018-08-29 23:38:57 +030067 /* CTR_DRBG_Generate(result->len * 8 bits, add1[:add1->len]) -> buf */
Nir Sonnenschein6275be32018-08-29 10:25:30 +030068 /* Then reseed if prediction resistance is enabled. */
69 TEST_ASSERT( mbedtls_ctr_drbg_random_with_add(
70 &ctx,
71 buf, result->len,
72 add1->x, add1->len ) == 0 );
73
74
75 if( reseed_mode == RESEED_SECOND )
76 {
Nir Sonnenschein85fcb582018-08-29 23:38:57 +030077 /* CTR_DRBG_Reseed(entropy[idx:idx+entropy->len],
78 * reseed[:reseed->len]) */
Nir Sonnenschein6275be32018-08-29 10:25:30 +030079 TEST_ASSERT( mbedtls_ctr_drbg_reseed(
80 &ctx,
81 reseed->x, reseed->len ) == 0 );
82 }
83
84 /* CTR_DRBG_Generate(result->len * 8 bits, add2->x[:add2->len]) -> buf */
85 /* Then reseed if prediction resistance is enabled. */
86 TEST_ASSERT( mbedtls_ctr_drbg_random_with_add(
87 &ctx,
88 buf, result->len,
89 add2->x, add2->len ) == 0 );
90 TEST_ASSERT( memcmp( buf, result->x, result->len ) == 0 );
91
92exit:
93 mbedtls_ctr_drbg_free( &ctx );
Nir Sonnenschein6275be32018-08-29 10:25:30 +030094}
95
Paul Bakker33b43f12013-08-20 11:48:36 +020096/* END_HEADER */
Paul Bakker0e04d0e2011-11-27 14:46:59 +000097
Paul Bakker33b43f12013-08-20 11:48:36 +020098/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099 * depends_on:MBEDTLS_CTR_DRBG_C
Paul Bakker33b43f12013-08-20 11:48:36 +0200100 * END_DEPENDENCIES
101 */
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000102
Paul Bakker33b43f12013-08-20 11:48:36 +0200103/* BEGIN_CASE */
Nir Sonnenschein6275be32018-08-29 10:25:30 +0300104void ctr_drbg_special_behaviours( )
Paul Bakker185ccf72016-07-14 13:21:10 +0100105{
106 mbedtls_ctr_drbg_context ctx;
107 unsigned char output[512];
108 unsigned char additional[512];
109
110 mbedtls_ctr_drbg_init( &ctx );
111 memset( output, 0, sizeof( output ) );
112 memset( additional, 0, sizeof( additional ) );
113
114 TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx,
115 output, MBEDTLS_CTR_DRBG_MAX_REQUEST + 1,
116 additional, 16 ) ==
117 MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG );
118 TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx,
119 output, 16,
120 additional, MBEDTLS_CTR_DRBG_MAX_INPUT + 1 ) ==
121 MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
122
123 TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, additional,
124 MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + 1 ) ==
125 MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
Andres Amaya Garcia6a543362017-01-17 23:04:22 +0000126
127 mbedtls_ctr_drbg_set_entropy_len( &ctx, ~0 );
128 TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, additional,
129 MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) ==
130 MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
Paul Bakker185ccf72016-07-14 13:21:10 +0100131exit:
132 mbedtls_ctr_drbg_free( &ctx );
133}
134/* END_CASE */
135
Gilles Peskine5ef5a9a2018-08-03 20:27:50 +0200136
137/* BEGIN_CASE */
Nir Sonnenschein6275be32018-08-29 10:25:30 +0300138void ctr_drbg_validate_no_reseed( data_t * add_init, data_t * entropy,
139 data_t * add1, data_t * add2,
140 data_t * result_string )
Gilles Peskine5ef5a9a2018-08-03 20:27:50 +0200141{
Nir Sonnenscheinacedc912018-08-29 23:57:45 +0300142 data_t empty = { 0, 0 };
Nir Sonnenschein85fcb582018-08-29 23:38:57 +0300143 ctr_drbg_validate_internal( RESEED_NEVER, add_init,
144 entropy->len, entropy,
145 &empty, add1, add2,
146 result_string );
147 goto exit; // goto is needed to avoid warning ( no test assertions in func)
Gilles Peskine5ef5a9a2018-08-03 20:27:50 +0200148}
149/* END_CASE */
150
151/* BEGIN_CASE */
Nir Sonnenschein6275be32018-08-29 10:25:30 +0300152void ctr_drbg_validate_pr( data_t * add_init, data_t * entropy,
153 data_t * add1, data_t * add2,
154 data_t * result_string )
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000155{
Nir Sonnenscheinacedc912018-08-29 23:57:45 +0300156 data_t empty = { 0, 0 };
Nir Sonnenschein85fcb582018-08-29 23:38:57 +0300157 ctr_drbg_validate_internal( RESEED_ALWAYS, add_init,
158 entropy->len / 3, entropy,
159 &empty, add1, add2,
160 result_string );
161 goto exit; // goto is needed to avoid warning ( no test assertions in func)
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000162}
Paul Bakker33b43f12013-08-20 11:48:36 +0200163/* END_CASE */
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000164
Paul Bakker33b43f12013-08-20 11:48:36 +0200165/* BEGIN_CASE */
Nir Sonnenschein85fcb582018-08-29 23:38:57 +0300166void ctr_drbg_validate_reseed_between( data_t * add_init, data_t * entropy,
Azim Khan5fcca462018-06-29 11:05:32 +0100167 data_t * add1, data_t * add_reseed,
Nir Sonnenschein6275be32018-08-29 10:25:30 +0300168 data_t * add2, data_t * result_string )
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000169{
Nir Sonnenschein85fcb582018-08-29 23:38:57 +0300170 ctr_drbg_validate_internal( RESEED_SECOND, add_init,
171 entropy->len / 2, entropy,
172 add_reseed, add1, add2,
173 result_string );
174 goto exit; // goto is needed to avoid warning ( no test assertions in func)
Paul Bakker0e04d0e2011-11-27 14:46:59 +0000175}
Paul Bakker33b43f12013-08-20 11:48:36 +0200176/* END_CASE */
Manuel Pégourié-Gonnardb3b205e2014-01-31 12:04:06 +0100177
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100178/* BEGIN_CASE */
Nir Sonnenschein85fcb582018-08-29 23:38:57 +0300179void ctr_drbg_validate_reseed_first( data_t * add_init, data_t * entropy,
180 data_t * add1, data_t * add_reseed,
181 data_t * add2, data_t * result_string )
182{
183 ctr_drbg_validate_internal( RESEED_FIRST, add_init,
184 entropy->len / 2, entropy,
185 add_reseed, add1, add2,
186 result_string );
187 goto exit; // goto is needed to avoid warning ( no test assertions in func)
188}
189/* END_CASE */
190
Gilles Peskine69971662019-10-23 19:39:36 +0200191/* BEGIN_CASE */
192void ctr_drbg_entropy_strength( int expected_bit_strength )
193{
194 unsigned char entropy[/*initial entropy*/ MBEDTLS_CTR_DRBG_ENTROPY_LEN +
195 /*nonce*/ MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN +
196 /*reseed*/ MBEDTLS_CTR_DRBG_ENTROPY_LEN];
197 mbedtls_ctr_drbg_context ctx;
198 size_t last_idx;
199 size_t byte_strength = expected_bit_strength / 8;
Nir Sonnenschein85fcb582018-08-29 23:38:57 +0300200
Gilles Peskine69971662019-10-23 19:39:36 +0200201 mbedtls_ctr_drbg_init( &ctx );
202 test_offset_idx = 0;
203 test_max_idx = sizeof( entropy );
204 memset( entropy, 0, sizeof( entropy ) );
205
206 /* The initial seeding must grab at least byte_strength bytes of entropy
207 * for the entropy input and byte_strength/2 bytes for a nonce. */
208 TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx,
209 mbedtls_test_entropy_func, entropy,
210 NULL, 0 ) == 0 );
211 TEST_ASSERT( test_offset_idx >= ( byte_strength * 3 + 1 ) / 2 );
212 last_idx = test_offset_idx;
213
214 /* A reseed must grab at least byte_strength bytes of entropy. */
215 TEST_ASSERT( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) == 0 );
216 TEST_ASSERT( test_offset_idx - last_idx >= byte_strength );
217
218exit:
219 mbedtls_ctr_drbg_free( &ctx );
220}
221/* END_CASE */
Nir Sonnenschein85fcb582018-08-29 23:38:57 +0300222
223/* BEGIN_CASE */
Gilles Peskinec949de02019-10-22 19:14:26 +0200224void ctr_drbg_entropy_usage( int entropy_nonce_len )
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100225{
226 unsigned char out[16];
227 unsigned char add[16];
228 unsigned char entropy[1024];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229 mbedtls_ctr_drbg_context ctx;
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100230 size_t i, reps = 10;
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200231 size_t expected_idx = 0;
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100232
Manuel Pégourié-Gonnard8d128ef2015-04-28 22:38:08 +0200233 mbedtls_ctr_drbg_init( &ctx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100234 test_offset_idx = 0;
Gilles Peskineef0624f2018-08-03 20:23:09 +0200235 test_max_idx = sizeof( entropy );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100236 memset( entropy, 0, sizeof( entropy ) );
237 memset( out, 0, sizeof( out ) );
238 memset( add, 0, sizeof( add ) );
239
Gilles Peskinec949de02019-10-22 19:14:26 +0200240 if( entropy_nonce_len >= 0 )
241 TEST_ASSERT( mbedtls_ctr_drbg_set_nonce_len( &ctx, entropy_nonce_len ) == 0 );
242
Gavin Acquroff6aceb512020-03-01 17:06:11 -0800243 /* Set reseed interval before seed */
244 mbedtls_ctr_drbg_set_reseed_interval( &ctx, 2 * reps );
245
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100246 /* Init must use entropy */
Reut Caspie278b362017-10-19 08:49:19 +0100247 TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx, mbedtls_test_entropy_func, entropy, NULL, 0 ) == 0 );
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200248 expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_LEN;
Gilles Peskinec949de02019-10-22 19:14:26 +0200249 if( entropy_nonce_len >= 0 )
250 expected_idx += entropy_nonce_len;
Gilles Peskinee9a34542019-10-22 20:43:24 +0200251 else
Gilles Peskine69971662019-10-23 19:39:36 +0200252 expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN;
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200253 TEST_EQUAL( test_offset_idx, expected_idx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100254
Gavin Acquroff6aceb512020-03-01 17:06:11 -0800255 /* By default, PR is off, and reseed interval was set to
256 * 2 * reps so the next few calls should not use entropy */
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100257 for( i = 0; i < reps; i++ )
258 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259 TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) - 4 ) == 0 );
260 TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, out, sizeof( out ) - 4,
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100261 add, sizeof( add ) ) == 0 );
262 }
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200263 TEST_EQUAL( test_offset_idx, expected_idx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100264
265 /* While at it, make sure we didn't write past the requested length */
266 TEST_ASSERT( out[sizeof( out ) - 4] == 0 );
267 TEST_ASSERT( out[sizeof( out ) - 3] == 0 );
268 TEST_ASSERT( out[sizeof( out ) - 2] == 0 );
269 TEST_ASSERT( out[sizeof( out ) - 1] == 0 );
270
Gavin Acquroff6aceb512020-03-01 17:06:11 -0800271 /* There have been 2 * reps calls to random. The next call should reseed */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272 TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200273 expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_LEN;
274 TEST_EQUAL( test_offset_idx, expected_idx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100275
Gavin Acquroff6aceb512020-03-01 17:06:11 -0800276 /* Set reseed interval after seed */
277 mbedtls_ctr_drbg_set_reseed_interval( &ctx, 4 * reps + 1 );
278
279 /* The next few calls should not reseed */
280 for( i = 0; i < (2 * reps); i++ )
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100281 {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282 TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
283 TEST_ASSERT( mbedtls_ctr_drbg_random_with_add( &ctx, out, sizeof( out ) ,
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100284 add, sizeof( add ) ) == 0 );
285 }
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200286 TEST_EQUAL( test_offset_idx, expected_idx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100287
Gilles Peskined9199932018-09-11 16:41:54 +0200288 /* Call update with too much data (sizeof entropy > MAX(_SEED)_INPUT).
289 * Make sure it's detected as an error and doesn't cause memory
290 * corruption. */
TRodziewicz26371e42021-06-08 16:45:41 +0200291 TEST_ASSERT( mbedtls_ctr_drbg_update(
Gilles Peskined9199932018-09-11 16:41:54 +0200292 &ctx, entropy, sizeof( entropy ) ) != 0 );
Manuel Pégourié-Gonnardf5f25b32014-11-27 14:04:56 +0100293
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100294 /* Now enable PR, so the next few calls should all reseed */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200295 mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON );
296 TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200297 expected_idx += MBEDTLS_CTR_DRBG_ENTROPY_LEN;
298 TEST_EQUAL( test_offset_idx, expected_idx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100299
300 /* Finally, check setting entropy_len */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301 mbedtls_ctr_drbg_set_entropy_len( &ctx, 42 );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302 TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200303 expected_idx += 42;
304 TEST_EQUAL( test_offset_idx, expected_idx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100305
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200306 mbedtls_ctr_drbg_set_entropy_len( &ctx, 13 );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307 TEST_ASSERT( mbedtls_ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
Gilles Peskine58b56ce2019-10-22 19:10:01 +0200308 expected_idx += 13;
309 TEST_EQUAL( test_offset_idx, expected_idx );
Paul Bakkera317a982014-06-18 16:44:11 +0200310
Paul Bakkerbd51b262014-07-10 15:26:12 +0200311exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312 mbedtls_ctr_drbg_free( &ctx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100313}
314/* END_CASE */
315
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200316/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
Azim Khanf1aaec92017-05-30 14:23:15 +0100317void ctr_drbg_seed_file( char * path, int ret )
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100318{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319 mbedtls_ctr_drbg_context ctx;
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100320
Manuel Pégourié-Gonnard8d128ef2015-04-28 22:38:08 +0200321 mbedtls_ctr_drbg_init( &ctx );
322
Ronald Cron6c5bd7f2020-06-10 14:08:26 +0200323 TEST_ASSERT( mbedtls_ctr_drbg_seed( &ctx, mbedtls_test_rnd_std_rand,
324 NULL, NULL, 0 ) == 0 );
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200325 TEST_ASSERT( mbedtls_ctr_drbg_write_seed_file( &ctx, path ) == ret );
326 TEST_ASSERT( mbedtls_ctr_drbg_update_seed_file( &ctx, path ) == ret );
Paul Bakkera317a982014-06-18 16:44:11 +0200327
Paul Bakkerbd51b262014-07-10 15:26:12 +0200328exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329 mbedtls_ctr_drbg_free( &ctx );
Manuel Pégourié-Gonnard7575daa2014-01-31 12:16:54 +0100330}
331/* END_CASE */
332
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200333/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100334void ctr_drbg_selftest( )
Manuel Pégourié-Gonnardb3b205e2014-01-31 12:04:06 +0100335{
Andres AG93012e82016-09-09 09:10:28 +0100336 TEST_ASSERT( mbedtls_ctr_drbg_self_test( 1 ) == 0 );
Manuel Pégourié-Gonnardb3b205e2014-01-31 12:04:06 +0100337}
338/* END_CASE */