EVP_KDF.pod 9.9 KB

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