=pod =head1 NAME EVP_KDF_KB - The Key-Based EVP_KDF implementation =head1 DESCRIPTION The EVP_KDF_KB algorithm implements the Key-Based key derivation function (KBKDF). KBKDF derives a key from repeated application of a keyed MAC to an input secret (and other optional values). =head2 Numeric identity B is the numeric identity for this implementation; it can be used with the EVP_KDF_CTX_new_id() function. =head2 Supported controls The supported controls are: =over 4 =item B This control expects one argument: C Sets the mode for the KBKDF operation. There are two supported modes: =over 4 =item B The counter mode of KBKDF should be used. This is the default. =item B The feedback mode of KBKDF should be used. =back =item B This control expects one argument: C Sets the mac type for the KBKDF operation. There are two supported mac types: =over 4 =item B The HMAC with the digest set by B should be used as the mac. =item B The CMAC with the cipher set by B should be used as the mac. =back =item B =item B =item B =item B These controls work as described in L. =item B This control expects two arguments: C, C =item B This control expects two arguments: C, C It is used only in the feedback mode and the length must be the same as the block length of the cipher in CMAC or the size of the digest in HMAC. =back The controls B, B, B, and B correspond to KI, Label, Context, and IV (respectively) in SP800-108. As in that document, salt, info, and seed are optional and may be omitted. Depending on whether mac is CMAC or HMAC, either digest or cipher is required (respectively) and the other is unused. =head1 NOTES A context for KBKDF can be obtained by calling: EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_KB); The output length of an KBKDF is specified via the C parameter to the L function. Note that currently OpenSSL only implements counter and feedback modes. Other variants may be supported in the future. =head1 EXAMPLES This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret", Label "label", and Context "context". EVP_KDF_CTX *kctx; unsigned char out[10]; kctx = EVP_KDF_CTX_new_id(EVP_KDF_KB); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_MAC_TYPE, EVP_KDF_KB_MAC_TYPE_HMAC); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", strlen("secret")); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "label", strlen("label")); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_INFO, "context", strlen("context")); if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) error("EVP_KDF_derive"); EVP_KDF_CTX_free(kctx); This example derives 10 bytes using FEEDBACK-CMAC-AES256, with KI "secret", Label "label", Context "context", and IV "sixteen bytes iv". EVP_KDF_CTX *kctx; unsigned char out[10]; unsigned char *iv = "sixteen bytes iv"; kctx = EVP_KDF_CTX_new_id(EVP_KDF_KB); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_CIPHER, EVP_aes_256_cbc()); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_MAC_TYPE, EVP_KDF_KB_MAC_TYPE_CMAC); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_MODE, EVP_KDF_KB_MODE_FEEDBACK); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", strlen("secret")); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "label", strlen("label")); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_INFO, "context", strlen("context")); EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KB_SEED, iv, strlen(iv)); if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) error("EVP_KDF_derive"); EVP_KDF_CTX_free(kctx); =head1 CONFORMING TO NIST SP800-108, IETF RFC 6803, IETF RFC 8009. =head1 SEE ALSO L, L, L, L, L, L, L =head1 HISTORY This functionality was added to OpenSSL 3.0. =head1 COPYRIGHT Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. Copyright 2019 Red Hat, Inc. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. =cut