Use crypto-bigint's reduction in ed448

Achieves feasible performance in the ed448 which makes it potentially viable
for real world usage.

Accordingly prepares a new release, updating the README.
This commit is contained in:
Luke Parker
2023-04-19 02:25:19 -04:00
parent 21026136bd
commit 334873b6a5
6 changed files with 33 additions and 11 deletions

View File

@@ -69,6 +69,7 @@ macro_rules! field {
(
$FieldName: ident,
$MODULUS_PADDED_STR: ident,
$MODULUS_STR: ident,
$MODULUS: ident,
$WIDE_MODULUS: ident,
@@ -89,12 +90,14 @@ macro_rules! field {
use rand_core::RngCore;
use generic_array::{typenum::U57, GenericArray};
use crypto_bigint::{Integer, NonZero, Encoding};
use crypto_bigint::{Integer, NonZero, Encoding, impl_modulus};
use ff::{Field, PrimeField, FieldBits, PrimeFieldBits, helpers::sqrt_ratio_generic};
use $crate::backend::u8_from_bool;
impl_modulus!(CryptoBigIntModulus, U512, $MODULUS_PADDED_STR);
fn reduce(x: U1024) -> U512 {
U512::from_le_slice(&x.rem(&NonZero::new($WIDE_MODULUS).unwrap()).to_le_bytes()[.. 64])
}
@@ -121,9 +124,12 @@ macro_rules! field {
&y,
&$MODULUS.0
));
math_op!($FieldName, $FieldName, Mul, mul, MulAssign, mul_assign, |x, y| reduce(U1024::from(
U512::mul_wide(&x, &y)
)));
math_op!($FieldName, $FieldName, Mul, mul, MulAssign, mul_assign, |x, y| {
use crypto_bigint::modular::constant_mod::{ResidueParams, Residue};
Residue::<CryptoBigIntModulus, { CryptoBigIntModulus::LIMBS }>::new(&x)
.mul(&Residue::<CryptoBigIntModulus, { CryptoBigIntModulus::LIMBS }>::new(&y))
.retrieve()
});
from_wrapper!($FieldName, U512, u8);
from_wrapper!($FieldName, U512, u16);