#![allow(incomplete_features)] #![feature(generic_const_exprs)] #![feature(const_trait_impl)] #[cfg(feature = "rand")] #[test] fn test_fp12_sqr_mul() { use rand::SeedableRng; let mut rng = rand_chacha::ChaCha8Rng::from_seed(SEED); for _ in 0..TEST_COUNT { let a = Fp12Element::rand(&mut rng).mont_form(); let c = a.mont_sqr().mont_rdc(); let d = a.mont_mul(a).mont_rdc(); assert_eq!(c, d) } } #[cfg(feature = "rand")] #[test] fn test_fp12_mont_inv() { use rand::SeedableRng; use cryptix_field::field::{MulIdentity, montgomery::Montgomery}; let mut rng = rand_chacha::ChaCha8Rng::from_seed(SEED); for _ in 0..20 { // c = aR let a = Fp12Element::rand(&mut rng).mont_form(); // b = a^-1 * R let b = a.mont_inv(); // c * b^-1 * R^-1 * R^-1 = 1 assert_eq!(a.mont_mul(b), Fp12Element::ONE.mont_mul_fp(BN254::RR_P)); } } #[cfg(feature = "rand")] #[test] fn test_fp12_property() { use rand::SeedableRng; use cryptix_field::field::MulIdentity; let mut rng = rand_chacha::ChaCha8Rng::from_seed(SEED); for _ in 0..TEST_COUNT { // c = aR let a = Fp12Element::rand(&mut rng); // b = a^-1 * R let b = a.mont_mul(Fp12Element::ONE); // c * b^-1 * R^-1 * R^-1 = 1 assert_eq!(a.mont_rdc(), b); } } #[cfg(feature = "rand")] #[test] fn test_fp12_map() { use rand::SeedableRng; use cryptix_field::Modular; let mut rng = rand_chacha::ChaCha8Rng::from_seed(SEED); for _ in 0..20 { let a = Fp12Element::rand(&mut rng).mont_form(); let c = a.map_frob(); let b = a.mont_exp(BN254::P).mont_rdc(); let c = c.mont_rdc(); assert_eq!(b, c); } } #[cfg(feature = "rand")] #[test] fn test_fp12_map2() { use rand::SeedableRng; let mut rng = rand_chacha::ChaCha8Rng::from_seed(SEED); for _ in 0..20 { let a = Fp12Element::rand(&mut rng).mont_form(); let b = a.map2_frob(); let c = a.map_frob().map_frob(); assert_eq!(b, c); } } #[cfg(feature = "rand")] #[test] fn test_fp12_sparse_mul() { use rand::SeedableRng; use cryptix_field::group::AddIdentity; use cryptix_bn254::galoisfield::fp2::Fp2Element; let mut b = Fp12Element::ZERO; let mut rng = rand_chacha::ChaCha8Rng::from_seed(SEED); for _ in 0..20 { let a = Fp12Element::rand(&mut rng); b.0.0 = Fp2Element::rand(&mut rng); b.0.1 = Fp2Element::rand(&mut rng); b.1.0 = Fp2Element::rand(&mut rng); let c = b.sparse_mul(a); let d = a.mont_mul(b); assert_eq!(d, c); } }