ThePassionate commented on PR #4113:
URL: https://github.com/apache/nuttx-apps/pull/4113#issuecomment-7120177096

   All four points addressed:
   
   1. CFB128/OFB now reject a call with `*iv_off != 0` on entry with 
`MBEDTLS_ERR_AES_BAD_INPUT_DATA` - your first option. The partial call itself 
still processes, and `*iv_off` now follows the mbedtls semantics, `(*iv_off + 
length) % 16`; the *next* chained call gets the error instead of a reused 
keystream.
   2. The `ivlen` lines are dropped from this PR, for exactly the reason you 
describe: they stay in the context and leak into later CBC/ECB/XTS/CTR calls 
(for CTR a virtio device would read past the 12-byte nonce+counter remainder), 
and without `olen` they don't make these modes work on virtio anyway. Virtio 
support needs its own pass that sets `ivlen`/`olen` in every mode.
   3. `mbedtls_aes_crypt_cfb8()` returns early on `length == 0`, so `input - 
16` is never formed on a NULL input.
   4. Testing: a multi-call case now runs through the alt on sim:sim/crypto - 
one-shot vs whole-block chained encrypt and decrypt for CFB128/CFB8/OFB, every 
ciphertext cross-checked against a reference implementation (python 
cryptography, the SP 800-38A key/iv/plaintext). Chained and one-shot results 
are identical, the partial-then-chain path returns the error as intended, and 
length 0 is harmless:
   
   ```
   ivtest cfb128 encrypt chain success
   ivtest cfb128 decrypt one-shot success
   ivtest cfb128 decrypt chain success
   ivtest cfb8 encrypt chain success
   ivtest cfb8 decrypt one-shot success
   ivtest cfb8 decrypt chain success
   ivtest ofb encrypt chain success
   ivtest ofb decrypt one-shot success
   ivtest ofb decrypt chain success
   ivtest cfb128 partial 20 ok success (ret 0)
   ivtest cfb128 partial iv_off = 4
   ivtest cfb128 partial next rejected success (ret -33)
   ivtest cfb128 entry iv_off!=0 rejected success (ret -33)
   ivtest cfb8 length 0 (NULL buffers) success (ret 0)
   
   --- reference cross-check (host python cryptography, SP 800-38A) ---
   cfb128 ref: 50ff...3aa625 -> MATCH
   cfb8   ref: 5055...faf6 -> MATCH
   ofb    ref: 50ff...a771 -> MATCH
   ```
   
   (`ret -33` is `MBEDTLS_ERR_AES_BAD_INPUT_DATA`.) The CFB128 memset is kept 
for both directions (harmless, as you note).
   


-- 
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]

Reply via email to