Skip to content

Commit 6e06240

Browse files
committed
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.
1 parent b6b8de1 commit 6e06240

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

wolfcrypt/src/evp.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,16 @@ static int evpCipherBlock(WOLFSSL_EVP_CIPHER_CTX *ctx,
695695
break;
696696
#if defined(WOLFSSL_DES_ECB)
697697
case WC_DES_ECB_TYPE:
698-
ret = wc_Des_EcbEncrypt(&ctx->cipher.des, out, in, inl);
698+
if (ctx->enc)
699+
ret = wc_Des_EcbEncrypt(&ctx->cipher.des, out, in, inl);
700+
else
701+
ret = wc_Des_EcbDecrypt(&ctx->cipher.des, out, in, inl);
699702
break;
700703
case WC_DES_EDE3_ECB_TYPE:
701-
ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, out, in, inl);
704+
if (ctx->enc)
705+
ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, out, in, inl);
706+
else
707+
ret = wc_Des3_EcbDecrypt(&ctx->cipher.des3, out, in, inl);
702708
break;
703709
#endif
704710
#endif
@@ -8749,13 +8755,19 @@ void wolfSSL_EVP_init(void)
87498755
#ifdef WOLFSSL_DES_ECB
87508756
case WC_DES_ECB_TYPE :
87518757
WOLFSSL_MSG("DES ECB");
8752-
ret = wc_Des_EcbEncrypt(&ctx->cipher.des, dst, src, len);
8758+
if (ctx->enc)
8759+
ret = wc_Des_EcbEncrypt(&ctx->cipher.des, dst, src, len);
8760+
else
8761+
ret = wc_Des_EcbDecrypt(&ctx->cipher.des, dst, src, len);
87538762
if (ret == 0)
87548763
ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE);
87558764
break;
87568765
case WC_DES_EDE3_ECB_TYPE :
87578766
WOLFSSL_MSG("DES3 ECB");
8758-
ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, dst, src, len);
8767+
if (ctx->enc)
8768+
ret = wc_Des3_EcbEncrypt(&ctx->cipher.des3, dst, src, len);
8769+
else
8770+
ret = wc_Des3_EcbDecrypt(&ctx->cipher.des3, dst, src, len);
87598771
if (ret == 0)
87608772
ret = (int)((len / DES_BLOCK_SIZE) * DES_BLOCK_SIZE);
87618773
break;

0 commit comments

Comments
 (0)