Sets the mode for the KBKDF operation. There are two supported modes:
Sets the mac type for the KBKDF operation. There are two supported mac types:
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.
The controls EVP_KDF_CTRL_SET_KEY, EVP_KDF_CTRL_SET_SALT, EVP_KDF_CTRL_SET_KB_INFO, and EVP_KDF_CTRL_SET_KB_SEED 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.
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_KB);
The output length of an KBKDF is specified via the "keylen" parameter to the EVP_KDF_derive(3) function.
Note that currently OpenSSL only implements counter and feedback modes. Other variants may be supported in the future.
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);
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 <https://www.openssl.org/source/license.html>.