halo2curves/pluto_eris/
fp.rs

1use core::convert::TryInto;
2
3use halo2derive::impl_field;
4use rand::RngCore;
5use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
6
7use crate::ff_ext::ExtField;
8
9impl_field!(
10    pluto_eris_fp,
11    Fp,
12    modulus = "24000000000024000130e0000d7f70e4a803ca76f439266f443f9a5cda8a6c7be4a7a5fe8fadffd6a2a7e8c30006b9459ffffcd300000001",
13    mul_gen = "a",
14    zeta = "480000000000360001c950000d7ee0e4a803c956d01c903d720dc8ad8b38dffaf50c100004c37ffffffe",
15    from_uniform = [64, 72, 112],
16    endian = "little",
17);
18
19crate::extend_field_legendre!(Fp);
20crate::impl_binops_calls!(Fp);
21crate::impl_binops_additive!(Fp, Fp);
22crate::impl_binops_multiplicative!(Fp, Fp);
23crate::field_bits!(Fp);
24crate::serialize_deserialize_primefield!(Fp);
25crate::impl_from_u64!(Fp);
26crate::impl_from_bool!(Fp);
27
28impl ExtField for Fp {
29    const NON_RESIDUE: Self = Fp::from_raw([
30        0x9ffffcd2fffffffc,
31        0xa2a7e8c30006b945,
32        0xe4a7a5fe8fadffd6,
33        0x443f9a5cda8a6c7b,
34        0xa803ca76f439266f,
35        0x0130e0000d7f70e4,
36        0x2400000000002400,
37    ]);
38    fn mul_by_nonresidue(&self) -> Self {
39        (self.double().double() + self).neg()
40    }
41    fn frobenius_map(&mut self, _: usize) {}
42}
43
44#[cfg(test)]
45mod test {
46    use super::Fp;
47    use crate::{
48        arith_test, constants_test, from_uniform_bytes_test, legendre_test, serde_test, test,
49    };
50
51    constants_test!(Fp);
52
53    arith_test!(Fp);
54    legendre_test!(Fp);
55    test!(arith, Fp, sqrt_test, 1000);
56
57    serde_test!(Fp PrimeFieldBits);
58    from_uniform_bytes_test!(Fp, 1000, L 64, L 72, L 112);
59}