This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 7706d3254 crypto/mbedtls: support AES-256-CMAC in cmac_alt
7706d3254 is described below
commit 7706d3254e40132546d4323103813ed5b5fa5137
Author: makejian <[email protected]>
AuthorDate: Mon Nov 23 10:44:51 2026 +0800
crypto/mbedtls: support AES-256-CMAC in cmac_alt
mbedtls_cipher_cmac_starts() only accepted MBEDTLS_CIPHER_AES_128_ECB,
so a CMAC over an AES-256 key failed with
MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA even though the cryptodev backend
has supported CRYPTO_AES_256_CMAC sessions since the kernel gained the
algorithm in apache/nuttx#21957. Accept MBEDTLS_CIPHER_AES_256_ECB too
and pick CRYPTO_AES_256_CMAC as the mac for it; the key length of the
session already selects the 256-bit key schedule.
A keybits that does not match the cipher is now rejected on entry: a
256-bit cipher fed a 128-bit key would otherwise open a session with
the wrong key schedule, and a keybits over 256 would overflow
cmac_ctx->key[CMAC_KEY_MAX_SIZE] in the memcpy.
Build-tested with sim:sim/crypto and CONFIG_CRYPTO_MBEDTLS with
CONFIG_MBEDTLS_CMAC_ALT enabled; not run on hardware.
Signed-off-by: makejian <[email protected]>
---
crypto/mbedtls/source/cmac_alt.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/crypto/mbedtls/source/cmac_alt.c b/crypto/mbedtls/source/cmac_alt.c
index c9060f7d9..76c153e33 100644
--- a/crypto/mbedtls/source/cmac_alt.c
+++ b/crypto/mbedtls/source/cmac_alt.c
@@ -48,12 +48,21 @@ int mbedtls_cipher_cmac_starts(FAR mbedtls_cipher_context_t
*ctx,
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
}
+ if (keybits != mbedtls_cipher_info_get_key_bitlen(ctx->cipher_info))
+ {
+ return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
+ }
+
switch (ctx->cipher_info->type)
{
case MBEDTLS_CIPHER_AES_128_ECB:
cipher_type = CRYPTO_AES_CMAC;
mac_type = CRYPTO_AES_128_CMAC;
break;
+ case MBEDTLS_CIPHER_AES_256_ECB:
+ cipher_type = CRYPTO_AES_CMAC;
+ mac_type = CRYPTO_AES_256_CMAC;
+ break;
default:
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
}