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 B<OSSL_KDF_PARAM_PROPERTIES> ("properties") <UTF8 string>
26 =item B<OSSL_KDF_PARAM_DIGEST> ("digest") <UTF8 string>
28 =item B<OSSL_KDF_PARAM_DIGEST> ("mac") <UTF8 string>
30 =item B<OSSL_KDF_PARAM_KEY> ("key") <octet string>
32 =item B<OSSL_KDF_PARAM_SALT> ("salt") <octet string>
34 =item B<OSSL_KDF_PARAM_INFO> ("info") <octet string>
38 The parameters key, salt, and info correspond to KI, Label, and Context
39 (respectively) in SP800-108. As in that document, salt and info are optional
40 and may be omitted. Currently, only HMAC is supported for mac.
44 A context for KBKDF can be obtained by calling:
46 EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
47 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
49 The output length of an KBKDF is specified via the C<keylen>
50 parameter to the L<EVP_KDF_derive(3)> function.
52 Note that currently OpenSSL only implements Counter mode with HMAC. Other
53 variants may be supported in the future.
57 This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret",
58 Label "label", and Context "context".
62 unsigned char out[10];
63 OSSL_PARAM params[6], *p = params;
65 kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
66 kctx = EVP_KDF_CTX_new(kdf);
69 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
71 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
73 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
74 "secret", strlen("secret"))
75 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
76 "context", strlen("context"));
77 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
78 "label", strlen("label"));
79 *p = OSSL_PARAM_construct_end();
80 if (EVP_KDF_CTX_set_params(kctx, params) <= 0)
81 error("EVP_KDF_CTX_set_params");
82 else if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0)
83 error("EVP_KDF_derive");
85 EVP_KDF_CTX_free(kctx);
89 NIST SP800-108, IETF RFC 8009.
94 L<EVP_KDF_CTX_new_id(3)>,
95 L<EVP_KDF_CTX_free(3)>,
99 L<EVP_KDF(3)/PARAMETERS>
103 This functionality was added to OpenSSL 3.0.
107 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
108 Copyright 2019 Red Hat, Inc.
110 Licensed under the Apache License 2.0 (the "License"). You may not use
111 this file except in compliance with the License. You can obtain a copy
112 in the file LICENSE in the source distribution or at
113 L<https://www.openssl.org/source/license.html>.