test_suite_entropy.function 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /* BEGIN_HEADER */
  2. #include "mbedtls/entropy.h"
  3. #include "mbedtls/entropy_poll.h"
  4. #include "mbedtls/md.h"
  5. #include "string.h"
  6. typedef enum
  7. {
  8. DUMMY_CONSTANT_LENGTH, /* Output context->length bytes */
  9. DUMMY_REQUESTED_LENGTH, /* Output whatever length was requested */
  10. DUMMY_FAIL, /* Return an error code */
  11. } entropy_dummy_instruction;
  12. typedef struct
  13. {
  14. entropy_dummy_instruction instruction;
  15. size_t length; /* Length to return for DUMMY_CONSTANT_LENGTH */
  16. size_t calls; /* Incremented at each call */
  17. } entropy_dummy_context;
  18. /*
  19. * Dummy entropy source
  20. *
  21. * If data is NULL, write exactly the requested length.
  22. * Otherwise, write the length indicated by data or error if negative
  23. */
  24. static int entropy_dummy_source( void *arg, unsigned char *output,
  25. size_t len, size_t *olen )
  26. {
  27. entropy_dummy_context *context = arg;
  28. ++context->calls;
  29. switch( context->instruction )
  30. {
  31. case DUMMY_CONSTANT_LENGTH:
  32. *olen = context->length;
  33. break;
  34. case DUMMY_REQUESTED_LENGTH:
  35. *olen = len;
  36. break;
  37. case DUMMY_FAIL:
  38. return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
  39. }
  40. memset( output, 0x2a, *olen );
  41. return( 0 );
  42. }
  43. /*
  44. * Ability to clear entropy sources to allow testing with just predefined
  45. * entropy sources. This function or tests depending on it might break if there
  46. * are internal changes to how entropy sources are registered.
  47. *
  48. * To be called immediately after mbedtls_entropy_init().
  49. *
  50. * Just resetting the counter. New sources will overwrite existing ones.
  51. * This might break memory checks in the future if sources need 'free-ing' then
  52. * as well.
  53. */
  54. static void entropy_clear_sources( mbedtls_entropy_context *ctx )
  55. {
  56. ctx->source_count = 0;
  57. }
  58. #if defined(MBEDTLS_ENTROPY_NV_SEED)
  59. /*
  60. * NV seed read/write functions that use a buffer instead of a file
  61. */
  62. static unsigned char buffer_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
  63. int buffer_nv_seed_read( unsigned char *buf, size_t buf_len )
  64. {
  65. if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
  66. return( -1 );
  67. memcpy( buf, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE );
  68. return( 0 );
  69. }
  70. int buffer_nv_seed_write( unsigned char *buf, size_t buf_len )
  71. {
  72. if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
  73. return( -1 );
  74. memcpy( buffer_seed, buf, MBEDTLS_ENTROPY_BLOCK_SIZE );
  75. return( 0 );
  76. }
  77. /*
  78. * NV seed read/write helpers that fill the base seedfile
  79. */
  80. static int write_nv_seed( unsigned char *buf, size_t buf_len )
  81. {
  82. FILE *f;
  83. if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
  84. return( -1 );
  85. if( ( f = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "w" ) ) == NULL )
  86. return( -1 );
  87. if( fwrite( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) !=
  88. MBEDTLS_ENTROPY_BLOCK_SIZE )
  89. return( -1 );
  90. fclose( f );
  91. return( 0 );
  92. }
  93. int read_nv_seed( unsigned char *buf, size_t buf_len )
  94. {
  95. FILE *f;
  96. if( buf_len != MBEDTLS_ENTROPY_BLOCK_SIZE )
  97. return( -1 );
  98. if( ( f = fopen( MBEDTLS_PLATFORM_STD_NV_SEED_FILE, "rb" ) ) == NULL )
  99. return( -1 );
  100. if( fread( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) !=
  101. MBEDTLS_ENTROPY_BLOCK_SIZE )
  102. return( -1 );
  103. fclose( f );
  104. return( 0 );
  105. }
  106. #endif /* MBEDTLS_ENTROPY_NV_SEED */
  107. /* END_HEADER */
  108. /* BEGIN_DEPENDENCIES
  109. * depends_on:MBEDTLS_ENTROPY_C
  110. * END_DEPENDENCIES
  111. */
  112. /* BEGIN_CASE */
  113. void entropy_init_free( int reinit )
  114. {
  115. mbedtls_entropy_context ctx;
  116. /* Double free is not explicitly documented to work, but it is convenient
  117. * to call mbedtls_entropy_free() unconditionally on an error path without
  118. * checking whether it has already been called in the success path. */
  119. mbedtls_entropy_init( &ctx );
  120. mbedtls_entropy_free( &ctx );
  121. if( reinit )
  122. mbedtls_entropy_init( &ctx );
  123. mbedtls_entropy_free( &ctx );
  124. /* This test case always succeeds, functionally speaking. A plausible
  125. * bug might trigger an invalid pointer dereference or a memory leak. */
  126. goto exit;
  127. }
  128. /* END_CASE */
  129. /* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
  130. void entropy_seed_file( char * path, int ret )
  131. {
  132. mbedtls_entropy_context ctx;
  133. mbedtls_entropy_init( &ctx );
  134. TEST_ASSERT( mbedtls_entropy_write_seed_file( &ctx, path ) == ret );
  135. TEST_ASSERT( mbedtls_entropy_update_seed_file( &ctx, path ) == ret );
  136. exit:
  137. mbedtls_entropy_free( &ctx );
  138. }
  139. /* END_CASE */
  140. /* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
  141. void entropy_write_base_seed_file( int ret )
  142. {
  143. mbedtls_entropy_context ctx;
  144. mbedtls_entropy_init( &ctx );
  145. TEST_ASSERT( mbedtls_entropy_write_seed_file( &ctx, MBEDTLS_PLATFORM_STD_NV_SEED_FILE ) == ret );
  146. TEST_ASSERT( mbedtls_entropy_update_seed_file( &ctx, MBEDTLS_PLATFORM_STD_NV_SEED_FILE ) == ret );
  147. exit:
  148. mbedtls_entropy_free( &ctx );
  149. }
  150. /* END_CASE */
  151. /* BEGIN_CASE */
  152. void entropy_no_sources( )
  153. {
  154. mbedtls_entropy_context ctx;
  155. unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
  156. mbedtls_entropy_init( &ctx );
  157. entropy_clear_sources( &ctx );
  158. TEST_EQUAL( mbedtls_entropy_func( &ctx, buf, sizeof( buf ) ),
  159. MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED );
  160. exit:
  161. mbedtls_entropy_free( &ctx );
  162. }
  163. /* END_CASE */
  164. /* BEGIN_CASE */
  165. void entropy_too_many_sources( )
  166. {
  167. mbedtls_entropy_context ctx;
  168. size_t i;
  169. entropy_dummy_context dummy = {DUMMY_REQUESTED_LENGTH, 0, 0};
  170. mbedtls_entropy_init( &ctx );
  171. /*
  172. * It's hard to tell precisely when the error will occur,
  173. * since we don't know how many sources were automatically added.
  174. */
  175. for( i = 0; i < MBEDTLS_ENTROPY_MAX_SOURCES; i++ )
  176. (void) mbedtls_entropy_add_source( &ctx, entropy_dummy_source, &dummy,
  177. 16, MBEDTLS_ENTROPY_SOURCE_WEAK );
  178. TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source, &dummy,
  179. 16, MBEDTLS_ENTROPY_SOURCE_WEAK )
  180. == MBEDTLS_ERR_ENTROPY_MAX_SOURCES );
  181. exit:
  182. mbedtls_entropy_free( &ctx );
  183. }
  184. /* END_CASE */
  185. /* BEGIN_CASE depends_on:ENTROPY_HAVE_STRONG */
  186. void entropy_func_len( int len, int ret )
  187. {
  188. mbedtls_entropy_context ctx;
  189. unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE + 10] = { 0 };
  190. unsigned char acc[MBEDTLS_ENTROPY_BLOCK_SIZE + 10] = { 0 };
  191. size_t i, j;
  192. mbedtls_entropy_init( &ctx );
  193. /*
  194. * See comments in mbedtls_entropy_self_test()
  195. */
  196. for( i = 0; i < 8; i++ )
  197. {
  198. TEST_ASSERT( mbedtls_entropy_func( &ctx, buf, len ) == ret );
  199. for( j = 0; j < sizeof( buf ); j++ )
  200. acc[j] |= buf[j];
  201. }
  202. if( ret == 0 )
  203. for( j = 0; j < (size_t) len; j++ )
  204. TEST_ASSERT( acc[j] != 0 );
  205. for( j = len; j < sizeof( buf ); j++ )
  206. TEST_ASSERT( acc[j] == 0 );
  207. exit:
  208. mbedtls_entropy_free( &ctx );
  209. }
  210. /* END_CASE */
  211. /* BEGIN_CASE */
  212. void entropy_source_fail( char * path )
  213. {
  214. mbedtls_entropy_context ctx;
  215. unsigned char buf[16];
  216. entropy_dummy_context dummy = {DUMMY_FAIL, 0, 0};
  217. mbedtls_entropy_init( &ctx );
  218. TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
  219. &dummy, 16,
  220. MBEDTLS_ENTROPY_SOURCE_WEAK )
  221. == 0 );
  222. TEST_ASSERT( mbedtls_entropy_func( &ctx, buf, sizeof( buf ) )
  223. == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
  224. TEST_ASSERT( mbedtls_entropy_gather( &ctx )
  225. == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
  226. #if defined(MBEDTLS_FS_IO) && defined(MBEDTLS_ENTROPY_NV_SEED)
  227. TEST_ASSERT( mbedtls_entropy_write_seed_file( &ctx, path )
  228. == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
  229. TEST_ASSERT( mbedtls_entropy_update_seed_file( &ctx, path )
  230. == MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
  231. #else
  232. ((void) path);
  233. #endif
  234. exit:
  235. mbedtls_entropy_free( &ctx );
  236. }
  237. /* END_CASE */
  238. /* BEGIN_CASE */
  239. void entropy_threshold( int threshold, int chunk_size, int result )
  240. {
  241. mbedtls_entropy_context ctx;
  242. entropy_dummy_context strong =
  243. {DUMMY_CONSTANT_LENGTH, MBEDTLS_ENTROPY_BLOCK_SIZE, 0};
  244. entropy_dummy_context weak = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
  245. unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
  246. int ret;
  247. mbedtls_entropy_init( &ctx );
  248. entropy_clear_sources( &ctx );
  249. /* Set strong source that reaches its threshold immediately and
  250. * a weak source whose threshold is a test parameter. */
  251. TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
  252. &strong, 1,
  253. MBEDTLS_ENTROPY_SOURCE_STRONG ) == 0 );
  254. TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
  255. &weak, threshold,
  256. MBEDTLS_ENTROPY_SOURCE_WEAK ) == 0 );
  257. ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) );
  258. if( result >= 0 )
  259. {
  260. TEST_ASSERT( ret == 0 );
  261. #if defined(MBEDTLS_ENTROPY_NV_SEED)
  262. /* If the NV seed functionality is enabled, there are two entropy
  263. * updates: before and after updating the NV seed. */
  264. result *= 2;
  265. #endif
  266. TEST_ASSERT( weak.calls == (size_t) result );
  267. }
  268. else
  269. {
  270. TEST_ASSERT( ret == result );
  271. }
  272. exit:
  273. mbedtls_entropy_free( &ctx );
  274. }
  275. /* END_CASE */
  276. /* BEGIN_CASE */
  277. void entropy_calls( int strength1, int strength2,
  278. int threshold, int chunk_size,
  279. int result )
  280. {
  281. /*
  282. * if result >= 0: result = expected number of calls to source 1
  283. * if result < 0: result = expected return code from mbedtls_entropy_func()
  284. */
  285. mbedtls_entropy_context ctx;
  286. entropy_dummy_context dummy1 = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
  287. entropy_dummy_context dummy2 = {DUMMY_CONSTANT_LENGTH, chunk_size, 0};
  288. unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 };
  289. int ret;
  290. mbedtls_entropy_init( &ctx );
  291. entropy_clear_sources( &ctx );
  292. TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
  293. &dummy1, threshold,
  294. strength1 ) == 0 );
  295. TEST_ASSERT( mbedtls_entropy_add_source( &ctx, entropy_dummy_source,
  296. &dummy2, threshold,
  297. strength2 ) == 0 );
  298. ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) );
  299. if( result >= 0 )
  300. {
  301. TEST_ASSERT( ret == 0 );
  302. #if defined(MBEDTLS_ENTROPY_NV_SEED)
  303. /* If the NV seed functionality is enabled, there are two entropy
  304. * updates: before and after updating the NV seed. */
  305. result *= 2;
  306. #endif
  307. TEST_ASSERT( dummy1.calls == (size_t) result );
  308. }
  309. else
  310. {
  311. TEST_ASSERT( ret == result );
  312. }
  313. exit:
  314. mbedtls_entropy_free( &ctx );
  315. }
  316. /* END_CASE */
  317. /* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */
  318. void nv_seed_file_create( )
  319. {
  320. unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
  321. memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
  322. TEST_ASSERT( write_nv_seed( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  323. }
  324. /* END_CASE */
  325. /* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO:MBEDTLS_PLATFORM_NV_SEED_ALT */
  326. void entropy_nv_seed_std_io( )
  327. {
  328. unsigned char io_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
  329. unsigned char check_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
  330. memset( io_seed, 1, MBEDTLS_ENTROPY_BLOCK_SIZE );
  331. memset( check_seed, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
  332. mbedtls_platform_set_nv_seed( mbedtls_platform_std_nv_seed_read,
  333. mbedtls_platform_std_nv_seed_write );
  334. /* Check if platform NV read and write manipulate the same data */
  335. TEST_ASSERT( write_nv_seed( io_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  336. TEST_ASSERT( mbedtls_nv_seed_read( check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) ==
  337. MBEDTLS_ENTROPY_BLOCK_SIZE );
  338. TEST_ASSERT( memcmp( io_seed, check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  339. memset( check_seed, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
  340. /* Check if platform NV write and raw read manipulate the same data */
  341. TEST_ASSERT( mbedtls_nv_seed_write( io_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) ==
  342. MBEDTLS_ENTROPY_BLOCK_SIZE );
  343. TEST_ASSERT( read_nv_seed( check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  344. TEST_ASSERT( memcmp( io_seed, check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  345. }
  346. /* END_CASE */
  347. /* BEGIN_CASE depends_on:MBEDTLS_MD_C:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_PLATFORM_NV_SEED_ALT */
  348. void entropy_nv_seed( data_t * read_seed )
  349. {
  350. #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
  351. const mbedtls_md_info_t *md_info =
  352. mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 );
  353. #elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR)
  354. const mbedtls_md_info_t *md_info =
  355. mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 );
  356. #else
  357. #error "Unsupported entropy accumulator"
  358. #endif
  359. mbedtls_md_context_t accumulator;
  360. mbedtls_entropy_context ctx;
  361. int (*original_mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ) =
  362. mbedtls_nv_seed_read;
  363. int (*original_mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ) =
  364. mbedtls_nv_seed_write;
  365. unsigned char header[2];
  366. unsigned char entropy[MBEDTLS_ENTROPY_BLOCK_SIZE];
  367. unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE];
  368. unsigned char empty[MBEDTLS_ENTROPY_BLOCK_SIZE];
  369. unsigned char check_seed[MBEDTLS_ENTROPY_BLOCK_SIZE];
  370. unsigned char check_entropy[MBEDTLS_ENTROPY_BLOCK_SIZE];
  371. memset( entropy, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
  372. memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
  373. memset( empty, 0, MBEDTLS_ENTROPY_BLOCK_SIZE );
  374. memset( check_seed, 2, MBEDTLS_ENTROPY_BLOCK_SIZE );
  375. memset( check_entropy, 3, MBEDTLS_ENTROPY_BLOCK_SIZE );
  376. // Make sure we read/write NV seed from our buffers
  377. mbedtls_platform_set_nv_seed( buffer_nv_seed_read, buffer_nv_seed_write );
  378. mbedtls_md_init( &accumulator );
  379. mbedtls_entropy_init( &ctx );
  380. entropy_clear_sources( &ctx );
  381. TEST_ASSERT( mbedtls_entropy_add_source( &ctx, mbedtls_nv_seed_poll, NULL,
  382. MBEDTLS_ENTROPY_BLOCK_SIZE,
  383. MBEDTLS_ENTROPY_SOURCE_STRONG ) == 0 );
  384. // Set the initial NV seed to read
  385. TEST_ASSERT( read_seed->len >= MBEDTLS_ENTROPY_BLOCK_SIZE );
  386. memcpy( buffer_seed, read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE );
  387. // Do an entropy run
  388. TEST_ASSERT( mbedtls_entropy_func( &ctx, entropy, sizeof( entropy ) ) == 0 );
  389. // Determine what should have happened with manual entropy internal logic
  390. // Init accumulator
  391. header[1] = MBEDTLS_ENTROPY_BLOCK_SIZE;
  392. TEST_ASSERT( mbedtls_md_setup( &accumulator, md_info, 0 ) == 0 );
  393. // First run for updating write_seed
  394. header[0] = 0;
  395. TEST_ASSERT( mbedtls_md_starts( &accumulator ) == 0 );
  396. TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
  397. TEST_ASSERT( mbedtls_md_update( &accumulator,
  398. read_seed->x, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  399. TEST_ASSERT( mbedtls_md_finish( &accumulator, buf ) == 0 );
  400. TEST_ASSERT( mbedtls_md_starts( &accumulator ) == 0 );
  401. TEST_ASSERT( mbedtls_md_update( &accumulator,
  402. buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  403. TEST_ASSERT( mbedtls_md( md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
  404. check_seed ) == 0 );
  405. // Second run for actual entropy (triggers mbedtls_entropy_update_nv_seed)
  406. header[0] = MBEDTLS_ENTROPY_SOURCE_MANUAL;
  407. TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
  408. TEST_ASSERT( mbedtls_md_update( &accumulator,
  409. empty, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  410. header[0] = 0;
  411. TEST_ASSERT( mbedtls_md_update( &accumulator, header, 2 ) == 0 );
  412. TEST_ASSERT( mbedtls_md_update( &accumulator,
  413. check_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  414. TEST_ASSERT( mbedtls_md_finish( &accumulator, buf ) == 0 );
  415. TEST_ASSERT( mbedtls_md( md_info, buf, MBEDTLS_ENTROPY_BLOCK_SIZE,
  416. check_entropy ) == 0 );
  417. // Check result of both NV file and entropy received with the manual calculations
  418. TEST_ASSERT( memcmp( check_seed, buffer_seed, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  419. TEST_ASSERT( memcmp( check_entropy, entropy, MBEDTLS_ENTROPY_BLOCK_SIZE ) == 0 );
  420. exit:
  421. mbedtls_md_free( &accumulator );
  422. mbedtls_entropy_free( &ctx );
  423. mbedtls_nv_seed_read = original_mbedtls_nv_seed_read;
  424. mbedtls_nv_seed_write = original_mbedtls_nv_seed_write;
  425. }
  426. /* END_CASE */
  427. /* BEGIN_CASE depends_on:ENTROPY_HAVE_STRONG:MBEDTLS_SELF_TEST */
  428. void entropy_selftest( int result )
  429. {
  430. TEST_ASSERT( mbedtls_entropy_self_test( 1 ) == result );
  431. }
  432. /* END_CASE */