2
0

hash.c 30 KB

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