From 6e0624065f5ccac89f699b45d1b2cfbdc1d49ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 1 Apr 2026 08:57:38 +0200 Subject: [PATCH] Make sure ECB decrypt function is called in EVP This only makes an actual difference when FREESCALE_MMCAU is defined (otherwise encrypt and decrypt are the same), but better for clarity still. --- wolfcrypt/src/evp.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index fc4f68eb9f..b802958a9e 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -695,10 +695,16 @@ static int evpCipherBlock(WOLFSSL_EVP_CIPHER_CTX *ctx, break; #if defined(WOLFSSL_DES_ECB) case WC_DES_ECB_TYPE: - ret = wc_Des_EcbEncrypt(&ctx->cipher.des, out, in, inl); + if (ctx->enc) + ret = wc_Des_EcbEncrypt(&ctx->cipher.des, out, in, inl); + else + ret = wc_Des_EcbDecrypt(&ctx->cipher.des, out, in, inl); break; case WC_DES_EDE3_ECB_TYPE: - ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, out, in, inl); + if (ctx->enc) + ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, out, in, inl); + else + ret = wc_Des3_EcbDecrypt(&ctx->cipher.des3, out, in, inl); break; #endif #endif @@ -8749,13 +8755,19 @@ void wolfSSL_EVP_init(void) #ifdef WOLFSSL_DES_ECB case WC_DES_ECB_TYPE : WOLFSSL_MSG("DES ECB"); - ret = wc_Des_EcbEncrypt(&ctx->cipher.des, dst, src, len); + if (ctx->enc) + ret = wc_Des_EcbEncrypt(&ctx->cipher.des, dst, src, len); + else + ret = wc_Des_EcbDecrypt(&ctx->cipher.des, dst, src, len); if (ret == 0) ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break; case WC_DES_EDE3_ECB_TYPE : WOLFSSL_MSG("DES3 ECB"); - ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, dst, src, len); + if (ctx->enc) + ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, dst, src, len); + else + ret = wc_Des3_EcbDecrypt(&ctx->cipher.des3, dst, src, len); if (ret == 0) ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE); break;