test_suite_entropy.function 16 KB

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