sha3.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*!
  2. \ingroup SHA
  3. \brief This function initializes SHA3-224. This is automatically
  4. called by wc_Sha3_224Hash.
  5. \return 0 Returned upon successfully initializing
  6. \param sha3 pointer to the sha3 structure to use for encryption
  7. _Example_
  8. \code
  9. wc_Sha3 sha3[1];
  10. if ((ret = wc_InitSha3_224(sha3, NULL, INVALID_DEVID)) != 0) {
  11. WOLFSSL_MSG("wc_InitSha3_224 failed");
  12. }
  13. else {
  14. wc_Sha3_224_Update(sha3, data, len);
  15. wc_Sha3_224_Final(sha3, hash);
  16. }
  17. \endcode
  18. \sa wc_Sha3_224Hash
  19. \sa wc_Sha3_224_Update
  20. \sa wc_Sha3_224_Final
  21. */
  22. int wc_InitSha3_224(wc_Sha3* sha3, void* heap, int devId);
  23. /*!
  24. \ingroup SHA
  25. \brief Can be called to continually hash the provided byte
  26. array of length len.
  27. \return 0 Returned upon successfully adding the data to the digest.
  28. \param sha3 pointer to the sha3 structure to use for encryption
  29. \param data the data to be hashed
  30. \param len length of data to be hashed
  31. _Example_
  32. \code
  33. wc_Sha3 sha3[1];
  34. byte data[] = { Data to be hashed };
  35. word32 len = sizeof(data);
  36. if ((ret = wc_InitSha3_224(sha3, NULL, INVALID_DEVID)) != 0) {
  37. WOLFSSL_MSG("wc_InitSha3_224 failed");
  38. }
  39. else {
  40. wc_Sha3_224_Update(sha3, data, len);
  41. wc_Sha3_224_Final(sha3, hash);
  42. }
  43. \endcode
  44. \sa wc_Sha3_224Hash
  45. \sa wc_Sha3_224_Final
  46. \sa wc_InitSha3_224
  47. */
  48. int wc_Sha3_224_Update(wc_Sha3* sha, const byte* data, word32 len);
  49. /*!
  50. \ingroup SHA
  51. \brief Finalizes hashing of data. Result is placed into hash.
  52. Resets state of sha3 struct.
  53. \return 0 Returned upon successfully finalizing.
  54. \param sha3 pointer to the sha3 structure to use for encryption
  55. \param hash Byte array to hold hash value.
  56. _Example_
  57. \code
  58. wc_Sha3 sha3[1];
  59. byte data[] = { Data to be hashed };
  60. word32 len = sizeof(data);
  61. if ((ret = wc_InitSha3_224(sha3, NULL, INVALID_DEVID)) != 0) {
  62. WOLFSSL_MSG("wc_InitSha3_224 failed");
  63. }
  64. else {
  65. wc_Sha3_224_Update(sha3, data, len);
  66. wc_Sha3_224_Final(sha3, hash);
  67. }
  68. \endcode
  69. \sa wc_Sha3_224Hash
  70. \sa wc_Sha3_224_GetHash
  71. \sa wc_InitSha3_224
  72. */
  73. int wc_Sha3_224_Final(wc_Sha3* sha3, byte* hash);
  74. /*!
  75. \ingroup SHA
  76. \brief Resets the wc_Sha3 structure. Note: this is only supported
  77. if you have WOLFSSL_TI_HASH defined.
  78. \return none No returns.
  79. \param sha3 Pointer to the sha3 structure to be freed.
  80. _Example_
  81. \code
  82. wc_Sha3 sha3;
  83. byte data[] = { Data to be hashed };
  84. word32 len = sizeof(data);
  85. if ((ret = wc_InitSha3_224(&sha3, NULL, INVALID_DEVID)) != 0) {
  86. WOLFSSL_MSG("wc_InitSha3_224 failed");
  87. }
  88. else {
  89. wc_Sha3_224_Update(&sha3, data, len);
  90. wc_Sha3_224_Final(&sha3, hash);
  91. wc_Sha3_224_Free(&sha3);
  92. }
  93. \endcode
  94. \sa wc_InitSha3_224
  95. \sa wc_Sha3_224_Update
  96. \sa wc_Sha3_224_Final
  97. */
  98. void wc_Sha3_224_Free(wc_Sha3*);
  99. /*!
  100. \ingroup SHA
  101. \brief Gets hash data. Result is placed into hash. Does not
  102. reset state of sha3 struct.
  103. \return 0 Returned upon successful copying of the hash.
  104. \param sha3 pointer to the sha3 structure to use for encryption
  105. \param hash Byte array to hold hash value.
  106. _Example_
  107. \code
  108. wc_Sha3 sha3[1];
  109. if ((ret = wc_InitSha3_224(sha3, NULL, INVALID_DEVID)) != 0) {
  110. WOLFSSL_MSG("wc_InitSha3_224 failed");
  111. }
  112. else {
  113. wc_Sha3_224_Update(sha3, data, len);
  114. wc_Sha3_224_GetHash(sha3, hash);
  115. }
  116. \endcode
  117. \sa wc_Sha3_224Hash
  118. \sa wc_Sha3_224_Final
  119. \sa wc_InitSha3_224
  120. \sa wc_Sha3_224_Copy
  121. */
  122. int wc_Sha3_224_GetHash(wc_Sha3* sha3, byte* hash);
  123. /*!
  124. \ingroup SHA
  125. \brief Copy the state of the hash.
  126. \return 0 Returned upon successful copying.
  127. \param sha3 pointer to the sha3 structure to copy
  128. \param dst pointer to the sha3 structure to copy into
  129. _Example_
  130. \code
  131. wc_Sha3 sha3[1];
  132. wc_Sha3 sha3_dup[1];
  133. if ((ret = wc_InitSha3_224(sha3, NULL, INVALID_DEVID)) != 0) {
  134. WOLFSSL_MSG("wc_InitSha3_224 failed");
  135. }
  136. else {
  137. wc_Sha3_224_Update(sha3, data, len);
  138. wc_Sha3_224_Copy(sha3, sha3_dup);
  139. }
  140. \endcode
  141. \sa wc_Sha3_224Hash
  142. \sa wc_Sha3_224_Final
  143. \sa wc_InitSha3_224
  144. \sa wc_Sha3_224_GetHash
  145. */
  146. int wc_Sha3_224_Copy(wc_Sha3* sha3, wc_Sha3* dst);
  147. /*!
  148. \ingroup SHA
  149. \brief This function initializes SHA3-256. This is automatically
  150. called by wc_Sha3_256Hash.
  151. \return 0 Returned upon successfully initializing
  152. \param sha3 pointer to the sha3 structure to use for encryption
  153. _Example_
  154. \code
  155. wc_Sha3 sha3[1];
  156. if ((ret = wc_InitSha3_256(sha3, NULL, INVALID_DEVID)) != 0) {
  157. WOLFSSL_MSG("wc_InitSha3_256 failed");
  158. }
  159. else {
  160. wc_Sha3_256_Update(sha3, data, len);
  161. wc_Sha3_256_Final(sha3, hash);
  162. }
  163. \endcode
  164. \sa wc_Sha3_256Hash
  165. \sa wc_Sha3_256_Update
  166. \sa wc_Sha3_256_Final
  167. */
  168. int wc_InitSha3_256(wc_Sha3* sha3, void* heap, int devId);
  169. /*!
  170. \ingroup SHA
  171. \brief Can be called to continually hash the provided byte
  172. array of length len.
  173. \return 0 Returned upon successfully adding the data to the digest.
  174. \param sha3 pointer to the sha3 structure to use for encryption
  175. \param data the data to be hashed
  176. \param len length of data to be hashed
  177. _Example_
  178. \code
  179. wc_Sha3 sha3[1];
  180. byte data[] = { Data to be hashed };
  181. word32 len = sizeof(data);
  182. if ((ret = wc_InitSha3_256(sha3, NULL, INVALID_DEVID)) != 0) {
  183. WOLFSSL_MSG("wc_InitSha3_256 failed");
  184. }
  185. else {
  186. wc_Sha3_256_Update(sha3, data, len);
  187. wc_Sha3_256_Final(sha3, hash);
  188. }
  189. \endcode
  190. \sa wc_Sha3_256Hash
  191. \sa wc_Sha3_256_Final
  192. \sa wc_InitSha3_256
  193. */
  194. int wc_Sha3_256_Update(wc_Sha3* sha, const byte* data, word32 len);
  195. /*!
  196. \ingroup SHA
  197. \brief Finalizes hashing of data. Result is placed into hash.
  198. Resets state of sha3 struct.
  199. \return 0 Returned upon successfully finalizing.
  200. \param sha3 pointer to the sha3 structure to use for encryption
  201. \param hash Byte array to hold hash value.
  202. _Example_
  203. \code
  204. wc_Sha3 sha3[1];
  205. byte data[] = { Data to be hashed };
  206. word32 len = sizeof(data);
  207. if ((ret = wc_InitSha3_256(sha3, NULL, INVALID_DEVID)) != 0) {
  208. WOLFSSL_MSG("wc_InitSha3_256 failed");
  209. }
  210. else {
  211. wc_Sha3_256_Update(sha3, data, len);
  212. wc_Sha3_256_Final(sha3, hash);
  213. }
  214. \endcode
  215. \sa wc_Sha3_256Hash
  216. \sa wc_Sha3_256_GetHash
  217. \sa wc_InitSha3_256
  218. */
  219. int wc_Sha3_256_Final(wc_Sha3* sha3, byte* hash);
  220. /*!
  221. \ingroup SHA
  222. \brief Resets the wc_Sha3 structure. Note: this is only supported
  223. if you have WOLFSSL_TI_HASH defined.
  224. \return none No returns.
  225. \param sha3 Pointer to the sha3 structure to be freed.
  226. _Example_
  227. \code
  228. wc_Sha3 sha3;
  229. byte data[] = { Data to be hashed };
  230. word32 len = sizeof(data);
  231. if ((ret = wc_InitSha3_256(&sha3, NULL, INVALID_DEVID)) != 0) {
  232. WOLFSSL_MSG("wc_InitSha3_256 failed");
  233. }
  234. else {
  235. wc_Sha3_256_Update(&sha3, data, len);
  236. wc_Sha3_256_Final(&sha3, hash);
  237. wc_Sha3_256_Free(&sha3);
  238. }
  239. \endcode
  240. \sa wc_InitSha3_256
  241. \sa wc_Sha3_256_Update
  242. \sa wc_Sha3_256_Final
  243. */
  244. void wc_Sha3_256_Free(wc_Sha3*);
  245. /*!
  246. \ingroup SHA
  247. \brief Gets hash data. Result is placed into hash. Does not
  248. reset state of sha3 struct.
  249. \return 0 Returned upon successful copying of the hash.
  250. \param sha3 pointer to the sha3 structure to use for encryption
  251. \param hash Byte array to hold hash value.
  252. _Example_
  253. \code
  254. wc_Sha3 sha3[1];
  255. if ((ret = wc_InitSha3_256(sha3, NULL, INVALID_DEVID)) != 0) {
  256. WOLFSSL_MSG("wc_InitSha3_256 failed");
  257. }
  258. else {
  259. wc_Sha3_256_Update(sha3, data, len);
  260. wc_Sha3_256_GetHash(sha3, hash);
  261. }
  262. \endcode
  263. \sa wc_Sha3_256Hash
  264. \sa wc_Sha3_256_Final
  265. \sa wc_InitSha3_256
  266. \sa wc_Sha3_256_Copy
  267. */
  268. int wc_Sha3_256_GetHash(wc_Sha3* sha3, byte* hash);
  269. /*!
  270. \ingroup SHA
  271. \brief Copy the state of the hash.
  272. \return 0 Returned upon successful copying.
  273. \param sha3 pointer to the sha3 structure to copy
  274. \param dst pointer to the sha3 structure to copy into
  275. _Example_
  276. \code
  277. wc_Sha3 sha3[1];
  278. wc_Sha3 sha3_dup[1];
  279. if ((ret = wc_InitSha3_256(sha3, NULL, INVALID_DEVID)) != 0) {
  280. WOLFSSL_MSG("wc_InitSha3_256 failed");
  281. }
  282. else {
  283. wc_Sha3_256_Update(sha3, data, len);
  284. wc_Sha3_256_Copy(sha3, sha3_dup);
  285. }
  286. \endcode
  287. \sa wc_Sha3_256Hash
  288. \sa wc_Sha3_256_Final
  289. \sa wc_InitSha3_256
  290. \sa wc_Sha3_256_GetHash
  291. */
  292. int wc_Sha3_256_Copy(wc_Sha3* sha3, wc_Sha3* dst);
  293. /*!
  294. \ingroup SHA
  295. \brief This function initializes SHA3-384. This is automatically
  296. called by wc_Sha3_384Hash.
  297. \return 0 Returned upon successfully initializing
  298. \param sha3 pointer to the sha3 structure to use for encryption
  299. _Example_
  300. \code
  301. wc_Sha3 sha3[1];
  302. if ((ret = wc_InitSha3_384(sha3, NULL, INVALID_DEVID)) != 0) {
  303. WOLFSSL_MSG("wc_InitSha3_384 failed");
  304. }
  305. else {
  306. wc_Sha3_384_Update(sha3, data, len);
  307. wc_Sha3_384_Final(sha3, hash);
  308. }
  309. \endcode
  310. \sa wc_Sha3_384Hash
  311. \sa wc_Sha3_384_Update
  312. \sa wc_Sha3_384_Final
  313. */
  314. int wc_InitSha3_384(wc_Sha3* sha3, void* heap, int devId);
  315. /*!
  316. \ingroup SHA
  317. \brief Can be called to continually hash the provided byte
  318. array of length len.
  319. \return 0 Returned upon successfully adding the data to the digest.
  320. \param sha3 pointer to the sha3 structure to use for encryption
  321. \param data the data to be hashed
  322. \param len length of data to be hashed
  323. _Example_
  324. \code
  325. wc_Sha3 sha3[1];
  326. byte data[] = { Data to be hashed };
  327. word32 len = sizeof(data);
  328. if ((ret = wc_InitSha3_384(sha3, NULL, INVALID_DEVID)) != 0) {
  329. WOLFSSL_MSG("wc_InitSha3_384 failed");
  330. }
  331. else {
  332. wc_Sha3_384_Update(sha3, data, len);
  333. wc_Sha3_384_Final(sha3, hash);
  334. }
  335. \endcode
  336. \sa wc_Sha3_384Hash
  337. \sa wc_Sha3_384_Final
  338. \sa wc_InitSha3_384
  339. */
  340. int wc_Sha3_384_Update(wc_Sha3* sha, const byte* data, word32 len);
  341. /*!
  342. \ingroup SHA
  343. \brief Finalizes hashing of data. Result is placed into hash.
  344. Resets state of sha3 struct.
  345. \return 0 Returned upon successfully finalizing.
  346. \param sha3 pointer to the sha3 structure to use for encryption
  347. \param hash Byte array to hold hash value.
  348. _Example_
  349. \code
  350. wc_Sha3 sha3[1];
  351. byte data[] = { Data to be hashed };
  352. word32 len = sizeof(data);
  353. if ((ret = wc_InitSha3_384(sha3, NULL, INVALID_DEVID)) != 0) {
  354. WOLFSSL_MSG("wc_InitSha3_384 failed");
  355. }
  356. else {
  357. wc_Sha3_384_Update(sha3, data, len);
  358. wc_Sha3_384_Final(sha3, hash);
  359. }
  360. \endcode
  361. \sa wc_Sha3_384Hash
  362. \sa wc_Sha3_384_GetHash
  363. \sa wc_InitSha3_384
  364. */
  365. int wc_Sha3_384_Final(wc_Sha3* sha3, byte* hash);
  366. /*!
  367. \ingroup SHA
  368. \brief Resets the wc_Sha3 structure. Note: this is only supported
  369. if you have WOLFSSL_TI_HASH defined.
  370. \return none No returns.
  371. \param sha3 Pointer to the sha3 structure to be freed.
  372. _Example_
  373. \code
  374. wc_Sha3 sha3;
  375. byte data[] = { Data to be hashed };
  376. word32 len = sizeof(data);
  377. if ((ret = wc_InitSha3_384(&sha3, NULL, INVALID_DEVID)) != 0) {
  378. WOLFSSL_MSG("wc_InitSha3_384 failed");
  379. }
  380. else {
  381. wc_Sha3_384_Update(&sha3, data, len);
  382. wc_Sha3_384_Final(&sha3, hash);
  383. wc_Sha3_384_Free(&sha3);
  384. }
  385. \endcode
  386. \sa wc_InitSha3_384
  387. \sa wc_Sha3_384_Update
  388. \sa wc_Sha3_384_Final
  389. */
  390. void wc_Sha3_384_Free(wc_Sha3*);
  391. /*!
  392. \ingroup SHA
  393. \brief Gets hash data. Result is placed into hash. Does not
  394. reset state of sha3 struct.
  395. \return 0 Returned upon successful copying of the hash.
  396. \param sha3 pointer to the sha3 structure to use for encryption
  397. \param hash Byte array to hold hash value.
  398. _Example_
  399. \code
  400. wc_Sha3 sha3[1];
  401. if ((ret = wc_InitSha3_384(sha3, NULL, INVALID_DEVID)) != 0) {
  402. WOLFSSL_MSG("wc_InitSha3_38384ailed");
  403. }
  404. else {
  405. wc_Sha3_384_Update(sha3, data, len);
  406. wc_Sha3_384_GetHash(sha3, hash);
  407. }
  408. \endcode
  409. \sa wc_Sha3_384Hash
  410. \sa wc_Sha3_384_Final
  411. \sa wc_InitSha3_384
  412. \sa wc_Sha3_384_Copy
  413. */
  414. int wc_Sha3_384_GetHash(wc_Sha3* sha3, byte* hash);
  415. /*!
  416. \ingroup SHA
  417. \brief Copy the state of the hash.
  418. \return 0 Returned upon successful copying.
  419. \param sha3 pointer to the sha3 structure to copy
  420. \param dst pointer to the sha3 structure to copy into
  421. _Example_
  422. \code
  423. wc_Sha3 sha3[1];
  424. wc_Sha3 sha3_dup[1];
  425. if ((ret = wc_InitSha3_384(sha3, NULL, INVALID_DEVID)) != 0) {
  426. WOLFSSL_MSG("wc_InitSha3_384 failed");
  427. }
  428. else {
  429. wc_Sha3_384_Update(sha3, data, len);
  430. wc_Sha3_384_Copy(sha3, sha3_dup);
  431. }
  432. \endcode
  433. \sa wc_Sha3_384Hash
  434. \sa wc_Sha3_384_Final
  435. \sa wc_InitSha3_384
  436. \sa wc_Sha3_384_GetHash
  437. */
  438. int wc_Sha3_384_Copy(wc_Sha3* sha3, wc_Sha3* dst);
  439. /*!
  440. \ingroup SHA
  441. \brief This function initializes SHA3-512. This is automatically
  442. called by wc_Sha3_512Hash.
  443. \return 0 Returned upon successfully initializing
  444. \param sha3 pointer to the sha3 structure to use for encryption
  445. _Example_
  446. \code
  447. wc_Sha3 sha3[1];
  448. if ((ret = wc_InitSha3_512(sha3, NULL, INVALID_DEVID)) != 0) {
  449. WOLFSSL_MSG("wc_InitSha3_512 failed");
  450. }
  451. else {
  452. wc_Sha3_512_Update(sha3, data, len);
  453. wc_Sha3_512_Final(sha3, hash);
  454. }
  455. \endcode
  456. \sa wc_Sha3_512Hash
  457. \sa wc_Sha3_512_Update
  458. \sa wc_Sha3_512_Final
  459. */
  460. int wc_InitSha3_512(wc_Sha3* sha3, void* heap, int devId);
  461. /*!
  462. \ingroup SHA
  463. \brief Can be called to continually hash the provided byte
  464. array of length len.
  465. \return 0 Returned upon successfully adding the data to the digest.
  466. \param sha3 pointer to the sha3 structure to use for encryption
  467. \param data the data to be hashed
  468. \param len length of data to be hashed
  469. _Example_
  470. \code
  471. wc_Sha3 sha3[1];
  472. byte data[] = { Data to be hashed };
  473. word32 len = sizeof(data);
  474. if ((ret = wc_InitSha3_512(sha3, NULL, INVALID_DEVID)) != 0) {
  475. WOLFSSL_MSG("wc_InitSha3_512 failed");
  476. }
  477. else {
  478. wc_Sha3_512_Update(sha3, data, len);
  479. wc_Sha3_512_Final(sha3, hash);
  480. }
  481. \endcode
  482. \sa wc_Sha3_512Hash
  483. \sa wc_Sha3_512_Final
  484. \sa wc_InitSha3_512
  485. */
  486. int wc_Sha3_512_Update(wc_Sha3* sha, const byte* data, word32 len);
  487. /*!
  488. \ingroup SHA
  489. \brief Finalizes hashing of data. Result is placed into hash.
  490. Resets state of sha3 struct.
  491. \return 0 Returned upon successfully finalizing.
  492. \param sha3 pointer to the sha3 structure to use for encryption
  493. \param hash Byte array to hold hash value.
  494. _Example_
  495. \code
  496. wc_Sha3 sha3[1];
  497. byte data[] = { Data to be hashed };
  498. word32 len = sizeof(data);
  499. if ((ret = wc_InitSha3_512(sha3, NULL, INVALID_DEVID)) != 0) {
  500. WOLFSSL_MSG("wc_InitSha3_512 failed");
  501. }
  502. else {
  503. wc_Sha3_512_Update(sha3, data, len);
  504. wc_Sha3_512_Final(sha3, hash);
  505. }
  506. \endcode
  507. \sa wc_Sha3_512Hash
  508. \sa wc_Sha3_512_GetHash
  509. \sa wc_InitSha3_512
  510. */
  511. int wc_Sha3_512_Final(wc_Sha3* sha3, byte* hash);
  512. /*!
  513. \ingroup SHA
  514. \brief Resets the wc_Sha3 structure. Note: this is only supported
  515. if you have WOLFSSL_TI_HASH defined.
  516. \return none No returns.
  517. \param sha3 Pointer to the sha3 structure to be freed.
  518. _Example_
  519. \code
  520. wc_Sha3 sha3;
  521. byte data[] = { Data to be hashed };
  522. word32 len = sizeof(data);
  523. if ((ret = wc_InitSha3_512(&sha3, NULL, INVALID_DEVID)) != 0) {
  524. WOLFSSL_MSG("wc_InitSha3_512 failed");
  525. }
  526. else {
  527. wc_Sha3_512_Update(&sha3, data, len);
  528. wc_Sha3_512_Final(&sha3, hash);
  529. wc_Sha3_512_Free(&sha3);
  530. }
  531. \endcode
  532. \sa wc_InitSha3_512
  533. \sa wc_Sha3_512_Update
  534. \sa wc_Sha3_512_Final
  535. */
  536. void wc_Sha3_512_Free(wc_Sha3*);
  537. /*!
  538. \ingroup SHA
  539. \brief Gets hash data. Result is placed into hash. Does not
  540. reset state of sha3 struct.
  541. \return 0 Returned upon successful copying of the hash.
  542. \param sha3 pointer to the sha3 structure to use for encryption
  543. \param hash Byte array to hold hash value.
  544. _Example_
  545. \code
  546. wc_Sha3 sha3[1];
  547. if ((ret = wc_InitSha3_512(sha3, NULL, INVALID_DEVID)) != 0) {
  548. WOLFSSL_MSG("wc_InitSha3_512 failed");
  549. }
  550. else {
  551. wc_Sha3_512_Update(sha3, data, len);
  552. wc_Sha3_512_GetHash(sha3, hash);
  553. }
  554. \endcode
  555. \sa wc_Sha3_512Hash
  556. \sa wc_Sha3_512_Final
  557. \sa wc_InitSha3_512
  558. \sa wc_Sha3_512_Copy
  559. */
  560. int wc_Sha3_512_GetHash(wc_Sha3* sha3, byte* hash);
  561. /*!
  562. \ingroup SHA
  563. \brief Copy the state of the hash.
  564. \return 0 Returned upon successful copying.
  565. \param sha3 pointer to the sha3 structure to copy
  566. \param dst pointer to the sha3 structure to copy into
  567. _Example_
  568. \code
  569. wc_Sha3 sha3[1];
  570. wc_Sha3 sha3_dup[1];
  571. if ((ret = wc_InitSha3_512(sha3, NULL, INVALID_DEVID)) != 0) {
  572. WOLFSSL_MSG("wc_InitSha3_512 failed");
  573. }
  574. else {
  575. wc_Sha3_512_Update(sha3, data, len);
  576. wc_Sha3_512_Copy(sha3, sha3_dup);
  577. }
  578. \endcode
  579. \sa wc_Sha3_512Hash
  580. \sa wc_Sha3_512_Final
  581. \sa wc_InitSha3_512
  582. \sa wc_Sha3_512_GetHash
  583. */
  584. int wc_Sha3_512_Copy(wc_Sha3* sha3, wc_Sha3* dst);
  585. /*!
  586. \ingroup SHA
  587. \brief This function initializes SHAKE-128. This is automatically
  588. called by wc_Shake128Hash.
  589. \return 0 Returned upon successfully initializing
  590. \param shake pointer to the shake structure to use for encryption
  591. _Example_
  592. \code
  593. wc_Shake shake[1];
  594. if ((ret = wc_InitShake128(shake, NULL, INVALID_DEVID)) != 0) {
  595. WOLFSSL_MSG("wc_InitShake128 failed");
  596. }
  597. else {
  598. wc_Shake128_Update(shake, data, len);
  599. wc_Shake128_Final(shake, hash);
  600. }
  601. \endcode
  602. \sa wc_Shake128Hash
  603. \sa wc_Shake128_Update
  604. \sa wc_Shake128_Final
  605. */
  606. int wc_InitShake128(wc_Shake* shake, void* heap, int devId);
  607. /*!
  608. \ingroup SHA
  609. \brief Can be called to continually hash the provided byte
  610. array of length len.
  611. \return 0 Returned upon successfully adding the data to the digest.
  612. \param shake pointer to the shake structure to use for encryption
  613. \param data the data to be hashed
  614. \param len length of data to be hashed
  615. _Example_
  616. \code
  617. wc_Shake shake[1];
  618. byte data[] = { Data to be hashed };
  619. word32 len = sizeof(data);
  620. if ((ret = wc_InitShake128(shake, NULL, INVALID_DEVID)) != 0) {
  621. WOLFSSL_MSG("wc_InitShake128 failed");
  622. }
  623. else {
  624. wc_Shake128_Update(shake, data, len);
  625. wc_Shake128_Final(shake, hash);
  626. }
  627. \endcode
  628. \sa wc_Shake128Hash
  629. \sa wc_Shake128_Final
  630. \sa wc_InitShake128
  631. */
  632. int wc_Shake128_Update(wc_Shake* sha, const byte* data, word32 len);
  633. /*!
  634. \ingroup SHA
  635. \brief Finalizes hashing of data. Result is placed into hash.
  636. Resets state of shake struct.
  637. \return 0 Returned upon successfully finalizing.
  638. \param shake pointer to the shake structure to use for encryption
  639. \param hash Byte array to hold hash value.
  640. _Example_
  641. \code
  642. wc_Shake shake[1];
  643. byte data[] = { Data to be hashed };
  644. word32 len = sizeof(data);
  645. if ((ret = wc_InitShake128(shake, NULL, INVALID_DEVID)) != 0) {
  646. WOLFSSL_MSG("wc_InitShake128 failed");
  647. }
  648. else {
  649. wc_Shake128_Update(shake, data, len);
  650. wc_Shake128_Final(shake, hash);
  651. }
  652. \endcode
  653. \sa wc_Shake128Hash
  654. \sa wc_Shake128_GetHash
  655. \sa wc_InitShake128
  656. */
  657. int wc_Shake128_Final(wc_Shake* shake, byte* hash);
  658. /*!
  659. \ingroup SHA
  660. \brief Called to absorb the provided byte array of length len. Cannot
  661. be called incrementally.
  662. \return 0 Returned upon successfully absorbed the data.
  663. \param shake pointer to the shake structure to use for encryption
  664. \param data the data to be absorbed
  665. \param len length of data to be absorbed
  666. _Example_
  667. \code
  668. wc_Shake shake[1];
  669. byte data[] = { Data to be hashed };
  670. word32 len = sizeof(data);
  671. byte out[2 * WC_SHA3_128_BLOCK_SIZE];
  672. int blocks = 2;
  673. if ((ret = wc_InitShake128(shake, NULL, INVALID_DEVID)) != 0) {
  674. WOLFSSL_MSG("wc_InitShake128 failed");
  675. }
  676. else {
  677. wc_Shake128_Absorb(shake, data, len);
  678. wc_Shake128_SqueezeBlocks(shake, out, blocks);
  679. }
  680. \endcode
  681. \sa wc_Shake128_SqueezeBlocks
  682. \sa wc_InitShake128
  683. */
  684. int wc_Shake128_Absorb(wc_Shake* sha, const byte* data, word32 len);
  685. /*!
  686. \ingroup SHA
  687. \brief Squeeze out more blocks of data. Result is placed into out. Can be
  688. called inrementally.
  689. \return 0 Returned upon successfully squeezing.
  690. \param shake pointer to the shake structure to use for encryption
  691. \param hash Byte array to hold output.
  692. \param blocks Number of blocks to squeeze out. Each block is
  693. WC_SHA3_128_BLOCK_SIZE bytes in length.
  694. _Example_
  695. \code
  696. wc_Shake shake[1];
  697. byte data[] = { Data to be hashed };
  698. word32 len = sizeof(data);
  699. byte out[2 * WC_SHA3_128_BLOCK_SIZE];
  700. int blocks = 2;
  701. if ((ret = wc_InitShake128(shake, NULL, INVALID_DEVID)) != 0) {
  702. WOLFSSL_MSG("wc_InitShake128 failed");
  703. }
  704. else {
  705. wc_Shake128_Absorb(shake, data, len);
  706. wc_Shake128_SqueezeBlocks(shake, out, blocks);
  707. }
  708. \endcode
  709. \sa wc_Shake128_Absorb
  710. \sa wc_InitShake128
  711. */
  712. int wc_Shake128_SqueezeBlocks(wc_Shake* shake, byte* out, word32 blockCnt);
  713. /*!
  714. \ingroup SHA
  715. \brief Resets the wc_Shake structure. Note: this is only supported
  716. if you have WOLFSSL_TI_HASH defined.
  717. \return none No returns.
  718. \param shake Pointer to the shake structure to be freed.
  719. _Example_
  720. \code
  721. wc_Shake shake;
  722. byte data[] = { Data to be hashed };
  723. word32 len = sizeof(data);
  724. if ((ret = wc_InitShake128(&shake, NULL, INVALID_DEVID)) != 0) {
  725. WOLFSSL_MSG("wc_InitShake128 failed");
  726. }
  727. else {
  728. wc_Shake128_Update(&shake, data, len);
  729. wc_Shake128_Final(&shake, hash);
  730. wc_Shake128_Free(&shake);
  731. }
  732. \endcode
  733. \sa wc_InitShake128
  734. \sa wc_Shake128_Update
  735. \sa wc_Shake128_Final
  736. */
  737. void wc_Shake128_Free(wc_Shake*);
  738. /*!
  739. \ingroup SHA
  740. \brief Gets hash data. Result is placed into hash. Does not
  741. reset state of shake struct.
  742. \return 0 Returned upon successful copying of the hash.
  743. \param shake pointer to the shake structure to use for encryption
  744. \param hash Byte array to hold hash value.
  745. _Example_
  746. \code
  747. wc_Shake shake[1];
  748. if ((ret = wc_InitShake128(shake, NULL, INVALID_DEVID)) != 0) {
  749. WOLFSSL_MSG("wc_InitShake128 failed");
  750. }
  751. else {
  752. wc_Shake128_Update(shake, data, len);
  753. wc_Shake128_GetHash(shake, hash);
  754. }
  755. \endcode
  756. \sa wc_Shake128Hash
  757. \sa wc_Shake128_Final
  758. \sa wc_InitShake128
  759. \sa wc_Shake128_Copy
  760. */
  761. int wc_Shake128_GetHash(wc_Shake* shake, byte* hash);
  762. /*!
  763. \ingroup SHA
  764. \brief Copy the state of the hash.
  765. \return 0 Returned upon successful copying.
  766. \param shake pointer to the shake structure to copy
  767. \param dst pointer to the shake structure to copy into
  768. _Example_
  769. \code
  770. wc_Shake shake[1];
  771. wc_Shake shake_dup[1];
  772. if ((ret = wc_InitShake128(shake, NULL, INVALID_DEVID)) != 0) {
  773. WOLFSSL_MSG("wc_InitShake128 failed");
  774. }
  775. else {
  776. wc_Shake128_Update(shake, data, len);
  777. wc_Shake128_Copy(shake, shake_dup);
  778. }
  779. \endcode
  780. \sa wc_Shake128Hash
  781. \sa wc_Shake128_Final
  782. \sa wc_InitShake128
  783. \sa wc_Shake128_GetHash
  784. */
  785. int wc_Shake128_Copy(wc_Shake* shake, wc_Shake* dst);
  786. /*!
  787. \ingroup SHA
  788. \brief This function initializes SHAKE-256. This is automatically
  789. called by wc_Shake256Hash.
  790. \return 0 Returned upon successfully initializing
  791. \param shake pointer to the shake structure to use for encryption
  792. _Example_
  793. \code
  794. wc_Shake shake[1];
  795. if ((ret = wc_InitShake256(shake, NULL, INVALID_DEVID)) != 0) {
  796. WOLFSSL_MSG("wc_InitShake256 failed");
  797. }
  798. else {
  799. wc_Shake256_Update(shake, data, len);
  800. wc_Shake256_Final(shake, hash);
  801. }
  802. \endcode
  803. \sa wc_Shake256Hash
  804. \sa wc_Shake256_Update
  805. \sa wc_Shake256_Final
  806. */
  807. int wc_InitShake256(wc_Shake* shake, void* heap, int devId);
  808. /*!
  809. \ingroup SHA
  810. \brief Can be called to continually hash the provided byte
  811. array of length len.
  812. \return 0 Returned upon successfully adding the data to the digest.
  813. \param shake pointer to the shake structure to use for encryption
  814. \param data the data to be hashed
  815. \param len length of data to be hashed
  816. _Example_
  817. \code
  818. wc_Shake shake[1];
  819. byte data[] = { Data to be hashed };
  820. word32 len = sizeof(data);
  821. if ((ret = wc_InitShake256(shake, NULL, INVALID_DEVID)) != 0) {
  822. WOLFSSL_MSG("wc_InitShake256 failed");
  823. }
  824. else {
  825. wc_Shake256_Update(shake, data, len);
  826. wc_Shake256_Final(shake, hash);
  827. }
  828. \endcode
  829. \sa wc_Shake256Hash
  830. \sa wc_Shake256_Final
  831. \sa wc_InitShake256
  832. */
  833. int wc_Shake256_Update(wc_Shake* sha, const byte* data, word32 len);
  834. /*!
  835. \ingroup SHA
  836. \brief Finalizes hashing of data. Result is placed into hash.
  837. Resets state of shake struct.
  838. \return 0 Returned upon successfully finalizing.
  839. \param shake pointer to the shake structure to use for encryption
  840. \param hash Byte array to hold hash value.
  841. _Example_
  842. \code
  843. wc_Shake shake[1];
  844. byte data[] = { Data to be hashed };
  845. word32 len = sizeof(data);
  846. if ((ret = wc_InitShake256(shake, NULL, INVALID_DEVID)) != 0) {
  847. WOLFSSL_MSG("wc_InitShake256 failed");
  848. }
  849. else {
  850. wc_Shake256_Update(shake, data, len);
  851. wc_Shake256_Final(shake, hash);
  852. }
  853. \endcode
  854. \sa wc_Shake256Hash
  855. \sa wc_Shake256_GetHash
  856. \sa wc_InitShake256
  857. */
  858. int wc_Shake256_Final(wc_Shake* shake, byte* hash);
  859. /*!
  860. \ingroup SHA
  861. \brief Called to absorb the provided byte array of length len. Cannot
  862. be called incrementally.
  863. \return 0 Returned upon successfully absorbed the data.
  864. \param shake pointer to the shake structure to use for encryption
  865. \param data the data to be absorbed
  866. \param len length of data to be absorbed
  867. _Example_
  868. \code
  869. wc_Shake shake[1];
  870. byte data[] = { Data to be hashed };
  871. word32 len = sizeof(data);
  872. byte out[2 * WC_SHA3_256_BLOCK_SIZE];
  873. int blocks = 2;
  874. if ((ret = wc_InitShake256(shake, NULL, INVALID_DEVID)) != 0) {
  875. WOLFSSL_MSG("wc_InitShake256 failed");
  876. }
  877. else {
  878. wc_Shake256_Absorb(shake, data, len);
  879. wc_Shake256_SqueezeBlocks(shake, out, blocks);
  880. }
  881. \endcode
  882. \sa wc_Shake256_SqueezeBlocks
  883. \sa wc_InitShake256
  884. */
  885. int wc_Shake256_Absorb(wc_Shake* sha, const byte* data, word32 len);
  886. /*!
  887. \ingroup SHA
  888. \brief Squeeze out more blocks of data. Result is placed into out. Can be
  889. called incrementally.
  890. \return 0 Returned upon successfully squeezing.
  891. \param shake pointer to the shake structure to use for encryption
  892. \param hash Byte array to hold output.
  893. \param blocks Number of blocks to squeeze out. Each block is
  894. WC_SHA3_256_BLOCK_SIZE bytes in length.
  895. _Example_
  896. \code
  897. wc_Shake shake[1];
  898. byte data[] = { Data to be hashed };
  899. word32 len = sizeof(data);
  900. byte out[2 * WC_SHA3_256_BLOCK_SIZE];
  901. int blocks = 2;
  902. if ((ret = wc_InitShake256(shake, NULL, INVALID_DEVID)) != 0) {
  903. WOLFSSL_MSG("wc_InitShake256 failed");
  904. }
  905. else {
  906. wc_Shake256_Absorb(shake, data, len);
  907. wc_Shake256_SqueezeBlocks(shake, out, blocks);
  908. }
  909. \endcode
  910. \sa wc_Shake256_Absorb
  911. \sa wc_InitShake256
  912. */
  913. int wc_Shake256_SqueezeBlocks(wc_Shake* shake, byte* out, word32 blockCnt);
  914. /*!
  915. \ingroup SHA
  916. \brief Resets the wc_Shake structure. Note: this is only supported
  917. if you have WOLFSSL_TI_HASH defined.
  918. \return none No returns.
  919. \param shake Pointer to the shake structure to be freed.
  920. _Example_
  921. \code
  922. wc_Shake shake;
  923. byte data[] = { Data to be hashed };
  924. word32 len = sizeof(data);
  925. if ((ret = wc_InitShake256(&shake, NULL, INVALID_DEVID)) != 0) {
  926. WOLFSSL_MSG("wc_InitShake256 failed");
  927. }
  928. else {
  929. wc_Shake256_Update(&shake, data, len);
  930. wc_Shake256_Final(&shake, hash);
  931. wc_Shake256_Free(&shake);
  932. }
  933. \endcode
  934. \sa wc_InitShake256
  935. \sa wc_Shake256_Update
  936. \sa wc_Shake256_Final
  937. */
  938. void wc_Shake256_Free(wc_Shake*);
  939. /*!
  940. \ingroup SHA
  941. \brief Gets hash data. Result is placed into hash. Does not
  942. reset state of shake struct.
  943. \return 0 Returned upon successful copying of the hash.
  944. \param shake pointer to the shake structure to use for encryption
  945. \param hash Byte array to hold hash value.
  946. _Example_
  947. \code
  948. wc_Shake shake[1];
  949. if ((ret = wc_InitShake256(shake, NULL, INVALID_DEVID)) != 0) {
  950. WOLFSSL_MSG("wc_InitShake256 failed");
  951. }
  952. else {
  953. wc_Shake256_Update(shake, data, len);
  954. wc_Shake256_GetHash(shake, hash);
  955. }
  956. \endcode
  957. \sa wc_Shake256Hash
  958. \sa wc_Shake256_Final
  959. \sa wc_InitShake256
  960. \sa wc_Shake256_Copy
  961. */
  962. int wc_Shake256_GetHash(wc_Shake* shake, byte* hash);
  963. /*!
  964. \ingroup SHA
  965. \brief Copy the state of the hash.
  966. \return 0 Returned upon successful copying.
  967. \param shake pointer to the shake structure to copy
  968. \param dst pointer to the shake structure to copy into
  969. _Example_
  970. \code
  971. wc_Shake shake[1];
  972. wc_Shake shake_dup[1];
  973. if ((ret = wc_InitShake256(shake, NULL, INVALID_DEVID)) != 0) {
  974. WOLFSSL_MSG("wc_InitShake256 failed");
  975. }
  976. else {
  977. wc_Shake256_Update(shake, data, len);
  978. wc_Shake256_Copy(shake, shake_dup);
  979. }
  980. \endcode
  981. \sa wc_Shake256Hash
  982. \sa wc_Shake256_Final
  983. \sa wc_InitShake256
  984. \sa wc_Shake256_GetHash
  985. */
  986. int wc_Shake256_Copy(wc_Shake* shake, wc_Shake* dst);