EVP_KDF.pod 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. =pod
  2. =head1 NAME
  3. EVP_KDF, EVP_KDF_fetch, EVP_KDF_free, EVP_KDF_up_ref,
  4. EVP_KDF_CTX, EVP_KDF_CTX_new, EVP_KDF_CTX_free, EVP_KDF_CTX_dup,
  5. EVP_KDF_CTX_reset, EVP_KDF_derive,
  6. EVP_KDF_CTX_get_kdf_size,
  7. EVP_KDF_get0_provider, EVP_KDF_CTX_kdf, EVP_KDF_is_a,
  8. EVP_KDF_get0_name, EVP_KDF_names_do_all, EVP_KDF_get0_description,
  9. EVP_KDF_CTX_get_params, EVP_KDF_CTX_set_params, EVP_KDF_do_all_provided,
  10. EVP_KDF_get_params, EVP_KDF_gettable_params,
  11. EVP_KDF_gettable_ctx_params, EVP_KDF_settable_ctx_params,
  12. EVP_KDF_CTX_gettable_params, EVP_KDF_CTX_settable_params - EVP KDF routines
  13. =head1 SYNOPSIS
  14. #include <openssl/kdf.h>
  15. typedef struct evp_kdf_st EVP_KDF;
  16. typedef struct evp_kdf_ctx_st EVP_KDF_CTX;
  17. EVP_KDF_CTX *EVP_KDF_CTX_new(EVP_KDF *kdf);
  18. const EVP_KDF *EVP_KDF_CTX_kdf(EVP_KDF_CTX *ctx);
  19. void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx);
  20. EVP_KDF_CTX *EVP_KDF_CTX_dup(const EVP_KDF_CTX *src);
  21. void EVP_KDF_CTX_reset(EVP_KDF_CTX *ctx);
  22. size_t EVP_KDF_CTX_get_kdf_size(EVP_KDF_CTX *ctx);
  23. int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen,
  24. const OSSL_PARAM params[]);
  25. int EVP_KDF_up_ref(EVP_KDF *kdf);
  26. void EVP_KDF_free(EVP_KDF *kdf);
  27. EVP_KDF *EVP_KDF_fetch(OSSL_LIB_CTX *libctx, const char *algorithm,
  28. const char *properties);
  29. int EVP_KDF_is_a(const EVP_KDF *kdf, const char *name);
  30. const char *EVP_KDF_get0_name(const EVP_KDF *kdf);
  31. const char *EVP_KDF_get0_description(const EVP_KDF *kdf);
  32. const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
  33. void EVP_KDF_do_all_provided(OSSL_LIB_CTX *libctx,
  34. void (*fn)(EVP_KDF *kdf, void *arg),
  35. void *arg);
  36. int EVP_KDF_names_do_all(const EVP_KDF *kdf,
  37. void (*fn)(const char *name, void *data),
  38. void *data);
  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(const EVP_KDF *kdf);
  46. const OSSL_PARAM *EVP_KDF_CTX_settable_params(const EVP_KDF *kdf);
  47. const OSSL_PROVIDER *EVP_KDF_get0_provider(const EVP_KDF *kdf);
  48. =head1 DESCRIPTION
  49. The EVP KDF routines are a high-level interface to Key Derivation Function
  50. algorithms and should be used instead of algorithm-specific functions.
  51. After creating a B<EVP_KDF_CTX> for the required algorithm using
  52. EVP_KDF_CTX_new(), inputs to the algorithm are supplied either by
  53. passing them as part of the EVP_KDF_derive() call or using calls
  54. to EVP_KDF_CTX_set_params() before calling EVP_KDF_derive() to derive
  55. the key.
  56. =head2 Types
  57. B<EVP_KDF> is a type that holds the implementation of a KDF.
  58. B<EVP_KDF_CTX> is a context type that holds the algorithm inputs.
  59. =head2 Algorithm implementation fetching
  60. EVP_KDF_fetch() fetches an implementation of a KDF I<algorithm>, given
  61. a library context I<libctx> and a set of I<properties>.
  62. See L<crypto(7)/ALGORITHM FETCHING> for further information.
  63. See L<OSSL_PROVIDER-default(7)/Key Derivation Function (KDF)> for the lists of
  64. algorithms supported by the default provider.
  65. The returned value must eventually be freed with
  66. L<EVP_KDF_free(3)>.
  67. EVP_KDF_up_ref() increments the reference count of an already fetched
  68. KDF.
  69. EVP_KDF_free() frees a fetched algorithm.
  70. NULL is a valid parameter, for which this function is a no-op.
  71. =head2 Context manipulation functions
  72. EVP_KDF_CTX_new() creates a new context for the KDF implementation I<kdf>.
  73. EVP_KDF_CTX_free() frees up the context I<ctx>. If I<ctx> is NULL, nothing
  74. is done.
  75. EVP_KDF_CTX_kdf() returns the B<EVP_KDF> associated with the context
  76. I<ctx>.
  77. =head2 Computing functions
  78. EVP_KDF_CTX_reset() resets the context to the default state as if the context
  79. had just been created.
  80. EVP_KDF_derive() processes any parameters in I<Params> and then derives
  81. I<keylen> bytes of key material and places it in the I<key> buffer.
  82. If the algorithm produces a fixed amount of output then an error will
  83. occur unless the I<keylen> parameter is equal to that output size,
  84. as returned by EVP_KDF_CTX_get_kdf_size().
  85. EVP_KDF_get_params() retrieves details about the implementation
  86. I<kdf>.
  87. The set of parameters given with I<params> determine exactly what
  88. parameters should be retrieved.
  89. Note that a parameter that is unknown in the underlying context is
  90. simply ignored.
  91. EVP_KDF_CTX_get_params() retrieves chosen parameters, given the
  92. context I<ctx> and its underlying context.
  93. The set of parameters given with I<params> determine exactly what
  94. parameters should be retrieved.
  95. Note that a parameter that is unknown in the underlying context is
  96. simply ignored.
  97. EVP_KDF_CTX_set_params() passes chosen parameters to the underlying
  98. context, given a context I<ctx>.
  99. The set of parameters given with I<params> determine exactly what
  100. parameters are passed down.
  101. Note that a parameter that is unknown in the underlying context is
  102. simply ignored.
  103. Also, what happens when a needed parameter isn't passed down is
  104. defined by the implementation.
  105. EVP_KDF_gettable_params() returns an L<OSSL_PARAM(3)> array that describes
  106. the retrievable and settable parameters. EVP_KDF_gettable_params()
  107. returns parameters that can be used with EVP_KDF_get_params().
  108. EVP_KDF_gettable_ctx_params() and EVP_KDF_CTX_gettable_params()
  109. return constant L<OSSL_PARAM(3)> arrays that describe the retrievable
  110. parameters that can be used with EVP_KDF_CTX_get_params().
  111. EVP_KDF_gettable_ctx_params() returns the parameters that can be retrieved
  112. from the algorithm, whereas EVP_KDF_CTX_gettable_params() returns
  113. the parameters that can be retrieved in the context's current state.
  114. EVP_KDF_settable_ctx_params() and EVP_KDF_CTX_settable_params() return
  115. constant L<OSSL_PARAM(3)> arrays that describe the settable parameters that
  116. can be used with EVP_KDF_CTX_set_params(). EVP_KDF_settable_ctx_params()
  117. returns the parameters that can be retrieved from the algorithm,
  118. whereas EVP_KDF_CTX_settable_params() returns the parameters that can
  119. be retrieved in the context's current state.
  120. =head2 Information functions
  121. EVP_KDF_CTX_get_kdf_size() returns the output size if the algorithm produces a fixed amount
  122. of output and B<SIZE_MAX> otherwise. If an error occurs then 0 is returned.
  123. For some algorithms an error may result if input parameters necessary to
  124. calculate a fixed output size have not yet been supplied.
  125. EVP_KDF_is_a() returns 1 if I<kdf> is an implementation of an
  126. algorithm that's identifiable with I<name>, otherwise 0.
  127. EVP_KDF_get0_provider() returns the provider that holds the implementation
  128. of the given I<kdf>.
  129. EVP_KDF_do_all_provided() traverses all KDF implemented by all activated
  130. providers in the given library context I<libctx>, and for each of the
  131. implementations, calls the given function I<fn> with the implementation method
  132. and the given I<arg> as argument.
  133. EVP_KDF_get0_name() return the name of the given KDF. For fetched KDFs
  134. with multiple names, only one of them is returned; it's
  135. recommended to use EVP_KDF_names_do_all() instead.
  136. EVP_KDF_names_do_all() traverses all names for I<kdf>, and calls
  137. I<fn> with each name and I<data>.
  138. EVP_KDF_get0_description() returns a description of the I<kdf>, meant for
  139. display and human consumption. The description is at the discretion of
  140. the I<kdf> implementation.
  141. =head1 PARAMETERS
  142. The standard parameter names are:
  143. =over 4
  144. =item "pass" (B<OSSL_KDF_PARAM_PASSWORD>) <octet string>
  145. Some KDF implementations require a password.
  146. For those KDF implementations that support it, this parameter sets the password.
  147. =item "salt" (B<OSSL_KDF_PARAM_SALT>) <octet string>
  148. Some KDF implementations can take a non-secret unique cryptographic salt.
  149. For those KDF implementations that support it, this parameter sets the salt.
  150. The default value, if any, is implementation dependent.
  151. =item "iter" (B<OSSL_KDF_PARAM_ITER>) <unsigned integer>
  152. Some KDF implementations require an iteration count.
  153. For those KDF implementations that support it, this parameter sets the
  154. iteration count.
  155. The default value, if any, is implementation dependent.
  156. =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
  157. =item "mac" (B<OSSL_KDF_PARAM_MAC>) <UTF8 string>
  158. =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
  159. =item "cipher" (B<OSSL_KDF_PARAM_CIPHER>) <UTF8 string>
  160. For KDF implementations that use an underlying computation MAC, digest or
  161. cipher, these parameters set what the algorithm should be.
  162. The value is always the name of the intended algorithm,
  163. or the properties.
  164. Note that not all algorithms may support all possible underlying
  165. implementations.
  166. =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
  167. Some KDF implementations require a key.
  168. For those KDF implementations that support it, this octet string parameter
  169. sets the key.
  170. =item "info" (B<OSSL_KDF_PARAM_INFO>) <octet string>
  171. Some KDF implementations, such as L<EVP_KDF-HKDF(7)>, take an 'info' parameter
  172. for binding the derived key material
  173. to application- and context-specific information.
  174. This parameter sets the info, fixed info, other info or shared info argument.
  175. You can specify this parameter multiple times, and each instance will
  176. be concatenated to form the final value.
  177. =item "maclen" (B<OSSL_KDF_PARAM_MAC_SIZE>) <unsigned integer>
  178. Used by implementations that use a MAC with a variable output size (KMAC).
  179. For those KDF implementations that support it, this parameter
  180. sets the MAC output size.
  181. The default value, if any, is implementation dependent.
  182. The length must never exceed what can be given with a B<size_t>.
  183. =item "maxmem_bytes" (B<OSSL_KDF_PARAM_SCRYPT_MAXMEM>) <unsigned integer>
  184. Memory-hard password-based KDF algorithms, such as scrypt, use an amount of
  185. memory that depends on the load factors provided as input.
  186. For those KDF implementations that support it, this B<uint64_t> parameter sets
  187. an upper limit on the amount of memory that may be consumed while performing
  188. a key derivation.
  189. If this memory usage limit is exceeded because the load factors are chosen
  190. too high, the key derivation will fail.
  191. The default value is implementation dependent.
  192. The memory size must never exceed what can be given with a B<size_t>.
  193. =back
  194. =head1 RETURN VALUES
  195. EVP_KDF_fetch() returns a pointer to a newly fetched B<EVP_KDF>, or
  196. NULL if allocation failed.
  197. EVP_KDF_get0_provider() returns a pointer to the provider for the KDF, or
  198. NULL on error.
  199. EVP_KDF_up_ref() returns 1 on success, 0 on error.
  200. EVP_KDF_CTX_new() returns either the newly allocated
  201. B<EVP_KDF_CTX> structure or NULL if an error occurred.
  202. EVP_KDF_CTX_free() and EVP_KDF_CTX_reset() do not return a value.
  203. EVP_KDF_CTX_get_kdf_size() returns the output size. B<SIZE_MAX> is returned to indicate
  204. that the algorithm produces a variable amount of output; 0 to indicate failure.
  205. EVP_KDF_get0_name() returns the name of the KDF, or NULL on error.
  206. EVP_KDF_names_do_all() returns 1 if the callback was called for all names. A
  207. return value of 0 means that the callback was not called for any names.
  208. The remaining functions return 1 for success and 0 or a negative value for
  209. failure. In particular, a return value of -2 indicates the operation is not
  210. supported by the KDF algorithm.
  211. =head1 NOTES
  212. The KDF life-cycle is described in L<life_cycle-kdf(7)>. In the future,
  213. the transitions described there will be enforced. When this is done, it will
  214. not be considered a breaking change to the API.
  215. =head1 SEE ALSO
  216. L<OSSL_PROVIDER-default(7)/Key Derivation Function (KDF)>,
  217. L<life_cycle-kdf(7)>.
  218. =head1 HISTORY
  219. This functionality was added in OpenSSL 3.0.
  220. =head1 COPYRIGHT
  221. Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
  222. Licensed under the Apache License 2.0 (the "License"). You may not use
  223. this file except in compliance with the License. You can obtain a copy
  224. in the file LICENSE in the source distribution or at
  225. L<https://www.openssl.org/source/license.html>.
  226. =cut