blake2.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*!
  2. \ingroup BLAKE2
  3. \brief This function initializes a Blake2b structure for use with the
  4. Blake2 hash function.
  5. \return 0 Returned upon successfully initializing the Blake2b structure and
  6. setting the digest size.
  7. \param b2b pointer to the Blake2b structure to initialize
  8. \param digestSz length of the blake 2 digest to implement
  9. _Example_
  10. \code
  11. Blake2b b2b;
  12. // initialize Blake2b structure with 64 byte digest
  13. wc_InitBlake2b(&b2b, 64);
  14. \endcode
  15. \sa wc_Blake2bUpdate
  16. */
  17. int wc_InitBlake2b(Blake2b* b2b, word32 digestSz);
  18. /*!
  19. \ingroup BLAKE2
  20. \brief This function updates the Blake2b hash with the given input data.
  21. This function should be called after wc_InitBlake2b, and repeated until
  22. one is ready for the final hash: wc_Blake2bFinal.
  23. \return 0 Returned upon successfully update the Blake2b structure with
  24. the given data
  25. \return -1 Returned if there is a failure while compressing the input data
  26. \param b2b pointer to the Blake2b structure to update
  27. \param data pointer to a buffer containing the data to append
  28. \param sz length of the input data to append
  29. _Example_
  30. \code
  31. int ret;
  32. Blake2b b2b;
  33. // initialize Blake2b structure with 64 byte digest
  34. wc_InitBlake2b(&b2b, 64);
  35. byte plain[] = { // initialize input };
  36. ret = wc_Blake2bUpdate(&b2b, plain, sizeof(plain));
  37. if( ret != 0) {
  38. // error updating blake2b
  39. }
  40. \endcode
  41. \sa wc_InitBlake2b
  42. \sa wc_Blake2bFinal
  43. */
  44. int wc_Blake2bUpdate(Blake2b* b2b, const byte* data, word32 sz);
  45. /*!
  46. \ingroup BLAKE2
  47. \brief This function computes the Blake2b hash of the previously supplied
  48. input data. The output hash will be of length requestSz, or, if
  49. requestSz==0, the digestSz of the b2b structure. This function should be
  50. called after wc_InitBlake2b and wc_Blake2bUpdate has been processed for
  51. each piece of input data desired.
  52. \return 0 Returned upon successfully computing the Blake2b hash
  53. \return -1 Returned if there is a failure while parsing the Blake2b hash
  54. \param b2b pointer to the Blake2b structure to update
  55. \param final pointer to a buffer in which to store the blake2b hash.
  56. Should be of length requestSz
  57. \param requestSz length of the digest to compute. When this is zero,
  58. b2b->digestSz will be used instead
  59. _Example_
  60. \code
  61. int ret;
  62. Blake2b b2b;
  63. byte hash[64];
  64. // initialize Blake2b structure with 64 byte digest
  65. wc_InitBlake2b(&b2b, 64);
  66. ... // call wc_Blake2bUpdate to add data to hash
  67. ret = wc_Blake2bFinal(&b2b, hash, 64);
  68. if( ret != 0) {
  69. // error generating blake2b hash
  70. }
  71. \endcode
  72. \sa wc_InitBlake2b
  73. \sa wc_Blake2bUpdate
  74. */
  75. int wc_Blake2bFinal(Blake2b* b2b, byte* final, word32 requestSz);