@@ -17,15 +17,6 @@ of the KDF).
1717
1818The output is considered to be keying material.
1919
20- =head2 Fixed-Digest HKDF
21-
22- B<HKDF-SHA256>, B<HKDF-SHA384> and B<HKDF-SHA512> are fixed-digest versions
23- of the B<HKDF> algorithm. Each algorithm has its own OID. These algorithms
24- are instantiated with the appropriate digest already configured, thus it is
25- not necessary to set the digest using the B<OSSL_KDF_PARAM_DIGEST> parameter.
26- An attempt to set the digest to anything other than the pre-configured digest
27- will result in an error.
28-
2920=head2 Identity
3021
3122The following algorithms are available for this implementation; they
@@ -40,12 +31,20 @@ mere OID which came out in this form after a call to L<OBJ_obj2txt(3)>).
4031
4132=item "HKDF"
4233
34+ The B<OSSL_KDF_PARAM_DIGEST> parameter must be set for B<HKDF> before it can
35+ be used.
36+
4337=item "HKDF-SHA256", "id-alg-hkdf-with-sha256", "1.2.840.113549.1.9.16.3.28"
4438
4539=item "HKDF-SHA384", "id-alg-hkdf-with-sha384", "1.2.840.113549.1.9.16.3.29"
4640
4741=item "HKDF-SHA512", "id-alg-hkdf-with-sha512", "1.2.840.113549.1.9.16.3.30"
4842
43+ B<HKDF-SHA256>, B<HKDF-SHA384> and B<HKDF-SHA512> are fixed-digest versions
44+ of B<HKDF> with the appropriate digest already configured.
45+ L<EVP_KDF_CTX_reset(3)> will not reset the context's digest for fixed-digest
46+ versions.
47+
4948=back
5049
5150=head2 Supported parameters
@@ -58,6 +57,8 @@ The supported parameters are:
5857
5958=item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
6059
60+ Attempting to set the digest on a fixed-digest B<HKDF> will result in an error.
61+
6162=item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
6263
6364=item "salt" (B<OSSL_KDF_PARAM_SALT>) <octet string>
@@ -84,8 +85,9 @@ up for HKDF will perform an extract followed by an expand operation in one go.
8485The derived key returned will be the result after the expand operation. The
8586intermediate fixed-length pseudorandom key K is not returned.
8687
87- In this mode the digest, key, salt and info values must be set before a key is
88- derived otherwise an error will occur.
88+ In this mode the key, salt and info values must be set before a key is
89+ derived otherwise an error will occur. For non-fixed mode (B<HKDF>) the digest
90+ must also be set.
8991
9092=item "EXTRACT_ONLY" or B<EVP_KDF_HKDF_MODE_EXTRACT_ONLY>
9193
@@ -94,17 +96,19 @@ operation. The value returned will be the intermediate fixed-length pseudorandom
9496key K. The I<keylen> parameter must match the size of K, which can be looked
9597up by calling EVP_KDF_CTX_get_kdf_size() after setting the mode and digest.
9698
97- The digest, key and salt values must be set before a key is derived otherwise
98- an error will occur.
99+ The key and salt values must be set before a key is derived otherwise
100+ an error will occur. For non-fixed mode (B<HKDF>) the digest
101+ must also be set.
99102
100103=item "EXPAND_ONLY" or B<EVP_KDF_HKDF_MODE_EXPAND_ONLY>
101104
102105In this mode calling L<EVP_KDF_derive(3)> will just perform the expand
103106operation. The input key should be set to the intermediate fixed-length
104107pseudorandom key K returned from a previous extract operation.
105108
106- The digest, key and info values must be set before a key is derived otherwise
107- an error will occur.
109+ The key and info values must be set before a key is derived otherwise
110+ an error will occur. For non-fixed mode (B<HKDF>) the digest
111+ must also be set.
108112
109113=back
110114
@@ -148,6 +152,8 @@ after setting the mode and digest on the B<EVP_KDF_CTX>.
148152
149153=head1 EXAMPLES
150154
155+ =head2 HKDF Algorithm
156+
151157This example derives 10 bytes using SHA-256 with the secret key "secret",
152158salt value "salt" and info value "label":
153159
@@ -175,6 +181,33 @@ salt value "salt" and info value "label":
175181
176182 EVP_KDF_CTX_free(kctx);
177183
184+ =head2 HKDF-SHA256 Algorithm
185+
186+ This example derives 10 bytes using HKDF-SHA256 with the secret key "secret",
187+ salt value "salt" and info value "label":
188+
189+ EVP_KDF *kdf;
190+ EVP_KDF_CTX *kctx;
191+ unsigned char out[10];
192+ OSSL_PARAM params[4], *p = params;
193+
194+ kdf = EVP_KDF_fetch(NULL, "HKDF-SHA256", NULL);
195+ kctx = EVP_KDF_CTX_new(kdf);
196+ EVP_KDF_free(kdf);
197+
198+ *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
199+ "secret", (size_t)6);
200+ *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
201+ "label", (size_t)5);
202+ *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
203+ "salt", (size_t)4);
204+ *p = OSSL_PARAM_construct_end();
205+ if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
206+ error("EVP_KDF_derive");
207+ }
208+
209+ EVP_KDF_CTX_free(kctx);
210+
178211=head1 CONFORMING TO
179212
180213RFC 5869 and RFC 8619
0 commit comments