hkdf.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* $OpenBSD: hkdf.h,v 1.3 2023/08/11 04:52:08 tb Exp $ */
  2. /* Copyright (c) 2014, Google Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  15. #ifndef OPENSSL_HEADER_HKDF_H
  16. #define OPENSSL_HEADER_HKDF_H
  17. #include <openssl/evp.h>
  18. #if defined(__cplusplus)
  19. extern "C" {
  20. #endif
  21. /*
  22. * HKDF computes HKDF (as specified by RFC 5869) of initial keying
  23. * material |secret| with |salt| and |info| using |digest|, and
  24. * outputs |out_len| bytes to |out_key|. It returns one on success and
  25. * zero on error.
  26. *
  27. * HKDF is an Extract-and-Expand algorithm. It does not do any key
  28. * stretching, and as such, is not suited to be used alone to generate
  29. * a key from a password.
  30. */
  31. int HKDF(uint8_t *out_key, size_t out_len, const EVP_MD *digest,
  32. const uint8_t *secret, size_t secret_len, const uint8_t *salt,
  33. size_t salt_len, const uint8_t *info, size_t info_len);
  34. /*
  35. * HKDF_extract computes a HKDF PRK (as specified by RFC 5869) from
  36. * initial keying material |secret| and salt |salt| using |digest|,
  37. * and outputs |out_len| bytes to |out_key|. The maximum output size
  38. * is |EVP_MAX_MD_SIZE|. It returns one on success and zero on error.
  39. */
  40. int HKDF_extract(uint8_t *out_key, size_t *out_len, const EVP_MD *digest,
  41. const uint8_t *secret, size_t secret_len,
  42. const uint8_t *salt, size_t salt_len);
  43. /*
  44. * HKDF_expand computes a HKDF OKM (as specified by RFC 5869) of
  45. * length |out_len| from the PRK |prk| and info |info| using |digest|,
  46. * and outputs the result to |out_key|. It returns one on success and
  47. * zero on error.
  48. */
  49. int HKDF_expand(uint8_t *out_key, size_t out_len,
  50. const EVP_MD *digest, const uint8_t *prk, size_t prk_len,
  51. const uint8_t *info, size_t info_len);
  52. #if defined(__cplusplus)
  53. } /* extern C */
  54. #endif
  55. #endif /* OPENSSL_HEADER_HKDF_H */