mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Move the entirety of ed448 to Residue, offering a further 2-4x speedup
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
use zeroize::Zeroize;
|
||||
use zeroize::{DefaultIsZeroes, Zeroize};
|
||||
|
||||
use crypto_bigint::{U512, U1024};
|
||||
|
||||
/// Ed448 field element.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Zeroize)]
|
||||
pub struct FieldElement(pub(crate) U512);
|
||||
use crypto_bigint::{
|
||||
U512, U1024,
|
||||
modular::constant_mod::{ResidueParams, Residue},
|
||||
};
|
||||
|
||||
const MODULUS_PADDED_STR: &str = concat!(
|
||||
"00000000000000",
|
||||
@@ -13,18 +12,27 @@ const MODULUS_PADDED_STR: &str = concat!(
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
);
|
||||
|
||||
impl_modulus!(FieldModulus, U512, MODULUS_PADDED_STR);
|
||||
pub(crate) type ResidueType = Residue<FieldModulus, { FieldModulus::LIMBS }>;
|
||||
|
||||
/// Ed448 field element.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
|
||||
pub struct FieldElement(pub(crate) ResidueType);
|
||||
|
||||
impl DefaultIsZeroes for FieldElement {}
|
||||
|
||||
const MODULUS_STR: &str = concat!(
|
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
);
|
||||
|
||||
// 2**448 - 2**224 - 1
|
||||
pub(crate) const MODULUS: FieldElement = FieldElement(U512::from_be_hex(concat!(
|
||||
pub(crate) const MODULUS: U512 = U512::from_be_hex(concat!(
|
||||
"00000000000000",
|
||||
"00",
|
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
)));
|
||||
));
|
||||
|
||||
const WIDE_MODULUS: U1024 = U1024::from_be_hex(concat!(
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
@@ -35,25 +43,18 @@ const WIDE_MODULUS: U1024 = U1024::from_be_hex(concat!(
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
));
|
||||
|
||||
pub(crate) const Q_4: FieldElement =
|
||||
FieldElement(MODULUS.0.saturating_add(&U512::ONE).wrapping_div(&U512::from_u8(4)));
|
||||
pub(crate) const Q_4: FieldElement = FieldElement(ResidueType::new(
|
||||
&MODULUS.saturating_add(&U512::ONE).wrapping_div(&U512::from_u8(4)),
|
||||
));
|
||||
|
||||
field!(
|
||||
FieldElement,
|
||||
MODULUS_PADDED_STR,
|
||||
ResidueType,
|
||||
MODULUS_STR,
|
||||
MODULUS,
|
||||
WIDE_MODULUS,
|
||||
448,
|
||||
concat!(
|
||||
"00000000000000000000000000000000000000000000000000000080ffffffff",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffff7f0000000000000000",
|
||||
),
|
||||
7,
|
||||
concat!(
|
||||
"fefffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffff",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000",
|
||||
),
|
||||
concat!(
|
||||
"3100000000000000000000000000000000000000000000000000000000000000",
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
|
||||
Reference in New Issue
Block a user