EVP_PKEY_CTX_SET_TLS1_PRF_MD(3ossl)
π EVP_PKEY_CTX_SET_TLS1_PRF_MD β TLS PRF key derivation algorithm π
okay bestie, welcome to the 3ossl manual page for EVP_PKEY_CTX_set_tls1_prf_md and its two besties. this is the TLS PRF key derivation algorithm, and itβs lowkey iconic. letβs get into it π
πΈ NAME πΈ
EVP_PKEY_CTX_set_tls1_prf_md, EVP_PKEY_CTX_set1_tls1_prf_secret, EVP_PKEY_CTX_add1_tls1_prf_seed β the TLS PRF key derivation algorithm. periodt.
β¨ SYNOPSIS β¨
#include <openssl/kdf.h>
int EVP_PKEY_CTX_set_tls1_prf_md(EVP_PKEY_CTX *pctx, const EVP_MD *md);
int EVP_PKEY_CTX_set1_tls1_prf_secret(EVP_PKEY_CTX *pctx,
unsigned char *sec, int seclen);
int EVP_PKEY_CTX_add1_tls1_prf_seed(EVP_PKEY_CTX *pctx,
unsigned char *seed, int seedlen);
π DESCRIPTION π
the EVP_PKEY_TLS1_PRF algorithm implements the PRF key derivation function for TLS. no cap. it has no associated private key and only implements key derivation using EVP_PKEY_derive(3). itβs giving βspecialist behaviour onlyβ and honestly, we respect it.
EVP_PKEY_set_tls1_prf_md() sets the message digest associated with the TLS PRF. EVP_md5_sha1() is treated as a special case which uses the PRF algorithm using both MD5 and SHA1 as used in TLS 1.0 and 1.1. iconique behaviour.
EVP_PKEY_CTX_set_tls1_prf_secret() sets the secret value of the TLS PRF to seclen bytes of the buffer sec. any existing secret value is replaced and any seed is reset. so yes, it really said βnew secret, who dis?β π
EVP_PKEY_CTX_add1_tls1_prf_seed() sets the seed to seedlen bytes of seed. if a seed is already set it is appended to the existing value. itβs additive, bestie. itβs not replacing anything.
π STRING CTRLS π
the TLS PRF also supports string based control operations using EVP_PKEY_CTX_ctrl_str(3). yup, string ctrl girlies rise.
- the type parameter
"md"uses the supplied value as the name of the digest algorithm to use. - the type parameters
"secret"and"seed"use the supplied value parameter as a secret or seed value. - the names
"hexsecret"and"hexseed"are similar except they take a hex string which is converted to binary. hex girlies, this oneβs for you π§
π¦ NOTES π¦
a context for the TLS PRF can be obtained by calling:
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
the digest, secret value and seed must be set before a key is derived or an error occurs. no skipping steps, bestie. the vibe check will fail.
the total length of all seeds cannot exceed 1024 bytes in length: this should be more than enough for any normal use of the TLS PRF. like, genuinely plenty. donβt make it weird.
the output length of the PRF is specified by the length parameter in the EVP_PKEY_derive() function. since the output length is variable, setting the buffer to NULL is not meaningful for the TLS PRF. so donβt do that. itβs not that kind of party.
optimised versions of the TLS PRF can be implemented in an ENGINE. fancy.
π₯ 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. so if you see -2, thatβs the algorithm saying βnot my departmentβ π
π EXAMPLES π
this example derives 10 bytes using SHA-256 with the secret key "secret" and seed value "seed":
EVP_PKEY_CTX *pctx;
unsigned char out[10];
size_t outlen = sizeof(out);
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
if (EVP_PKEY_derive_init(pctx) <= 0)
/* Error */
if (EVP_PKEY_CTX_set_tls1_prf_md(pctx, EVP_sha256()) <= 0)
/* Error */
if (EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, "secret", 6) <= 0)
/* Error */
if (EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, "seed", 4) <= 0)
/* Error */
if (EVP_PKEY_derive(pctx, out, &outlen) <= 0)
/* Error */
π SEE ALSO π
β HISTORY β
all of the functions described here were converted from macros to functions in OpenSSL 3.0. glow-up era.
π COPYRIGHT π
Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
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>.
xoxo, bestie π β source/version 3.5.6, dated 2026-04-0 (with EVP_PKEY_CTX_SET_TLS1_PRF_MD(3ossl) trailing in the footer), and thatβs literally the whole page π«Ά
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms