Latest update
This commit is contained in:
+24
-26
@@ -31,7 +31,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
unsigned char *out, size_t outlen, int fatal)
|
||||
{
|
||||
static const unsigned char label_prefix[] = "tls13 ";
|
||||
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
|
||||
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_PKEY_HKDF);
|
||||
int ret;
|
||||
size_t hkdflabellen;
|
||||
size_t hashlen;
|
||||
@@ -45,7 +45,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
+ 1 + EVP_MAX_MD_SIZE];
|
||||
WPACKET pkt;
|
||||
|
||||
if (pctx == NULL)
|
||||
if (kctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (labellen > TLS13_MAX_LABEL_LEN) {
|
||||
@@ -59,7 +59,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
*/
|
||||
SSLerr(SSL_F_TLS13_HKDF_EXPAND, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
|
||||
}
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
|| !WPACKET_sub_memcpy_u8(&pkt, data, (data == NULL) ? 0 : datalen)
|
||||
|| !WPACKET_get_total_written(&pkt, &hkdflabellen)
|
||||
|| !WPACKET_finish(&pkt)) {
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
WPACKET_cleanup(&pkt);
|
||||
if (fatal)
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_HKDF_EXPAND,
|
||||
@@ -84,15 +84,15 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = EVP_PKEY_derive_init(pctx) <= 0
|
||||
|| EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY)
|
||||
<= 0
|
||||
|| EVP_PKEY_CTX_set_hkdf_md(pctx, md) <= 0
|
||||
|| EVP_PKEY_CTX_set1_hkdf_key(pctx, secret, hashlen) <= 0
|
||||
|| EVP_PKEY_CTX_add1_hkdf_info(pctx, hkdflabel, hkdflabellen) <= 0
|
||||
|| EVP_PKEY_derive(pctx, out, &outlen) <= 0;
|
||||
ret = EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_HKDF_MODE,
|
||||
EVP_PKEY_HKDEF_MODE_EXPAND_ONLY) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, secret, hashlen) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_HKDF_INFO,
|
||||
hkdflabel, hkdflabellen) <= 0
|
||||
|| EVP_KDF_derive(kctx, out, outlen) <= 0;
|
||||
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
|
||||
if (ret != 0) {
|
||||
if (fatal)
|
||||
@@ -155,11 +155,11 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
size_t mdlen, prevsecretlen;
|
||||
int mdleni;
|
||||
int ret;
|
||||
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
|
||||
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_PKEY_HKDF);
|
||||
static const char derived_secret_label[] = "derived";
|
||||
unsigned char preextractsec[EVP_MAX_MD_SIZE];
|
||||
|
||||
if (pctx == NULL) {
|
||||
if (kctx == NULL) {
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_GENERATE_SECRET,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
@@ -192,7 +192,7 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_GENERATE_SECRET,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
EVP_MD_CTX_free(mctx);
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return 0;
|
||||
}
|
||||
EVP_MD_CTX_free(mctx);
|
||||
@@ -203,7 +203,7 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
sizeof(derived_secret_label) - 1, hash, mdlen,
|
||||
preextractsec, mdlen, 1)) {
|
||||
/* SSLfatal() already called */
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -211,21 +211,19 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
prevsecretlen = mdlen;
|
||||
}
|
||||
|
||||
ret = EVP_PKEY_derive_init(pctx) <= 0
|
||||
|| EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY)
|
||||
<= 0
|
||||
|| EVP_PKEY_CTX_set_hkdf_md(pctx, md) <= 0
|
||||
|| EVP_PKEY_CTX_set1_hkdf_key(pctx, insecret, insecretlen) <= 0
|
||||
|| EVP_PKEY_CTX_set1_hkdf_salt(pctx, prevsecret, prevsecretlen)
|
||||
<= 0
|
||||
|| EVP_PKEY_derive(pctx, outsecret, &mdlen)
|
||||
<= 0;
|
||||
ret = EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_HKDF_MODE,
|
||||
EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, insecret, insecretlen) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT,
|
||||
prevsecret, prevsecretlen) <= 0
|
||||
|| EVP_KDF_derive(kctx, outsecret, mdlen) <= 0;
|
||||
|
||||
if (ret != 0)
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_GENERATE_SECRET,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
if (prevsecret == preextractsec)
|
||||
OPENSSL_cleanse(preextractsec, mdlen);
|
||||
return ret == 0;
|
||||
|
||||
Reference in New Issue
Block a user