-
Notifications
You must be signed in to change notification settings - Fork 133
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
Update to new Scalar
API
#120
Conversation
|
||
impl EphemeralSecret { | ||
/// Perform a Diffie-Hellman key agreement between `self` and | ||
/// `their_public` key to produce a [`SharedSecret`]. | ||
pub fn diffie_hellman(self, their_public: &PublicKey) -> SharedSecret { | ||
SharedSecret(self.0 * their_public.0) | ||
SharedSecret(their_public.0.mul_clamped(self.0)) |
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.
This is equivalent because, in the old code, self.0
was the result of Scalar::from_bits_clamped
, which was unreduced.
@@ -112,7 +111,7 @@ impl EphemeralSecret { | |||
impl<'a> From<&'a EphemeralSecret> for PublicKey { | |||
/// Given an x25519 [`EphemeralSecret`] key, compute its corresponding [`PublicKey`]. | |||
fn from(secret: &'a EphemeralSecret) -> PublicKey { | |||
PublicKey(EdwardsPoint::mul_base(&secret.0).to_montgomery()) | |||
PublicKey(EdwardsPoint::mul_base_clamped(secret.0).to_montgomery()) |
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.
Same reasoning here, and in the multiple copies of this below
fn from(bytes: AllowUnreducedScalarBytes) -> Scalar { | ||
Scalar::from_bits_clamped(bytes.0) | ||
} | ||
} |
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.
We can remove this because (de)serialization of StaticSecret
is all bytes now
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 great!
This removes all uses of
Scalar::[from_bits, from_bits_clamped}
. Some comments inline.I'll update the git dependency once dalek-cryptography/curve25519-dalek#519 drops.