From 4470c2ecfc8b8d16a96483baf0d973edbf2e0870 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 13 Mar 2019 12:27:07 +0300 Subject: [PATCH] more api --- src/groups/mod.rs | 16 ++++++++-------- src/lib.rs | 9 +++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/groups/mod.rs b/src/groups/mod.rs index fc247a8..9d911c4 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -689,13 +689,13 @@ fn test_miller_loop() { assert_eq!(gt, Fq12::new(Fq6::new( - Fq2::new(Fq::from_str("14551901853310307118181117653102171756020286507151693083446930124375536995872").unwrap(), Fq::from_str("9312135802322424742640599513015426415694425842442244572104764725304978020017").unwrap()), - Fq2::new(Fq::from_str("2008578374540014049115224515107136454624926345291695498760935593377832328658").unwrap(), Fq::from_str("19401931167387470703307774451905975977586101231060812348184567722817888018105").unwrap()), + Fq2::new(Fq::from_str("14551901853310307118181117653102171756020286507151693083446930124375536995872").unwrap(), Fq::from_str("9312135802322424742640599513015426415694425842442244572104764725304978020017").unwrap()), + Fq2::new(Fq::from_str("2008578374540014049115224515107136454624926345291695498760935593377832328658").unwrap(), Fq::from_str("19401931167387470703307774451905975977586101231060812348184567722817888018105").unwrap()), Fq2::new(Fq::from_str("15835061253582829097893482726334173316772697321004871665993836763948321578465").unwrap(), Fq::from_str("2434436628082562384254182545550914004674636606111293955202388712261962820365").unwrap()) ), Fq6::new( - Fq2::new(Fq::from_str("2874440054453559166574356420729655370224872280550180463983603224123901706537").unwrap(), Fq::from_str("21199736323249863378180814900160978651989782296293186487853700340281870105680").unwrap()), - Fq2::new(Fq::from_str("19165582755854282767090326095669835261356341739532443976394958023142879015770").unwrap(), Fq::from_str("1381947898997178910398427566832118260186305708991760706544743699683050330259").unwrap()), + Fq2::new(Fq::from_str("2874440054453559166574356420729655370224872280550180463983603224123901706537").unwrap(), Fq::from_str("21199736323249863378180814900160978651989782296293186487853700340281870105680").unwrap()), + Fq2::new(Fq::from_str("19165582755854282767090326095669835261356341739532443976394958023142879015770").unwrap(), Fq::from_str("1381947898997178910398427566832118260186305708991760706544743699683050330259").unwrap()), Fq2::new(Fq::from_str("282285618133171001983721596014922591835675934808772882476123488581876545578").unwrap(), Fq::from_str("9533292755262567365755835323107174518472361243562718718917822947506880920117").unwrap()) ) ) @@ -1017,15 +1017,15 @@ fn predefined_pair() { let g2 = AffineG2::new( Fq2::new( Fq::from_str("10857046999023057135944570762232829481370756359578518086990519993285655852781") - .expect("a-coeff of g2 x generator is of the right order"), + .expect("a-coeff of g2 x generator is of the right order"), Fq::from_str("11559732032986387107991004021392285783925812861821192530917403151452391805634") - .expect("b-coeff of g2 x generator is of the right order"), + .expect("b-coeff of g2 x generator is of the right order"), ), Fq2::new( Fq::from_str("8495653923123431417604973247489272438418190587263600148770280649306958101930") - .expect("a-coeff of g2 y generator is of the right order"), + .expect("a-coeff of g2 y generator is of the right order"), Fq::from_str("4082367875863433681332203403145435568316851327593401208105741076214120093531") - .expect("b-coeff of g2 y generator is of the right order"), + .expect("b-coeff of g2 y generator is of the right order"), ), ).expect("Point(11559732032986387107991004021392285783925812861821192530917403151452391805634 * i + 10857046999023057135944570762232829481370756359578518086990519993285655852781, 4082367875863433681332203403145435568316851327593401208105741076214120093531 * i + 8495653923123431417604973247489272438418190587263600148770280649306958101930) is a valid generator for G2") .to_jacobian(); diff --git a/src/lib.rs b/src/lib.rs index d48a544..43d8b81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,6 +190,10 @@ impl Fq2 { Fq2(fields::Fq2::one()) } + pub fn i() -> Fq2 { + Fq2::new(Fq::zero(), Fq::one()) + } + pub fn zero() -> Fq2 { Fq2(fields::Fq2::zero()) } @@ -202,9 +206,14 @@ impl Fq2 { pub fn is_zero(&self) -> bool { self.0.is_zero() } + pub fn pow(&self, exp: Fq) -> Self { Fq2(self.0.pow(exp.0)) } + + pub fn neg(&self) -> Self { + Fq2(self.0.neg()) + } } pub trait Group