Skip to content

Commit

Permalink
Update MSRV (#113)
Browse files Browse the repository at this point in the history
* update rust-toolchain: 1.74.0

* fix clippy: remove unnecessary cast

fix clippy: remove unnecessary cast

* fix clippy: remove unnecesarry ref

* fix clippy: allow redundant closure call

* fix clippy: introduce iterators when possible

fix clippy: introduce iterators when possible

* fix clippy: tuple inicialization

* fix clippy: motgomery_form behind asm feature

* fix clippy: move use ::serde
  • Loading branch information
davidnevadoc authored Dec 15, 2023
1 parent 823212a commit 87c53b0
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.67.0
1.74.0
5 changes: 3 additions & 2 deletions src/derive/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<D: ::serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Self, D::Error> {
use ::serde::de::Error as _;
let bytes = if deserializer.is_human_readable() {
::hex::serde::deserialize(deserializer)?
} else {
Expand All @@ -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<D: ::serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Self, D::Error> {
use ::serde::de::Error as _;
let bytes = if deserializer.is_human_readable() {
::hex::serde::deserialize(deserializer)?
} else {
Expand Down Expand Up @@ -530,6 +530,7 @@ macro_rules! new_curve_impl {
}


#[allow(clippy::redundant_closure_call)]
fn hash_to_curve<'a>(domain_prefix: &'a str) -> Box<dyn Fn(&[u8]) -> Self + 'a> {
$hash_to_curve($curve_id, domain_prefix)
}
Expand Down
1 change: 1 addition & 0 deletions src/derive/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions src/ff_ext/inverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ impl<const B: usize, const L: usize> Add for &CInt<B, L> {
type Output = CInt<B, L>;
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::<B, L>::MASK;
*d = sum & CInt::<B, L>::MASK;
carry = sum >> B;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand Down Expand Up @@ -91,12 +91,12 @@ impl<const B: usize, const L: usize> Sub for &CInt<B, L> {
// 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::<B, L>::MASK) + carry;
data[i] = sum & CInt::<B, L>::MASK;
*d = sum & CInt::<B, L>::MASK;
carry = sum >> B;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand All @@ -120,12 +120,12 @@ impl<const B: usize, const L: usize> Neg for &CInt<B, L> {
// 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::<B, L>::MASK) + carry;
data[i] = sum & CInt::<B, L>::MASK;
*d = sum & CInt::<B, L>::MASK;
carry = sum >> B;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand All @@ -150,7 +150,7 @@ impl<const B: usize, const L: usize> Mul for &CInt<B, L> {
carry = (sum >> B) as u64;
}
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand Down Expand Up @@ -189,12 +189,12 @@ impl<const B: usize, const L: usize> Mul<i64> for &CInt<B, L> {
} 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::<B, L>::MASK;
*d = sum as u64 & CInt::<B, L>::MASK;
carry = (sum >> B) as u64;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand Down
33 changes: 17 additions & 16 deletions src/ff_ext/jacobi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ impl<const L: usize> Shr<u32> for &LInt<L> {
"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::<L>(data)
}
}

Expand All @@ -96,10 +97,10 @@ impl<const L: usize> Add for &LInt<L> {
type Output = LInt<L>;
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::<L>(data)
}
}

Expand Down Expand Up @@ -128,10 +129,10 @@ impl<const L: usize> Sub for &LInt<L> {
// 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::<L>(data)
}
}

Expand All @@ -155,10 +156,10 @@ impl<const L: usize> Neg for &LInt<L> {
// 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::<L>(data)
}
}

Expand All @@ -180,7 +181,7 @@ impl<const L: usize> Mul for &LInt<L> {
Self::Output::prodsum(self.0[i], other.0[k], data[i + k], carry);
}
}
Self::Output { 0: data }
LInt::<L>(data)
}
}

Expand Down Expand Up @@ -219,10 +220,10 @@ impl<const L: usize> Mul<i64> for &LInt<L> {
} 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::<L>(data)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &
let mut buckets: Vec<Bucket<C>> = 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);
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/pluto_eris/fields/fp12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/pluto_eris/fields/fp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/pluto_eris/fields/fp6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 87c53b0

Please sign in to comment.