mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Use U448 for Ed448 instead of U512
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
use zeroize::{DefaultIsZeroes, Zeroize};
|
||||
|
||||
use crypto_bigint::{
|
||||
U512, U1024,
|
||||
U448, U896,
|
||||
modular::constant_mod::{ResidueParams, Residue},
|
||||
};
|
||||
|
||||
const MODULUS_PADDED_STR: &str = concat!(
|
||||
"00000000000000",
|
||||
"00",
|
||||
const MODULUS_STR: &str = concat!(
|
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
);
|
||||
|
||||
impl_modulus!(FieldModulus, U512, MODULUS_PADDED_STR);
|
||||
impl_modulus!(FieldModulus, U448, MODULUS_STR);
|
||||
pub(crate) type ResidueType = Residue<FieldModulus, { FieldModulus::LIMBS }>;
|
||||
|
||||
/// Ed448 field element.
|
||||
@@ -21,30 +19,18 @@ 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: U512 = U512::from_be_hex(concat!(
|
||||
"00000000000000",
|
||||
"00",
|
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
));
|
||||
pub(crate) const MODULUS: U448 = U448::from_be_hex(MODULUS_STR);
|
||||
|
||||
const WIDE_MODULUS: U1024 = U1024::from_be_hex(concat!(
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"00000000000000",
|
||||
"00",
|
||||
const WIDE_MODULUS: U896 = U896::from_be_hex(concat!(
|
||||
"00000000000000000000000000000000000000000000000000000000",
|
||||
"00000000000000000000000000000000000000000000000000000000",
|
||||
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
));
|
||||
|
||||
pub(crate) const Q_4: FieldElement = FieldElement(ResidueType::new(
|
||||
&MODULUS.saturating_add(&U512::ONE).wrapping_div(&U512::from_u8(4)),
|
||||
&MODULUS.saturating_add(&U448::ONE).wrapping_div(&U448::from_u8(4)),
|
||||
));
|
||||
|
||||
field!(
|
||||
@@ -56,8 +42,8 @@ field!(
|
||||
448,
|
||||
7,
|
||||
concat!(
|
||||
"3100000000000000000000000000000000000000000000000000000000000000",
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"31000000000000000000000000000000000000000000000000000000",
|
||||
"00000000000000000000000000000000000000000000000000000000",
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user