The EVP_KDF_HKDF algorithm implements the HKDF key derivation function. HKDF follows the ``extract-then-expand'' paradigm, where the KDF logically consists of two modules. The first stage takes the input keying material and ``extracts'' from it a fixed-length pseudorandom key K. The second stage ``expands'' the key K into several additional pseudorandom keys (the output of the KDF).
Resets the context info buffer to zero length.
Sets the info value to the first infolen bytes of the buffer info. If a value is already set, the contents of the buffer are appended to the existing value.
The total length of the context info buffer cannot exceed 1024 bytes; this should be more than enough for any normal use of HKDF.
EVP_KDF_ctrl_str() takes two type strings for this control:
Sets the mode for the HKDF operation. There are three modes that are currently defined:
In this mode the digest, key, salt and info values must be set before a key is derived otherwise an error will occur.
The digest, key and salt values must be set before a key is derived otherwise an error will occur.
The digest, key and info values must be set before a key is derived otherwise an error will occur.
EVP_KDF_ctrl_str() type string: ``mode''
The value string is expected to be one of: ``EXTRACT_AND_EXPAND'', ``EXTRACT_ONLY'' or ``EXPAND_ONLY''.
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF);
The output length of an HKDF expand operation is specified via the "keylen" parameter to the EVP_KDF_derive(3) function. When using EVP_KDF_HKDF_MODE_EXTRACT_ONLY the "keylen" parameter must equal the size of the intermediate fixed-length pseudorandom key otherwise an error will occur. For that mode, the fixed output size can be looked up by calling EVP_KDF_size() after setting the mode and digest on the "EVP_KDF_CTX".
EVP_KDF_CTX *kctx; unsigned char out[10]; kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF); if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { error("EVP_KDF_CTRL_SET_MD"); } if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) { error("EVP_KDF_CTRL_SET_SALT"); } if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) { error("EVP_KDF_CTRL_SET_KEY"); } if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_HKDF_INFO, "label", (size_t)5) <= 0) { error("EVP_KDF_CTRL_ADD_HKDF_INFO"); } 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>.