cipher_wrap: remove *setkey_dec_func in CIPHER_ENCRYPT_ONLY

There is no need to set decrypt key under CIPHER_ENCRYPT_ONLY,
so we can remove *setkey_dec_func from ctx to save extra code size.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
Yanray Wang 2023-08-24 15:47:53 +08:00
parent 9141ad1223
commit db9b3095fb
3 changed files with 49 additions and 0 deletions

View file

@ -396,6 +396,7 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
ctx->key_bitlen = key_bitlen;
ctx->operation = operation;
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
/*
* For OFB, CFB and CTR mode always use the encryption key schedule
*/
@ -413,6 +414,10 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx,
}
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
#else
return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key,
ctx->key_bitlen);
#endif
}
int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx,