mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
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:
parent
21026136bd
commit
334873b6a5
6 changed files with 33 additions and 11 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -5091,7 +5091,7 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
|||
|
||||
[[package]]
|
||||
name = "minimal-ed448"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"crypto-bigint 0.5.1",
|
||||
"ff 0.13.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "minimal-ed448"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
description = "Unaudited, inefficient implementation of Ed448 in Rust"
|
||||
license = "MIT"
|
||||
repository = "https://github.com/serai-dex/serai/tree/develop/crypto/ed448"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# Minimal Ed448
|
||||
|
||||
Inefficient, barebones implementation of Ed448 bound to the ff/group API,
|
||||
rejecting torsion to achieve a PrimeGroup definition. This likely should not be
|
||||
used and was only done so another library under Serai could confirm its
|
||||
completion. It is minimally tested, yet should be correct for what it has. This
|
||||
has not undergone auditing.
|
||||
Barebones implementation of Ed448 bound to the ff/group API, rejecting torsion
|
||||
to achieve a PrimeGroup definition.
|
||||
|
||||
This library has not been audited. While it is complete, and decently tested,
|
||||
any usage of it should be carefully considered.
|
||||
|
||||
constant time and no_std.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,6 +6,13 @@ use crypto_bigint::{U512, U1024};
|
|||
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Zeroize)]
|
||||
pub struct FieldElement(pub(crate) U512);
|
||||
|
||||
const MODULUS_PADDED_STR: &str = concat!(
|
||||
"00000000000000",
|
||||
"00",
|
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
);
|
||||
|
||||
const MODULUS_STR: &str = concat!(
|
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
|
@ -33,6 +40,7 @@ pub(crate) const Q_4: FieldElement =
|
|||
|
||||
field!(
|
||||
FieldElement,
|
||||
MODULUS_PADDED_STR,
|
||||
MODULUS_STR,
|
||||
MODULUS,
|
||||
WIDE_MODULUS,
|
||||
|
|
|
@ -6,6 +6,13 @@ use crypto_bigint::{U512, U1024};
|
|||
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Zeroize)]
|
||||
pub struct Scalar(pub(crate) U512);
|
||||
|
||||
const MODULUS_PADDED_STR: &str = concat!(
|
||||
"00000000000000",
|
||||
"00",
|
||||
"3fffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3",
|
||||
);
|
||||
|
||||
const MODULUS_STR: &str = concat!(
|
||||
"3fffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3",
|
||||
|
@ -30,6 +37,7 @@ const WIDE_MODULUS: U1024 = U1024::from_be_hex(concat!(
|
|||
|
||||
field!(
|
||||
Scalar,
|
||||
MODULUS_PADDED_STR,
|
||||
MODULUS_STR,
|
||||
MODULUS,
|
||||
WIDE_MODULUS,
|
||||
|
|
Loading…
Reference in a new issue