kdf.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OPENSSL_KDF_H
  10. # define OPENSSL_KDF_H
  11. # pragma once
  12. # include <openssl/macros.h>
  13. # ifndef OPENSSL_NO_DEPRECATED_3_0
  14. # define HEADER_KDF_H
  15. # endif
  16. # include <stdarg.h>
  17. # include <stddef.h>
  18. # include <openssl/types.h>
  19. # include <openssl/core.h>
  20. # ifdef __cplusplus
  21. extern "C" {
  22. # endif
  23. int EVP_KDF_up_ref(EVP_KDF *kdf);
  24. void EVP_KDF_free(EVP_KDF *kdf);
  25. EVP_KDF *EVP_KDF_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
  26. const char *properties);
  27. EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf);
  28. void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
  29. EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
  30. const char *EVP_KDF_get0_description(const EVP_KDF *kdf);
  31. int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name);
  32. const char *EVP_KDF_get0_name(const EVP_KDF *kdf);
  33. const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
  34. const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
  35. void EVP_KDF_CTX_reset(EVP_KDF_CTX *ctx);
  36. size_t EVP_KDF_CTX_get_kdf_size(EVP_KDF_CTX *ctx);
  37. int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen,
  38. const OSSL_PARAM params[]);
  39. int EVP_KDF_get_params(EVP_KDF *kdf, OSSL_PARAM params[]);
  40. int EVP_KDF_CTX_get_params(EVP_KDF_CTX *ctx, OSSL_PARAM params[]);
  41. int EVP_KDF_CTX_set_params(EVP_KDF_CTX *ctx, const OSSL_PARAM params[]);
  42. const OSSL_PARAM *EVP_KDF_gettable_params(const EVP_KDF *kdf);
  43. const OSSL_PARAM *EVP_KDF_gettable_ctx_params(const EVP_KDF *kdf);
  44. const OSSL_PARAM *EVP_KDF_settable_ctx_params(const EVP_KDF *kdf);
  45. const OSSL_PARAM *EVP_KDF_CTX_gettable_params(EVP_KDF_CTX *ctx);
  46. const OSSL_PARAM *EVP_KDF_CTX_settable_params(EVP_KDF_CTX *ctx);
  47. void EVP_KDF_do_all_provided(OSSL_LIB_CTX *libctx,
  48. void (*fn)(EVP_KDF *kdf, void *arg),
  49. void *arg);
  50. int EVP_KDF_names_do_all(const EVP_KDF *kdf,
  51. void (*fn)(const char *name, void *data),
  52. void *data);
  53. # define EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND 0
  54. # define EVP_KDF_HKDF_MODE_EXTRACT_ONLY 1
  55. # define EVP_KDF_HKDF_MODE_EXPAND_ONLY 2
  56. #define EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV 65
  57. #define EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI 66
  58. #define EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV 67
  59. #define EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI 68
  60. #define EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV 69
  61. #define EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI 70
  62. /**** The legacy PKEY-based KDF API follows. ****/
  63. # define EVP_PKEY_CTRL_TLS_MD (EVP_PKEY_ALG_CTRL)
  64. # define EVP_PKEY_CTRL_TLS_SECRET (EVP_PKEY_ALG_CTRL + 1)
  65. # define EVP_PKEY_CTRL_TLS_SEED (EVP_PKEY_ALG_CTRL + 2)
  66. # define EVP_PKEY_CTRL_HKDF_MD (EVP_PKEY_ALG_CTRL + 3)
  67. # define EVP_PKEY_CTRL_HKDF_SALT (EVP_PKEY_ALG_CTRL + 4)
  68. # define EVP_PKEY_CTRL_HKDF_KEY (EVP_PKEY_ALG_CTRL + 5)
  69. # define EVP_PKEY_CTRL_HKDF_INFO (EVP_PKEY_ALG_CTRL + 6)
  70. # define EVP_PKEY_CTRL_HKDF_MODE (EVP_PKEY_ALG_CTRL + 7)
  71. # define EVP_PKEY_CTRL_PASS (EVP_PKEY_ALG_CTRL + 8)
  72. # define EVP_PKEY_CTRL_SCRYPT_SALT (EVP_PKEY_ALG_CTRL + 9)
  73. # define EVP_PKEY_CTRL_SCRYPT_N (EVP_PKEY_ALG_CTRL + 10)
  74. # define EVP_PKEY_CTRL_SCRYPT_R (EVP_PKEY_ALG_CTRL + 11)
  75. # define EVP_PKEY_CTRL_SCRYPT_P (EVP_PKEY_ALG_CTRL + 12)
  76. # define EVP_PKEY_CTRL_SCRYPT_MAXMEM_BYTES (EVP_PKEY_ALG_CTRL + 13)
  77. # define EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND \
  78. EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND
  79. # define EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY \
  80. EVP_KDF_HKDF_MODE_EXTRACT_ONLY
  81. # define EVP_PKEY_HKDEF_MODE_EXPAND_ONLY \
  82. EVP_KDF_HKDF_MODE_EXPAND_ONLY
  83. int EVP_PKEY_CTX_set_tls1_prf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
  84. int EVP_PKEY_CTX_set1_tls1_prf_secret(EVP_PKEY_CTX *pctx,
  85. const unsigned char *sec, int seclen);
  86. int EVP_PKEY_CTX_add1_tls1_prf_seed(EVP_PKEY_CTX *pctx,
  87. const unsigned char *seed, int seedlen);
  88. int EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
  89. int EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *ctx,
  90. const unsigned char *salt, int saltlen);
  91. int EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *ctx,
  92. const unsigned char *key, int keylen);
  93. int EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *ctx,
  94. const unsigned char *info, int infolen);
  95. int EVP_PKEY_CTX_set_hkdf_mode(EVP_PKEY_CTX *ctx, int mode);
  96. # define EVP_PKEY_CTX_hkdf_mode EVP_PKEY_CTX_set_hkdf_mode
  97. int EVP_PKEY_CTX_set1_pbe_pass(EVP_PKEY_CTX *ctx, const char *pass,
  98. int passlen);
  99. int EVP_PKEY_CTX_set1_scrypt_salt(EVP_PKEY_CTX *ctx,
  100. const unsigned char *salt, int saltlen);
  101. int EVP_PKEY_CTX_set_scrypt_N(EVP_PKEY_CTX *ctx, uint64_t n);
  102. int EVP_PKEY_CTX_set_scrypt_r(EVP_PKEY_CTX *ctx, uint64_t r);
  103. int EVP_PKEY_CTX_set_scrypt_p(EVP_PKEY_CTX *ctx, uint64_t p);
  104. int EVP_PKEY_CTX_set_scrypt_maxmem_bytes(EVP_PKEY_CTX *ctx,
  105. uint64_t maxmem_bytes);
  106. # ifdef __cplusplus
  107. }
  108. # endif
  109. #endif