Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
NAME
EVP_PKEY_CTX_set_hkdf_md, EVP_PKEY_CTX_set1_hkdf_salt, EVP_PKEY_CTX_set1_hkdf_key, EVP_PKEY_CTX_add1_hkdf_info, EVP_PKEY_CTX_hkdf_mode — HMAC-based Extract-and-Expand key derivation algorithmSYNOPSIS
#include <openssl/evp.h>#include <openssl/kdf.h>
EVP_PKEY_CTX_hkdf_mode(EVP_PKEY_CTX *pctx, int mode);
EVP_PKEY_CTX_set_hkdf_md(EVP_PKEY_CTX *pctx, const EVP_MD *md);
EVP_PKEY_CTX_set1_hkdf_salt(EVP_PKEY_CTX *pctx, unsigned char *salt, int saltlen);
EVP_PKEY_CTX_set1_hkdf_key(EVP_PKEY_CTX *pctx, unsigned char *key, int keylen);
EVP_PKEY_CTX_add1_hkdf_info(EVP_PKEY_CTX *pctx, unsigned char *info, int infolen);
DESCRIPTION
The EVP_PKEY_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).- EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND
-
This is the default mode. Calling EVP_PKEY_derive(3) on an EVP_PKEY_CTX set up for HKDF will perform an extract followed by an expand operation in one go. The derived key returned will be the result after the expand operation. The intermediate fixed-length pseudorandom key K is not returned.
- EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY
-
In this mode calling EVP_PKEY_derive(3) will just perform the extract operation. The value returned will be the intermediate fixed-length pseudorandom key K.
- EVP_PKEY_HKDEF_MODE_EXPAND_ONLY
-
In this mode calling EVP_PKEY_derive(3) will just perform the expand operation. The input key should be set to the intermediate fixed-length pseudorandom key K returned from a previous extract operation.
STRING CTRLS
HKDF also supports string based control operations via EVP_PKEY_CTX_ctrl_str(3). The type parameter "md" uses the supplied value as the name of the digest algorithm to use. The type parameter "mode" accepts "EXTRACT_AND_EXPAND", "EXTRACT_ONLY" and "EXPAND_ONLY" as value to determine the mode to use. The type parameters "salt", "key" and "info" use the supplied value parameter as a seed, key, or info. The names "hexsalt", "hexkey" and "hexinfo" are similar except they take a hex string which is converted to binary.NOTES
All these functions are implemented as macros.EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
RETURN VALUES
All these functions return 1 for success and 0 or a negative value for failure. In particular a return value of -2 indicates the operation is not supported by the public key algorithm.EXAMPLES
This example derives 10 bytes using SHA-256 with the secret key "secret", salt value "salt" and info value "label":EVP_PKEY_CTX *pctx; unsigned char out[10]; size_t outlen = sizeof(out); if ((pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)) == NULL) /* Error */ if (EVP_PKEY_derive_init(pctx) <= 0) /* Error */ if (EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0) /* Error */ if (EVP_PKEY_CTX_set1_hkdf_salt(pctx, "salt", 4) <= 0) /* Error */ if (EVP_PKEY_CTX_set1_hkdf_key(pctx, "secret", 6) <= 0) /* Error */ if (EVP_PKEY_CTX_add1_hkdf_info(pctx, "label", 5) <= 0) /* Error */ if (EVP_PKEY_derive(pctx, out, &outlen) <= 0) /* Error */