Repository navigation
Stop ChaCha20 block counter wrap and carry the XChaCha20 counter - #12194
aidangarske wants to merge 2 commits into
Conversation
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12194
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/chacha.h, tests/api/test_chacha.h
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12194
Scan targets checked: wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/chacha.h, tests/api/test_chacha.h
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
| blocks = (need / CHACHA_CHUNK_BYTES) + | ||
| (((need % CHACHA_CHUNK_BYTES) != 0) ? 1U : 0U); | ||
| /* An unused counter of 0 leaves 2^32 blocks, more than one call needs. */ | ||
| avail = ctx->cntExhausted ? 0U : (0U - ctx->nextBlock); |
There was a problem hiding this comment.
I'm hesitant to add in the extra tracking for if the counter is wrapping on ChaCha20 for these reasons.
- Some other libraries handle it by doing a carry over into the next word32. Chacha20 initially had a 64bit counter, but was reduced to a 32bit counter for AEAD purposes. So some libraries still just handle it as a 64bit counter which moves the warp around case out farther.
- None of the RFC's, as far as I know, explicitly state what behavior should happen here. Only that applications must not reuse the same nonce/counter value and that there is a limit on the amount of data that can be encrypted. This is similar to AES modes where IV's must not be reused. Right now having the counter wrap is similar to how the counter is handled with AES in wolfSSL.
For XChaCha20 the change to carry over in this PR with the counter is good.
There was a problem hiding this comment.
Could you maybe separate out the XChaCha20 and ChaCha20 counter changes? The XChaCha I think should go in but would like to discuss the ChaCha20 one.
F-16888- ChaCha20 block counter wraps and reuses keystreamreported in #12182.