-
Notifications
You must be signed in to change notification settings - Fork 482
Fix mod_final_25519 #129
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 mod_final_25519 #129
Conversation
src/crypto/x25519/mod.rs
Outdated
| } | ||
|
|
||
| fn mod_final_25519(x: Felem) -> Felem { | ||
| const MASK_64BITS: u128 = 0xffff_ffff_ffff_ffff; |
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.
Defining this as a const at the top and replacing all instances would definitely be welcome, along with 0x7fff_....
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.
Good idea.
src/crypto/x25519/mod.rs
Outdated
| acc1 = acc1.wrapping_add(acc0 >> 64); | ||
| acc2 = acc2.wrapping_add(acc1 >> 64); | ||
| acc3 = acc3.wrapping_add(acc2 >> 64); | ||
| acc3 &= 0x7fff_ffff_ffff_ffff; |
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.
What is this extra code doing? It doesn't make sense to me
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.
Looks like masking the top bit of the output. However is it not sufficient to execute just a single extra round of mul + add?
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.
I put the comments in the source code. What do you think?
551c60b to
699367b
Compare
src/crypto/x25519/tests.rs
Outdated
| mod tests { | ||
| use super::super::{mod_final_25519, mod_inv_25519, x25519_shared_key, Felem}; | ||
| use super::super::{ | ||
| mod_25519, mod_final_25519, mod_inv_25519, x25519_shared_key, Felem, Felem2, |
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.
mod_25519 and Felem2 never used
| assert_eq!(mod_final_25519(max + one).0, zero.0); | ||
| } | ||
|
|
||
| fn x25519_test_vectors() { |
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.
You've stolen this function's #[test] annotation
699367b to
fe70fbf
Compare
fe70fbf to
89d0276
Compare
No description provided.