1use zeroize::{DefaultIsZeroes, Zeroize};
2
3use crypto_bigint::{
4 U448, U896,
5 modular::constant_mod::{ResidueParams, Residue},
6};
7
8const MODULUS_STR: &str = concat!(
9 "fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
10 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
11);
12
13impl_modulus!(FieldModulus, U448, MODULUS_STR);
14pub(crate) type ResidueType = Residue<FieldModulus, { FieldModulus::LIMBS }>;
15
16#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
18pub struct FieldElement(pub(crate) ResidueType);
19
20impl DefaultIsZeroes for FieldElement {}
21
22pub(crate) const MODULUS: U448 = U448::from_be_hex(MODULUS_STR);
24
25const WIDE_MODULUS: U896 = U896::from_be_hex(concat!(
26 "00000000000000000000000000000000000000000000000000000000",
27 "00000000000000000000000000000000000000000000000000000000",
28 "fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",
29 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
30));
31
32pub(crate) const Q_4: FieldElement = FieldElement(ResidueType::new(
33 &MODULUS.saturating_add(&U448::ONE).wrapping_div(&U448::from_u8(4)),
34));
35
36field!(
37 FieldElement,
38 ResidueType,
39 MODULUS_STR,
40 MODULUS,
41 WIDE_MODULUS,
42 448,
43 7,
44 concat!(
45 "31000000000000000000000000000000000000000000000000000000",
46 "00000000000000000000000000000000000000000000000000000000",
47 ),
48);
49
50#[test]
51fn test_field() {
52 ff_group_tests::prime_field::test_prime_field_bits::<_, FieldElement>(&mut rand_core::OsRng);
53}