diff options
author | tb <> | 2024-05-22 14:02:08 +0000 |
---|---|---|
committer | tb <> | 2024-05-22 14:02:08 +0000 |
commit | c9e7f6cc4791caccd0623fc02585e3e9b39d6965 (patch) | |
tree | e097609e2839e2669ef6dccf478b997c6ee97d1c /src | |
parent | 2290dbcd032621fa2cada872b167afa988acbc21 (diff) | |
download | openbsd-c9e7f6cc4791caccd0623fc02585e3e9b39d6965.tar.gz openbsd-c9e7f6cc4791caccd0623fc02585e3e9b39d6965.tar.bz2 openbsd-c9e7f6cc4791caccd0623fc02585e3e9b39d6965.zip |
Fix in-place decryption for EVP_chacha20_poly1305()
Take the MAC before clobbering the input value on decryption. Fixes hangs
during the QUIC handshake with HAProxy using TLS_CHACHA20_POLY1305_SHA256.
Found, issue pinpointed, and initial fix tested by Lucas Gabriel Vuotto:
Let me take this opportunity to thank the HAProxy team for going out of
their way to keep supporting LibreSSL. It's much appreciated.
See https://github.com/haproxy/haproxy/issues/2569
tweak/ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/evp/e_chacha20poly1305.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/libcrypto/evp/e_chacha20poly1305.c b/src/lib/libcrypto/evp/e_chacha20poly1305.c index cc2e0157e6..816a8aa218 100644 --- a/src/lib/libcrypto/evp/e_chacha20poly1305.c +++ b/src/lib/libcrypto/evp/e_chacha20poly1305.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: e_chacha20poly1305.c,v 1.35 2024/04/09 13:52:41 beck Exp $ */ | 1 | /* $OpenBSD: e_chacha20poly1305.c,v 1.36 2024/05/22 14:02:08 tb Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> |
@@ -493,6 +493,8 @@ chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
493 | 493 | ||
494 | /* Update with AD or plaintext/ciphertext. */ | 494 | /* Update with AD or plaintext/ciphertext. */ |
495 | if (in != NULL) { | 495 | if (in != NULL) { |
496 | if (!ctx->encrypt || out == NULL) | ||
497 | CRYPTO_poly1305_update(&cpx->poly1305, in, len); | ||
496 | if (out == NULL) { | 498 | if (out == NULL) { |
497 | cpx->ad_len += len; | 499 | cpx->ad_len += len; |
498 | cpx->in_ad = 1; | 500 | cpx->in_ad = 1; |
@@ -502,8 +504,6 @@ chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
502 | } | 504 | } |
503 | if (ctx->encrypt && out != NULL) | 505 | if (ctx->encrypt && out != NULL) |
504 | CRYPTO_poly1305_update(&cpx->poly1305, out, len); | 506 | CRYPTO_poly1305_update(&cpx->poly1305, out, len); |
505 | else | ||
506 | CRYPTO_poly1305_update(&cpx->poly1305, in, len); | ||
507 | 507 | ||
508 | return len; | 508 | return len; |
509 | } | 509 | } |