5 EVP_KDF-KB - The Key-Based EVP_KDF implementation
9 The EVP_KDF-KB algorithm implements the Key-Based key derivation function
10 (KBKDF). KBKDF derives a key from repeated application of a keyed MAC to an
11 input secret (and other optional values).
15 "KBKDF" is the name for this implementation; it can be used with the
16 EVP_KDF_fetch() function.
18 =head2 Supported parameters
20 The supported parameters are:
24 =item "mode" (B<OSSL_KDF_PARAM_MODE>) <UTF8 string>
26 The mode parameter determines which flavor of KBKDF to use - currently the
27 choices are "counter" and "feedback". "counter" is the default, and will be
30 =item "mac" (B<OSSL_KDF_PARAM_MAC>) <UTF8 string>
32 The value is either CMAC, HMAC, KMAC128 or KMAC256.
34 =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
36 =item "cipher" (B<OSSL_KDF_PARAM_CIPHER>) <UTF8 string>
38 =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
40 =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
42 =item "salt" (B<OSSL_KDF_PARAM_SALT>) <octet string>
44 =item "info (B<OSSL_KDF_PARAM_INFO>) <octet string>
46 =item "seed" (B<OSSL_KDF_PARAM_SEED>) <octet string>
48 The seed parameter is unused in counter mode.
50 =item "use-l" (B<OSSL_KDF_PARAM_KBKDF_USE_L>) <integer>
52 Set to B<0> to disable use of the optional Fixed Input data 'L' (see SP800-108).
53 The default value of B<1> will be used if unspecified.
55 =item "use-separator" (B<OSSL_KDF_PARAM_KBKDF_USE_SEPARATOR>) <integer>
57 Set to B<0> to disable use of the optional Fixed Input data 'zero separator'
58 (see SP800-108) that is placed between the Label and Context.
59 The default value of B<1> will be used if unspecified.
61 =item "r" (B<OSSL_KDF_PARAM_KBKDF_R>) <integer>
63 Set the fixed value 'r', indicating the length of the counter in bits.
65 Supported values are B<8>, B<16>, B<24>, and B<32>.
66 The default value of B<32> will be used if unspecified.
70 Depending on whether mac is CMAC or HMAC, either digest or cipher is required
71 (respectively) and the other is unused. They are unused for KMAC128 and KMAC256.
73 The parameters key, salt, info, and seed correspond to KI, Label, Context, and
74 IV (respectively) in SP800-108. As in that document, salt, info, and seed are
75 optional and may be omitted.
77 "mac", "digest", cipher" and "properties" are described in
78 L<EVP_KDF(3)/PARAMETERS>.
82 A context for KBKDF can be obtained by calling:
84 EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
85 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
87 The output length of an KBKDF is specified via the C<keylen>
88 parameter to the L<EVP_KDF_derive(3)> function.
90 Note that currently OpenSSL only implements counter and feedback modes. Other
91 variants may be supported in the future.
95 This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret",
96 Label "label", and Context "context".
100 unsigned char out[10];
101 OSSL_PARAM params[6], *p = params;
103 kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
104 kctx = EVP_KDF_CTX_new(kdf);
107 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
109 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
111 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
112 "secret", strlen("secret"));
113 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
114 "label", strlen("label"));
115 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
116 "context", strlen("context"));
117 *p = OSSL_PARAM_construct_end();
118 if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
119 error("EVP_KDF_derive");
121 EVP_KDF_CTX_free(kctx);
123 This example derives 10 bytes using FEEDBACK-CMAC-AES256, with KI "secret",
124 Label "label", and IV "sixteen bytes iv".
128 unsigned char out[10];
129 OSSL_PARAM params[8], *p = params;
130 unsigned char *iv = "sixteen bytes iv";
132 kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
133 kctx = EVP_KDF_CTX_new(kdf);
136 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "AES256", 0);
137 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "CMAC", 0);
138 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MODE, "FEEDBACK", 0);
139 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
140 "secret", strlen("secret"));
141 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
142 "label", strlen("label"));
143 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
144 "context", strlen("context"));
145 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
147 *p = OSSL_PARAM_construct_end();
148 if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
149 error("EVP_KDF_derive");
151 EVP_KDF_CTX_free(kctx);
155 NIST SP800-108, IETF RFC 6803, IETF RFC 8009.
160 L<EVP_KDF_CTX_free(3)>,
161 L<EVP_KDF_CTX_get_kdf_size(3)>,
162 L<EVP_KDF_derive(3)>,
163 L<EVP_KDF(3)/PARAMETERS>
167 This functionality was added in OpenSSL 3.0.
169 Support for KMAC was added in OpenSSL 3.1.
173 Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
174 Copyright 2019 Red Hat, Inc.
176 Licensed under the Apache License 2.0 (the "License"). You may not use
177 this file except in compliance with the License. You can obtain a copy
178 in the file LICENSE in the source distribution or at
179 L<https://www.openssl.org/source/license.html>.