snarkvm_curves/bls12_377/
parameters.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use crate::{
17    bls12_377::{
18        Fq,
19        Fq2Parameters,
20        Fq6Parameters,
21        Fq12,
22        Fq12Parameters,
23        g1::Bls12_377G1Parameters,
24        g2::Bls12_377G2Parameters,
25    },
26    templates::bls12::{
27        Bls12,
28        Bls12Parameters,
29        G1Affine as Bls12G1Affine,
30        G1Prepared,
31        G1Projective as Bls12G1Projective,
32        G2Affine as Bls12G2Affine,
33        G2Prepared,
34        G2Projective as Bls12G2Projective,
35        TwistType,
36    },
37    traits::{PairingCurve, PairingEngine},
38};
39
40#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
41pub struct Bls12_377Parameters;
42
43impl Bls12Parameters for Bls12_377Parameters {
44    type Fp = Fq;
45    type Fp12Params = Fq12Parameters;
46    type Fp2Params = Fq2Parameters;
47    type Fp6Params = Fq6Parameters;
48    type G1Parameters = Bls12_377G1Parameters;
49    type G2Parameters = Bls12_377G2Parameters;
50
51    const TWIST_TYPE: TwistType = TwistType::D;
52    const X: &'static [u64] = &[0x8508c00000000001];
53    /// `x` is positive.
54    const X_IS_NEGATIVE: bool = false;
55}
56
57pub type Bls12_377 = Bls12<Bls12_377Parameters>;
58
59pub type G1Affine = Bls12G1Affine<Bls12_377Parameters>;
60pub type G1Projective = Bls12G1Projective<Bls12_377Parameters>;
61
62impl PairingCurve for G1Affine {
63    type Engine = Bls12_377;
64    type PairWith = G2Affine;
65    type PairingResult = Fq12;
66    type Prepared = G1Prepared<Bls12_377Parameters>;
67
68    fn prepare(&self) -> Self::Prepared {
69        Self::Prepared::from_affine(*self)
70    }
71
72    fn pairing_with(&self, other: &Self::PairWith) -> Self::PairingResult {
73        Bls12_377::pairing(*self, *other)
74    }
75}
76
77pub type G2Affine = Bls12G2Affine<Bls12_377Parameters>;
78pub type G2Projective = Bls12G2Projective<Bls12_377Parameters>;
79
80impl PairingCurve for G2Affine {
81    type Engine = Bls12_377;
82    type PairWith = G1Affine;
83    type PairingResult = Fq12;
84    type Prepared = G2Prepared<Bls12_377Parameters>;
85
86    fn prepare(&self) -> Self::Prepared {
87        Self::Prepared::from_affine(*self)
88    }
89
90    fn pairing_with(&self, other: &Self::PairWith) -> Self::PairingResult {
91        Bls12_377::pairing(*other, *self)
92    }
93}