kdf_sp800108.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2021, Stephan Mueller <smueller@chronox.de>
  4. */
  5. #ifndef _CRYPTO_KDF108_H
  6. #define _CRYPTO_KDF108_H
  7. #include <crypto/hash.h>
  8. #include <linux/uio.h>
  9. /**
  10. * Counter KDF generate operation according to SP800-108 section 5.1
  11. * as well as SP800-56A section 5.8.1 (Single-step KDF).
  12. *
  13. * @kmd Keyed message digest whose key was set with crypto_kdf108_setkey or
  14. * unkeyed message digest
  15. * @info optional context and application specific information - this may be
  16. * NULL
  17. * @info_vec number of optional context/application specific information entries
  18. * @dst destination buffer that the caller already allocated
  19. * @dlen length of the destination buffer - the KDF derives that amount of
  20. * bytes.
  21. *
  22. * To comply with SP800-108, the caller must provide Label || 0x00 || Context
  23. * in the info parameter.
  24. *
  25. * @return 0 on success, < 0 on error
  26. */
  27. int crypto_kdf108_ctr_generate(struct crypto_shash *kmd,
  28. const struct kvec *info, unsigned int info_nvec,
  29. u8 *dst, unsigned int dlen);
  30. /**
  31. * Counter KDF setkey operation
  32. *
  33. * @kmd Keyed message digest allocated by the caller. The key should not have
  34. * been set.
  35. * @key Seed key to be used to initialize the keyed message digest context.
  36. * @keylen This length of the key buffer.
  37. * @ikm The SP800-108 KDF does not support IKM - this parameter must be NULL
  38. * @ikmlen This parameter must be 0.
  39. *
  40. * According to SP800-108 section 7.2, the seed key must be at least as large as
  41. * the message digest size of the used keyed message digest. This limitation
  42. * is enforced by the implementation.
  43. *
  44. * SP800-108 allows the use of either a HMAC or a hash primitive. When
  45. * the caller intends to use a hash primitive, the call to
  46. * crypto_kdf108_setkey is not required and the key derivation operation can
  47. * immediately performed using crypto_kdf108_ctr_generate after allocating
  48. * a handle.
  49. *
  50. * @return 0 on success, < 0 on error
  51. */
  52. int crypto_kdf108_setkey(struct crypto_shash *kmd,
  53. const u8 *key, size_t keylen,
  54. const u8 *ikm, size_t ikmlen);
  55. #endif /* _CRYPTO_KDF108_H */