1
0

sha256.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*!
  2. \ingroup SHA
  3. \brief This function initializes SHA256. This is automatically
  4. called by wc_Sha256Hash.
  5. \return 0 Returned upon successfully initializing
  6. \param sha256 pointer to the sha256 structure to use for encryption
  7. _Example_
  8. \code
  9. Sha256 sha256[1];
  10. if ((ret = wc_InitSha256(sha256)) != 0) {
  11. WOLFSSL_MSG("wc_InitSha256 failed");
  12. }
  13. else {
  14. wc_Sha256Update(sha256, data, len);
  15. wc_Sha256Final(sha256, hash);
  16. }
  17. \endcode
  18. \sa wc_Sha256Hash
  19. \sa wc_Sha256Update
  20. \sa wc_Sha256Final
  21. */
  22. int wc_InitSha256(wc_Sha256*);
  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 sha256 pointer to the sha256 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. Sha256 sha256[1];
  34. byte data[] = { Data to be hashed };
  35. word32 len = sizeof(data);
  36. if ((ret = wc_InitSha256(sha256)) != 0) {
  37. WOLFSSL_MSG("wc_InitSha256 failed");
  38. }
  39. else {
  40. wc_Sha256Update(sha256, data, len);
  41. wc_Sha256Final(sha256, hash);
  42. }
  43. \endcode
  44. \sa wc_Sha256Hash
  45. \sa wc_Sha256Final
  46. \sa wc_InitSha256
  47. */
  48. int wc_Sha256Update(wc_Sha256* 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 sha256 struct.
  53. \return 0 Returned upon successfully finalizing.
  54. \param sha256 pointer to the sha256 structure to use for encryption
  55. \param hash Byte array to hold hash value.
  56. _Example_
  57. \code
  58. Sha256 sha256[1];
  59. byte data[] = { Data to be hashed };
  60. word32 len = sizeof(data);
  61. if ((ret = wc_InitSha256(sha256)) != 0) {
  62. WOLFSSL_MSG("wc_InitSha256 failed");
  63. }
  64. else {
  65. wc_Sha256Update(sha256, data, len);
  66. wc_Sha256Final(sha256, hash);
  67. }
  68. \endcode
  69. \sa wc_Sha256Hash
  70. \sa wc_Sha256GetHash
  71. \sa wc_InitSha256
  72. */
  73. int wc_Sha256Final(wc_Sha256* sha256, byte* hash);
  74. /*!
  75. \ingroup SHA
  76. \brief Resets the Sha256 structure. Note: this is only supported
  77. if you have WOLFSSL_TI_HASH defined.
  78. \return none No returns.
  79. \param sha256 Pointer to the sha256 structure to be freed.
  80. _Example_
  81. \code
  82. Sha256 sha256;
  83. byte data[] = { Data to be hashed };
  84. word32 len = sizeof(data);
  85. if ((ret = wc_InitSha256(&sha256)) != 0) {
  86. WOLFSSL_MSG("wc_InitSha256 failed");
  87. }
  88. else {
  89. wc_Sha256Update(&sha256, data, len);
  90. wc_Sha256Final(&sha256, hash);
  91. wc_Sha256Free(&sha256);
  92. }
  93. \endcode
  94. \sa wc_InitSha256
  95. \sa wc_Sha256Update
  96. \sa wc_Sha256Final
  97. */
  98. void wc_Sha256Free(wc_Sha256*);
  99. /*!
  100. \ingroup SHA
  101. \brief Gets hash data. Result is placed into hash. Does not
  102. reset state of sha256 struct.
  103. \return 0 Returned upon successfully finalizing.
  104. \param sha256 pointer to the sha256 structure to use for encryption
  105. \param hash Byte array to hold hash value.
  106. _Example_
  107. \code
  108. Sha256 sha256[1];
  109. if ((ret = wc_InitSha256(sha256)) != 0) {
  110. WOLFSSL_MSG("wc_InitSha256 failed");
  111. }
  112. else {
  113. wc_Sha256Update(sha256, data, len);
  114. wc_Sha256GetHash(sha256, hash);
  115. }
  116. \endcode
  117. \sa wc_Sha256Hash
  118. \sa wc_Sha256Final
  119. \sa wc_InitSha256
  120. */
  121. int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash);
  122. /*!
  123. \ingroup SHA
  124. \brief Used to initialize a Sha224 struct.
  125. \return 0 Success
  126. \return 1 Error returned because sha224 is null.
  127. \param sha224 Pointer to a Sha224 struct to initialize.
  128. _Example_
  129. \code
  130. Sha224 sha224;
  131. if(wc_InitSha224(&sha224) != 0)
  132. {
  133. // Handle error
  134. }
  135. \endcode
  136. \sa wc_Sha224Hash
  137. \sa wc_Sha224Update
  138. \sa wc_Sha224Final
  139. */
  140. int wc_InitSha224(wc_Sha224*);
  141. /*!
  142. \ingroup SHA
  143. \brief Can be called to continually hash the provided byte array
  144. of length len.
  145. \return 0 Success
  146. \return 1 Error returned if function fails.
  147. \return BAD_FUNC_ARG Error returned if sha224 or data is null.
  148. \param sha224 Pointer to the Sha224 structure to use for encryption.
  149. \param data Data to be hashed.
  150. \param len Length of data to be hashed.
  151. _Example_
  152. \code
  153. Sha224 sha224;
  154. byte data[] = { /* Data to be hashed };
  155. word32 len = sizeof(data);
  156. if ((ret = wc_InitSha224(&sha224)) != 0) {
  157. WOLFSSL_MSG("wc_InitSha224 failed");
  158. }
  159. else {
  160. wc_Sha224Update(&sha224, data, len);
  161. wc_Sha224Final(&sha224, hash);
  162. }
  163. \endcode
  164. \sa wc_InitSha224
  165. \sa wc_Sha224Final
  166. \sa wc_Sha224Hash
  167. */
  168. int wc_Sha224Update(wc_Sha224* sha224, const byte* data, word32 len);
  169. /*!
  170. \ingroup SHA
  171. \brief Finalizes hashing of data. Result is placed into hash.
  172. Resets state of sha224 struct.
  173. \return 0 Success
  174. \return <0 Error
  175. \param sha224 pointer to the sha224 structure to use for encryption
  176. \param hash Byte array to hold hash value.
  177. _Example_
  178. \code
  179. Sha224 sha224;
  180. byte data[] = { /* Data to be hashed };
  181. word32 len = sizeof(data);
  182. if ((ret = wc_InitSha224(&sha224)) != 0) {
  183. WOLFSSL_MSG("wc_InitSha224 failed");
  184. }
  185. else {
  186. wc_Sha224Update(&sha224, data, len);
  187. wc_Sha224Final(&sha224, hash);
  188. }
  189. \endcode
  190. \sa wc_InitSha224
  191. \sa wc_Sha224Hash
  192. \sa wc_Sha224Update
  193. */
  194. int wc_Sha224Final(wc_Sha224* sha224, byte* hash);