From 4ea0f59e0a5f2aae07566e71c3101484a3d7190f Mon Sep 17 00:00:00 2001 From: jmwample <8297368+jmwample@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:11:21 -0600 Subject: [PATCH] apply changes from upstream to forked crate --- curve25519-elligator2/Cargo.toml | 10 ++++++++++ curve25519-elligator2/src/backend/serial/u32/scalar.rs | 7 +++++-- curve25519-elligator2/src/backend/serial/u64/scalar.rs | 7 +++++-- .../src/backend/vector/ifma/edwards.rs | 2 +- curve25519-elligator2/src/backend/vector/ifma/field.rs | 2 +- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/curve25519-elligator2/Cargo.toml b/curve25519-elligator2/Cargo.toml index 242facd0..ebb1c709 100644 --- a/curve25519-elligator2/Cargo.toml +++ b/curve25519-elligator2/Cargo.toml @@ -77,3 +77,13 @@ digest = ["dep:digest", "elligator2"] [target.'cfg(all(not(curve25519_dalek_backend = "fiat"), not(curve25519_dalek_backend = "serial"), target_arch = "x86_64"))'.dependencies] curve25519-dalek-derive = { version = "0.1.1" } + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(allow_unused_unsafe)', + 'cfg(curve25519_dalek_backend, values("fiat", "serial", "simd"))', + 'cfg(curve25519_dalek_diagnostics, values("build"))', + 'cfg(curve25519_dalek_bits, values("32", "64"))', + 'cfg(nightly)', +] diff --git a/curve25519-elligator2/src/backend/serial/u32/scalar.rs b/curve25519-elligator2/src/backend/serial/u32/scalar.rs index 2d135d1d..82730675 100644 --- a/curve25519-elligator2/src/backend/serial/u32/scalar.rs +++ b/curve25519-elligator2/src/backend/serial/u32/scalar.rs @@ -12,6 +12,7 @@ use core::fmt::Debug; use core::ops::{Index, IndexMut}; +use subtle::{Choice, ConditionallySelectable}; #[cfg(feature = "zeroize")] use zeroize::Zeroize; @@ -196,10 +197,12 @@ impl Scalar29 { } // conditionally add l if the difference is negative - let underflow_mask = ((borrow >> 31) ^ 1).wrapping_sub(1); let mut carry: u32 = 0; for i in 0..9 { - carry = (carry >> 29) + difference[i] + (constants::L[i] & underflow_mask); + let underflow = Choice::from((borrow >> 31) as u8); + + let addend = u32::conditional_select(&0, &constants::L[i], underflow); + carry = (carry >> 29) + difference[i] + addend; difference[i] = carry & mask; } diff --git a/curve25519-elligator2/src/backend/serial/u64/scalar.rs b/curve25519-elligator2/src/backend/serial/u64/scalar.rs index 1cc2df4a..bcbdc2eb 100644 --- a/curve25519-elligator2/src/backend/serial/u64/scalar.rs +++ b/curve25519-elligator2/src/backend/serial/u64/scalar.rs @@ -13,6 +13,7 @@ use core::fmt::Debug; use core::ops::{Index, IndexMut}; +use subtle::{Choice, ConditionallySelectable}; #[cfg(feature = "zeroize")] use zeroize::Zeroize; @@ -185,10 +186,12 @@ impl Scalar52 { } // conditionally add l if the difference is negative - let underflow_mask = ((borrow >> 63) ^ 1).wrapping_sub(1); let mut carry: u64 = 0; for i in 0..5 { - carry = (carry >> 52) + difference[i] + (constants::L[i] & underflow_mask); + let underflow = Choice::from((borrow >> 63) as u8); + + let addend = u64::conditional_select(&0, &constants::L[i], underflow); + carry = (carry >> 52) + difference[i] + addend; difference[i] = carry & mask; } diff --git a/curve25519-elligator2/src/backend/vector/ifma/edwards.rs b/curve25519-elligator2/src/backend/vector/ifma/edwards.rs index c148bf15..625197e3 100644 --- a/curve25519-elligator2/src/backend/vector/ifma/edwards.rs +++ b/curve25519-elligator2/src/backend/vector/ifma/edwards.rs @@ -249,7 +249,7 @@ impl<'a> From<&'a edwards::EdwardsPoint> for NafLookupTable8 { } } -#[cfg(target_feature = "avx512ifma,avx512vl")] +#[cfg(all(target_feature = "avx512ifma", target_feature = "avx512vl"))] #[cfg(test)] mod test { use super::*; diff --git a/curve25519-elligator2/src/backend/vector/ifma/field.rs b/curve25519-elligator2/src/backend/vector/ifma/field.rs index deceebd8..993be1d7 100644 --- a/curve25519-elligator2/src/backend/vector/ifma/field.rs +++ b/curve25519-elligator2/src/backend/vector/ifma/field.rs @@ -629,7 +629,7 @@ impl<'a, 'b> Mul<&'b F51x4Reduced> for &'a F51x4Reduced { } } -#[cfg(target_feature = "avx512ifma,avx512vl")] +#[cfg(all(target_feature = "avx512ifma", target_feature = "avx512vl"))] #[cfg(test)] mod test { use super::*;