1
0

sha.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*!
  2. \ingroup SHA
  3. \brief This function initializes SHA. This is automatically called
  4. by wc_ShaHash.
  5. \return 0 Returned upon successfully initializing
  6. \param sha pointer to the sha structure to use for encryption
  7. _Example_
  8. \code
  9. Sha sha[1];
  10. if ((ret = wc_InitSha(sha)) != 0) {
  11. WOLFSSL_MSG("wc_InitSha failed");
  12. }
  13. else {
  14. wc_ShaUpdate(sha, data, len);
  15. wc_ShaFinal(sha, hash);
  16. }
  17. \endcode
  18. \sa wc_ShaHash
  19. \sa wc_ShaUpdate
  20. \sa wc_ShaFinal
  21. */
  22. WOLFSSL_API int wc_InitSha(wc_Sha*);
  23. /*!
  24. \ingroup SHA
  25. \brief Can be called to continually hash the provided byte array of
  26. length len.
  27. \return 0 Returned upon successfully adding the data to the digest.
  28. \param sha pointer to the sha 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. Sha sha[1];
  34. byte data[] = { // Data to be hashed };
  35. word32 len = sizeof(data);
  36. if ((ret = wc_InitSha(sha)) != 0) {
  37. WOLFSSL_MSG("wc_InitSha failed");
  38. }
  39. else {
  40. wc_ShaUpdate(sha, data, len);
  41. wc_ShaFinal(sha, hash);
  42. }
  43. \endcode
  44. \sa wc_ShaHash
  45. \sa wc_ShaFinal
  46. \sa wc_InitSha
  47. */
  48. WOLFSSL_API int wc_ShaUpdate(wc_Sha*, const byte*, word32);
  49. /*!
  50. \ingroup SHA
  51. \brief Finalizes hashing of data. Result is placed into hash.
  52. Resets state of sha struct.
  53. \return 0 Returned upon successfully finalizing.
  54. \param sha pointer to the sha structure to use for encryption
  55. \param hash Byte array to hold hash value.
  56. _Example_
  57. \code
  58. Sha sha[1];
  59. byte data[] = { Data to be hashed };
  60. word32 len = sizeof(data);
  61. if ((ret = wc_InitSha(sha)) != 0) {
  62. WOLFSSL_MSG("wc_InitSha failed");
  63. }
  64. else {
  65. wc_ShaUpdate(sha, data, len);
  66. wc_ShaFinal(sha, hash);
  67. }
  68. \endcode
  69. \sa wc_ShaHash
  70. \sa wc_InitSha
  71. \sa wc_ShaGetHash
  72. */
  73. WOLFSSL_API int wc_ShaFinal(wc_Sha*, byte*);
  74. /*!
  75. \ingroup SHA
  76. \brief Used to clean up memory used by an initialized Sha struct.
  77. Note: this is only supported if you have WOLFSSL_TI_HASH defined.
  78. \return No returns.
  79. \param sha Pointer to the Sha struct to free.
  80. _Example_
  81. \code
  82. Sha sha;
  83. wc_InitSha(&sha);
  84. // Use sha
  85. wc_ShaFree(&sha);
  86. \endcode
  87. \sa wc_InitSha
  88. \sa wc_ShaUpdate
  89. \sa wc_ShaFinal
  90. */
  91. WOLFSSL_API void wc_ShaFree(wc_Sha*);
  92. /*!
  93. \ingroup SHA
  94. \brief Gets hash data. Result is placed into hash. Does not reset state
  95. of sha struct.
  96. \return 0 Returned upon successfully finalizing.
  97. \param sha pointer to the sha structure to use for encryption
  98. \param hash Byte array to hold hash value.
  99. _Example_
  100. \code
  101. Sha sha[1];
  102. if ((ret = wc_InitSha(sha)) != 0) {
  103. WOLFSSL_MSG("wc_InitSha failed");
  104. }
  105. else {
  106. wc_ShaUpdate(sha, data, len);
  107. wc_ShaGetHash(sha, hash);
  108. }
  109. \endcode
  110. \sa wc_ShaHash
  111. \sa wc_ShaFinal
  112. \sa wc_InitSha
  113. */
  114. WOLFSSL_API int wc_ShaGetHash(wc_Sha*, byte*);