blake2.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright (c) 2021, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_BLAKE2_H
  15. #define OPENSSL_HEADER_BLAKE2_H
  16. #include <openssl/base.h>
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. #define BLAKE2B256_DIGEST_LENGTH (256 / 8)
  21. #define BLAKE2B_CBLOCK 128
  22. struct blake2b_state_st {
  23. uint64_t h[8];
  24. uint64_t t_low, t_high;
  25. union {
  26. uint8_t bytes[BLAKE2B_CBLOCK];
  27. uint64_t words[16];
  28. } block;
  29. size_t block_used;
  30. };
  31. // BLAKE2B256_Init initialises |b2b| to perform a BLAKE2b-256 hash. There are no
  32. // pointers inside |b2b| thus release of |b2b| is purely managed by the caller.
  33. OPENSSL_EXPORT void BLAKE2B256_Init(BLAKE2B_CTX *b2b);
  34. // BLAKE2B256_Update appends |len| bytes from |data| to the digest being
  35. // calculated by |b2b|.
  36. OPENSSL_EXPORT void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *data,
  37. size_t len);
  38. // BLAKE2B256_Final completes the digest calculated by |b2b| and writes
  39. // |BLAKE2B256_DIGEST_LENGTH| bytes to |out|.
  40. OPENSSL_EXPORT void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH],
  41. BLAKE2B_CTX *b2b);
  42. // BLAKE2B256 writes the BLAKE2b-256 digset of |len| bytes from |data| to
  43. // |out|.
  44. OPENSSL_EXPORT void BLAKE2B256(const uint8_t *data, size_t len,
  45. uint8_t out[BLAKE2B256_DIGEST_LENGTH]);
  46. #if defined(__cplusplus)
  47. } // extern C
  48. #endif
  49. #endif // OPENSSL_HEADER_BLAKE2_H