ark_models_ext/models/bw6/
mod.rs1use crate::{
2 models::{short_weierstrass::SWCurveConfig, CurveConfig},
3 pairing::{MillerLoopOutput, Pairing, PairingOutput},
4};
5
6pub use ark_ec::bw6::TwistType;
7use ark_ff::fields::{
8 fp3::Fp3Config,
9 fp6_2over3::{Fp6, Fp6Config},
10 PrimeField,
11};
12use ark_std::marker::PhantomData;
13use derivative::Derivative;
14
15pub trait BW6Config: 'static + Sized {
16 const X: <Self::Fp as PrimeField>::BigInt;
17 const X_IS_NEGATIVE: bool;
18 const ATE_LOOP_COUNT_1: &'static [u64];
19 const ATE_LOOP_COUNT_1_IS_NEGATIVE: bool;
20 const ATE_LOOP_COUNT_2: &'static [i8];
21 const ATE_LOOP_COUNT_2_IS_NEGATIVE: bool;
22 const TWIST_TYPE: TwistType;
23 type Fp: PrimeField + Into<<Self::Fp as PrimeField>::BigInt>;
24 type Fp3Config: Fp3Config<Fp = Self::Fp>;
25 type Fp6Config: Fp6Config<Fp3Config = Self::Fp3Config>;
26 type G1Config: SWCurveConfig<BaseField = Self::Fp>;
27 type G2Config: SWCurveConfig<
28 BaseField = Self::Fp,
29 ScalarField = <Self::G1Config as CurveConfig>::ScalarField,
30 >;
31
32 fn final_exponentiation(f: MillerLoopOutput<BW6<Self>>) -> Option<PairingOutput<BW6<Self>>>;
33
34 fn multi_miller_loop(
35 a: impl IntoIterator<Item = impl Into<G1Prepared<Self>>>,
36 b: impl IntoIterator<Item = impl Into<G2Prepared<Self>>>,
37 ) -> MillerLoopOutput<BW6<Self>>;
38}
39
40pub mod g1;
41pub mod g2;
42
43pub use self::{
44 g1::{G1Affine, G1Prepared, G1Projective},
45 g2::{G2Affine, G2Prepared, G2Projective},
46};
47
48#[derive(Derivative)]
49#[derivative(Copy, Clone, PartialEq, Eq, Debug, Hash)]
50pub struct BW6<P: BW6Config>(PhantomData<fn() -> P>);
51
52impl<P: BW6Config> Pairing for BW6<P> {
53 type BaseField = <P::G1Config as CurveConfig>::BaseField;
54 type ScalarField = <P::G1Config as CurveConfig>::ScalarField;
55 type G1 = G1Projective<P>;
56 type G1Affine = G1Affine<P>;
57 type G1Prepared = G1Prepared<P>;
58 type G2 = G2Projective<P>;
59 type G2Affine = G2Affine<P>;
60 type G2Prepared = G2Prepared<P>;
61 type TargetField = Fp6<P::Fp6Config>;
62
63 fn final_exponentiation(f: MillerLoopOutput<Self>) -> Option<PairingOutput<Self>> {
64 P::final_exponentiation(f)
65 }
66
67 fn multi_miller_loop(
68 a: impl IntoIterator<Item = impl Into<Self::G1Prepared>>,
69 b: impl IntoIterator<Item = impl Into<Self::G2Prepared>>,
70 ) -> MillerLoopOutput<Self> {
71 P::multi_miller_loop(a, b)
72 }
73}