hash.c 30 KB

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