1
0

test_wolfssl.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. /*
  2. * wolfssl unit tests
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <esp_system.h>
  7. #include "freertos/FreeRTOS.h"
  8. #include "freertos/task.h"
  9. #include "freertos/semphr.h"
  10. #include "unity.h"
  11. #include "sdkconfig.h"
  12. #include "esp_log.h"
  13. #include "esp_timer.h"
  14. #include <wolfssl/wolfcrypt/settings.h>
  15. #include <wolfssl/wolfcrypt/sha.h>
  16. #include <wolfssl/wolfcrypt/sha256.h>
  17. #include <wolfssl/wolfcrypt/sha512.h>
  18. #include <wolfssl/wolfcrypt/wc_port.h>
  19. #include <wolfssl/wolfcrypt/logging.h>
  20. #include <wolfssl/wolfcrypt/types.h>
  21. #include <wolfssl/wolfcrypt/wolfmath.h>
  22. #ifdef NO_INLINE
  23. #include <wolfssl/wolfcrypt/misc.h>
  24. #else
  25. #define WOLFSSL_MISC_INCLUDED
  26. #include <wolfcrypt/src/misc.c>
  27. #endif
  28. static const char* const TAG = "wolfssl unit test";
  29. static xSemaphoreHandle exit_semaph;
  30. static volatile bool exit_loop=false;
  31. static uint64_t startTime = 0;
  32. #define SHA_STACK_SIZE (20*1024)
  33. #define TIMES_SHA 500
  34. #define TIMES_AES 100
  35. #ifndef NO_SHA
  36. int sha_test();
  37. #endif
  38. #ifndef NO_SHA256
  39. int sha256_test();
  40. #endif
  41. #ifdef WOLFSSL_SHA384
  42. int sha384_test(void);
  43. #endif
  44. #ifdef WOLFSSL_SHA512
  45. int sha512_test(void);
  46. #endif
  47. static uint64_t rsa_elapsedTime = 0;
  48. static void esp32TimerStart()
  49. {
  50. startTime = esp_timer_get_time();
  51. }
  52. static uint64_t esp32elapsedTime()
  53. {
  54. /* return elapsed time since wc_esp32AesTimeStart() is called in us */
  55. return esp_timer_get_time() - startTime;
  56. }
  57. #ifndef NO_RSA
  58. int rsa_test(void);
  59. static void tskRsa_Test(void *pvParam)
  60. {
  61. int ret = 0;
  62. ESP_LOGI(TAG, "enter tskRsa_Test");
  63. while(exit_loop==false) {
  64. if(rsa_elapsedTime == 0) esp32TimerStart();
  65. ret = rsa_test();
  66. if(rsa_elapsedTime == 0) rsa_elapsedTime = esp32elapsedTime()/1000;
  67. if(ret != 0) {
  68. printf("result was not good(rsa_test)(%d)\n",ret);
  69. TEST_FAIL_MESSAGE("tskRsa_Test\n");
  70. }
  71. }
  72. ESP_LOGI(TAG, "leave tskRsa_Test");
  73. xSemaphoreGive(exit_semaph);
  74. vTaskDelete(NULL);
  75. }
  76. #endif
  77. #ifndef NO_AES
  78. int aes_test(void);
  79. static void tskAes_Test(void *pvParam)
  80. {
  81. int ret = 0;
  82. ESP_LOGI(TAG, "enter tskAes_Test");
  83. while(exit_loop==false) {
  84. ret = aes_test();
  85. if(ret != 0) {
  86. printf("result was not good(aes_test)(%d)\n",ret);
  87. TEST_FAIL_MESSAGE("tskAes_Test\n");
  88. }
  89. }
  90. ESP_LOGI(TAG, "leave tskAes_Test");
  91. xSemaphoreGive(exit_semaph);
  92. vTaskDelete(NULL);
  93. }
  94. int aesgcm_test(void);
  95. static void tskAesGcm_Test(void *pvParam)
  96. {
  97. int ret = 0;
  98. ESP_LOGI(TAG, "enter tskAesGcm_Test");
  99. while(exit_loop==false) {
  100. ret = aesgcm_test();
  101. if(ret != 0) {
  102. printf(" results was not good(%d). aesGcm_test\n",ret);
  103. TEST_FAIL_MESSAGE("aesGcm_test\n");
  104. }
  105. }
  106. ESP_LOGI(TAG, "leave tskAesGcm_Test");
  107. xSemaphoreGive(exit_semaph);
  108. vTaskDelete(NULL);
  109. }
  110. #ifdef WOLFSSL_AES_192
  111. int aes192_test(void);
  112. static void tskAes192_Test(void *pvParam)
  113. {
  114. int ret = 0;
  115. ESP_LOGI(TAG, "enter tskAes192_Test");
  116. while(exit_loop==false) {
  117. ret = aes192_test();
  118. if(ret != 0) {
  119. printf(" results was not good(%d). aes192_test\n",ret);
  120. TEST_FAIL_MESSAGE("aes192_test\n");
  121. }
  122. }
  123. ESP_LOGI(TAG, "leave tskAes192_Test");
  124. xSemaphoreGive(exit_semaph);
  125. vTaskDelete(NULL);
  126. }
  127. #endif
  128. #ifdef WOLFSSL_AES_256
  129. int aes256_test(void);
  130. static void tskAes256_Test(void *pvParam)
  131. {
  132. int ret = 0;
  133. ESP_LOGI(TAG, "enter tskAes256_Test");
  134. while(exit_loop==false) {
  135. ret = aes256_test();
  136. if(ret != 0) {
  137. printf(" results was not good(%d). aes256_test\n", ret);
  138. TEST_FAIL_MESSAGE("aes256_test\n");
  139. }
  140. }
  141. ESP_LOGI(TAG, "leave tskAes256_Test");
  142. xSemaphoreGive(exit_semaph);
  143. vTaskDelete(NULL);
  144. }
  145. #endif
  146. #if (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(WC_NO_RNG)
  147. int mp_performance_check(int mul, int mulmod, int exptmod)
  148. {
  149. int ret = 0;
  150. int i,j,k;
  151. word32 Xbits;
  152. word32 Ybits;
  153. word32 Pbits;
  154. byte strX[256];
  155. byte strY[256];
  156. byte strP[256];
  157. uint64_t elapsedTime1;
  158. uint64_t elapsedTime2;
  159. uint64_t elapsedTime3;
  160. RNG rng;
  161. mp_int z1, z2, z3, x, p, y;
  162. /* sanity check */
  163. if(!(mul||mulmod||exptmod)) return ret;
  164. XMEMSET(strX, 0, sizeof(strX));
  165. XMEMSET(strY, 0, sizeof(strY));
  166. XMEMSET(strP, 0, sizeof(strP));
  167. wc_InitRng(&rng);
  168. ret = wc_RNG_GenerateBlock(&rng, strX, sizeof(strX));
  169. if (ret != 0) {
  170. return -1; //generating block failed!
  171. }
  172. ret = wc_RNG_GenerateBlock(&rng, strY, sizeof(strY));
  173. if (ret != 0) {
  174. return -1; //generating block failed!
  175. }
  176. ret = wc_RNG_GenerateBlock(&rng, strP, sizeof(strP));
  177. if (ret != 0) {
  178. return -1; //generating block failed!
  179. }
  180. if((strP[255]&1) == 0) {
  181. strP[255] |= 1;
  182. }
  183. for(i = 0; i < 256; i+=16) {
  184. for(j = 0; j < 256; j+=16) {
  185. for(k = 0; k < 256; k+=16) {
  186. /* set init mp_int */
  187. if((ret = mp_init_multi(&z1, &x, &y, &p, &z2, NULL)) != MP_OKAY) {
  188. TEST_FAIL_MESSAGE("mp_init failed.\n");
  189. }
  190. /* set big-numbers into mp_inits */
  191. if(ret == 0 && mp_read_unsigned_bin(&x, (const byte*)&strX[i+1], i+1) != MP_OKAY) {
  192. ESP_LOGE(TAG,"failed to set strX into mp_init");
  193. return -1;
  194. }
  195. if(ret == 0 && mp_read_unsigned_bin(&y, (const byte*)&strY[j+1], j+1) != MP_OKAY) {
  196. ESP_LOGE(TAG,"failed to set strY into mp_init");
  197. return -1;
  198. }
  199. if(ret == 0 && mp_read_unsigned_bin(&p, (const byte*)&strP[k+1], k+1) != MP_OKAY) {
  200. ESP_LOGE(TAG,"failed to set strY into mp_init");
  201. return -1;
  202. }
  203. Xbits = mp_count_bits(&x);
  204. Ybits = mp_count_bits(&y);
  205. Pbits = mp_count_bits(&p);
  206. if(mul) {
  207. /* Z = X * Y */
  208. esp32TimerStart();
  209. if(ret == 0 && (ret = mp_mul(&x, &y, &z1)) != MP_OKAY) {
  210. printf("(%d,%d) Xbits = %d, Ybits = %d Pbits = %d ret = %d\n",
  211. i, j, Xbits, Ybits, Pbits, ret);
  212. TEST_FAIL_MESSAGE("mp_mul() failed");
  213. }
  214. elapsedTime1 = esp32elapsedTime();
  215. }
  216. if(mulmod) {
  217. /* Z = X^Y mod M */
  218. esp32TimerStart();
  219. if(ret == 0 && (ret = mp_mulmod(&x, &y, &p, &z2)) != MP_OKAY) {
  220. printf("(%d,%d) Xbits = %d, Ybits = %d Pbits = %d ret = %d\n",
  221. i , j, Xbits, Ybits, Pbits, ret);
  222. printf("X = %s Y = %s P = %s\n", mp_isodd(&x)==MP_YES?"ODD":"EVEN",
  223. mp_isodd(&y)==MP_YES?"ODD":"EVEN",
  224. mp_isodd(&p)==MP_YES?"ODD":"EVEN");
  225. TEST_FAIL_MESSAGE("mp_mulmod() failed");
  226. }
  227. elapsedTime2 = esp32elapsedTime();
  228. }
  229. if(exptmod) {
  230. /* Z = X^Y mod M */
  231. esp32TimerStart();
  232. if(ret == 0 && (ret = mp_exptmod(&x, &y, &p, &z3)) != MP_OKAY) {
  233. printf("(%d,%d) Xbits = %d, Ybits = %d Pbits = %d ret = %d\n",
  234. i , j, Xbits, Ybits, Pbits, ret);
  235. printf("X = %s Y = %s P = %s\n", mp_isodd(&x)==MP_YES?"ODD":"EVEN",
  236. mp_isodd(&y)==MP_YES?"ODD":"EVEN",
  237. mp_isodd(&p)==MP_YES?"ODD":"EVEN");
  238. TEST_FAIL_MESSAGE("mp_exptmod() failed");
  239. }
  240. elapsedTime3 = esp32elapsedTime()/1000;
  241. }
  242. printf("(%d,%d) Xbits = %d, Ybits = %d Pbits = %d",
  243. i , j, Xbits, Ybits, Pbits);
  244. if(mul) {
  245. printf(" mul = %llu (us)", (unsigned long long)elapsedTime1);
  246. }
  247. if(mulmod) {
  248. printf(" mulmod = %llu (us)\n", (unsigned long long)elapsedTime2);
  249. }
  250. if(exptmod) {
  251. printf(" exptmod = %llu (ms)\n", (unsigned long long)elapsedTime3);
  252. }
  253. }
  254. }
  255. }
  256. mp_clear(&z1);
  257. mp_clear(&z2);
  258. mp_clear(&z3);
  259. mp_clear(&x);
  260. mp_clear(&p);
  261. mp_clear(&y);
  262. wc_FreeRng(&rng);
  263. return ret;
  264. }
  265. /* Z = X * Y */
  266. int mp_unitest_mul(const char* strZ, const char* strX, const char* strY, int verbose)
  267. {
  268. int ret = 0;
  269. char* buf = NULL;
  270. char* bufZ = NULL;
  271. int radixX_size;
  272. int radixZ_size;
  273. int radixY_size;
  274. mp_int z, x, y;
  275. /* set init mp_int */
  276. if((ret = mp_init_multi(&z, &x, &y, NULL, NULL, NULL)) != MP_OKAY) {
  277. TEST_FAIL_MESSAGE("mp_init failed.\n");
  278. }
  279. /* set big-numbers into mp_inits */
  280. if(ret == 0 && mp_read_radix(&x, strX, 16) != MP_OKAY) {
  281. ESP_LOGE(TAG,"failed to set strX into mp_init");
  282. return -1;
  283. }
  284. if(ret == 0 && mp_read_radix(&y, strY, 16) != MP_OKAY) {
  285. ESP_LOGE(TAG,"failed to set strY into mp_init");
  286. return -1;
  287. }
  288. /* Z = X * Y */
  289. if(ret == 0 && (ret = mp_mul(&x, &y, &z)) != MP_OKAY) {
  290. TEST_FAIL_MESSAGE("mp_mul() failed\n");
  291. }
  292. mp_radix_size(&z, 16, &radixZ_size);
  293. bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  294. if(bufZ != NULL) {
  295. mp_toradix(&z, bufZ, 16);
  296. bufZ[radixZ_size-1] ='\0';
  297. }
  298. if(verbose) {
  299. mp_dump("x_value", &x, 1);
  300. mp_dump("y_value", &y, 1);
  301. mp_dump("z_value", &z, 1);
  302. mp_radix_size(&x, 16, &radixX_size);
  303. mp_radix_size(&y, 16, &radixY_size);
  304. radixX_size = max(radixX_size, radixY_size);
  305. buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  306. if(buf != NULL) {
  307. mp_toradix(&x, buf, 16);
  308. buf[radixX_size-1] ='\0';
  309. printf("X : %s ", buf);
  310. mp_toradix(&y, buf, 16);
  311. buf[radixY_size-1] ='\0';
  312. printf("Y : %s ", buf);
  313. }
  314. if(bufZ != NULL) {
  315. printf("Z : %s \n", bufZ);
  316. }
  317. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  318. }
  319. TEST_ASSERT_EQUAL_STRING_MESSAGE(strZ, bufZ,
  320. "mp_mulmod returns an unexpected result.");
  321. XFREE(bufZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  322. return 0;
  323. }
  324. int mp_unitest_mulmod(const char* strZ, const char* strX, const char* strY,
  325. const char* strM, int verbose)
  326. {
  327. int ret = 0;
  328. char* buf;
  329. char* bufZ;
  330. int radixX_size;
  331. int radixZ_size;
  332. int radixY_size;
  333. int radixM_size;
  334. mp_int z, x, y, m;
  335. /* set init mp_int */
  336. if((ret = mp_init_multi(&z, &x, &y, &m, NULL, NULL)) != MP_OKAY) {
  337. TEST_FAIL_MESSAGE("mp_init failed.\n");
  338. }
  339. /* set big-numbers into mp_inits */
  340. if(ret == 0 && mp_read_radix(&x, strX, 16) != MP_OKAY) {
  341. ESP_LOGE(TAG,"failed to set strX into mp_init");
  342. return -1;
  343. }
  344. if(ret == 0 && mp_read_radix(&y, strY, 16) != MP_OKAY) {
  345. ESP_LOGE(TAG,"failed to set strY into mp_init");
  346. return -1;
  347. }
  348. if(ret == 0 && mp_read_radix(&m, strM, 16) != MP_OKAY) {
  349. ESP_LOGE(TAG,"failed to set strM into mp_init");
  350. return -1;
  351. }
  352. /* Z = X^Y mod M */
  353. if(ret == 0 && (ret = mp_mulmod(&x, &y, &m, &z)) != MP_OKAY) {
  354. TEST_FAIL_MESSAGE("mp_mulmod() failed\n");
  355. }
  356. mp_radix_size(&z, 16, &radixZ_size);
  357. bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  358. if(bufZ != NULL) {
  359. mp_toradix(&z, bufZ, 16);
  360. bufZ[radixZ_size-1] ='\0';
  361. }
  362. if(verbose) {
  363. mp_dump("x_value", &x, 1);
  364. mp_dump("y_value", &y, 1);
  365. mp_dump("m_value", &m, 1);
  366. mp_dump("z_value", &z, 1);
  367. mp_radix_size(&x, 16, &radixX_size);
  368. mp_radix_size(&y, 16, &radixY_size);
  369. mp_radix_size(&m, 16, &radixM_size);
  370. radixX_size = max(radixX_size, max(radixY_size, radixM_size));
  371. buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  372. if(buf != NULL) {
  373. mp_toradix(&x, buf, 16);
  374. buf[radixX_size-1] ='\0';
  375. printf("X : %s ", buf);
  376. mp_toradix(&y, buf, 16);
  377. buf[radixY_size-1] ='\0';
  378. printf("Y : %s ", buf);
  379. mp_toradix(&m, buf, 16);
  380. buf[radixM_size-1] ='\0';
  381. printf("M : %s ", buf);
  382. }
  383. if(bufZ != NULL) {
  384. printf("Z : %s \n", bufZ);
  385. }
  386. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  387. }
  388. TEST_ASSERT_EQUAL_STRING_MESSAGE(strZ, bufZ,
  389. "mp_mulmod returns an unexpected result.");
  390. XFREE(bufZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  391. return 0;
  392. }
  393. int mp_unitest_exptmod(const char* strZ, const char* strX, const char* strY,
  394. const char* strM, int verbose)
  395. {
  396. int ret = 0;
  397. char* buf = NULL;
  398. char* bufZ = NULL;
  399. int radixX_size;
  400. int radixZ_size;
  401. int radixY_size;
  402. int radixM_size;
  403. mp_int z, x, y, m;
  404. /* set init mp_int */
  405. if((ret = mp_init_multi(&z, &x, &y, &m, NULL, NULL)) != MP_OKAY) {
  406. TEST_FAIL_MESSAGE("mp_init failed.\n");
  407. }
  408. /* set big-numbers into mp_inits */
  409. if(ret == 0 && mp_read_radix(&x, strX, 16) != MP_OKAY) {
  410. ESP_LOGE(TAG,"failed to set strX into mp_init");
  411. return -1;
  412. }
  413. if(ret == 0 && mp_read_radix(&y, strY, 16) != MP_OKAY) {
  414. ESP_LOGE(TAG,"failed to set strY into mp_init");
  415. return -1;
  416. }
  417. if(ret == 0 && mp_read_radix(&m, strM, 16) != MP_OKAY) {
  418. ESP_LOGE(TAG,"failed to set strM into mp_init");
  419. return -1;
  420. }
  421. /* Z = X^Y mod M */
  422. if(ret == 0 && (ret = mp_exptmod(&x, &y, &m, &z)) != MP_OKAY) {
  423. TEST_FAIL_MESSAGE("mp_exptmod() failed\n");
  424. }
  425. mp_radix_size(&z, 16, &radixZ_size);
  426. bufZ = (char*)XMALLOC(radixZ_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  427. if(bufZ != NULL) {
  428. mp_toradix(&z, bufZ, 16);
  429. bufZ[radixZ_size-1] ='\0';
  430. }
  431. if(verbose) {
  432. mp_dump("x_value", &x, 1);
  433. mp_dump("y_value", &y, 1);
  434. mp_dump("m_value", &m, 1);
  435. mp_dump("z_value", &z, 1);
  436. mp_radix_size(&x, 16, &radixX_size);
  437. mp_radix_size(&y, 16, &radixY_size);
  438. mp_radix_size(&m, 16, &radixM_size);
  439. radixX_size = max(radixX_size, max(radixY_size, radixM_size));
  440. buf = (char*)XMALLOC(radixX_size, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  441. if(buf != NULL) {
  442. mp_toradix(&x, buf, 16);
  443. buf[radixX_size-1] ='\0';
  444. printf("X : %s ", buf);
  445. mp_toradix(&y, buf, 16);
  446. buf[radixY_size-1] ='\0';
  447. printf("Y : %s ", buf);
  448. mp_toradix(&m, buf, 16);
  449. buf[radixM_size-1] ='\0';
  450. printf("M : %s ", buf);
  451. }
  452. if(bufZ != NULL) {
  453. printf("Z : %s \n", bufZ);
  454. }
  455. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  456. }
  457. TEST_ASSERT_EQUAL_STRING_MESSAGE(strZ, bufZ,
  458. "mp_exptmod returns an unexpected result.");
  459. XFREE(bufZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  460. return 0;
  461. }
  462. TEST_CASE("wolfssl mp exptmod test" , "[wolfssl]")
  463. {
  464. ESP_LOGI(TAG, "mp test");
  465. int verbose = 1;
  466. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("02", "5", "1", "3", verbose));
  467. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("01", "-5", "1", "3", verbose));
  468. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("CE331E6D30A77A57", "1234", "A",
  469. "FFFFFFFFFFFFFFFF", verbose));
  470. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("01000000", "1000", "2", "FFFFFFF", verbose));
  471. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("01000000", "2", "128",
  472. "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", verbose));
  473. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("014B5A90", "1234", "2", "FFFFFFF", verbose));
  474. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("01234321", "1111", "2", "FFFFFFFF", verbose));
  475. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("02", "5", "1", "3", verbose));
  476. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("22", "55", "1", "33", verbose));
  477. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("0222", "555", "1", "333", verbose));
  478. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("2222", "5555", "1", "3333", verbose));
  479. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("11", "5555", "1", "33", verbose));
  480. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("55", "1111", "1", "77", verbose));
  481. TEST_ASSERT_EQUAL(0, mp_unitest_exptmod("88", "1111", "2", "BB", verbose));
  482. }
  483. TEST_CASE("wolfssl mp mulmod test" , "[wolfssl]")
  484. {
  485. ESP_LOGI(TAG, "mp test");
  486. int verbose = 1;
  487. /* Z X Y M */
  488. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod("02", "5", "1", "3", verbose));
  489. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod("01", "-5", "1", "3", verbose));
  490. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod("02", "-64", "A", "3", verbose));
  491. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod("74C3AC", "123456", "55555", "AAAAA1", verbose));
  492. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod("73A068", "123456", "55555", "AAAAA3", verbose));
  493. mp_unitest_mulmod(
  494. "010C530243ADE5EA7C557E9A2FF5B4573195665A89CB921F573267B15CD2BCB6467E925235AA752CC2D08B07D31497B497744CA3685A46E76247439826628589DD814AC9EEE9EF8B4B44BEE2DB6065BE3C51B788E4ECFF39FB28C3D8EBE10FC9989D97CDC6624E32EBD222E222A2E93085FC2D05E4EB73375F7FC7B11E9B3024",
  495. "A4F780E83C3FAC34878787D4876BA7582E48C7637A26C6E720974FC7416150A3865D44F6D08E3DA38EB4296928C564D9A0008D8A0D63E0B8EF54D14D54FBEAB540E43D2ED6BE54806D9150C1944437CC3D8B2486A1FB932A6691B529E0E2A46524CB0825BA4F4E1B9C24554DB1913169E5373173A3B7CBBF77C3403C8C7AE86A",
  496. "6520379E44C1A2C359342010E1038F8C3644D9A47A9346A80C92B48A6986872D74C3BDDB49B2D93C554B588D4A4448614FADBC066CC10F3EB20A2422EA857B7DD0BF60C9CB7D733B12761BD785BCD122D97ECA0A8F1D0F705BC094B66EE5C96712AE3B14B5AA6AD9E50C6A3020BA01DA4FB94E3934527ADCDB3DE51C368B37C2",
  497. "BE7070B80418E528FE66D89088E0F1B7C3D0D23EE64B9474B0FFB0F763A5AB7EAFB62BB738161A50BFF1CA873AD5B0DAF8437A15B97EEA2A80D251B035AF07F3F25D243A4B8756481B3C249ADA7080BD3C8B034A0C8371DEE30370A2B760091B5EC73DA06460E3A9068DD3FF42BB0A94272D57420DB02DE0BA182560921192F3",
  498. verbose);
  499. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod(
  500. "76DBEC4349F316F82C27F59CD87378C83234E28C6E99990A5F9CDCF5A627CD1B2F405FA31AA0EAF7CB433B01D3592E5EF11134E4F8C8126D4DF33F4022A9A2A5B2FA1E6D25B66C628A9BE974136C823CE564E39D1ED099B5B401B8805DE19EFA776C6263265D6E9928714EBD74FFFFD89179BD594DCDC74F5687E311C26B613E539311DC310D36D04D831704524820DE3FC70BC2E43B929F9B4FF40DF4367B241095577C80B6BEB7F2BDE84282EEC9F9FE2A289E4115DB788803392C96A8A86A2FCABCBC6545BABB80F65CE2821C07DA899CEA8D172681F398341FC449D21630DDD0F100E28D351CFF2F2C4E2341B5851632FC6597E00149E98752A5895CDC41",
  501. "1678D8E98C4A0BA91E0F8318A15A453A562B36A4EC315B445617CF93CD5287B0284FEE83EF0A5DBEFCEC1801E402D860C050CE24F74D715B57A9E0BE2D8F91FF61F7124983270F06A2E6A00E33A32E26A1A358B1B178C969D37BCB544ED8B3A0AF3BFEA5AB970AE7613ACF0B5C7B5B4AB578C96911752528DA7B3B40189E75C67EC3F6CEA16D5B53C5742FF3C425EB7C3F20D5198CC5B8CCAD0A2D59AD58DD88FB203396341456CF9415CEB3BFB1FB7B2CFE9599E755AB8FD55C5A8B9AD044E6E2DE44FC996297C3C900F76D118572EDF860F507B3C1AC3590B9B47AD85F9D930CEDE1DA1F0AE0DCF69D6DE44304FE22704C51262B9230D00A988438555F7EAF",
  502. "3D76E6173983A5E1F98C04CDD512274E7259E7C26355A5BA7F067B343699E01D6FDE6A27E3D73B1BBFE2F32FC4B412F8D16F1F538D09227BEECDC9BFF1D05DCF0D28112209D3077C2F9E88BBE62AA7E61948172142B793E6AA65D11AFFF182F0D758609B113C45EF43934233767F0C2337853750892E4E45413C87D02D051DC4BAD0782724672E9C8AC888A2EFDDC5C3AC24B0BD846F473070C815A784B4E6C1E16F2F4428379E80AC9226CDE94C5141B316EA3573E64487EB460E80E888FF270A9AB06CD17447FE082C3F7B2809EAA20227E9AE1924978793947E67CB664D938E061F1CE4B1F36795ED7166022D8B35F3C671ECB77EA7B0AA481E1E0D575887",
  503. "E98A5D15A4D434B959A2DAAF74C8C9032638FA48FC4D306EEA7689CE4FF687DE323A466E38125837220D80AC2DAF2F123E627360666890B26F4717042BCAB726B710C213F97A620A933290420D162EFAD729D79F54E4FC6574F8F6436B4E9E347FCB6B1C1ADE8281BF085D3FC0B6B1A8A59C8170A74E3287151C780EF018FEEB4B372BE9E1F7FA51C658B9D80603EDC00318558B98FEB1F6D03DFA63C03819C700EF4D9960B4BACEE3CED96B2D7694FFFB77184AFE65F00A915C3B229485D02018592EA53303AC1B5F78321125EE7F9621A9D676978D667EB291D0362EA31DBFF185EDC03E60B85A9FAB80E0EA5D5F7556C74D518ED41F34A636F1301F51992F",
  504. verbose));
  505. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod(
  506. "DBEE64C8091CF78EC926AF5D51E06FD92FE0007DA3AF33317D9E131F3CDE711AFB30F8F61E6ACF99EAD21822E4DBC2B31B910D7E357230F255DA6C90EEA36A1E926A7F44CF34FBE544C1DC30B8DF4D5735495FEB1D0E10827222B6AF069BCD3F66120C4A19D8D533E4222FE65FCB323CF993A8DB07B896F0D10AAF94A996EB9B",
  507. "1572A17625B1609DB02793AEC41541DB2C9B0301EEF6805804945BA77656B207BF46F90762DEBB3E0057A43A95D09C6C852267E602FD3851D925323F875CB1E743818CBE17814D2DB4921BAA7DA2F8E5EFBD6373FF0E2020206BC89870F0B734AD3E331EB010CC713F09683165EC5BF551B3B70A497178EB926C0726EDDB2E37",
  508. "773FB6148DC513087EC9C4EAD4BA0DA49EB36EDE1A7AF88988EF363C11BC83E8306C817C47F34DCAEA560162552E4B89A9BD6F01F67402AAE38466069534A1E2CA65FEA32D4397956C6FD5B438F6F99530FAF89C252BB61451CC2EB35BD6DC1AEC2D095B3F3AD0B84E271FDC2AEEACA9595D076311830BD47480B67D6245BF56",
  509. "FF3011C23C6BB4D69E6BC193D148CE802DBEAFF7BAB2D7C3C4536E1502AA61B9EA059B79670BCED9FB988C1D6BF45AA7A05E5418E931447CC752D86DA03ED6142D7B159D1E398796DDA833552A8E32C0C4E5B8CBCD328DAD7BE5C67E4D6FF3A4C5A640BE903A336A24B2808112ACE37B2663CF88B9FF74233752F0C4275D451F",
  510. verbose));
  511. TEST_ASSERT_EQUAL(0, mp_unitest_mulmod(
  512. "7C65",
  513. "10000000000",
  514. "555555",
  515. "12345", verbose));
  516. }
  517. TEST_CASE("wolfssl mp mul test" , "[wolfssl]")
  518. {
  519. ESP_LOGI(TAG, "mp test");
  520. int verbose = 1;
  521. TEST_ASSERT_EQUAL(0, mp_unitest_mul("0A", "5", "2", verbose));
  522. TEST_ASSERT_EQUAL(0, mp_unitest_mul("-0A", "-5", "2", verbose));
  523. TEST_ASSERT_EQUAL(0, mp_unitest_mul("0A", "-5", "-2", verbose));
  524. TEST_ASSERT_EQUAL(0, mp_unitest_mul("06260060", "1234", "5678", verbose));
  525. TEST_ASSERT_EQUAL(0, mp_unitest_mul("038E83", "123", "321", verbose));
  526. TEST_ASSERT_EQUAL(0, mp_unitest_mul("75CD7FCBBC", "123456", "6789A", verbose));
  527. TEST_ASSERT_EQUAL(0, mp_unitest_mul(
  528. "19C26D7DC91D2123426ECCDB5A0290A9F7D9D01456D266BA549E859373D9D4FE0B4EDAE8763FA94458E4BED29CB7DD6CEF5C52136D2F310D2EABA373C750760EEE3FAE6EA618C60E9A4A0F2C3F3AC87612A0F032866F1CA4DA95CCCC47D2C51F",
  529. "77BDC7B4C5616B142B7762251075BA95FB475D570179E730D418A9143D18905F",
  530. "371280CB239B46A1BB0C036755ADF3C4474E1696FB2E70AA200225322C50270D44AE8490F24AA22D0FD9AE89EEF9449285FCED5FBC8F424A4A5E82DFEB3B0341",
  531. verbose));
  532. TEST_ASSERT_EQUAL(0, mp_unitest_mul(
  533. "033676FE7B625BF0759F7E8932B6B50D5F45E16E1C670AD20F1CDA5DFFA433685937CA8422A9CB916CC8",
  534. "165196BA298CD54975DC483C4D21A51EA0A146783CFB41522E76E50C",
  535. "24D9D5CA7D9CCC06F5E70F1963E6",
  536. verbose));
  537. TEST_ASSERT_EQUAL(0, mp_unitest_mul(
  538. "65D67946D0D9AB634DD18E5308A1F963C3AAE65F949A81C16C91B5B9DACE18A170ED73E3FC1F01EC8FF7D78EDD29B71FA00D9F5D8FF9116AA93E6F8F09DB306A8C1EEA42DCE9C8C9345B4B84E58CEED1F24A93B14FF47E81A766DF842A25BB941F3F07310C749B47E27C85D544FFE9021AB31AD3484AF40F738A04E9BCC0EFB6B36E56ABE76D982AD7B4D2527526F29B9CFD2A0F6570532C286EA7937354F1A6903480B4D8554E7ED707A08E07CAD5EB713752125163626CF52178574011072D2E536D126C2FF096505515FCA91B5BCEC2D765FC0A1AE90CC8F3C2E18529CF6647E4F732B1D16685189FE24148C752B3AF23F1D8481507CFB89DC1DC70E87B06748D4F1E32B489E1288FC5B02466C8395A59E92862F83F985D021B9C4C42B768BFD3FC81C189F7B88755EB879CF781EFC97C41D0ABB428F7351FA9D62A12A316FE2D2C24D8ECF87132D8476A1B0611793E9EFEE2ADDE1AB7116F69D7744150C770555C54B6BE88ECDD5CF33DF321147061FCB42BEF3D69663695FFD74D42493A",
  539. "13DADD9D122C5264497863C0BC2A893CD6C951E94198ABC0DAFF499BE89C6A425548B15F582E714D866563E4ACC81197D5B95BF87BD960D3647E51764F31977BFE2D0A7A7727C27BF7B3134148F126B5F1F0F00730C172C76D768874006C6C86E82F8698621773ED0B91CCA997FBC712D788D384E7831F51A6DD4FB4819D26026",
  540. "5210C04ED4FDF80D630BA81DCA6BA05495156D7DDBE1DEE0E057825F7FADACE70EBE4D5F82E51E465514DDC86E5B46DD780C182865A6C9E29F7456E3090229247BFC18094E31B15B1BE3A962601202D5C65979FF96CA64FB93F29110A76500DEB1003B6CEA2BA79CBAD007FA35610C43DE59FD0A22E07CA0A9943F6B101B4C9663AF0CADD26014586933AC536A917F4A62A31BD5EE8BFD452F63E4ED4D656DDC22D2413B44D02029887F7DC31200FD793C83F1927F306D00535EB1E0E8BEDA6486A41C509E8DB4369BC4D0C36767AA0127EC3E8C6EF4B5C07F2AD9FB51910B771F112A10F21128E26428B74F69586C486B04EEB64E84A36D4BD03C315B90CE8F",
  541. verbose));
  542. }
  543. TEST_CASE("wolfssl mp mul performance test" , "[wolfssl]")
  544. {
  545. int mul = 0, mulmod = 0, exptmod = 0;
  546. TEST_ASSERT_EQUAL(0, mp_performance_check(mul, mulmod, exptmod));
  547. }
  548. #endif/* (!NO_RSA || HAVE_ECC) && !WC_NO_RNG */
  549. TEST_CASE("wolfssl aes test" , "[wolfssl]")
  550. {
  551. ESP_LOGI(TAG, "aes test");
  552. TEST_ASSERT_EQUAL(0, aes_test());
  553. #ifdef WOLFSSL_AES_192
  554. ESP_LOGI(TAG, "aes_192 test");
  555. TEST_ASSERT_EQUAL(0, aes192_test());
  556. #endif
  557. #ifdef WOLFSSL_AES_256
  558. ESP_LOGI(TAG, "aes_256 test");
  559. TEST_ASSERT_EQUAL(0, aes256_test());
  560. #endif
  561. ESP_LOGI(TAG, "aes-gcm test");
  562. TEST_ASSERT_EQUAL(0, aesgcm_test());
  563. }
  564. #endif
  565. TEST_CASE("wolfssl sha crypt-test", "[wolfssl]")
  566. {
  567. #ifndef NO_SHA
  568. ESP_LOGI(TAG, "sha_test()");
  569. TEST_ASSERT_EQUAL(0, sha_test());
  570. #endif
  571. #ifndef NO_SHA256
  572. ESP_LOGI(TAG, "sha256_test()");
  573. TEST_ASSERT_EQUAL(0, sha256_test());
  574. #endif
  575. #ifdef WOLFSSL_SHA384
  576. ESP_LOGI(TAG, "sha384_test()");
  577. TEST_ASSERT_EQUAL(0, sha384_test());
  578. #endif
  579. #ifdef WOLFSSL_SHA512
  580. ESP_LOGI(TAG, "sha512_test()");
  581. TEST_ASSERT_EQUAL(0, sha512_test());
  582. #endif
  583. }
  584. #ifndef NO_SHA
  585. static void tskSha_Test(void *pvParam)
  586. {
  587. int ret = 0;
  588. ESP_LOGI(TAG, "enter tskSha_Test");
  589. while(exit_loop==false) {
  590. ret = sha_test();
  591. if(ret != 0) {
  592. printf(" results was not good(%d). sha_test\n", ret);
  593. TEST_FAIL_MESSAGE("tskSha_Test\n");
  594. }
  595. }
  596. ESP_LOGI(TAG, "leave tskSha_Test");
  597. xSemaphoreGive(exit_semaph);
  598. vTaskDelete(NULL);
  599. }
  600. #endif
  601. #ifndef NO_SHA256
  602. static void tskSha256_Test(void *pvParam)
  603. {
  604. int ret;
  605. ESP_LOGI(TAG, "enter tskSha256_Test");
  606. while(exit_loop==false) {
  607. ret = sha256_test();
  608. if(ret != 0) {
  609. printf("results was not good(%d). sha256_test\n", ret);
  610. TEST_FAIL_MESSAGE("sha256_test() failed");
  611. }
  612. }
  613. ESP_LOGI(TAG, "leave tskSha256_Test");
  614. xSemaphoreGive(exit_semaph);
  615. vTaskDelete(NULL);
  616. }
  617. #endif
  618. #ifdef WOLFSSL_SHA384
  619. static void tskSha384_Test(void *pvParam)
  620. {
  621. int ret = 0;
  622. ESP_LOGI(TAG, "enter tskSha384_Test");
  623. while(exit_loop==false) {
  624. ret = sha384_test();
  625. if(ret != 0) {
  626. printf("results was not good(%d). sha384_test\n", ret);
  627. TEST_FAIL_MESSAGE("sha384_test() failed\n");
  628. }
  629. }
  630. ESP_LOGI(TAG, "leave tskSha384_Test");
  631. xSemaphoreGive(exit_semaph);
  632. vTaskDelete(NULL);
  633. }
  634. #endif
  635. #ifdef WOLFSSL_SHA512
  636. static void tskSha512_Test(void *pvParam)
  637. {
  638. int ret = 0;
  639. ESP_LOGI(TAG, "enter tskSha512_Test");
  640. while(exit_loop==false) {
  641. ret = sha512_test();
  642. if(ret != 0) {
  643. printf(" results was not good(%d). sha512_test\n", ret);
  644. TEST_FAIL_MESSAGE("tskSha512_Test() failed\n");
  645. }
  646. }
  647. ESP_LOGI(TAG, "leave tskSha512_test()");
  648. xSemaphoreGive(exit_semaph);
  649. vTaskDelete(NULL);
  650. }
  651. #endif
  652. TEST_CASE("wolfssl sha multi-thread test ", "[wolfssl]")
  653. {
  654. int num = 0;
  655. int i;
  656. #ifndef NO_SHA
  657. num++;
  658. #endif
  659. #ifndef NO_SHA256
  660. num++;
  661. #endif
  662. #ifdef WOLFSSL_SHA384
  663. num++;
  664. #endif
  665. #ifdef WOLFSSL_SHA512
  666. num++;
  667. #endif
  668. exit_loop = false;
  669. exit_semaph = xSemaphoreCreateCounting(num, 0);
  670. #ifndef NO_SHA
  671. xTaskCreate(tskSha_Test, "sha_test", SHA_STACK_SIZE, NULL, 3, NULL);
  672. #endif
  673. #ifndef NO_SHA256
  674. xTaskCreate(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL);
  675. #endif
  676. #ifdef WOLFSSL_SHA384
  677. xTaskCreate(tskSha384_Test, "sha384_test", SHA_STACK_SIZE, NULL, 3, NULL);
  678. #endif
  679. #ifdef WOLFSSL_SHA512
  680. xTaskCreate(tskSha512_Test, "sha512_test", SHA_STACK_SIZE, NULL, 3, NULL);
  681. #endif
  682. ESP_LOGI(TAG, "Waiting for 10s ...");
  683. vTaskDelay(10000/portTICK_PERIOD_MS);
  684. exit_loop = true;
  685. for(i = 0;i < num;i++) {
  686. if(!xSemaphoreTake(exit_semaph, 2000/portTICK_PERIOD_MS)) {
  687. TEST_FAIL_MESSAGE("exit semaphore not released by test task");
  688. }
  689. }
  690. vSemaphoreDelete(exit_semaph);
  691. }
  692. TEST_CASE("wolfssl aes multi-thread test ", "[wolfssl]")
  693. {
  694. int num = 0;
  695. int i;
  696. #ifndef NO_AES
  697. num++;
  698. num++;
  699. #ifdef WOLFSSL_AES_192
  700. num++;
  701. #endif
  702. #ifdef WOLFSSL_AES_256
  703. num++;
  704. #endif
  705. #endif
  706. exit_loop = false;
  707. exit_semaph = xSemaphoreCreateCounting(num, 0);
  708. #ifndef NO_AES
  709. xTaskCreate(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL);
  710. xTaskCreate(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL);
  711. #endif
  712. #ifdef WOLFSSL_AES_192
  713. xTaskCreate(tskAes192_Test, "Aes192_test", SHA_STACK_SIZE, NULL, 3, NULL);
  714. #endif
  715. #ifdef WOLFSSL_AES_256
  716. xTaskCreate(tskAes256_Test, "Aes256_test", SHA_STACK_SIZE, NULL, 3, NULL);
  717. #endif
  718. ESP_LOGI(TAG, "Waiting for 10s ...");
  719. vTaskDelay(10000/portTICK_PERIOD_MS);
  720. exit_loop = true;
  721. for(i = 0;i < num;i++){
  722. if(!xSemaphoreTake(exit_semaph, 2000/portTICK_PERIOD_MS)) {
  723. TEST_FAIL_MESSAGE("exit semaphore not released by test task");
  724. }
  725. }
  726. vSemaphoreDelete(exit_semaph);
  727. }
  728. TEST_CASE("wolfssl aes sha sha256 multi-thread test ", "[wolfssl]")
  729. {
  730. int num = 0;
  731. int i;
  732. #ifndef NO_AES
  733. num++;
  734. num++;
  735. #ifdef WOLFSSL_AES_192
  736. num++;
  737. #endif
  738. #ifdef WOLFSSL_AES_256
  739. num++;
  740. #endif
  741. #endif
  742. #ifndef NO_SHA
  743. num++;
  744. #endif
  745. #ifndef NO_SHA256
  746. num++;
  747. #endif
  748. exit_loop = false;
  749. #ifndef CONFIG_FREERTOS_UNICORE
  750. num *= 2;
  751. printf("num=%d\n", num);
  752. exit_semaph = xSemaphoreCreateCounting(num, 0);
  753. #ifndef NO_AES
  754. if(xTaskCreatePinnedToCore(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  755. ESP_LOGE(TAG, "failed to create task -1 \n");
  756. if(xTaskCreatePinnedToCore(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  757. ESP_LOGE(TAG, "failed to create task -2 \n");
  758. if(xTaskCreatePinnedToCore(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  759. ESP_LOGE(TAG, "failed to create task -3 \n");
  760. if(xTaskCreatePinnedToCore(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  761. ESP_LOGE(TAG, "failed to create task -4 \n");
  762. #endif
  763. #ifdef WOLFSSL_AES_192
  764. if(xTaskCreatePinnedToCore(tskAes192_Test, "Aes192_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  765. ESP_LOGE(TAG, "failed to create task -5 \n");
  766. if(xTaskCreatePinnedToCore(tskAes192_Test, "Aes192_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  767. ESP_LOGE(TAG, "failed to create task -6 \n");
  768. #endif
  769. #ifdef WOLFSSL_AES_256
  770. if(xTaskCreatePinnedToCore(tskAes256_Test, "Aes256_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  771. ESP_LOGE(TAG, "failed to create task -7 \n");
  772. if(xTaskCreatePinnedToCore(tskAes256_Test, "Aes256_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  773. ESP_LOGE(TAG, "failed to create task -8 \n");
  774. #endif
  775. #ifndef NO_SHA
  776. if(xTaskCreatePinnedToCore(tskSha_Test, "Sha_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  777. ESP_LOGE(TAG, "failed to create task -9 \n");
  778. if(xTaskCreatePinnedToCore(tskSha_Test, "Sha_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  779. ESP_LOGE(TAG, "failed to create task -10 \n");
  780. #endif
  781. #ifndef NO_SHA256
  782. if(xTaskCreatePinnedToCore(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  783. ESP_LOGE(TAG, "failed to create task -11 \n");
  784. if(xTaskCreatePinnedToCore(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  785. ESP_LOGE(TAG, "failed to create task -12 \n");
  786. #endif
  787. #else
  788. exit_semaph = xSemaphoreCreateCounting(num, 0);
  789. #ifndef NO_AES
  790. xTaskCreate(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL);
  791. xTaskCreate(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL);
  792. #endif
  793. #ifdef WOLFSSL_AES_192
  794. xTaskCreate(tskAes192_Test, "Aes192_test", SHA_STACK_SIZE, NULL, 3, NULL);
  795. #endif
  796. #ifdef WOLFSSL_AES_256
  797. xTaskCreate(tskAes256_Test, "Aes256_test", SHA_STACK_SIZE, NULL, 3, NULL);
  798. #endif
  799. #ifndef NO_SHA
  800. xTaskCreate(tskSha_Test, "Sha_test", SHA_STACK_SIZE, NULL, 3, NULL);
  801. #endif
  802. #ifndef NO_SHA256
  803. xTaskCreate(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL);
  804. #endif
  805. #endif /* CONFIG_FREERTOS_UNICORE */
  806. ESP_LOGI(TAG, "Waiting for 15s ...");
  807. vTaskDelay(15000/portTICK_PERIOD_MS);
  808. exit_loop = true;
  809. for(i = 0;i < num;i++){
  810. if(!xSemaphoreTake(exit_semaph, 2000/portTICK_PERIOD_MS)) {
  811. TEST_FAIL_MESSAGE("exit semaphore not released by test task");
  812. }
  813. }
  814. vSemaphoreDelete(exit_semaph);
  815. }
  816. TEST_CASE("wolfssl aes sha384 sha512 multi-thread test ", "[wolfssl]")
  817. {
  818. int num = 0;
  819. int i;
  820. #ifndef NO_AES
  821. num++;
  822. num++;
  823. #ifdef WOLFSSL_AES_192
  824. num++;
  825. #endif
  826. #ifdef WOLFSSL_AES_256
  827. num++;
  828. #endif
  829. #endif
  830. #ifdef WOLFSSL_SHA384
  831. num++;
  832. #endif
  833. #ifdef WOLFSSL_SHA512
  834. num++;
  835. #endif
  836. exit_loop = false;
  837. #ifndef CONFIG_FREERTOS_UNICORE
  838. num *= 2;
  839. exit_semaph = xSemaphoreCreateCounting(num, 0);
  840. #ifndef NO_AES
  841. if(xTaskCreatePinnedToCore(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  842. ESP_LOGE(TAG, "failed to create task -1 \n");
  843. if(xTaskCreatePinnedToCore(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  844. ESP_LOGE(TAG, "failed to create task -2 \n");
  845. if(xTaskCreatePinnedToCore(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  846. ESP_LOGE(TAG, "failed to create task -3 \n");
  847. if(xTaskCreatePinnedToCore(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  848. ESP_LOGE(TAG, "failed to create task -4 \n");
  849. #endif
  850. #ifdef WOLFSSL_AES_192
  851. if(xTaskCreatePinnedToCore(tskAes192_Test, "Aes192_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  852. ESP_LOGE(TAG, "failed to create task -5 \n");
  853. if(xTaskCreatePinnedToCore(tskAes192_Test, "Aes192_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  854. ESP_LOGE(TAG, "failed to create task -6 \n");
  855. #endif
  856. #ifdef WOLFSSL_AES_256
  857. if(xTaskCreatePinnedToCore(tskAes256_Test, "Aes256_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  858. ESP_LOGE(TAG, "failed to create task -7 \n");
  859. if(xTaskCreatePinnedToCore(tskAes256_Test, "Aes256_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  860. ESP_LOGE(TAG, "failed to create task -8 \n");
  861. #endif
  862. #ifdef WOLFSSL_SHA384
  863. if(xTaskCreatePinnedToCore(tskSha384_Test, "sha384_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  864. ESP_LOGE(TAG, "failed to create task -13 \n");
  865. if(xTaskCreatePinnedToCore(tskSha384_Test, "sha384_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  866. ESP_LOGE(TAG, "failed to create task -14 \n");
  867. #endif
  868. #ifdef WOLFSSL_SHA512
  869. printf("start sha512\n");
  870. if(xTaskCreatePinnedToCore(tskSha512_Test, "Sha512_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  871. ESP_LOGE(TAG, "failed to create task -15 \n");
  872. if(xTaskCreatePinnedToCore(tskSha512_Test, "Sha512_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  873. ESP_LOGE(TAG, "failed to create task -16 \n");
  874. #endif
  875. #else
  876. exit_semaph = xSemaphoreCreateCounting(num, 0);
  877. #ifndef NO_AES
  878. xTaskCreate(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL);
  879. xTaskCreate(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL);
  880. #endif
  881. #ifdef WOLFSSL_AES_192
  882. xTaskCreate(tskAes192_Test, "Aes192_test", SHA_STACK_SIZE, NULL, 3, NULL);
  883. #endif
  884. #ifdef WOLFSSL_AES_256
  885. xTaskCreate(tskAes256_Test, "Aes256_test", SHA_STACK_SIZE, NULL, 3, NULL);
  886. #endif
  887. #ifndef NO_SHA
  888. xTaskCreate(tskSha_Test, "Sha_test", SHA_STACK_SIZE, NULL, 3, NULL);
  889. #endif
  890. #ifndef NO_SHA256
  891. xTaskCreate(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL);
  892. #endif
  893. #endif /* CONFIG_FREERTOS_UNICORE */
  894. ESP_LOGI(TAG, "Waiting for 15s ...");
  895. vTaskDelay(15000/portTICK_PERIOD_MS);
  896. exit_loop = true;
  897. for(i = 0;i < num;i++){
  898. if(!xSemaphoreTake(exit_semaph, 2000/portTICK_PERIOD_MS)) {
  899. TEST_FAIL_MESSAGE("exit semaphore not released by test task");
  900. }
  901. }
  902. vSemaphoreDelete(exit_semaph);
  903. }
  904. TEST_CASE("wolfssl aes sha256 rsa multi-thread test ", "[wolfssl]")
  905. {
  906. int num = 0;
  907. int i;
  908. #ifndef NO_AES
  909. num++;
  910. num++;
  911. #endif
  912. #ifndef NO_SHA256
  913. num++;
  914. #endif
  915. #ifndef NO_RSA
  916. num++;
  917. #endif
  918. exit_loop = false;
  919. #ifndef CONFIG_FREERTOS_UNICORE
  920. num *= 2;
  921. printf("num=%d\n", num);
  922. exit_semaph = xSemaphoreCreateCounting(num, 0);
  923. #ifndef NO_AES
  924. if(xTaskCreatePinnedToCore(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  925. ESP_LOGE(TAG, "failed to create task -1 \n");
  926. if(xTaskCreatePinnedToCore(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  927. ESP_LOGE(TAG, "failed to create task -2 \n");
  928. if(xTaskCreatePinnedToCore(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  929. ESP_LOGE(TAG, "failed to create task -3 \n");
  930. if(xTaskCreatePinnedToCore(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  931. ESP_LOGE(TAG, "failed to create task -4 \n");
  932. #endif
  933. #ifndef NO_SHA256
  934. if(xTaskCreatePinnedToCore(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  935. ESP_LOGE(TAG, "failed to create task -5 \n");
  936. if(xTaskCreatePinnedToCore(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  937. ESP_LOGE(TAG, "failed to create task -6 \n");
  938. #endif
  939. #ifndef NO_RSA
  940. if(xTaskCreatePinnedToCore(tskRsa_Test, "rsa_test", SHA_STACK_SIZE, NULL, 3, NULL, 0)!=pdPASS)
  941. ESP_LOGE(TAG, "failed to create task -7 \n");
  942. if(xTaskCreatePinnedToCore(tskRsa_Test, "rsa_test", SHA_STACK_SIZE, NULL, 3, NULL, 1)!=pdPASS)
  943. ESP_LOGE(TAG, "failed to create task -8 \n");
  944. #endif
  945. #else
  946. exit_semaph = xSemaphoreCreateCounting(num, 0);
  947. #ifndef NO_AES
  948. xTaskCreate(tskAes_Test, "Aes_test", SHA_STACK_SIZE, NULL, 3, NULL);
  949. xTaskCreate(tskAesGcm_Test, "AesGcm_test", SHA_STACK_SIZE, NULL, 3, NULL);
  950. #endif
  951. #ifndef NO_SHA256
  952. xTaskCreate(tskSha256_Test, "sha256_test", SHA_STACK_SIZE, NULL, 3, NULL);
  953. #endif
  954. #ifndef NO_RSA
  955. xTaskCreate(tskRsa_Test, "rsa_test", SHA_STACK_SIZE, NULL, 3, NULL);
  956. #endif
  957. #endif /* CONFIG_FREERTOS_UNICORE */
  958. ESP_LOGI(TAG, "Waiting for 15s ...");
  959. vTaskDelay(15000/portTICK_PERIOD_MS);
  960. exit_loop = true;
  961. /* wait until rsa test finishes */
  962. while(rsa_elapsedTime==0){ vTaskDelay(1); }
  963. ESP_LOGI(TAG, "Waiting another %llu s. rsa test would take more time to finish.",
  964. (rsa_elapsedTime+3000)/portTICK_PERIOD_MS);
  965. vTaskDelay((rsa_elapsedTime+3000)/portTICK_PERIOD_MS);
  966. for(i = 0;i < num;i++){
  967. if(!xSemaphoreTake(exit_semaph, 2000/portTICK_PERIOD_MS)) {
  968. TEST_FAIL_MESSAGE("exit semaphore not released by test task");
  969. }
  970. }
  971. vSemaphoreDelete(exit_semaph);
  972. }