diff --git a/rust-toolchain b/rust-toolchain index 77c582d8..dc87e8af 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.67.0 \ No newline at end of file +1.74.0 diff --git a/src/derive/curve.rs b/src/derive/curve.rs index c5a73128..e20f4ac3 100644 --- a/src/derive/curve.rs +++ b/src/derive/curve.rs @@ -305,11 +305,11 @@ macro_rules! new_curve_impl { } paste::paste! { - use ::serde::de::Error as _; impl<'de> ::serde::Deserialize<'de> for $name { fn deserialize>( deserializer: D, ) -> Result { + use ::serde::de::Error as _; let bytes = if deserializer.is_human_readable() { ::hex::serde::deserialize(deserializer)? } else { @@ -334,11 +334,11 @@ macro_rules! new_curve_impl { } paste::paste! { - use ::serde::de::Error as _; impl<'de> ::serde::Deserialize<'de> for $name_affine { fn deserialize>( deserializer: D, ) -> Result { + use ::serde::de::Error as _; let bytes = if deserializer.is_human_readable() { ::hex::serde::deserialize(deserializer)? } else { @@ -530,6 +530,7 @@ macro_rules! new_curve_impl { } + #[allow(clippy::redundant_closure_call)] fn hash_to_curve<'a>(domain_prefix: &'a str) -> Box Self + 'a> { $hash_to_curve($curve_id, domain_prefix) } diff --git a/src/derive/field.rs b/src/derive/field.rs index 5faee345..8d4ef783 100644 --- a/src/derive/field.rs +++ b/src/derive/field.rs @@ -63,6 +63,7 @@ macro_rules! field_common { $crate::ff_ext::jacobi::jacobi::<5>(&self.0, &$modulus.0) } + #[cfg(feature = "asm")] const fn montgomery_form(val: [u64; 4], r: $field) -> $field { // Converts a 4 64-bit limb value into its congruent field representation. // If `val` representes a 256 bit value then `r` should be R^2, diff --git a/src/ff_ext/inverse.rs b/src/ff_ext/inverse.rs index 53285e6c..d149b3ec 100644 --- a/src/ff_ext/inverse.rs +++ b/src/ff_ext/inverse.rs @@ -57,12 +57,12 @@ impl Add for &CInt { type Output = CInt; fn add(self, other: Self) -> Self::Output { let (mut data, mut carry) = ([0; L], 0); - for i in 0..L { + for (i, d) in data.iter_mut().enumerate().take(L) { let sum = self.0[i] + other.0[i] + carry; - data[i] = sum & CInt::::MASK; + *d = sum & CInt::::MASK; carry = sum >> B; } - Self::Output { 0: data } + CInt::(data) } } @@ -91,12 +91,12 @@ impl Sub for &CInt { // addition algorithm, where the carry flag is initialized with 1 and // the chunks of the second argument are bitwise inverted let (mut data, mut carry) = ([0; L], 1); - for i in 0..L { + for (i, d) in data.iter_mut().enumerate().take(L) { let sum = self.0[i] + (other.0[i] ^ CInt::::MASK) + carry; - data[i] = sum & CInt::::MASK; + *d = sum & CInt::::MASK; carry = sum >> B; } - Self::Output { 0: data } + CInt::(data) } } @@ -120,12 +120,12 @@ impl Neg for &CInt { // For the two's complement code the additive negation is the result // of adding 1 to the bitwise inverted argument's representation let (mut data, mut carry) = ([0; L], 1); - for i in 0..L { + for (i, d) in data.iter_mut().enumerate().take(L) { let sum = (self.0[i] ^ CInt::::MASK) + carry; - data[i] = sum & CInt::::MASK; + *d = sum & CInt::::MASK; carry = sum >> B; } - Self::Output { 0: data } + CInt::(data) } } @@ -150,7 +150,7 @@ impl Mul for &CInt { carry = (sum >> B) as u64; } } - Self::Output { 0: data } + CInt::(data) } } @@ -189,12 +189,12 @@ impl Mul for &CInt { } else { (other, 0, 0) }; - for i in 0..L { + for (i, d) in data.iter_mut().enumerate().take(L) { let sum = (carry as u128) + ((self.0[i] ^ mask) as u128) * (other as u128); - data[i] = sum as u64 & CInt::::MASK; + *d = sum as u64 & CInt::::MASK; carry = (sum >> B) as u64; } - Self::Output { 0: data } + CInt::(data) } } diff --git a/src/ff_ext/jacobi.rs b/src/ff_ext/jacobi.rs index 8c559352..db5f8c4f 100644 --- a/src/ff_ext/jacobi.rs +++ b/src/ff_ext/jacobi.rs @@ -74,14 +74,15 @@ impl Shr for &LInt { "Cannot shift by 0 or more than 63 bits!" ); let (mut data, right) = ([0; L], u64::BITS - bits); - for i in 0..(L - 1) { - data[i] = (self.0[i] >> bits) | (self.0[i + 1] << right); + + for (i, d) in data.iter_mut().enumerate().take(L - 1) { + *d = (self.0[i] >> bits) | (self.0[i + 1] << right); } data[L - 1] = self.0[L - 1] >> bits; if self.is_negative() { data[L - 1] |= u64::MAX << right; } - Self::Output { 0: data } + LInt::(data) } } @@ -96,10 +97,10 @@ impl Add for &LInt { type Output = LInt; fn add(self, other: Self) -> Self::Output { let (mut data, mut carry) = ([0; L], false); - for i in 0..L { - (data[i], carry) = Self::Output::sum(self.0[i], other.0[i], carry); + for (i, d) in data.iter_mut().enumerate().take(L) { + (*d, carry) = Self::Output::sum(self.0[i], other.0[i], carry); } - Self::Output { 0: data } + LInt::(data) } } @@ -128,10 +129,10 @@ impl Sub for &LInt { // addition algorithm, where the carry flag is initialized with "true" // and the chunks of the second argument are bitwise inverted let (mut data, mut carry) = ([0; L], true); - for i in 0..L { - (data[i], carry) = Self::Output::sum(self.0[i], !other.0[i], carry); + for (i, d) in data.iter_mut().enumerate().take(L) { + (*d, carry) = Self::Output::sum(self.0[i], !other.0[i], carry); } - Self::Output { 0: data } + LInt::(data) } } @@ -155,10 +156,10 @@ impl Neg for &LInt { // For the two's complement code the additive negation is the result // of adding 1 to the bitwise inverted argument's representation let (mut data, mut carry) = ([0; L], true); - for i in 0..L { - (data[i], carry) = (!self.0[i]).overflowing_add(carry as u64); + for (i, d) in data.iter_mut().enumerate().take(L) { + (*d, carry) = (!self.0[i]).overflowing_add(carry as u64); } - Self::Output { 0: data } + LInt::(data) } } @@ -180,7 +181,7 @@ impl Mul for &LInt { Self::Output::prodsum(self.0[i], other.0[k], data[i + k], carry); } } - Self::Output { 0: data } + LInt::(data) } } @@ -219,10 +220,10 @@ impl Mul for &LInt { } else { (other as u64, 0, 0) }; - for i in 0..L { - (data[i], carry) = Self::Output::prodsum(self.0[i] ^ mask, other, 0, carry); + for (i, d) in data.iter_mut().enumerate().take(L) { + (*d, carry) = Self::Output::prodsum(self.0[i] ^ mask, other, 0, carry); } - Self::Output { 0: data } + LInt::(data) } } diff --git a/src/msm.rs b/src/msm.rs index 2ab8f7a1..1a3709c1 100644 --- a/src/msm.rs +++ b/src/msm.rs @@ -102,7 +102,7 @@ pub fn multiexp_serial(coeffs: &[C::Scalar], bases: &[C], acc: & let mut buckets: Vec> = vec![Bucket::None; 1 << (c - 1)]; for (coeff, base) in coeffs.iter().zip(bases.iter()) { - let coeff = get_booth_index(current_window as usize, c, coeff.as_ref()); + let coeff = get_booth_index(current_window, c, coeff.as_ref()); if coeff.is_positive() { buckets[coeff as usize - 1].add_assign(base); } @@ -333,7 +333,7 @@ mod test { acc = acc.double(); } - let idx = super::get_booth_index(i as usize, window, u.as_ref()); + let idx = super::get_booth_index(i, window, u.as_ref()); if idx.is_negative() { acc += table[idx.unsigned_abs() as usize].neg(); diff --git a/src/pluto_eris/fields/fp12.rs b/src/pluto_eris/fields/fp12.rs index e5b6a3c8..7a2fd89d 100644 --- a/src/pluto_eris/fields/fp12.rs +++ b/src/pluto_eris/fields/fp12.rs @@ -643,7 +643,7 @@ fn test_frobenius() { let mut b = a; for _ in 0..i { - a = a.pow_vartime(&[ + a = a.pow_vartime([ 0x9ffffcd300000001, 0xa2a7e8c30006b945, 0xe4a7a5fe8fadffd6, diff --git a/src/pluto_eris/fields/fp2.rs b/src/pluto_eris/fields/fp2.rs index 14536fb6..ca2924fe 100644 --- a/src/pluto_eris/fields/fp2.rs +++ b/src/pluto_eris/fields/fp2.rs @@ -381,7 +381,7 @@ impl Field for Fp2 { }; // Algorithm (not constant time) - let b = self.pow_vartime(&[ + let b = self.pow_vartime([ // (p-1)/4 = // 0x900000000000900004c3800035fdc392a00f29dbd0e499bd10fe69736a29b1ef929e97fa3eb7ff5a8a9fa30c001ae5167ffff34c0000000 0x67ffff34c0000000, @@ -747,7 +747,7 @@ fn test_frobenius() { let mut b = a; for _ in 0..i { - a = a.pow_vartime(&[ + a = a.pow_vartime([ 0x9ffffcd300000001, 0xa2a7e8c30006b945, 0xe4a7a5fe8fadffd6, diff --git a/src/pluto_eris/fields/fp6.rs b/src/pluto_eris/fields/fp6.rs index 9fcbb01b..99cad3e4 100644 --- a/src/pluto_eris/fields/fp6.rs +++ b/src/pluto_eris/fields/fp6.rs @@ -762,7 +762,7 @@ fn test_frobenius() { let mut b = a; for _ in 0..i { - a = a.pow_vartime(&[ + a = a.pow_vartime([ // p 0x9ffffcd300000001, 0xa2a7e8c30006b945,