diff options
author | jsing <> | 2022-01-06 18:18:13 +0000 |
---|---|---|
committer | jsing <> | 2022-01-06 18:18:13 +0000 |
commit | 58c29787c787c30889a5c9cdee9a109dfb201177 (patch) | |
tree | 55e65ff60eda9b321ba83b99fd14b7b9679f97bb /src | |
parent | 38644dd08ee472ac4f6b951f8e2dcfd989ce7fb6 (diff) | |
download | openbsd-58c29787c787c30889a5c9cdee9a109dfb201177.tar.gz openbsd-58c29787c787c30889a5c9cdee9a109dfb201177.tar.bz2 openbsd-58c29787c787c30889a5c9cdee9a109dfb201177.zip |
Allocate and free the EVP_AEAD_CTX struct in tls13_record_protection.
This brings the code more in line with the tls12_record_layer and reduces
the effort needed to make EVP_AEAD_CTX opaque.
Prompted by and ok tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libssl/tls13_record_layer.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c index 40ac9b7cd4..b49d237951 100644 --- a/src/lib/libssl/tls13_record_layer.c +++ b/src/lib/libssl/tls13_record_layer.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_record_layer.c,v 1.65 2021/12/15 17:57:45 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_record_layer.c,v 1.66 2022/01/06 18:18:13 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -25,7 +25,7 @@ static ssize_t tls13_record_layer_write_record(struct tls13_record_layer *rl, | |||
25 | uint8_t content_type, const uint8_t *content, size_t content_len); | 25 | uint8_t content_type, const uint8_t *content, size_t content_len); |
26 | 26 | ||
27 | struct tls13_record_protection { | 27 | struct tls13_record_protection { |
28 | EVP_AEAD_CTX aead_ctx; | 28 | EVP_AEAD_CTX *aead_ctx; |
29 | struct tls13_secret iv; | 29 | struct tls13_secret iv; |
30 | struct tls13_secret nonce; | 30 | struct tls13_secret nonce; |
31 | uint8_t seq_num[TLS13_RECORD_SEQ_NUM_LEN]; | 31 | uint8_t seq_num[TLS13_RECORD_SEQ_NUM_LEN]; |
@@ -40,12 +40,15 @@ tls13_record_protection_new(void) | |||
40 | void | 40 | void |
41 | tls13_record_protection_clear(struct tls13_record_protection *rp) | 41 | tls13_record_protection_clear(struct tls13_record_protection *rp) |
42 | { | 42 | { |
43 | EVP_AEAD_CTX_cleanup(&rp->aead_ctx); | 43 | if (rp->aead_ctx != NULL) { |
44 | EVP_AEAD_CTX_cleanup(rp->aead_ctx); | ||
45 | freezero(rp->aead_ctx, sizeof(*rp->aead_ctx)); | ||
46 | } | ||
44 | 47 | ||
45 | tls13_secret_cleanup(&rp->iv); | 48 | tls13_secret_cleanup(&rp->iv); |
46 | tls13_secret_cleanup(&rp->nonce); | 49 | tls13_secret_cleanup(&rp->nonce); |
47 | 50 | ||
48 | memset(rp->seq_num, 0, sizeof(rp->seq_num)); | 51 | memset(rp, 0, sizeof(*rp)); |
49 | } | 52 | } |
50 | 53 | ||
51 | void | 54 | void |
@@ -458,6 +461,9 @@ tls13_record_layer_set_traffic_key(const EVP_AEAD *aead, const EVP_MD *hash, | |||
458 | 461 | ||
459 | tls13_record_protection_clear(rp); | 462 | tls13_record_protection_clear(rp); |
460 | 463 | ||
464 | if ((rp->aead_ctx = calloc(1, sizeof(*rp->aead_ctx))) == NULL) | ||
465 | return 0; | ||
466 | |||
461 | if (!tls13_secret_init(&rp->iv, EVP_AEAD_nonce_length(aead))) | 467 | if (!tls13_secret_init(&rp->iv, EVP_AEAD_nonce_length(aead))) |
462 | goto err; | 468 | goto err; |
463 | if (!tls13_secret_init(&rp->nonce, EVP_AEAD_nonce_length(aead))) | 469 | if (!tls13_secret_init(&rp->nonce, EVP_AEAD_nonce_length(aead))) |
@@ -470,7 +476,7 @@ tls13_record_layer_set_traffic_key(const EVP_AEAD *aead, const EVP_MD *hash, | |||
470 | if (!tls13_hkdf_expand_label(&key, hash, traffic_key, "key", &context)) | 476 | if (!tls13_hkdf_expand_label(&key, hash, traffic_key, "key", &context)) |
471 | goto err; | 477 | goto err; |
472 | 478 | ||
473 | if (!EVP_AEAD_CTX_init(&rp->aead_ctx, aead, key.data, key.len, | 479 | if (!EVP_AEAD_CTX_init(rp->aead_ctx, aead, key.data, key.len, |
474 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL)) | 480 | EVP_AEAD_DEFAULT_TAG_LENGTH, NULL)) |
475 | goto err; | 481 | goto err; |
476 | 482 | ||
@@ -550,7 +556,7 @@ tls13_record_layer_open_record_protected(struct tls13_record_layer *rl) | |||
550 | rl->read->seq_num)) | 556 | rl->read->seq_num)) |
551 | goto err; | 557 | goto err; |
552 | 558 | ||
553 | if (!EVP_AEAD_CTX_open(&rl->read->aead_ctx, | 559 | if (!EVP_AEAD_CTX_open(rl->read->aead_ctx, |
554 | content, &out_len, content_len, | 560 | content, &out_len, content_len, |
555 | rl->read->nonce.data, rl->read->nonce.len, | 561 | rl->read->nonce.data, rl->read->nonce.len, |
556 | CBS_data(&enc_record), CBS_len(&enc_record), | 562 | CBS_data(&enc_record), CBS_len(&enc_record), |
@@ -728,7 +734,7 @@ tls13_record_layer_seal_record_protected(struct tls13_record_layer *rl, | |||
728 | * this would avoid a copy since the inner would be passed as two | 734 | * this would avoid a copy since the inner would be passed as two |
729 | * separate pieces. | 735 | * separate pieces. |
730 | */ | 736 | */ |
731 | if (!EVP_AEAD_CTX_seal(&rl->write->aead_ctx, | 737 | if (!EVP_AEAD_CTX_seal(rl->write->aead_ctx, |
732 | enc_record, &out_len, enc_record_len, | 738 | enc_record, &out_len, enc_record_len, |
733 | rl->write->nonce.data, rl->write->nonce.len, | 739 | rl->write->nonce.data, rl->write->nonce.len, |
734 | inner, inner_len, header, header_len)) | 740 | inner, inner_len, header, header_len)) |