summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2025-06-06 07:41:01 +0000
committertb <>2025-06-06 07:41:01 +0000
commit96a76161020b928e1e01f56826e2cdd5bb4adf3f (patch)
tree8fefb7b54a21ac65b877a6d1bcf8b9221365ffb0 /src
parentf1973c71ce2d980d7dc43c67f3dca6fac6b8c2b9 (diff)
downloadopenbsd-96a76161020b928e1e01f56826e2cdd5bb4adf3f.tar.gz
openbsd-96a76161020b928e1e01f56826e2cdd5bb4adf3f.tar.bz2
openbsd-96a76161020b928e1e01f56826e2cdd5bb4adf3f.zip
Fix EVP_DecryptFinal() for CCM ciphers
There is an old trap that you must not call EVP_*Final() when using AES-CCM. While encrypting this happens to be a noop and succeeds, but when decrypting, the call fails. This behavior changed in OpenSSL and BoringSSL, making the trap even worse since we now fail when the others succeed. This is an adaptation of OpenSSL commit 197421b1 to fix this. See also https://github.com/sfackler/rust-openssl/pull/1805#issuecomment-2734788336 ok beck kenjiro
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/e_aes.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index a0f192905d..74d86c98d8 100644
--- a/src/lib/libcrypto/evp/e_aes.c
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_aes.c,v 1.69 2025/06/03 08:42:15 kenjiro Exp $ */ 1/* $OpenBSD: e_aes.c,v 1.70 2025/06/06 07:41:01 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -2032,7 +2032,14 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
2032 CCM128_CONTEXT *ccm = &cctx->ccm; 2032 CCM128_CONTEXT *ccm = &cctx->ccm;
2033 2033
2034 /* If not set up, return error */ 2034 /* If not set up, return error */
2035 if (!cctx->iv_set && !cctx->key_set) 2035 if (!cctx->key_set)
2036 return -1;
2037
2038 /* EVP_*Final() doesn't return any data */
2039 if (in == NULL && out != NULL)
2040 return 0;
2041
2042 if (!cctx->iv_set)
2036 return -1; 2043 return -1;
2037 if (!ctx->encrypt && !cctx->tag_set) 2044 if (!ctx->encrypt && !cctx->tag_set)
2038 return -1; 2045 return -1;
@@ -2051,9 +2058,7 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
2051 CRYPTO_ccm128_aad(ccm, in, len); 2058 CRYPTO_ccm128_aad(ccm, in, len);
2052 return len; 2059 return len;
2053 } 2060 }
2054 /* EVP_*Final() doesn't return any data */ 2061
2055 if (!in)
2056 return 0;
2057 /* If not set length yet do it */ 2062 /* If not set length yet do it */
2058 if (!cctx->len_set) { 2063 if (!cctx->len_set) {
2059 if (CRYPTO_ccm128_setiv(ccm, ctx->iv, 15 - cctx->L, len)) 2064 if (CRYPTO_ccm128_setiv(ccm, ctx->iv, 15 - cctx->L, len))