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
No known key found for this signature in database
5 changed files with 25 additions and 20 deletions

19
Cargo.lock generated
View file

@ -1488,6 +1488,17 @@ dependencies = [
"zeroize",
]
[[package]]
name = "crypto-bigint"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c2538c4e68e52548bacb3e83ac549f903d44f011ac9d5abb5e132e67d0808f7"
dependencies = [
"rand_core 0.6.4",
"subtle",
"zeroize",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
@ -1626,7 +1637,7 @@ dependencies = [
name = "dalek-ff-group"
version = "0.2.0"
dependencies = [
"crypto-bigint",
"crypto-bigint 0.5.1",
"curve25519-dalek 3.2.0",
"digest 0.10.6",
"ff",
@ -2089,7 +2100,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3"
dependencies = [
"base16ct",
"crypto-bigint",
"crypto-bigint 0.4.9",
"der",
"digest 0.10.6",
"ff",
@ -4925,7 +4936,7 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
name = "minimal-ed448"
version = "0.2.0"
dependencies = [
"crypto-bigint",
"crypto-bigint 0.5.1",
"dalek-ff-group",
"ff",
"ff-group-tests",
@ -6869,7 +6880,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb"
dependencies = [
"crypto-bigint",
"crypto-bigint 0.4.9",
"hmac 0.12.1",
"zeroize",
]

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> {