1
0

md5.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*!
  2. \ingroup MD5
  3. \brief This function initializes md5. This is automatically
  4. called by wc_Md5Hash.
  5. \return 0 Returned upon successfully initializing.
  6. \return BAD_FUNC_ARG Returned if the Md5 structure is passed
  7. as a NULL value.
  8. \param md5 pointer to the md5 structure to use for encryption
  9. _Example_
  10. \code
  11. Md5 md5;
  12. byte* hash;
  13. if ((ret = wc_InitMd5(&md5)) != 0) {
  14. WOLFSSL_MSG("wc_Initmd5 failed");
  15. }
  16. else {
  17. ret = wc_Md5Update(&md5, data, len);
  18. if (ret != 0) {
  19. // Md5 Update Failure Case.
  20. }
  21. ret = wc_Md5Final(&md5, hash);
  22. if (ret != 0) {
  23. // Md5 Final Failure Case.
  24. }
  25. }
  26. \endcode
  27. \sa wc_Md5Hash
  28. \sa wc_Md5Update
  29. \sa wc_Md5Final
  30. */
  31. int wc_InitMd5(wc_Md5*);
  32. /*!
  33. \ingroup MD5
  34. \brief Can be called to continually hash the provided byte array of
  35. length len.
  36. \return 0 Returned upon successfully adding the data to the digest.
  37. \return BAD_FUNC_ARG Returned if the Md5 structure is NULL or if
  38. data is NULL and len is greater than zero. The function should
  39. not return an error if the data parameter is NULL and len is zero.
  40. \param md5 pointer to the md5 structure to use for encryption
  41. \param data the data to be hashed
  42. \param len length of data to be hashed
  43. _Example_
  44. \code
  45. Md5 md5;
  46. byte data[] = { Data to be hashed };
  47. word32 len = sizeof(data);
  48. if ((ret = wc_InitMd5(&md5)) != 0) {
  49. WOLFSSL_MSG("wc_Initmd5 failed");
  50. }
  51. else {
  52. ret = wc_Md5Update(&md5, data, len);
  53. if (ret != 0) {
  54. // Md5 Update Error Case.
  55. }
  56. ret = wc_Md5Final(&md5, hash);
  57. if (ret != 0) {
  58. // Md5 Final Error Case.
  59. }
  60. }
  61. \endcode
  62. \sa wc_Md5Hash
  63. \sa wc_Md5Final
  64. \sa wc_InitMd5
  65. */
  66. int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len);
  67. /*!
  68. \ingroup MD5
  69. \brief Finalizes hashing of data. Result is placed into hash. Md5
  70. Struct is reset. Note: This function will also return the result
  71. of calling IntelQaSymMd5() in the case that HAVE_INTEL_QA is defined.
  72. \return 0 Returned upon successfully finalizing.
  73. \return BAD_FUNC_ARG Returned if the Md5 structure or hash pointer
  74. is passed in NULL.
  75. \param md5 pointer to the md5 structure to use for encryption
  76. \param hash Byte array to hold hash value.
  77. _Example_
  78. \code
  79. md5 md5[1];
  80. byte data[] = { Data to be hashed };
  81. word32 len = sizeof(data);
  82. if ((ret = wc_InitMd5(md5)) != 0) {
  83. WOLFSSL_MSG("wc_Initmd5 failed");
  84. }
  85. else {
  86. ret = wc_Md5Update(md5, data, len);
  87. if (ret != 0) {
  88. // Md5 Update Failure Case.
  89. }
  90. ret = wc_Md5Final(md5, hash);
  91. if (ret != 0) {
  92. // Md5 Final Failure Case.
  93. }
  94. }
  95. \endcode
  96. \sa wc_Md5Hash
  97. \sa wc_InitMd5
  98. \sa wc_Md5GetHash
  99. */
  100. int wc_Md5Final(wc_Md5* md5, byte* hash);
  101. /*!
  102. \ingroup MD5
  103. \brief Resets the Md5 structure. Note: this is only supported if
  104. you have WOLFSSL_TI_HASH defined.
  105. \return none No returns.
  106. \param md5 Pointer to the Md5 structure to be reset.
  107. _Example_
  108. \code
  109. Md5 md5;
  110. byte data[] = { Data to be hashed };
  111. word32 len = sizeof(data);
  112. if ((ret = wc_InitMd5(&md5)) != 0) {
  113. WOLFSSL_MSG("wc_InitMd5 failed");
  114. }
  115. else {
  116. wc_Md5Update(&md5, data, len);
  117. wc_Md5Final(&md5, hash);
  118. wc_Md5Free(&md5);
  119. }
  120. \endcode
  121. \sa wc_InitMd5
  122. \sa wc_Md5Update
  123. \sa wc_Md5Final
  124. */
  125. void wc_Md5Free(wc_Md5*);
  126. /*!
  127. \ingroup MD5
  128. \brief Gets hash data. Result is placed into hash. Md5 struct
  129. is not reset.
  130. \return none No returns
  131. \param md5 pointer to the md5 structure to use for encryption.
  132. \param hash Byte array to hold hash value.
  133. _Example_
  134. \code
  135. md5 md5[1];
  136. if ((ret = wc_InitMd5(md5)) != 0) {
  137. WOLFSSL_MSG("wc_Initmd5 failed");
  138. }
  139. else {
  140. wc_Md5Update(md5, data, len);
  141. wc_Md5GetHash(md5, hash);
  142. }
  143. \endcode
  144. \sa wc_Md5Hash
  145. \sa wc_Md5Final
  146. \sa wc_InitMd5
  147. */
  148. int wc_Md5GetHash(wc_Md5* md5, byte* hash);