Skip to content

Commit

Permalink
more lints and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample committed Jun 26, 2024
1 parent c3fa8ef commit 5ebdcda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions curve25519-elligator2/src/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ impl EdwardsPoint {

// rfc9380 should always result in a valid point since no field elements
// are invalid. so unwrap should be safe.
#[allow(clippy::unwrap_used)]
let fe1 = MontgomeryPoint::from_representative::<Legacy>(&res).unwrap();
let E1_opt = fe1.to_edwards(sign_bit);

Expand Down
10 changes: 5 additions & 5 deletions curve25519-elligator2/src/elligator2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl MapToPointVariant for Randomized {

fn to_representative(point: &[u8; 32], tweak: u8) -> CtOption<[u8; 32]> {
let u = EdwardsPoint::mul_base_clamped_dirty(*point);
representative_from_pubkey(&u, tweak).into()
representative_from_pubkey(&u, tweak)
}

fn mul_base_clamped(bytes: [u8; 32]) -> EdwardsPoint {
Expand Down Expand Up @@ -306,7 +306,7 @@ impl MontgomeryPoint {
/// This function is the inverse of `to_representative`.
pub fn from_representative<T: MapToPointVariant>(representative: &[u8; 32]) -> Option<Self> {
let b: Option<EdwardsPoint> = T::from_representative(representative).into();
b.and_then(|x| Some(x.to_montgomery()))
b.map(|x| x.to_montgomery())
}

/// Mapts a point on the curve to a representative.
Expand Down Expand Up @@ -359,8 +359,7 @@ impl EdwardsPoint {
///
/// This function is the inverse of `to_representative`.
pub fn from_representative<T: MapToPointVariant>(representative: &[u8; 32]) -> Option<Self> {
let b: Option<EdwardsPoint> = T::from_representative(representative).into();
b.and_then(|x| Some(x))
T::from_representative(representative).into()
}

/// Mapts a point on the curve to a representative.
Expand Down Expand Up @@ -444,6 +443,7 @@ cfg_if! {
}
}

#[allow(clippy::identity_op)]
fn select_low_order_point(a: &FieldElement, b: &FieldElement, cofactor: u8) -> FieldElement {
// bit 0
let c0 = !Choice::from((cofactor >> 1) & 1);
Expand Down Expand Up @@ -558,7 +558,7 @@ pub(crate) fn point_to_representative(

// a := point
let a = &FieldElement::from_bytes(&point.0);
let a_neg = -&*a;
let a_neg = -a;

let is_encodable = is_encodable(a);

Expand Down
9 changes: 6 additions & 3 deletions x25519-dalek/src/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ impl<'a> From<&'a [u8; 32]> for PublicRepresentative {
impl<'a> From<&'a EphemeralSecret> for Option<PublicRepresentative> {
/// Given an x25519 [`EphemeralSecret`] key, compute its corresponding [`PublicRepresentative`].
fn from(secret: &'a EphemeralSecret) -> Option<PublicRepresentative> {
let repres = curve25519_elligator2::elligator2::representative_from_privkey(&secret.0, secret.1);
let repres =
curve25519_elligator2::elligator2::representative_from_privkey(&secret.0, secret.1);
let res: Option<[u8; 32]> = repres;
Some(PublicRepresentative(res?))
}
Expand All @@ -501,7 +502,8 @@ impl<'a> From<&'a EphemeralSecret> for Option<PublicRepresentative> {
impl<'a> From<&'a ReusableSecret> for Option<PublicRepresentative> {
/// Given an x25519 [`ReusableSecret`] key, compute its corresponding [`PublicRepresentative`].
fn from(secret: &'a ReusableSecret) -> Option<PublicRepresentative> {
let repres = curve25519_elligator2::elligator2::representative_from_privkey(&secret.0, secret.1);
let repres =
curve25519_elligator2::elligator2::representative_from_privkey(&secret.0, secret.1);
let res: Option<[u8; 32]> = repres;
Some(PublicRepresentative(res?))
}
Expand All @@ -512,7 +514,8 @@ impl<'a> From<&'a ReusableSecret> for Option<PublicRepresentative> {
impl<'a> From<&'a StaticSecret> for Option<PublicRepresentative> {
/// Given an x25519 [`StaticSecret`] key, compute its corresponding [`PublicRepresentative`].
fn from(secret: &'a StaticSecret) -> Option<PublicRepresentative> {
let repres = curve25519_elligator2::elligator2::representative_from_privkey(&secret.0, secret.1);
let repres =
curve25519_elligator2::elligator2::representative_from_privkey(&secret.0, secret.1);
let res: Option<[u8; 32]> = repres;
Some(PublicRepresentative(res?))
}
Expand Down

0 comments on commit 5ebdcda

Please sign in to comment.