hash.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /* hash.c has unit tests
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #include <stdio.h>
  26. #include <wolfssl/wolfcrypt/md4.h>
  27. #include <wolfssl/wolfcrypt/md5.h>
  28. #include <wolfssl/wolfcrypt/sha.h>
  29. #include <wolfssl/wolfcrypt/sha256.h>
  30. #include <wolfssl/wolfcrypt/sha512.h>
  31. #include <wolfssl/wolfcrypt/ripemd.h>
  32. #include <wolfssl/wolfcrypt/hmac.h>
  33. #include <tests/unit.h>
  34. typedef struct testVector {
  35. const char* input;
  36. const char* output;
  37. size_t inLen;
  38. size_t outLen;
  39. } testVector;
  40. int md4_test(void);
  41. int md5_test(void);
  42. int sha_test(void);
  43. int sha224_test(void);
  44. int sha256_test(void);
  45. int sha512_test(void);
  46. int sha384_test(void);
  47. int ripemd_test(void);
  48. int hmac_md5_test(void);
  49. int hmac_sha_test(void);
  50. int hmac_sha224_test(void);
  51. int hmac_sha256_test(void);
  52. int hmac_sha384_test(void);
  53. int HashTest(void)
  54. {
  55. int ret = 0;
  56. printf(" Begin HASH Tests\n");
  57. #ifndef NO_MD4
  58. if ( (ret = md4_test()) ) {
  59. printf( " MD4 test failed!\n");
  60. return ret;
  61. } else
  62. printf( " MD4 test passed!\n");
  63. #endif
  64. #ifndef NO_MD5
  65. if ( (ret = md5_test()) ) {
  66. printf( " MD5 test failed!\n");
  67. return ret;
  68. } else
  69. printf( " MD5 test passed!\n");
  70. #endif
  71. #ifndef NO_SHA
  72. if ( (ret = sha_test()) ) {
  73. printf( " SHA test failed!\n");
  74. return ret;
  75. } else
  76. printf( " SHA test passed!\n");
  77. #endif
  78. #ifdef WOLFSSL_SHA224
  79. if ( (ret = sha224_test()) ) {
  80. printf( " SHA-224 test failed!\n");
  81. return ret;
  82. } else
  83. printf( " SHA-224 test passed!\n");
  84. #endif
  85. #ifndef NO_SHA256
  86. if ( (ret = sha256_test()) ) {
  87. printf( " SHA-256 test failed!\n");
  88. return ret;
  89. } else
  90. printf( " SHA-256 test passed!\n");
  91. #endif
  92. #ifdef WOLFSSL_SHA512
  93. if ( (ret = sha512_test()) ) {
  94. printf( " SHA-512 test failed!\n");
  95. return ret;
  96. } else
  97. printf( " SHA-512 test passed!\n");
  98. #endif
  99. #ifdef WOLFSSL_SHA384
  100. if ( (ret = sha384_test()) ) {
  101. printf( " SHA-384 test failed!\n");
  102. return ret;
  103. } else
  104. printf( " SHA-384 test passed!\n");
  105. #endif
  106. #ifdef WOLFSSL_RIPEMD
  107. if ( (ret = ripemd_test()) ) {
  108. printf( " RIPEMD test failed!\n");
  109. return ret;
  110. } else
  111. printf( " RIPEMD test passed!\n");
  112. #endif
  113. #ifndef NO_HMAC
  114. #if !defined(NO_MD5) && !(defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) \
  115. && (HAVE_FIPS_VERSION >= 5))
  116. if ( (ret = hmac_md5_test()) ) {
  117. printf( " HMAC-MD5 test failed!\n");
  118. return ret;
  119. } else
  120. printf( " HMAC-MD5 test passed!\n");
  121. #endif
  122. #ifndef NO_SHA
  123. if ( (ret = hmac_sha_test()) ) {
  124. printf( " HMAC-SHA test failed!\n");
  125. return ret;
  126. } else
  127. printf( " HMAC-SHA test passed!\n");
  128. #endif
  129. #ifdef WOLFSSL_SHA224
  130. if ( (ret = hmac_sha224_test()) ) {
  131. printf( " HMAC-SHA224 test failed!\n");
  132. return ret;
  133. } else
  134. printf( " HMAC-SHA224 test passed!\n");
  135. #endif
  136. #ifndef NO_SHA256
  137. if ( (ret = hmac_sha256_test()) ) {
  138. printf( " HMAC-SHA256 test failed!\n");
  139. return ret;
  140. } else
  141. printf( " HMAC-SHA256 test passed!\n");
  142. #endif
  143. #ifdef WOLFSSL_SHA384
  144. if ( (ret = hmac_sha384_test()) ) {
  145. printf( " HMAC-SHA384 test failed!\n");
  146. return ret;
  147. } else
  148. printf( " HMAC-SHA384 test passed!\n");
  149. #endif
  150. #endif
  151. printf(" End HASH Tests\n");
  152. return 0;
  153. }
  154. #ifndef NO_MD4
  155. int md4_test(void)
  156. {
  157. Md4 md4;
  158. byte hash[MD4_DIGEST_SIZE];
  159. testVector a, b, c, d, e, f, g;
  160. testVector test_md4[7];
  161. int times = sizeof(test_md4) / sizeof(testVector), i;
  162. a.input = "";
  163. a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
  164. "\xc0";
  165. a.inLen = XSTRLEN(a.input);
  166. a.outLen = XSTRLEN(a.output);
  167. b.input = "a";
  168. b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
  169. "\x24";
  170. b.inLen = XSTRLEN(b.input);
  171. b.outLen = XSTRLEN(b.output);
  172. c.input = "abc";
  173. c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
  174. "\x9d";
  175. c.inLen = XSTRLEN(c.input);
  176. c.outLen = XSTRLEN(c.output);
  177. d.input = "message digest";
  178. d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
  179. "\x4b";
  180. d.inLen = XSTRLEN(d.input);
  181. d.outLen = XSTRLEN(d.output);
  182. e.input = "abcdefghijklmnopqrstuvwxyz";
  183. e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
  184. "\xa9";
  185. e.inLen = XSTRLEN(e.input);
  186. e.outLen = XSTRLEN(e.output);
  187. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  188. "6789";
  189. f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
  190. "\xe4";
  191. f.inLen = XSTRLEN(f.input);
  192. f.outLen = XSTRLEN(f.output);
  193. g.input = "1234567890123456789012345678901234567890123456789012345678"
  194. "9012345678901234567890";
  195. g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
  196. "\x36";
  197. g.inLen = XSTRLEN(g.input);
  198. g.outLen = XSTRLEN(g.output);
  199. test_md4[0] = a;
  200. test_md4[1] = b;
  201. test_md4[2] = c;
  202. test_md4[3] = d;
  203. test_md4[4] = e;
  204. test_md4[5] = f;
  205. test_md4[6] = g;
  206. wc_InitMd4(&md4);
  207. for (i = 0; i < times; ++i) {
  208. wc_Md4Update(&md4, (byte*)test_md4[i].input, (word32)test_md4[i].inLen);
  209. wc_Md4Final(&md4, hash);
  210. if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0)
  211. return -205 - i;
  212. }
  213. return 0;
  214. }
  215. #endif /* NO_MD4 */
  216. #ifndef NO_MD5
  217. int md5_test(void)
  218. {
  219. int ret;
  220. wc_Md5 md5;
  221. byte hash[WC_MD5_DIGEST_SIZE];
  222. testVector a, b, c, d, e;
  223. testVector test_md5[5];
  224. int times = sizeof(test_md5) / sizeof(testVector), i;
  225. a.input = "abc";
  226. a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  227. "\x72";
  228. a.inLen = XSTRLEN(a.input);
  229. a.outLen = XSTRLEN(a.output);
  230. b.input = "message digest";
  231. b.output = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
  232. "\xd0";
  233. b.inLen = XSTRLEN(b.input);
  234. b.outLen = XSTRLEN(b.output);
  235. c.input = "abcdefghijklmnopqrstuvwxyz";
  236. c.output = "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
  237. "\x3b";
  238. c.inLen = XSTRLEN(c.input);
  239. c.outLen = XSTRLEN(c.output);
  240. d.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  241. "6789";
  242. d.output = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
  243. "\x9f";
  244. d.inLen = XSTRLEN(d.input);
  245. d.outLen = XSTRLEN(d.output);
  246. e.input = "1234567890123456789012345678901234567890123456789012345678"
  247. "9012345678901234567890";
  248. e.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  249. "\x7a";
  250. e.inLen = XSTRLEN(e.input);
  251. e.outLen = XSTRLEN(e.output);
  252. test_md5[0] = a;
  253. test_md5[1] = b;
  254. test_md5[2] = c;
  255. test_md5[3] = d;
  256. test_md5[4] = e;
  257. ret = wc_InitMd5(&md5);
  258. if (ret) {
  259. return ret;
  260. }
  261. for (i = 0; i < times; ++i) {
  262. ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
  263. (word32)test_md5[i].inLen);
  264. if (ret) {
  265. return ret;
  266. }
  267. ret = wc_Md5Final(&md5, hash);
  268. if (ret) {
  269. return ret;
  270. }
  271. if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0)
  272. return -5 - i;
  273. }
  274. wc_Md5Free(&md5);
  275. return 0;
  276. }
  277. #endif /* NO_MD5 */
  278. #ifndef NO_SHA
  279. int sha_test(void)
  280. {
  281. wc_Sha sha;
  282. byte hash[WC_SHA_DIGEST_SIZE];
  283. testVector a, b, c, d;
  284. testVector test_sha[4];
  285. int ret = 0;
  286. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  287. a.input = "abc";
  288. a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  289. "\x6C\x9C\xD0\xD8\x9D";
  290. a.inLen = XSTRLEN(a.input);
  291. a.outLen = XSTRLEN(a.output);
  292. b.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  293. b.output = "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
  294. "\xE5\xE5\x46\x70\xF1";
  295. b.inLen = XSTRLEN(b.input);
  296. b.outLen = XSTRLEN(b.output);
  297. c.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  298. "aaaaaa";
  299. c.output = "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
  300. "\x2A\x25\xEC\x64\x4D";
  301. c.inLen = XSTRLEN(c.input);
  302. c.outLen = XSTRLEN(c.output);
  303. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  304. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  305. "aaaaaaaaaa";
  306. d.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  307. "\x53\x99\x5E\x26\xA0";
  308. d.inLen = XSTRLEN(d.input);
  309. d.outLen = XSTRLEN(d.output);
  310. test_sha[0] = a;
  311. test_sha[1] = b;
  312. test_sha[2] = c;
  313. test_sha[3] = d;
  314. ret = wc_InitSha(&sha);
  315. if (ret != 0)
  316. return ret;
  317. for (i = 0; i < times; ++i) {
  318. wc_ShaUpdate(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen);
  319. wc_ShaFinal(&sha, hash);
  320. if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0)
  321. return -10 - i;
  322. }
  323. wc_ShaFree(&sha);
  324. return 0;
  325. }
  326. #endif /* NO_SHA */
  327. #ifdef WOLFSSL_SHA224
  328. int sha224_test(void)
  329. {
  330. wc_Sha224 sha;
  331. byte hash[WC_SHA224_DIGEST_SIZE];
  332. testVector a, b;
  333. testVector test_sha[2];
  334. int ret;
  335. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  336. a.input = "abc";
  337. a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55"
  338. "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  339. a.inLen = XSTRLEN(a.input);
  340. a.outLen = WC_SHA224_DIGEST_SIZE;
  341. b.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  342. b.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  343. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  344. b.inLen = XSTRLEN(b.input);
  345. b.outLen = WC_SHA224_DIGEST_SIZE;
  346. test_sha[0] = a;
  347. test_sha[1] = b;
  348. ret = wc_InitSha224(&sha);
  349. if (ret != 0)
  350. return -4005;
  351. for (i = 0; i < times; ++i) {
  352. ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen);
  353. if (ret != 0)
  354. return ret;
  355. ret = wc_Sha224Final(&sha, hash);
  356. if (ret != 0)
  357. return ret;
  358. if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  359. return -10 - i;
  360. }
  361. wc_Sha224Free(&sha);
  362. return 0;
  363. }
  364. #endif
  365. #ifndef NO_SHA256
  366. int sha256_test(void)
  367. {
  368. wc_Sha256 sha;
  369. byte hash[WC_SHA256_DIGEST_SIZE];
  370. testVector a, b;
  371. testVector test_sha[2];
  372. int ret;
  373. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  374. a.input = "abc";
  375. a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  376. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  377. "\x15\xAD";
  378. a.inLen = XSTRLEN(a.input);
  379. a.outLen = XSTRLEN(a.output);
  380. b.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  381. b.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  382. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  383. "\x06\xC1";
  384. b.inLen = XSTRLEN(b.input);
  385. b.outLen = XSTRLEN(b.output);
  386. test_sha[0] = a;
  387. test_sha[1] = b;
  388. ret = wc_InitSha256(&sha);
  389. if (ret != 0)
  390. return ret;
  391. for (i = 0; i < times; ++i) {
  392. ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen);
  393. if (ret != 0)
  394. return ret;
  395. ret = wc_Sha256Final(&sha, hash);
  396. if (ret != 0)
  397. return ret;
  398. if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0)
  399. return -10 - i;
  400. }
  401. wc_Sha256Free(&sha);
  402. return 0;
  403. }
  404. #endif
  405. #ifdef WOLFSSL_SHA512
  406. int sha512_test(void)
  407. {
  408. wc_Sha512 sha;
  409. byte hash[WC_SHA512_DIGEST_SIZE];
  410. testVector a, b;
  411. testVector test_sha[2];
  412. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  413. int ret;
  414. a.input = "abc";
  415. a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  416. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  417. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  418. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  419. "\xa5\x4c\xa4\x9f";
  420. a.inLen = XSTRLEN(a.input);
  421. a.outLen = XSTRLEN(a.output);
  422. b.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  423. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  424. b.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  425. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  426. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  427. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  428. "\x87\x4b\xe9\x09";
  429. b.inLen = XSTRLEN(b.input);
  430. b.outLen = XSTRLEN(b.output);
  431. test_sha[0] = a;
  432. test_sha[1] = b;
  433. ret = wc_InitSha512(&sha);
  434. if (ret != 0)
  435. return ret;
  436. for (i = 0; i < times; ++i) {
  437. ret = wc_Sha512Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen);
  438. if (ret != 0)
  439. return ret;
  440. ret = wc_Sha512Final(&sha, hash);
  441. if (ret != 0)
  442. return ret;
  443. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  444. return -10 - i;
  445. }
  446. wc_Sha512Free(&sha);
  447. return 0;
  448. }
  449. #endif
  450. #ifdef WOLFSSL_SHA384
  451. int sha384_test(void)
  452. {
  453. wc_Sha384 sha;
  454. byte hash[WC_SHA384_DIGEST_SIZE];
  455. testVector a, b;
  456. testVector test_sha[2];
  457. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  458. int ret;
  459. a.input = "abc";
  460. a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  461. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  462. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  463. "\xc8\x25\xa7";
  464. a.inLen = XSTRLEN(a.input);
  465. a.outLen = XSTRLEN(a.output);
  466. b.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  467. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  468. b.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  469. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  470. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  471. "\x74\x60\x39";
  472. b.inLen = XSTRLEN(b.input);
  473. b.outLen = XSTRLEN(b.output);
  474. test_sha[0] = a;
  475. test_sha[1] = b;
  476. ret = wc_InitSha384(&sha);
  477. if (ret != 0)
  478. return ret;
  479. for (i = 0; i < times; ++i) {
  480. ret = wc_Sha384Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen);
  481. if (ret != 0)
  482. return ret;
  483. ret = wc_Sha384Final(&sha, hash);
  484. if (ret != 0)
  485. return ret;
  486. if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  487. return -10 - i;
  488. }
  489. wc_Sha384Free(&sha);
  490. return 0;
  491. }
  492. #endif
  493. #ifdef WOLFSSL_RIPEMD
  494. int ripemd_test(void)
  495. {
  496. RipeMd ripemd;
  497. int ret;
  498. byte hash[RIPEMD_DIGEST_SIZE];
  499. testVector a, b, c, d;
  500. testVector test_ripemd[4];
  501. int times = sizeof(test_ripemd) / sizeof(struct testVector), i;
  502. a.input = "abc";
  503. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  504. "\xb0\x87\xf1\x5a\x0b\xfc";
  505. a.inLen = XSTRLEN(a.input);
  506. a.outLen = XSTRLEN(a.output);
  507. b.input = "message digest";
  508. b.output = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
  509. "\x5f\xfa\x21\x59\x5f\x36";
  510. b.inLen = XSTRLEN(b.input);
  511. b.outLen = XSTRLEN(b.output);
  512. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  513. c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
  514. "\xf4\x9a\xda\x62\xeb\x2b";
  515. c.inLen = XSTRLEN(c.input);
  516. c.outLen = XSTRLEN(c.output);
  517. d.input = "12345678901234567890123456789012345678901234567890123456"
  518. "789012345678901234567890";
  519. d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
  520. "\x82\xbf\x63\x32\x6b\xfb";
  521. d.inLen = XSTRLEN(d.input);
  522. d.outLen = XSTRLEN(d.output);
  523. test_ripemd[0] = a;
  524. test_ripemd[1] = b;
  525. test_ripemd[2] = c;
  526. test_ripemd[3] = d;
  527. ret = wc_InitRipeMd(&ripemd);
  528. if (ret) {
  529. return ret;
  530. }
  531. for (i = 0; i < times; ++i) {
  532. ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
  533. (word32)test_ripemd[i].inLen);
  534. if (ret) {
  535. return ret;
  536. }
  537. ret = wc_RipeMdFinal(&ripemd, hash);
  538. if (ret) {
  539. return ret;
  540. }
  541. if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
  542. return -10 - i;
  543. }
  544. return 0;
  545. }
  546. #endif /* WOLFSSL_RIPEMD */
  547. #if !defined(NO_HMAC) && !defined(NO_MD5)
  548. int hmac_md5_test(void)
  549. {
  550. Hmac hmac;
  551. byte hash[WC_MD5_DIGEST_SIZE];
  552. const char* keys[]=
  553. {
  554. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  555. "Jefe",
  556. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  557. };
  558. testVector a, b, c;
  559. testVector test_hmac[3];
  560. int ret;
  561. int times = sizeof(test_hmac) / sizeof(testVector), i;
  562. a.input = "Hi There";
  563. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  564. "\x9d";
  565. a.inLen = XSTRLEN(a.input);
  566. a.outLen = XSTRLEN(a.output);
  567. b.input = "what do ya want for nothing?";
  568. b.output = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
  569. "\x38";
  570. b.inLen = XSTRLEN(b.input);
  571. b.outLen = XSTRLEN(b.output);
  572. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  573. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  574. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  575. "\xDD\xDD\xDD\xDD\xDD\xDD";
  576. c.output = "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
  577. "\xf6";
  578. c.inLen = XSTRLEN(c.input);
  579. c.outLen = XSTRLEN(c.output);
  580. test_hmac[0] = a;
  581. test_hmac[1] = b;
  582. test_hmac[2] = c;
  583. ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
  584. if (ret != 0)
  585. return -20009;
  586. for (i = 0; i < times; ++i) {
  587. #if defined(HAVE_FIPS)
  588. if (i == 1)
  589. continue; /* fips not allowed */
  590. #endif
  591. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
  592. if (ret != 0)
  593. return -4014;
  594. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  595. (word32)test_hmac[i].inLen);
  596. if (ret != 0)
  597. return -4015;
  598. ret = wc_HmacFinal(&hmac, hash);
  599. if (ret != 0)
  600. return -4016;
  601. if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0)
  602. return -20 - i;
  603. }
  604. wc_HmacFree(&hmac);
  605. return 0;
  606. }
  607. #endif
  608. #if !defined(NO_HMAC) && !defined(NO_SHA)
  609. int hmac_sha_test(void)
  610. {
  611. Hmac hmac;
  612. byte hash[WC_SHA_DIGEST_SIZE];
  613. const char* keys[]=
  614. {
  615. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  616. "\x0b\x0b\x0b",
  617. "Jefe",
  618. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  619. "\xAA\xAA\xAA"
  620. };
  621. testVector a, b, c;
  622. testVector test_hmac[3];
  623. int ret;
  624. int times = sizeof(test_hmac) / sizeof(testVector), i;
  625. a.input = "Hi There";
  626. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  627. "\x8e\xf1\x46\xbe\x00";
  628. a.inLen = XSTRLEN(a.input);
  629. a.outLen = XSTRLEN(a.output);
  630. b.input = "what do ya want for nothing?";
  631. b.output = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf"
  632. "\x9c\x25\x9a\x7c\x79";
  633. b.inLen = XSTRLEN(b.input);
  634. b.outLen = XSTRLEN(b.output);
  635. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  636. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  637. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  638. "\xDD\xDD\xDD\xDD\xDD\xDD";
  639. c.output = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b"
  640. "\x4f\x63\xf1\x75\xd3";
  641. c.inLen = XSTRLEN(c.input);
  642. c.outLen = XSTRLEN(c.output);
  643. test_hmac[0] = a;
  644. test_hmac[1] = b;
  645. test_hmac[2] = c;
  646. ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
  647. if (ret != 0)
  648. return -20009;
  649. for (i = 0; i < times; ++i) {
  650. #if defined(HAVE_FIPS)
  651. if (i == 1)
  652. continue; /* fips not allowed */
  653. #endif
  654. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
  655. if (ret != 0)
  656. return -4017;
  657. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  658. (word32)test_hmac[i].inLen);
  659. if (ret != 0)
  660. return -4018;
  661. ret = wc_HmacFinal(&hmac, hash);
  662. if (ret != 0)
  663. return -4019;
  664. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0)
  665. return -20 - i;
  666. }
  667. wc_HmacFree(&hmac);
  668. return 0;
  669. }
  670. #endif
  671. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  672. int hmac_sha224_test(void)
  673. {
  674. Hmac hmac;
  675. byte hash[WC_SHA224_DIGEST_SIZE];
  676. const char* keys[]=
  677. {
  678. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  679. "\x0b\x0b\x0b",
  680. "Jefe",
  681. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  682. "\xAA\xAA\xAA"
  683. };
  684. testVector a, b, c;
  685. testVector test_hmac[3];
  686. int ret;
  687. int times = sizeof(test_hmac) / sizeof(testVector), i;
  688. a.input = "Hi There";
  689. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  690. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  691. a.inLen = XSTRLEN(a.input);
  692. a.outLen = WC_SHA224_DIGEST_SIZE;
  693. b.input = "what do ya want for nothing?";
  694. b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
  695. "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
  696. b.inLen = XSTRLEN(b.input);
  697. b.outLen = WC_SHA224_DIGEST_SIZE;
  698. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  699. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  700. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  701. "\xDD\xDD\xDD\xDD\xDD\xDD";
  702. c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
  703. "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
  704. c.inLen = XSTRLEN(c.input);
  705. c.outLen = WC_SHA224_DIGEST_SIZE;
  706. test_hmac[0] = a;
  707. test_hmac[1] = b;
  708. test_hmac[2] = c;
  709. ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
  710. if (ret != 0)
  711. return -20009;
  712. for (i = 0; i < times; ++i) {
  713. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  714. if (i == 1)
  715. continue; /* cavium can't handle short keys, fips not allowed */
  716. #endif
  717. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i],(word32)XSTRLEN(keys[i]));
  718. if (ret != 0)
  719. return -4021;
  720. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  721. (word32)test_hmac[i].inLen);
  722. if (ret != 0)
  723. return -4022;
  724. ret = wc_HmacFinal(&hmac, hash);
  725. if (ret != 0)
  726. return -4023;
  727. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  728. return -20 - i;
  729. }
  730. wc_HmacFree(&hmac);
  731. return 0;
  732. }
  733. #endif
  734. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  735. int hmac_sha256_test(void)
  736. {
  737. Hmac hmac;
  738. byte hash[WC_SHA256_DIGEST_SIZE];
  739. const char* keys[]=
  740. {
  741. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  742. "\x0b\x0b\x0b",
  743. "Jefe",
  744. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  745. "\xAA\xAA\xAA"
  746. };
  747. testVector a, b, c;
  748. testVector test_hmac[3];
  749. int ret;
  750. int times = sizeof(test_hmac) / sizeof(testVector), i;
  751. a.input = "Hi There";
  752. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  753. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  754. "\xcf\xf7";
  755. a.inLen = XSTRLEN(a.input);
  756. a.outLen = XSTRLEN(a.output);
  757. b.input = "what do ya want for nothing?";
  758. b.output = "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75"
  759. "\xc7\x5a\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec"
  760. "\x38\x43";
  761. b.inLen = XSTRLEN(b.input);
  762. b.outLen = XSTRLEN(b.output);
  763. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  764. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  765. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  766. "\xDD\xDD\xDD\xDD\xDD\xDD";
  767. c.output = "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81"
  768. "\xa7\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5"
  769. "\x65\xfe";
  770. c.inLen = XSTRLEN(c.input);
  771. c.outLen = XSTRLEN(c.output);
  772. test_hmac[0] = a;
  773. test_hmac[1] = b;
  774. test_hmac[2] = c;
  775. ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
  776. if (ret != 0)
  777. return -20009;
  778. for (i = 0; i < times; ++i) {
  779. #if defined(HAVE_FIPS)
  780. if (i == 1)
  781. continue; /* fips not allowed */
  782. #endif
  783. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i],
  784. (word32)XSTRLEN(keys[i]));
  785. if (ret != 0)
  786. return -4020;
  787. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  788. (word32)test_hmac[i].inLen);
  789. if (ret != 0)
  790. return -4021;
  791. ret = wc_HmacFinal(&hmac, hash);
  792. if (ret != 0)
  793. return -4022;
  794. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0)
  795. return -20 - i;
  796. }
  797. wc_HmacFree(&hmac);
  798. return 0;
  799. }
  800. #endif
  801. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  802. int hmac_sha384_test(void)
  803. {
  804. Hmac hmac;
  805. byte hash[WC_SHA384_DIGEST_SIZE];
  806. const char* keys[]=
  807. {
  808. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  809. "\x0b\x0b\x0b",
  810. "Jefe",
  811. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  812. "\xAA\xAA\xAA"
  813. };
  814. testVector a, b, c;
  815. testVector test_hmac[3];
  816. int ret;
  817. int times = sizeof(test_hmac) / sizeof(testVector), i;
  818. a.input = "Hi There";
  819. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  820. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  821. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  822. "\xfa\x9c\xb6";
  823. a.inLen = XSTRLEN(a.input);
  824. a.outLen = XSTRLEN(a.output);
  825. b.input = "what do ya want for nothing?";
  826. b.output = "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b"
  827. "\x1b\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22"
  828. "\x44\x5e\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa"
  829. "\xb2\x16\x49";
  830. b.inLen = XSTRLEN(b.input);
  831. b.outLen = XSTRLEN(b.output);
  832. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  833. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  834. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  835. "\xDD\xDD\xDD\xDD\xDD\xDD";
  836. c.output = "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8"
  837. "\x6f\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66"
  838. "\x14\x4b\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01"
  839. "\xa3\x4f\x27";
  840. c.inLen = XSTRLEN(c.input);
  841. c.outLen = XSTRLEN(c.output);
  842. test_hmac[0] = a;
  843. test_hmac[1] = b;
  844. test_hmac[2] = c;
  845. ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
  846. if (ret != 0)
  847. return -20009;
  848. for (i = 0; i < times; ++i) {
  849. #if defined(HAVE_FIPS)
  850. if (i == 1)
  851. continue; /* fips not allowed */
  852. #endif
  853. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i],
  854. (word32)XSTRLEN(keys[i]));
  855. if (ret != 0)
  856. return -4023;
  857. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  858. (word32)test_hmac[i].inLen);
  859. if (ret != 0)
  860. return -4024;
  861. ret = wc_HmacFinal(&hmac, hash);
  862. if (ret != 0)
  863. return -4025;
  864. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  865. return -20 - i;
  866. }
  867. wc_HmacFree(&hmac);
  868. return 0;
  869. }
  870. #endif