kdf.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* kdf.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/kdf.h
  23. */
  24. #ifndef NO_KDF
  25. #ifndef WOLF_CRYPT_KDF_H
  26. #define WOLF_CRYPT_KDF_H
  27. #if defined(HAVE_FIPS) && \
  28. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  29. #include <wolfssl/wolfcrypt/fips.h>
  30. #endif
  31. #include <wolfssl/wolfcrypt/hmac.h>
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. enum max_prf {
  36. #ifdef HAVE_FFDHE_8192
  37. MAX_PRF_HALF = 516, /* Maximum half secret len */
  38. #elif defined(HAVE_FFDHE_6144)
  39. MAX_PRF_HALF = 388, /* Maximum half secret len */
  40. #else
  41. MAX_PRF_HALF = 260, /* Maximum half secret len */
  42. #endif
  43. MAX_PRF_LABSEED = 128, /* Maximum label + seed len */
  44. MAX_PRF_DIG = 224 /* Maximum digest len */
  45. };
  46. #ifdef WOLFSSL_HAVE_PRF
  47. WOLFSSL_API int wc_PRF(byte* result, word32 resLen, const byte* secret,
  48. word32 secLen, const byte* seed, word32 seedLen, int hash,
  49. void* heap, int devId);
  50. WOLFSSL_API int wc_PRF_TLSv1(byte* digest, word32 digLen, const byte* secret,
  51. word32 secLen, const byte* label, word32 labLen,
  52. const byte* seed, word32 seedLen, void* heap, int devId);
  53. WOLFSSL_API int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret,
  54. word32 secLen, const byte* label, word32 labLen,
  55. const byte* seed, word32 seedLen, int useAtLeastSha256,
  56. int hash_type, void* heap, int devId);
  57. #endif /* WOLFSSL_HAVE_PRF */
  58. #ifdef HAVE_HKDF
  59. enum {
  60. /*
  61. MAX_HKDF_LABEL_SZ = OPAQUE16_LEN +
  62. OPAQUE8_LEN + PROTOCOL_LABEL_SZ + MAX_LABEL_SZ +
  63. OPAQUE8_LEN + WC_MAX_DIGEST_SIZE
  64. */
  65. MAX_TLS13_HKDF_LABEL_SZ = 47 + WC_MAX_DIGEST_SIZE
  66. };
  67. WOLFSSL_API int wc_Tls13_HKDF_Extract(byte* prk, const byte* salt, int saltLen,
  68. byte* ikm, int ikmLen, int digest);
  69. WOLFSSL_API int wc_Tls13_HKDF_Expand_Label(byte* okm, word32 okmLen,
  70. const byte* prk, word32 prkLen,
  71. const byte* protocol, word32 protocolLen,
  72. const byte* label, word32 labelLen,
  73. const byte* info, word32 infoLen,
  74. int digest);
  75. #endif /* HAVE_HKDF */
  76. #ifdef WOLFSSL_WOLFSSH
  77. WOLFSSL_API int wc_SSH_KDF(byte hashId, byte keyId,
  78. byte* key, word32 keySz,
  79. const byte* k, word32 kSz,
  80. const byte* h, word32 hSz,
  81. const byte* sessionId, word32 sessionIdSz);
  82. #endif /* WOLFSSL_WOLFSSH */
  83. #ifdef __cplusplus
  84. } /* extern "C" */
  85. #endif
  86. #endif /* WOLF_CRYPT_KDF_H */
  87. #endif /* NO_KDF */