decaf377/ark_curve/
bls12_377.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
use crate::fields::{fp::Fp, fq::Fq};
use ark_ec::{
    bls12::{Bls12, Bls12Config, TwistType},
    models::short_weierstrass::SWCurveConfig,
    models::CurveConfig,
    short_weierstrass::Affine,
};
use ark_ff::{fields::models::fp2::Fp2Config, Field, Fp12Config, Fp2, Fp6, Fp6Config};

pub struct F2Config;

impl Fp2Config for F2Config {
    type Fp = Fp;

    const NONRESIDUE: Fp = Fp::QUADRATIC_NON_RESIDUE;

    const FROBENIUS_COEFF_FP2_C1: &'static [Fp] = &[Fp::ONE, Fp::MINUS_ONE];
}

#[derive(Debug, Clone, Copy)]
pub struct F6Config;

impl Fp6Config for F6Config {
    type Fp2Config = F2Config;

    const NONRESIDUE: Fp2<Self::Fp2Config> = Fp2::new(Fp::ZERO, Fp::ONE);

    const FROBENIUS_COEFF_FP6_C1: &'static [Fp2<Self::Fp2Config>] = &[
        Fp2::new(Fp::ONE, Fp::ZERO),
        Fp2::new(
            Fp::from_montgomery_limbs([
                6382252053795993818,
                1383562296554596171,
                11197251941974877903,
                6684509567199238270,
                6699184357838251020,
                19987743694136192,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                15766275933608376691,
                15635974902606112666,
                1934946774703877852,
                18129354943882397960,
                15437979634065614942,
                101285514078273488,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(Fp::MINUS_ONE, Fp::ZERO),
        Fp2::new(
            Fp::from_montgomery_limbs([
                3203870859294639911,
                276961138506029237,
                9479726329337356593,
                13645541738420943632,
                7584832609311778094,
                101110569012358506,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                12266591053191808654,
                4471292606164064357,
                295287422898805027,
                2200696361737783943,
                17292781406793965788,
                19812798628221209,
            ]),
            Fp::ZERO,
        ),
    ];

    const FROBENIUS_COEFF_FP6_C2: &'static [Fp2<Self::Fp2Config>] = &[
        Fp2::new(Fp::ONE, Fp::ZERO),
        Fp2::new(
            Fp::from_montgomery_limbs([
                15766275933608376691,
                15635974902606112666,
                1934946774703877852,
                18129354943882397960,
                15437979634065614942,
                101285514078273488,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                3203870859294639911,
                276961138506029237,
                9479726329337356593,
                13645541738420943632,
                7584832609311778094,
                101110569012358506,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(Fp::ONE, Fp::ZERO),
        Fp2::new(
            Fp::from_montgomery_limbs([
                15766275933608376691,
                15635974902606112666,
                1934946774703877852,
                18129354943882397960,
                15437979634065614942,
                101285514078273488,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                3203870859294639911,
                276961138506029237,
                9479726329337356593,
                13645541738420943632,
                7584832609311778094,
                101110569012358506,
            ]),
            Fp::ZERO,
        ),
    ];
}

#[derive(Debug, Clone, Copy)]
pub struct F12Config;

impl Fp12Config for F12Config {
    type Fp6Config = F6Config;

    const NONRESIDUE: Fp6<Self::Fp6Config> = Fp6::new(Fp2::ZERO, Fp2::ONE, Fp2::ZERO);

    const FROBENIUS_COEFF_FP12_C1: &'static [Fp2<F2Config>] = &[
        Fp2::new(Fp::ONE, Fp::ZERO),
        Fp2::new(
            Fp::from_montgomery_limbs([
                7981638599956744862,
                11830407261614897732,
                6308788297503259939,
                10596665404780565693,
                11693741422477421038,
                61545186993886319,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                6382252053795993818,
                1383562296554596171,
                11197251941974877903,
                6684509567199238270,
                6699184357838251020,
                19987743694136192,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                10965161018967488287,
                18251363109856037426,
                7036083669251591763,
                16109345360066746489,
                4679973768683352764,
                96952949334633821,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                15766275933608376691,
                15635974902606112666,
                1934946774703877852,
                18129354943882397960,
                15437979634065614942,
                101285514078273488,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                2983522419010743425,
                6420955848241139694,
                727295371748331824,
                5512679955286180796,
                11432976419915483342,
                35407762340747501,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(Fp::MINUS_ONE, Fp::ZERO),
        Fp2::new(
            Fp::from_montgomery_limbs([
                1604484313133888867,
                8276860247155279292,
                14368189973808974556,
                9733385900839616209,
                2590275544672608076,
                59553125712608379,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                3203870859294639911,
                276961138506029237,
                9479726329337356593,
                13645541738420943632,
                7584832609311778094,
                101110569012358506,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                17067705967832697058,
                1855904398914139597,
                13640894602060642732,
                4220705945553435413,
                9604043198466676350,
                24145363371860877,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                12266591053191808654,
                4471292606164064357,
                295287422898805027,
                2200696361737783943,
                17292781406793965788,
                19812798628221209,
            ]),
            Fp::ZERO,
        ),
        Fp2::new(
            Fp::from_montgomery_limbs([
                6602600494079890304,
                13686311660529037330,
                1502938825854351055,
                14817371350334001107,
                2851040547234545772,
                85690550365747197,
            ]),
            Fp::ZERO,
        ),
    ];
}

pub struct OurG1Config;

impl CurveConfig for OurG1Config {
    type BaseField = Fp;

    type ScalarField = Fq;

    const COFACTOR: &'static [u64] = &[0x0, 0x170b5d4430000000];

    const COFACTOR_INV: Self::ScalarField = Fq::from_montgomery_limbs([
        2013239619100046060,
        4201184776506987597,
        2526766393982337036,
        1114629510922847535,
    ]);
}

const G1_GENERATOR_X: Fp = Fp::from_montgomery_limbs([
    2742467569752756724,
    14217256487979144792,
    6635299530028159197,
    8509097278468658840,
    14518893593143693938,
    46181716169194829,
]);

const G1_GENERATOR_Y: Fp = Fp::from_montgomery_limbs([
    9336971515457667571,
    28021381849722296,
    18085035374859187530,
    14013031479170682136,
    3369780711397861396,
    35370409237953649,
]);

impl SWCurveConfig for OurG1Config {
    const COEFF_A: Self::BaseField = Fp::ZERO;

    const COEFF_B: Self::BaseField = Fp::ONE;

    const GENERATOR: Affine<Self> = Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);
}

pub struct OurG2Config;

impl CurveConfig for OurG2Config {
    type BaseField = Fp2<F2Config>;

    type ScalarField = Fq;

    const COFACTOR: &'static [u64] = &[
        0x0000000000000001,
        0x452217cc90000000,
        0xa0f3622fba094800,
        0xd693e8c36676bd09,
        0x8c505634fae2e189,
        0xfbb36b00e1dcc40c,
        0xddd88d99a6f6a829,
        0x26ba558ae9562a,
    ];

    const COFACTOR_INV: Self::ScalarField = Fq::from_montgomery_limbs([
        15499857013495546999,
        4613531467548868169,
        14546778081091178013,
        549402535258503313,
    ]);
}

pub const G2_GENERATOR_X: Fp2<F2Config> = Fp2::new(
    Fp::from_montgomery_limbs([
        7534593107747697243,
        7390176809662624395,
        16990527120569264207,
        2168572232730518502,
        9443417493680878057,
        109821976444144002,
    ]),
    Fp::from_montgomery_limbs([
        6846220294590070585,
        17925825951095956135,
        15355657819052935248,
        16808496983586309946,
        18438381910454061441,
        78904498268135389,
    ]),
);

pub const G2_GENERATOR_Y: Fp2<F2Config> = Fp2::new(
    Fp::from_montgomery_limbs([
        15398259615690998543,
        413927750809907693,
        6945668964135547374,
        3622202639115414553,
        11542235856284301842,
        111174645670174930,
    ]),
    Fp::from_montgomery_limbs([
        6296061721506977525,
        16832990956758385678,
        2538166719760928425,
        9449086974571632418,
        3122185334549858583,
        25052933797626130,
    ]),
);

impl SWCurveConfig for OurG2Config {
    const COEFF_A: Self::BaseField = Fp2::new(OurG1Config::COEFF_A, OurG1Config::COEFF_A);

    const COEFF_B: Self::BaseField = Fp2::new(
        Fp::ZERO,
        Fp::from_montgomery_limbs([
            9255502405446297221,
            10229180150694123945,
            9215585410771530959,
            13357015519562362907,
            5437107869987383107,
            16259554076827459,
        ]),
    );

    const GENERATOR: Affine<Self> = Affine::new_unchecked(G2_GENERATOR_X, G2_GENERATOR_Y);
}

/// A marker struct for our implementation of BLS12-377 over our backend fields, using Arkworks.
pub struct Config;

impl Bls12Config for Config {
    const X: &'static [u64] = &[0x8508c00000000001];
    /// `x` is positive
    const X_IS_NEGATIVE: bool = false;

    const TWIST_TYPE: TwistType = TwistType::D;

    type Fp = Fp;

    type Fp2Config = F2Config;

    type Fp6Config = F6Config;

    type Fp12Config = F12Config;

    type G1Config = OurG1Config;

    type G2Config = OurG2Config;
}

pub type Bls12_377 = Bls12<Config>;