blake2.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* blake2.h
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*!
  22. \file wolfssl/wolfcrypt/blake2.h
  23. */
  24. #ifndef WOLF_CRYPT_BLAKE2_H
  25. #define WOLF_CRYPT_BLAKE2_H
  26. #include <wolfssl/wolfcrypt/settings.h>
  27. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  28. #include <wolfssl/wolfcrypt/blake2-int.h>
  29. /* call old functions if using fips for the sake of hmac @wc_fips */
  30. #ifdef HAVE_FIPS
  31. /* Since hmac can call blake functions provide original calls */
  32. #define wc_InitBlake2b InitBlake2b
  33. #define wc_Blake2bUpdate Blake2bUpdate
  34. #define wc_Blake2bFinal Blake2bFinal
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /* in bytes, variable digest size up to 512 bits (64 bytes) */
  40. enum {
  41. #ifdef HAVE_BLAKE2B
  42. BLAKE2B_ID = WC_HASH_TYPE_BLAKE2B,
  43. BLAKE2B_256 = 32, /* 256 bit type, SSL default */
  44. #endif
  45. #ifdef HAVE_BLAKE2S
  46. BLAKE2S_ID = WC_HASH_TYPE_BLAKE2S,
  47. BLAKE2S_256 = 32 /* 256 bit type */
  48. #endif
  49. };
  50. #ifdef HAVE_BLAKE2B
  51. /* BLAKE2b digest */
  52. typedef struct Blake2b {
  53. blake2b_state S[1]; /* our state */
  54. word32 digestSz; /* digest size used on init */
  55. } Blake2b;
  56. #endif
  57. #ifdef HAVE_BLAKE2S
  58. /* BLAKE2s digest */
  59. typedef struct Blake2s {
  60. blake2s_state S[1]; /* our state */
  61. word32 digestSz; /* digest size used on init */
  62. } Blake2s;
  63. #endif
  64. #ifdef HAVE_BLAKE2B
  65. WOLFSSL_API int wc_InitBlake2b(Blake2b* b2b, word32 digestSz);
  66. WOLFSSL_API int wc_InitBlake2b_WithKey(Blake2b* b2b, word32 digestSz,
  67. const byte *key, word32 keylen);
  68. WOLFSSL_API int wc_Blake2bUpdate(Blake2b* b2b, const byte* data, word32 sz);
  69. WOLFSSL_API int wc_Blake2bFinal(Blake2b* b2b, byte* final, word32 requestSz);
  70. #endif
  71. #ifdef HAVE_BLAKE2S
  72. WOLFSSL_API int wc_InitBlake2s(Blake2s* b2s, word32 digestSz);
  73. WOLFSSL_API int wc_InitBlake2s_WithKey(Blake2s* b2s, word32 digestSz,
  74. const byte *key, word32 keylen);
  75. WOLFSSL_API int wc_Blake2sUpdate(Blake2s* b2s, const byte* data, word32 sz);
  76. WOLFSSL_API int wc_Blake2sFinal(Blake2s* b2s, byte* final, word32 requestSz);
  77. #endif
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* HAVE_BLAKE2 || HAVE_BLAKE2S */
  82. #endif /* WOLF_CRYPT_BLAKE2_H */