cederom commented on PR #4114:
URL: https://github.com/apache/nuttx-apps/pull/4114#issuecomment-7116470029
Thanks — the change itself is correct. `CRYPTO_AES_256_CMAC` is accepted by
`cryptodev.c`, has its own `auth_hash_cmac_aes_256` in `xform.c`, and is routed
through `swcr_authenc()` in `cryptosoft.c`, so the session this now requests is
a valid one. Two requests before merge:
**1. Validate `keybits` against the cipher type**
Before this PR, the cipher type was always AES-128 and `keybits` was never
checked. Now there are two cipher types, so a mismatch matters more. Upstream
`mbedtls_cipher_cmac_starts()` goes through `mbedtls_cipher_setkey()`, which
rejects a key length that doesn't match `cipher_info`. The alt implementation
skips that check, and the kernel picks the AES key schedule from `keylen` alone
(`aes_cmac_setkey()` → `aes_setkey(..., len)`). As a result:
- `MBEDTLS_CIPHER_AES_256_ECB` with `keybits == 128` creates a session
labelled `CRYPTO_AES_256_CMAC` that silently computes AES-128-CMAC instead of
failing.
- `keybits > 256` overflows `cmac_ctx->key[CMAC_KEY_MAX_SIZE]` in the
`memcpy()` (this one is older than the PR, but the same check fixes it).
Suggest adding, before the `switch`:
if (keybits != mbedtls_cipher_info_get_key_bitlen(ctx->cipher_info))
{
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
}
**2. Testing**
The description says the `aescmac` test passes for 128- and 256-bit keys.
But `testing/drivers/crypto/aescmac.c` talks to `/dev/crypto` directly, so it
never goes through `cmac_alt.c` and doesn't test this change. Could you run
something that goes through mbedtls, e.g. a short `mbedtls_cipher_cmac()` call
with `mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_256_ECB)`, checked
against the SP 800-38B AES-256 vectors (Mlen=0 →
`028962f61b7bf89efc6b551f4667d983`), or the CMAC part of `mbedselftest`? Then
please update the testing section to match.
Mislabelled test key: the comment in testing/drivers/crypto/aescmac.c calls
the AES-256 key the standard SP 800-38B key, but it isn't. The second half of
the key differs from the NIST key (...726e0816778eceb3ce instead of
...d72d9810a30914dff4). I computed the tags with Python's cryptography package,
and they are correct for the key in the file, so the test is self-consistent.
It just isn't using the NIST vectors the comment claims.
Minor: the commit message could name the kernel commit/PR that added
`CRYPTO_AES_256_CMAC` instead of "since the kernel gained the algorithm".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]