Update crypto-bigint to 0.5

This commit is contained in:
Luke Parker
2023-03-17 15:31:04 -04:00
parent f2218b4d4e
commit 9952c67d98
5 changed files with 25 additions and 20 deletions

View File

@@ -22,7 +22,7 @@ subtle = "^2.4"
ff = { version = "0.12", features = ["bits"] }
group = "0.12"
crypto-bigint = "0.4"
crypto-bigint = "0.5"
sha2 = "0.9"
curve25519-dalek = "^3.2"

View File

@@ -8,7 +8,7 @@ use subtle::{
ConditionallySelectable,
};
use crypto_bigint::{Integer, Encoding, U256, U512};
use crypto_bigint::{Integer, NonZero, Encoding, U256, U512};
use group::ff::{Field, PrimeField, FieldBits, PrimeFieldBits};
@@ -78,7 +78,7 @@ const MOD_3_8: FieldElement =
const MOD_5_8: FieldElement = FieldElement(MOD_3_8.0.saturating_sub(&U256::ONE));
fn reduce(x: U512) -> U256 {
U256::from_le_slice(&x.reduce(&WIDE_MODULUS).unwrap().to_le_bytes()[.. 32])
U256::from_le_slice(&x.rem(&NonZero::new(WIDE_MODULUS).unwrap()).to_le_bytes()[.. 32])
}
constant_time!(FieldElement, U256);
@@ -87,10 +87,7 @@ math!(
FieldElement,
|x, y| U256::add_mod(&x, &y, &MODULUS),
|x, y| U256::sub_mod(&x, &y, &MODULUS),
|x, y| {
let wide = U256::mul_wide(&x, &y);
reduce(U512::from((wide.1, wide.0)))
}
|x, y| reduce(U512::from(U256::mul_wide(&x, &y)))
);
from_uint!(FieldElement, U256);
@@ -125,7 +122,7 @@ impl Field for FieldElement {
FieldElement(reduce(self.0.square()))
}
fn double(&self) -> Self {
FieldElement((self.0 << 1).reduce(&MODULUS).unwrap())
FieldElement((self.0 << 1).rem(&NonZero::new(MODULUS).unwrap()))
}
fn invert(&self) -> CtOption<Self> {

View File

@@ -24,7 +24,7 @@ ff = { version = "0.12", features = ["bits"] }
group = "0.12"
generic-array = "0.14"
crypto-bigint = { version = "0.4", features = ["zeroize"] }
crypto-bigint = { version = "0.5", features = ["zeroize"] }
dalek-ff-group = { path = "../dalek-ff-group", version = "0.2" }

View File

@@ -33,7 +33,7 @@ macro_rules! field {
use rand_core::RngCore;
use generic_array::{typenum::U57, GenericArray};
use crypto_bigint::{Integer, Encoding};
use crypto_bigint::{Integer, NonZero, Encoding};
use group::ff::{Field, PrimeField, FieldBits, PrimeFieldBits};
@@ -45,7 +45,7 @@ macro_rules! field {
use $crate::backend::u8_from_bool;
fn reduce(x: U1024) -> U512 {
U512::from_le_slice(&x.reduce(&$WIDE_MODULUS).unwrap().to_le_bytes()[.. 64])
U512::from_le_slice(&x.rem(&NonZero::new($WIDE_MODULUS).unwrap()).to_le_bytes()[.. 64])
}
constant_time!($FieldName, U512);
@@ -54,10 +54,7 @@ macro_rules! field {
$FieldName,
|x, y| U512::add_mod(&x, &y, &$MODULUS.0),
|x, y| U512::sub_mod(&x, &y, &$MODULUS.0),
|x, y| {
let wide = U512::mul_wide(&x, &y);
reduce(U1024::from((wide.1, wide.0)))
}
|x, y| reduce(U1024::from(U512::mul_wide(&x, &y)))
);
from_uint!($FieldName, U512);
@@ -122,7 +119,7 @@ macro_rules! field {
*self * self
}
fn double(&self) -> Self {
$FieldName((self.0 << 1).reduce(&$MODULUS.0).unwrap())
$FieldName((self.0 << 1).rem(&NonZero::new($MODULUS.0).unwrap()))
}
fn invert(&self) -> CtOption<Self> {