-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix padding calculation for large AADs in xchacha20poly1305 secretstream push/pull #73
Conversation
✅ Deploy Preview for dryoc-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor suggestions, but otherwise it looks good.
For anyone reading, here's more detail on the bug: this would only fail in debug mode, but not release mode. In release mode, it will silently succeed. Here's a simple demonstration of the problem: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=af06abf7079edb5b16fc860693102d71 While libsodium's implementation is technically wrong, it works fine because C isn't fussy about the overflow, but Rust is strict. For reference, the padding is described in RFC 7539 here: https://datatracker.ietf.org/doc/html/rfc7539#section-2.8.1 In terms of security risk, this is pretty innocuous but still worth fixing. |
It's not related to this PR, but I should also implement the missing AEAD functions ( |
I did some housekeeping, you'll need to rebase against |
Changes addressed 👍 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #73 +/- ##
==========================================
+ Coverage 65.55% 65.60% +0.05%
==========================================
Files 43 43
Lines 3170 3172 +2
==========================================
+ Hits 2078 2081 +3
+ Misses 1092 1091 -1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thank you kindly!
mac.update(&_pad0[..((0x10 - (associated_data.len() % 0x10)) & 0xf)]);
Previous code did not include the modulus, thus failing on AADs larger than 16 bytes. The XChaCha20 specification allows much more than that.
The original libsodium implementation in C does a similar operation:
Without the fix, it fails: