diff --git a/myzkp/src/modules/curve.rs b/myzkp/src/modules/curve.rs index 44c6f6f..570eb74 100644 --- a/myzkp/src/modules/curve.rs +++ b/myzkp/src/modules/curve.rs @@ -234,7 +234,7 @@ pub fn weil_pairing( return (fp_qs / fp_s) / (fq_ps / fq_s); } -pub fn tate_pairing( +pub fn general_tate_pairing( p: EllipticCurvePoint, q: EllipticCurvePoint, ell: BigInt, @@ -249,6 +249,17 @@ pub fn tate_pairing( return f.pow((modulus - BigInt::one()) / ell); } +pub fn tate_pairing( + p: EllipticCurvePoint, + q: EllipticCurvePoint, + ell: BigInt, + modulus: BigInt, +) -> F { + let fp_q = miller(p.clone(), q.clone(), ell.clone()); + + return fp_q.pow((modulus - BigInt::one()) / ell); +} + #[macro_export] macro_rules! define_myzkp_curve_type { ($name:ident, $a:expr, $b:expr) => { @@ -363,7 +374,7 @@ mod tests { } #[test] - fn test_tate_pairing() { + fn test_general_tate_pairing() { let p = EllipticCurvePoint::, CurveA30B34>::new( FiniteFieldElement::::from_value(36_i64), FiniteFieldElement::::from_value(60_i64), @@ -386,7 +397,7 @@ mod tests { ); let order = 5.to_bigint().unwrap(); - let tate = tate_pairing( + let tate = general_tate_pairing( p.clone(), q.clone(), order.clone(), @@ -394,7 +405,7 @@ mod tests { Some(s.clone()), ); - let tate_prime = tate_pairing( + let tate_prime = general_tate_pairing( p_prime.clone(), q_prime.clone(), order.clone(), @@ -407,4 +418,39 @@ mod tests { tate_prime.sanitize() ); } + + #[test] + fn test_tate_pairing() { + let p = EllipticCurvePoint::, CurveA30B34>::new( + FiniteFieldElement::::from_value(36_i64), + FiniteFieldElement::::from_value(60_i64), + ); + let q = EllipticCurvePoint::, CurveA30B34>::new( + FiniteFieldElement::::from_value(121_i64), + FiniteFieldElement::::from_value(387_i64), + ); + let p_prime = EllipticCurvePoint::, CurveA30B34>::new( + FiniteFieldElement::::from_value(617_i64), + FiniteFieldElement::::from_value(5_i64), + ); + let q_prime = EllipticCurvePoint::, CurveA30B34>::new( + FiniteFieldElement::::from_value(121_i64), + FiniteFieldElement::::from_value(244_i64), + ); + let order = 5.to_bigint().unwrap(); + + let tate = tate_pairing(p.clone(), q.clone(), order.clone(), BigInt::from(631)); + + let tate_prime = tate_pairing( + p_prime.clone(), + q_prime.clone(), + order.clone(), + BigInt::from(631), + ); + + assert_eq!( + tate.pow(12_i32.to_bigint().unwrap()).sanitize(), + tate_prime.sanitize() + ); + } }