EVP_KDF-HKDF.7ossl 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "EVP_KDF-HKDF 7ossl"
  58. .TH EVP_KDF-HKDF 7ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. EVP_KDF\-HKDF \- The HKDF EVP_KDF implementation
  65. .SH DESCRIPTION
  66. .IX Header "DESCRIPTION"
  67. Support for computing the \fBHKDF\fR KDF through the \fBEVP_KDF\fR API.
  68. .PP
  69. The EVP_KDF\-HKDF algorithm implements the HKDF key derivation function.
  70. HKDF follows the "extract-then-expand" paradigm, where the KDF logically
  71. consists of two modules. The first stage takes the input keying material
  72. and "extracts" from it a fixed-length pseudorandom key K. The second stage
  73. "expands" the key K into several additional pseudorandom keys (the output
  74. of the KDF).
  75. .PP
  76. The output is considered to be keying material.
  77. .SS Identity
  78. .IX Subsection "Identity"
  79. "HKDF" is the name for this implementation; it
  80. can be used with the \fBEVP_KDF_fetch()\fR function.
  81. .SS "Supported parameters"
  82. .IX Subsection "Supported parameters"
  83. The supported parameters are:
  84. .IP """properties"" (\fBOSSL_KDF_PARAM_PROPERTIES\fR) <UTF8 string>" 4
  85. .IX Item """properties"" (OSSL_KDF_PARAM_PROPERTIES) <UTF8 string>"
  86. .PD 0
  87. .IP """digest"" (\fBOSSL_KDF_PARAM_DIGEST\fR) <UTF8 string>" 4
  88. .IX Item """digest"" (OSSL_KDF_PARAM_DIGEST) <UTF8 string>"
  89. .IP """key"" (\fBOSSL_KDF_PARAM_KEY\fR) <octet string>" 4
  90. .IX Item """key"" (OSSL_KDF_PARAM_KEY) <octet string>"
  91. .IP """salt"" (\fBOSSL_KDF_PARAM_SALT\fR) <octet string>" 4
  92. .IX Item """salt"" (OSSL_KDF_PARAM_SALT) <octet string>"
  93. .PD
  94. These parameters work as described in "PARAMETERS" in \fBEVP_KDF\fR\|(3).
  95. .IP """info"" (\fBOSSL_KDF_PARAM_INFO\fR) <octet string>" 4
  96. .IX Item """info"" (OSSL_KDF_PARAM_INFO) <octet string>"
  97. This parameter sets the info value.
  98. The length of the context info buffer cannot exceed 1024 bytes;
  99. this should be more than enough for any normal use of HKDF.
  100. .IP """mode"" (\fBOSSL_KDF_PARAM_MODE\fR) <UTF8 string> or <integer>" 4
  101. .IX Item """mode"" (OSSL_KDF_PARAM_MODE) <UTF8 string> or <integer>"
  102. This parameter sets the mode for the HKDF operation.
  103. There are three modes that are currently defined:
  104. .RS 4
  105. .IP """EXTRACT_AND_EXPAND"" or \fBEVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND\fR" 4
  106. .IX Item """EXTRACT_AND_EXPAND"" or EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND"
  107. This is the default mode. Calling \fBEVP_KDF_derive\fR\|(3) on an EVP_KDF_CTX set
  108. up for HKDF will perform an extract followed by an expand operation in one go.
  109. The derived key returned will be the result after the expand operation. The
  110. intermediate fixed-length pseudorandom key K is not returned.
  111. .Sp
  112. In this mode the digest, key, salt and info values must be set before a key is
  113. derived otherwise an error will occur.
  114. .IP """EXTRACT_ONLY"" or \fBEVP_KDF_HKDF_MODE_EXTRACT_ONLY\fR" 4
  115. .IX Item """EXTRACT_ONLY"" or EVP_KDF_HKDF_MODE_EXTRACT_ONLY"
  116. In this mode calling \fBEVP_KDF_derive\fR\|(3) will just perform the extract
  117. operation. The value returned will be the intermediate fixed-length pseudorandom
  118. key K. The \fIkeylen\fR parameter must match the size of K, which can be looked
  119. up by calling \fBEVP_KDF_CTX_get_kdf_size()\fR after setting the mode and digest.
  120. .Sp
  121. The digest, key and salt values must be set before a key is derived otherwise
  122. an error will occur.
  123. .IP """EXPAND_ONLY"" or \fBEVP_KDF_HKDF_MODE_EXPAND_ONLY\fR" 4
  124. .IX Item """EXPAND_ONLY"" or EVP_KDF_HKDF_MODE_EXPAND_ONLY"
  125. In this mode calling \fBEVP_KDF_derive\fR\|(3) will just perform the expand
  126. operation. The input key should be set to the intermediate fixed-length
  127. pseudorandom key K returned from a previous extract operation.
  128. .Sp
  129. The digest, key and info values must be set before a key is derived otherwise
  130. an error will occur.
  131. .RE
  132. .RS 4
  133. .RE
  134. .PP
  135. The OpenSSL FIPS provider also supports the following parameters:
  136. .IP """fips-indicator"" (\fBOSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR\fR) <integer>" 4
  137. .IX Item """fips-indicator"" (OSSL_KDF_PARAM_FIPS_APPROVED_INDICATOR) <integer>"
  138. A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
  139. This may be used after calling EVP_KDF_derive. It returns 0 if "key-check"
  140. is set to 0 and the check fails.
  141. .IP """key-check"" (\fBOSSL_KDF_PARAM_FIPS_KEY_CHECK\fR) <integer>" 4
  142. .IX Item """key-check"" (OSSL_KDF_PARAM_FIPS_KEY_CHECK) <integer>"
  143. The default value of 1 causes an error during \fBEVP_KDF_CTX_set_params()\fR if the
  144. length of used key-derivation key (\fBOSSL_KDF_PARAM_KEY\fR) is shorter than 112
  145. bits.
  146. Setting this to zero will ignore the error and set the approved
  147. "fips-indicator" to 0.
  148. This option breaks FIPS compliance if it causes the approved "fips-indicator"
  149. to return 0.
  150. .SH NOTES
  151. .IX Header "NOTES"
  152. A context for HKDF can be obtained by calling:
  153. .PP
  154. .Vb 2
  155. \& EVP_KDF *kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
  156. \& EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
  157. .Ve
  158. .PP
  159. The output length of an HKDF expand operation is specified via the \fIkeylen\fR
  160. parameter to the \fBEVP_KDF_derive\fR\|(3) function. When using
  161. EVP_KDF_HKDF_MODE_EXTRACT_ONLY the \fIkeylen\fR parameter must equal the size of
  162. the intermediate fixed-length pseudorandom key otherwise an error will occur.
  163. For that mode, the fixed output size can be looked up by calling \fBEVP_KDF_CTX_get_kdf_size()\fR
  164. after setting the mode and digest on the \fBEVP_KDF_CTX\fR.
  165. .SH EXAMPLES
  166. .IX Header "EXAMPLES"
  167. This example derives 10 bytes using SHA\-256 with the secret key "secret",
  168. salt value "salt" and info value "label":
  169. .PP
  170. .Vb 4
  171. \& EVP_KDF *kdf;
  172. \& EVP_KDF_CTX *kctx;
  173. \& unsigned char out[10];
  174. \& OSSL_PARAM params[5], *p = params;
  175. \&
  176. \& kdf = EVP_KDF_fetch(NULL, "HKDF", NULL);
  177. \& kctx = EVP_KDF_CTX_new(kdf);
  178. \& EVP_KDF_free(kdf);
  179. \&
  180. \& *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  181. \& SN_sha256, strlen(SN_sha256));
  182. \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
  183. \& "secret", (size_t)6);
  184. \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  185. \& "label", (size_t)5);
  186. \& *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  187. \& "salt", (size_t)4);
  188. \& *p = OSSL_PARAM_construct_end();
  189. \& if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
  190. \& error("EVP_KDF_derive");
  191. \& }
  192. \&
  193. \& EVP_KDF_CTX_free(kctx);
  194. .Ve
  195. .SH "CONFORMING TO"
  196. .IX Header "CONFORMING TO"
  197. RFC 5869
  198. .SH "SEE ALSO"
  199. .IX Header "SEE ALSO"
  200. \&\fBEVP_KDF\fR\|(3),
  201. \&\fBEVP_KDF_CTX_new\fR\|(3),
  202. \&\fBEVP_KDF_CTX_free\fR\|(3),
  203. \&\fBEVP_KDF_CTX_get_kdf_size\fR\|(3),
  204. \&\fBEVP_KDF_CTX_set_params\fR\|(3),
  205. \&\fBEVP_KDF_derive\fR\|(3),
  206. "PARAMETERS" in \fBEVP_KDF\fR\|(3),
  207. \&\fBEVP_KDF\-TLS13_KDF\fR\|(7)
  208. .SH HISTORY
  209. .IX Header "HISTORY"
  210. This functionality was added in OpenSSL 3.0.
  211. .SH COPYRIGHT
  212. .IX Header "COPYRIGHT"
  213. Copyright 2016\-2024 The OpenSSL Project Authors. All Rights Reserved.
  214. .PP
  215. Licensed under the Apache License 2.0 (the "License"). You may not use
  216. this file except in compliance with the License. You can obtain a copy
  217. in the file LICENSE in the source distribution or at
  218. <https://www.openssl.org/source/license.html>.