use cryptix_bigint::{BigUInt, bigint, property::IsBigInt}; use cryptix_field::{Element, Modular, field::montgomery::Montgomery, PrimeModular, OddModular}; use cryptix_field::field::primefield::FpElement; pub type U256 = BigUInt; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct BN254; impl Modular for BN254 { const P: U256 = bigint!(U256, "2523648240000001BA344D80000000086121000000000013A700000000000013"); } /// # Safety /// /// the modular P is indeed a prime number, this comes from [the parameter of ec BN254](https://neuromancer.sk/std/bn/bn254#) impl PrimeModular for BN254 { } /// # Safety /// /// P is odd impl OddModular for BN254 { } impl Montgomery for BN254 { const R_P: FpElement = { FpElement(Element::new_unchecked(bigint!(U256, "212ba4f27ffffff5a2c62effffffffcdb939ffffffffff8a15ffffffffffff8e"))) }; const R_INV_P: FpElement = { FpElement(Element::new_unchecked(bigint!(U256, "1a7344bac91f117ea513ec0ed5682406b6c15140174d61b28b762ae9cf6d3b46"))) }; /* * # Safety * * this is the pre-computed value of R * R mod P, must less than P */ const RR_P: FpElement = { FpElement(Element::new_unchecked(bigint!(U256, "1B0A32FDF6403A3D281E3A1B7F86954F55EFBF6E8C1CC3F1B3E886745370473D"))) }; const NEG_P_INV_B: ::Dig = 0x8435e50d79435e5; }