hash.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*!
  2. \ingroup wolfCrypt
  3. \brief This function will return the OID for the wc_HashType provided.
  4. \return OID returns value greater than 0
  5. \return HASH_TYPE_E hash type not supported.
  6. \return BAD_FUNC_ARG one of the provided arguments is incorrect.
  7. \param hash_type A hash type from the “enum wc_HashType” such
  8. as “WC_HASH_TYPE_SHA256”.
  9. _Example_
  10. \code
  11. enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
  12. int oid = wc_HashGetOID(hash_type);
  13. if (oid > 0) {
  14. // Success
  15. }
  16. \endcode
  17. \sa wc_HashGetDigestSize
  18. \sa wc_Hash
  19. */
  20. int wc_HashGetOID(enum wc_HashType hash_type);
  21. /*!
  22. \ingroup wolfCrypt
  23. \brief This function returns the size of the digest (output) for a
  24. hash_type. The returns size is used to make sure the output buffer
  25. provided to wc_Hash is large enough.
  26. \return Success A positive return value indicates the digest size
  27. for the hash.
  28. \return Error Returns HASH_TYPE_E if hash_type is not supported.
  29. \return Failure Returns BAD_FUNC_ARG if an invalid hash_type was used.
  30. \param hash_type A hash type from the “enum wc_HashType” such as
  31. “WC_HASH_TYPE_SHA256”.
  32. _Example_
  33. \code
  34. int hash_len = wc_HashGetDigestSize(hash_type);
  35. if (hash_len <= 0) {
  36. WOLFSSL_MSG("Invalid hash type/len");
  37. return BAD_FUNC_ARG;
  38. }
  39. \endcode
  40. \sa wc_Hash
  41. */
  42. int wc_HashGetDigestSize(enum wc_HashType hash_type);
  43. /*!
  44. \ingroup wolfCrypt
  45. \brief This function performs a hash on the provided data buffer
  46. and returns it in the hash buffer provided.
  47. \return 0 Success, else error (such as BAD_FUNC_ARG or BUFFER_E).
  48. \param hash_type A hash type from the “enum wc_HashType”
  49. such as “WC_HASH_TYPE_SHA256”.
  50. \param data Pointer to buffer containing the data to hash.
  51. \param data_len Length of the data buffer.
  52. \param hash Pointer to buffer used to output the final hash to.
  53. \param hash_len Length of the hash buffer.
  54. _Example_
  55. \code
  56. enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
  57. int hash_len = wc_HashGetDigestSize(hash_type);
  58. if (hash_len > 0) {
  59. int ret = wc_Hash(hash_type, data, data_len, hash_data, hash_len);
  60. if(ret == 0) {
  61. // Success
  62. }
  63. }
  64. \endcode
  65. \sa wc_HashGetDigestSize
  66. */
  67. int wc_Hash(enum wc_HashType hash_type,
  68. const byte* data, word32 data_len,
  69. byte* hash, word32 hash_len);
  70. /*!
  71. \ingroup MD5
  72. \brief Convenience function, handles all the hashing and places the
  73. result into hash.
  74. \return 0 Returned upon successfully hashing the data.
  75. \return Memory_E memory error, unable to allocate memory. This is only
  76. possible with the small stack option enabled.
  77. \param data the data to hash
  78. \param len the length of data
  79. \param hash Byte array to hold hash value.
  80. _Example_
  81. \code
  82. const byte* data;
  83. word32 data_len;
  84. byte* hash;
  85. int ret;
  86. ...
  87. ret = wc_Md5Hash(data, data_len, hash);
  88. if (ret != 0) {
  89. // Md5 Hash Failure Case.
  90. }
  91. \endcode
  92. \sa wc_Md5Hash
  93. \sa wc_Md5Final
  94. \sa wc_InitMd5
  95. */
  96. int wc_Md5Hash(const byte* data, word32 len, byte* hash);
  97. /*!
  98. \ingroup SHA
  99. \brief Convenience function, handles all the hashing and places the
  100. result into hash.
  101. \return 0 Returned upon successfully ….
  102. \return Memory_E memory error, unable to allocate memory. This is only
  103. possible with the small stack option enabled.
  104. \param data the data to hash
  105. \param len the length of data
  106. \param hash Byte array to hold hash value.
  107. _Example_
  108. \code
  109. none
  110. \endcode
  111. \sa wc_ShaHash
  112. \sa wc_ShaFinal
  113. \sa wc_InitSha
  114. */
  115. int wc_ShaHash(const byte* data, word32 len, byte* hash);
  116. /*!
  117. \ingroup SHA
  118. \brief Convenience function, handles all the hashing and places the
  119. result into hash.
  120. \return 0 Success
  121. \return <0 Error
  122. \param data the data to hash
  123. \param len the length of data
  124. \param hash Byte array to hold hash value.
  125. _Example_
  126. \code
  127. none
  128. \endcode
  129. \sa wc_InitSha224
  130. \sa wc_Sha224Update
  131. \sa wc_Sha224Final
  132. */
  133. int wc_Sha224Hash(const byte* data, word32 len, byte* hash);
  134. /*!
  135. \ingroup SHA
  136. \brief Convenience function, handles all the hashing and places the
  137. result into hash.
  138. \return 0 Returned upon successfully …
  139. \return Memory_E memory error, unable to allocate memory. This is only
  140. possible with the small stack option enabled.
  141. \param data the data to hash
  142. \param len the length of data
  143. \param hash Byte array to hold hash value.
  144. _Example_
  145. \code
  146. none
  147. \endcode
  148. \sa wc_Sha256Hash
  149. \sa wc_Sha256Final
  150. \sa wc_InitSha256
  151. */
  152. int wc_Sha256Hash(const byte* data, word32 len, byte* hash);
  153. /*!
  154. \ingroup SHA
  155. \brief Convenience function, handles all the hashing and places the
  156. result into hash.
  157. \return 0 Returned upon successfully hashing the data
  158. \return Memory_E memory error, unable to allocate memory. This is only
  159. possible with the small stack option enabled.
  160. \param data the data to hash
  161. \param len the length of data
  162. \param hash Byte array to hold hash value.
  163. _Example_
  164. \code
  165. none
  166. \endcode
  167. \sa wc_Sha384Hash
  168. \sa wc_Sha384Final
  169. \sa wc_InitSha384
  170. */
  171. int wc_Sha384Hash(const byte* data, word32 len, byte* hash);
  172. /*!
  173. \ingroup SHA
  174. \brief Convenience function, handles all the hashing and places the
  175. result into hash.
  176. \return 0 Returned upon successfully hashing the inputted data
  177. \return Memory_E memory error, unable to allocate memory. This is only
  178. possible with the small stack option enabled.
  179. \param data the data to hash
  180. \param len the length of data
  181. \param hash Byte array to hold hash value.
  182. _Example_
  183. \code
  184. none
  185. \endcode
  186. \sa wc_Sha512Hash
  187. \sa wc_Sha512Final
  188. \sa wc_InitSha512
  189. */
  190. int wc_Sha512Hash(const byte* data, word32 len, byte* hash);
  191. /*!
  192. \ingroup SHA
  193. \brief Convenience function, handles all the hashing and places the
  194. result into hash.
  195. \return 0 Returned upon successfully hashing the data
  196. \return Memory_E memory error, unable to allocate memory. This is only
  197. possible with the small stack option enabled.
  198. \param data the data to hash
  199. \param len the length of data
  200. \param hash Byte array to hold hash value.
  201. _Example_
  202. \code
  203. none
  204. \endcode
  205. \sa wc_InitSha3_224
  206. \sa wc_Sha3_224_Update
  207. \sa wc_Sha3_224_Final
  208. */
  209. int wc_Sha3_224Hash(const byte* data, word32 len, byte* hash);
  210. /*!
  211. \ingroup SHA
  212. \brief Convenience function, handles all the hashing and places the
  213. result into hash.
  214. \return 0 Returned upon successfully hashing the data
  215. \return Memory_E memory error, unable to allocate memory. This is only
  216. possible with the small stack option enabled.
  217. \param data the data to hash
  218. \param len the length of data
  219. \param hash Byte array to hold hash value.
  220. _Example_
  221. \code
  222. none
  223. \endcode
  224. \sa wc_InitSha3_256
  225. \sa wc_Sha3_256_Update
  226. \sa wc_Sha3_256_Final
  227. */
  228. int wc_Sha3_256Hash(const byte* data, word32 len, byte* hash);
  229. /*!
  230. \ingroup SHA
  231. \brief Convenience function, handles all the hashing and places the
  232. result into hash.
  233. \return 0 Returned upon successfully hashing the data
  234. \return Memory_E memory error, unable to allocate memory. This is only
  235. possible with the small stack option enabled.
  236. \param data the data to hash
  237. \param len the length of data
  238. \param hash Byte array to hold hash value.
  239. _Example_
  240. \code
  241. none
  242. \endcode
  243. \sa wc_InitSha3_384
  244. \sa wc_Sha3_384_Update
  245. \sa wc_Sha3_384_Final
  246. */
  247. int wc_Sha3_384Hash(const byte* data, word32 len, byte* hash);
  248. /*!
  249. \ingroup SHA
  250. \brief Convenience function, handles all the hashing and places the
  251. result into hash.
  252. \return 0 Returned upon successfully hashing the inputted data
  253. \return Memory_E memory error, unable to allocate memory. This is only
  254. possible with the small stack option enabled.
  255. \param data the data to hash
  256. \param len the length of data
  257. \param hash Byte array to hold hash value.
  258. _Example_
  259. \code
  260. none
  261. \endcode
  262. \sa wc_InitSha3_512
  263. \sa wc_Sha3_512_Update
  264. \sa wc_Sha3_512_Final
  265. */
  266. int wc_Sha3_512Hash(const byte* data, word32 len, byte* hash);
  267. /*!
  268. \ingroup SHA
  269. \brief Convenience function, handles all the hashing and places the
  270. result into hash.
  271. \return 0 Returned upon successfully hashing the inputted data
  272. \return Memory_E memory error, unable to allocate memory. This is only
  273. possible with the small stack option enabled.
  274. \param data the data to hash
  275. \param len the length of data
  276. \param hash Byte array to hold hash value.
  277. _Example_
  278. \code
  279. none
  280. \endcode
  281. \sa wc_InitShake128
  282. \sa wc_Shake128_Update
  283. \sa wc_Shake128_Final
  284. */
  285. int wc_Shake128Hash(const byte* data, word32 len, byte* hash);
  286. /*!
  287. \ingroup SHA
  288. \brief Convenience function, handles all the hashing and places the
  289. result into hash.
  290. \return 0 Returned upon successfully hashing the inputted data
  291. \return Memory_E memory error, unable to allocate memory. This is only
  292. possible with the small stack option enabled.
  293. \param data the data to hash
  294. \param len the length of data
  295. \param hash Byte array to hold hash value.
  296. _Example_
  297. \code
  298. none
  299. \endcode
  300. \sa wc_InitShake256
  301. \sa wc_Shake256_Update
  302. \sa wc_Shake256_Final
  303. */
  304. int wc_Shake256Hash(const byte* data, word32 len, byte* hash);