From cd25d2252655268326ebb78ccee61a846a3e57db Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Fri, 10 Nov 2023 15:33:27 +0800 Subject: [PATCH] cipher.c: remove checks for CBC,XTS,KW,KWP in cipher_setkey We have checks for CBC, XTS and KW modes in check_config.h. This means we should never get a successful build with above three modes. Therefore, the checks in cipher_setkey is not necessary as other error will be emitted if asking for those modes in the cipher. Additionally, removing the checks can save extra code size. Signed-off-by: Yanray Wang --- library/cipher.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/library/cipher.c b/library/cipher.c index 909324aaef..33da580555 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -320,15 +320,6 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; } #if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) - /* CBC, XTS, KW and KWP mode always need decryption, return an error to - * indicate those modes are not available under - * MBEDTLS_BLOCK_CIPHER_NO_DECRYPT. */ - if (MBEDTLS_MODE_CBC == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_XTS == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_KWP == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) && MBEDTLS_DECRYPT == operation) { return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;