-
Notifications
You must be signed in to change notification settings - Fork 146
/
g2_test.go
791 lines (656 loc) · 18.2 KB
/
g2_test.go
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
// Copyright 2020 Consensys Software Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by consensys/gnark-crypto DO NOT EDIT
package bls12378
import (
"fmt"
"math/big"
"math/rand"
"testing"
"github.com/consensys/gnark-crypto/ecc/bls12-378/internal/fptower"
"github.com/consensys/gnark-crypto/ecc/bls12-378/fr"
"github.com/leanovate/gopter"
"github.com/leanovate/gopter/prop"
)
func TestG2AffineEndomorphism(t *testing.T) {
t.Parallel()
parameters := gopter.DefaultTestParameters()
if testing.Short() {
parameters.MinSuccessfulTests = nbFuzzShort
} else {
parameters.MinSuccessfulTests = nbFuzz
}
properties := gopter.NewProperties(parameters)
properties.Property("[BLS12-378] check that phi(P) = lambdaGLV * P", prop.ForAll(
func(a fptower.E2) bool {
var p, res1, res2 G2Jac
g := MapToG2(a)
p.FromAffine(&g)
res1.phi(&p)
res2.mulWindowed(&p, &lambdaGLV)
return p.IsInSubGroup() && res1.Equal(&res2)
},
GenE2(),
))
properties.Property("[BLS12-378] check that phi^2(P) + phi(P) + P = 0", prop.ForAll(
func(a fptower.E2) bool {
var p, res, tmp G2Jac
g := MapToG2(a)
p.FromAffine(&g)
tmp.phi(&p)
res.phi(&tmp).
AddAssign(&tmp).
AddAssign(&p)
return res.Z.IsZero()
},
GenE2(),
))
properties.Property("[BLS12-378] check that psi^2(P) = -phi(P)", prop.ForAll(
func(a fptower.E2) bool {
var p, res1, res2 G2Jac
g := MapToG2(a)
p.FromAffine(&g)
res1.psi(&p).psi(&res1).Neg(&res1)
res2.Set(&p)
res2.X.MulByElement(&res2.X, &thirdRootOneG1)
return p.IsInSubGroup() && res1.Equal(&res2)
},
GenE2(),
))
properties.TestingRun(t, gopter.ConsoleReporter(false))
}
func TestG2AffineIsOnCurve(t *testing.T) {
t.Parallel()
parameters := gopter.DefaultTestParameters()
if testing.Short() {
parameters.MinSuccessfulTests = nbFuzzShort
} else {
parameters.MinSuccessfulTests = nbFuzz
}
properties := gopter.NewProperties(parameters)
properties.Property("[BLS12-378] g2Gen (affine) should be on the curve", prop.ForAll(
func(a fptower.E2) bool {
var op1, op2 G2Affine
op1.FromJacobian(&g2Gen)
op2.Set(&op1)
op2.Y.Mul(&op2.Y, &a)
return op1.IsOnCurve() && !op2.IsOnCurve()
},
GenE2(),
))
properties.Property("[BLS12-378] g2Gen (Jacobian) should be on the curve", prop.ForAll(
func(a fptower.E2) bool {
var op1, op2, op3 G2Jac
op1.Set(&g2Gen)
op3.Set(&g2Gen)
op2 = fuzzG2Jac(&g2Gen, a)
op3.Y.Mul(&op3.Y, &a)
return op1.IsOnCurve() && op2.IsOnCurve() && !op3.IsOnCurve()
},
GenE2(),
))
properties.Property("[BLS12-378] IsInSubGroup and MulBy subgroup order should be the same", prop.ForAll(
func(a fptower.E2) bool {
var op1, op2 G2Jac
op1 = fuzzG2Jac(&g2Gen, a)
_r := fr.Modulus()
op2.ScalarMultiplication(&op1, _r)
return op1.IsInSubGroup() && op2.Z.IsZero()
},
GenE2(),
))
properties.TestingRun(t, gopter.ConsoleReporter(false))
}
func TestG2AffineConversions(t *testing.T) {
t.Parallel()
parameters := gopter.DefaultTestParameters()
if testing.Short() {
parameters.MinSuccessfulTests = nbFuzzShort
} else {
parameters.MinSuccessfulTests = nbFuzz
}
properties := gopter.NewProperties(parameters)
properties.Property("[BLS12-378] Affine representation should be independent of the Jacobian representative", prop.ForAll(
func(a fptower.E2) bool {
g := fuzzG2Jac(&g2Gen, a)
var op1 G2Affine
op1.FromJacobian(&g)
return op1.X.Equal(&g2Gen.X) && op1.Y.Equal(&g2Gen.Y)
},
GenE2(),
))
properties.Property("[BLS12-378] Affine representation should be independent of a Extended Jacobian representative", prop.ForAll(
func(a fptower.E2) bool {
var g g2JacExtended
g.X.Set(&g2Gen.X)
g.Y.Set(&g2Gen.Y)
g.ZZ.Set(&g2Gen.Z)
g.ZZZ.Set(&g2Gen.Z)
gfuzz := fuzzg2JacExtended(&g, a)
var op1 G2Affine
op1.fromJacExtended(&gfuzz)
return op1.X.Equal(&g2Gen.X) && op1.Y.Equal(&g2Gen.Y)
},
GenE2(),
))
properties.Property("[BLS12-378] Jacobian representation should be the same as the affine representative", prop.ForAll(
func(a fptower.E2) bool {
var g G2Jac
var op1 G2Affine
op1.X.Set(&g2Gen.X)
op1.Y.Set(&g2Gen.Y)
var one fptower.E2
one.SetOne()
g.FromAffine(&op1)
return g.X.Equal(&g2Gen.X) && g.Y.Equal(&g2Gen.Y) && g.Z.Equal(&one)
},
GenE2(),
))
properties.Property("[BLS12-378] Converting affine symbol for infinity to Jacobian should output correct infinity in Jacobian", prop.ForAll(
func() bool {
var g G2Affine
g.X.SetZero()
g.Y.SetZero()
var op1 G2Jac
op1.FromAffine(&g)
var one, zero fptower.E2
one.SetOne()
return op1.X.Equal(&one) && op1.Y.Equal(&one) && op1.Z.Equal(&zero)
},
))
properties.Property("[BLS12-378] Converting infinity in extended Jacobian to affine should output infinity symbol in Affine", prop.ForAll(
func() bool {
var g G2Affine
var op1 g2JacExtended
var zero fptower.E2
op1.X.Set(&g2Gen.X)
op1.Y.Set(&g2Gen.Y)
g.fromJacExtended(&op1)
return g.X.Equal(&zero) && g.Y.Equal(&zero)
},
))
properties.Property("[BLS12-378] Converting infinity in extended Jacobian to Jacobian should output infinity in Jacobian", prop.ForAll(
func() bool {
var g G2Jac
var op1 g2JacExtended
var zero, one fptower.E2
one.SetOne()
op1.X.Set(&g2Gen.X)
op1.Y.Set(&g2Gen.Y)
g.fromJacExtended(&op1)
return g.X.Equal(&one) && g.Y.Equal(&one) && g.Z.Equal(&zero)
},
))
properties.Property("[BLS12-378] [Jacobian] Two representatives of the same class should be equal", prop.ForAll(
func(a, b fptower.E2) bool {
op1 := fuzzG2Jac(&g2Gen, a)
op2 := fuzzG2Jac(&g2Gen, b)
return op1.Equal(&op2)
},
GenE2(),
GenE2(),
))
properties.TestingRun(t, gopter.ConsoleReporter(false))
}
func TestG2AffineOps(t *testing.T) {
t.Parallel()
parameters := gopter.DefaultTestParameters()
parameters.MinSuccessfulTests = 10
properties := gopter.NewProperties(parameters)
genScalar := GenFr()
properties.Property("[BLS12-378-381] [-s]G = -[s]G", prop.ForAll(
func(s fr.Element) bool {
g := g2GenAff
var gj G2Jac
var nbs, bs big.Int
s.BigInt(&bs)
nbs.Neg(&bs)
var res = true
// mulGLV
{
var op1, op2 G2Affine
op1.ScalarMultiplication(&g, &bs).Neg(&op1)
op2.ScalarMultiplication(&g, &nbs)
res = res && op1.Equal(&op2)
}
// mulWindowed
{
var op1, op2 G2Jac
op1.mulWindowed(&gj, &bs).Neg(&op1)
op2.mulWindowed(&gj, &nbs)
res = res && op1.Equal(&op2)
}
return res
},
GenFr(),
))
properties.Property("[BLS12-378] [Jacobian] Add should call double when having adding the same point", prop.ForAll(
func(a, b fptower.E2) bool {
fop1 := fuzzG2Jac(&g2Gen, a)
fop2 := fuzzG2Jac(&g2Gen, b)
var op1, op2 G2Jac
op1.Set(&fop1).AddAssign(&fop2)
op2.Double(&fop2)
return op1.Equal(&op2)
},
GenE2(),
GenE2(),
))
properties.Property("[BLS12-378] [Jacobian] Adding the opposite of a point to itself should output inf", prop.ForAll(
func(a, b fptower.E2) bool {
fop1 := fuzzG2Jac(&g2Gen, a)
fop2 := fuzzG2Jac(&g2Gen, b)
fop2.Neg(&fop2)
fop1.AddAssign(&fop2)
return fop1.Equal(&g2Infinity)
},
GenE2(),
GenE2(),
))
properties.Property("[BLS12-378] [Jacobian] Adding the inf to a point should not modify the point", prop.ForAll(
func(a fptower.E2) bool {
fop1 := fuzzG2Jac(&g2Gen, a)
fop1.AddAssign(&g2Infinity)
var op2 G2Jac
op2.Set(&g2Infinity)
op2.AddAssign(&g2Gen)
return fop1.Equal(&g2Gen) && op2.Equal(&g2Gen)
},
GenE2(),
))
properties.Property("[BLS12-378] [Jacobian Extended] addMixed (-G) should equal subMixed(G)", prop.ForAll(
func(a fptower.E2) bool {
fop1 := fuzzG2Jac(&g2Gen, a)
var p1, p1Neg G2Affine
p1.FromJacobian(&fop1)
p1Neg = p1
p1Neg.Y.Neg(&p1Neg.Y)
var o1, o2 g2JacExtended
o1.addMixed(&p1Neg)
o2.subMixed(&p1)
return o1.X.Equal(&o2.X) &&
o1.Y.Equal(&o2.Y) &&
o1.ZZ.Equal(&o2.ZZ) &&
o1.ZZZ.Equal(&o2.ZZZ)
},
GenE2(),
))
properties.Property("[BLS12-378] [Jacobian Extended] doubleMixed (-G) should equal doubleNegMixed(G)", prop.ForAll(
func(a fptower.E2) bool {
fop1 := fuzzG2Jac(&g2Gen, a)
var p1, p1Neg G2Affine
p1.FromJacobian(&fop1)
p1Neg = p1
p1Neg.Y.Neg(&p1Neg.Y)
var o1, o2 g2JacExtended
o1.doubleMixed(&p1Neg)
o2.doubleNegMixed(&p1)
return o1.X.Equal(&o2.X) &&
o1.Y.Equal(&o2.Y) &&
o1.ZZ.Equal(&o2.ZZ) &&
o1.ZZZ.Equal(&o2.ZZZ)
},
GenE2(),
))
properties.Property("[BLS12-378] [Jacobian] Addmix the negation to itself should output 0", prop.ForAll(
func(a fptower.E2) bool {
fop1 := fuzzG2Jac(&g2Gen, a)
fop1.Neg(&fop1)
var op2 G2Affine
op2.FromJacobian(&g2Gen)
fop1.AddMixed(&op2)
return fop1.Equal(&g2Infinity)
},
GenE2(),
))
properties.Property("[BLS12-378] scalar multiplication (double and add) should depend only on the scalar mod r", prop.ForAll(
func(s fr.Element) bool {
r := fr.Modulus()
var g G2Jac
g.ScalarMultiplication(&g2Gen, r)
var scalar, blindedScalar, rminusone big.Int
var op1, op2, op3, gneg G2Jac
rminusone.SetUint64(1).Sub(r, &rminusone)
op3.mulWindowed(&g2Gen, &rminusone)
gneg.Neg(&g2Gen)
s.BigInt(&scalar)
blindedScalar.Mul(&scalar, r).Add(&blindedScalar, &scalar)
op1.mulWindowed(&g2Gen, &scalar)
op2.mulWindowed(&g2Gen, &blindedScalar)
return op1.Equal(&op2) && g.Equal(&g2Infinity) && !op1.Equal(&g2Infinity) && gneg.Equal(&op3)
},
genScalar,
))
properties.Property("[BLS12-378] psi should map points from E' to itself", prop.ForAll(
func() bool {
var a G2Jac
a.psi(&g2Gen)
return a.IsOnCurve() && !a.Equal(&g2Gen)
},
))
properties.Property("[BLS12-378] scalar multiplication (GLV) should depend only on the scalar mod r", prop.ForAll(
func(s fr.Element) bool {
r := fr.Modulus()
var g G2Jac
g.mulGLV(&g2Gen, r)
var scalar, blindedScalar, rminusone big.Int
var op1, op2, op3, gneg G2Jac
rminusone.SetUint64(1).Sub(r, &rminusone)
op3.ScalarMultiplication(&g2Gen, &rminusone)
gneg.Neg(&g2Gen)
s.BigInt(&scalar)
blindedScalar.Mul(&scalar, r).Add(&blindedScalar, &scalar)
op1.ScalarMultiplication(&g2Gen, &scalar)
op2.ScalarMultiplication(&g2Gen, &blindedScalar)
return op1.Equal(&op2) && g.Equal(&g2Infinity) && !op1.Equal(&g2Infinity) && gneg.Equal(&op3)
},
genScalar,
))
properties.Property("[BLS12-378] GLV and Double and Add should output the same result", prop.ForAll(
func(s fr.Element) bool {
var r big.Int
var op1, op2 G2Jac
s.BigInt(&r)
op1.mulWindowed(&g2Gen, &r)
op2.mulGLV(&g2Gen, &r)
return op1.Equal(&op2) && !op1.Equal(&g2Infinity)
},
genScalar,
))
properties.TestingRun(t, gopter.ConsoleReporter(false))
}
func TestG2AffineCofactorCleaning(t *testing.T) {
t.Parallel()
parameters := gopter.DefaultTestParameters()
if testing.Short() {
parameters.MinSuccessfulTests = nbFuzzShort
} else {
parameters.MinSuccessfulTests = nbFuzz
}
properties := gopter.NewProperties(parameters)
properties.Property("[BLS12-378] Clearing the cofactor of a random point should set it in the r-torsion", prop.ForAll(
func() bool {
var a, x, b fptower.E2
a.SetRandom()
x.Square(&a).Mul(&x, &a).Add(&x, &bTwistCurveCoeff)
for x.Legendre() != 1 {
a.SetRandom()
x.Square(&a).Mul(&x, &a).Add(&x, &bTwistCurveCoeff)
}
b.Sqrt(&x)
var point, pointCleared, infinity G2Jac
point.X.Set(&a)
point.Y.Set(&b)
point.Z.SetOne()
pointCleared.ClearCofactor(&point)
infinity.Set(&g2Infinity)
return point.IsOnCurve() && pointCleared.IsInSubGroup() && !pointCleared.Equal(&infinity)
},
))
properties.TestingRun(t, gopter.ConsoleReporter(false))
}
func TestG2AffineBatchScalarMultiplication(t *testing.T) {
parameters := gopter.DefaultTestParameters()
if testing.Short() {
parameters.MinSuccessfulTests = nbFuzzShort
} else {
parameters.MinSuccessfulTests = nbFuzzShort
}
properties := gopter.NewProperties(parameters)
genScalar := GenFr()
// size of the multiExps
const nbSamples = 10
properties.Property("[BLS12-378] BatchScalarMultiplication should be consistent with individual scalar multiplications", prop.ForAll(
func(mixer fr.Element) bool {
// mixer ensures that all the words of a fpElement are set
var sampleScalars [nbSamples]fr.Element
for i := 1; i <= nbSamples; i++ {
sampleScalars[i-1].SetUint64(uint64(i)).
Mul(&sampleScalars[i-1], &mixer)
}
result := BatchScalarMultiplicationG2(&g2GenAff, sampleScalars[:])
if len(result) != len(sampleScalars) {
return false
}
for i := 0; i < len(result); i++ {
var expectedJac G2Jac
var expected G2Affine
var b big.Int
expectedJac.ScalarMultiplication(&g2Gen, sampleScalars[i].BigInt(&b))
expected.FromJacobian(&expectedJac)
if !result[i].Equal(&expected) {
return false
}
}
return true
},
genScalar,
))
properties.TestingRun(t, gopter.ConsoleReporter(false))
}
// ------------------------------------------------------------
// benches
func BenchmarkG2JacIsInSubGroup(b *testing.B) {
var a G2Jac
a.Set(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.IsInSubGroup()
}
}
func BenchmarkG2JacEqual(b *testing.B) {
var scalar fptower.E2
if _, err := scalar.SetRandom(); err != nil {
b.Fatalf("failed to set scalar: %s", err)
}
var a G2Jac
a.ScalarMultiplication(&g2Gen, big.NewInt(42))
b.Run("equal", func(b *testing.B) {
var scalarSquared fptower.E2
scalarSquared.Square(&scalar)
aZScaled := a
aZScaled.X.Mul(&aZScaled.X, &scalarSquared)
aZScaled.Y.Mul(&aZScaled.Y, &scalarSquared).Mul(&aZScaled.Y, &scalar)
aZScaled.Z.Mul(&aZScaled.Z, &scalar)
// Check the setup.
if !a.Equal(&aZScaled) {
b.Fatalf("invalid test setup")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.Equal(&aZScaled)
}
})
b.Run("not equal", func(b *testing.B) {
var aPlus1 G2Jac
aPlus1.AddAssign(&g2Gen)
// Check the setup.
if a.Equal(&aPlus1) {
b.Fatalf("invalid test setup")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.Equal(&aPlus1)
}
})
}
func BenchmarkBatchAddG2Affine(b *testing.B) {
var P, R pG2AffineC16
var RR ppG2AffineC16
ridx := make([]int, len(P))
// TODO P == R may produce skewed benches
fillBenchBasesG2(P[:])
fillBenchBasesG2(R[:])
for i := 0; i < len(ridx); i++ {
ridx[i] = i
}
// random permute
rand.Shuffle(len(ridx), func(i, j int) { ridx[i], ridx[j] = ridx[j], ridx[i] })
for i, ri := range ridx {
RR[i] = &R[ri]
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
batchAddG2Affine[pG2AffineC16, ppG2AffineC16, cG2AffineC16](&RR, &P, len(P))
}
}
func BenchmarkG2AffineBatchScalarMultiplication(b *testing.B) {
// ensure every words of the scalars are filled
var mixer fr.Element
mixer.SetString("7716837800905789770901243404444209691916730933998574719964609384059111546487")
const pow = 15
const nbSamples = 1 << pow
var sampleScalars [nbSamples]fr.Element
for i := 1; i <= nbSamples; i++ {
sampleScalars[i-1].SetUint64(uint64(i)).
Mul(&sampleScalars[i-1], &mixer)
}
for i := 5; i <= pow; i++ {
using := 1 << i
b.Run(fmt.Sprintf("%d points", using), func(b *testing.B) {
b.ResetTimer()
for j := 0; j < b.N; j++ {
_ = BatchScalarMultiplicationG2(&g2GenAff, sampleScalars[:using])
}
})
}
}
func BenchmarkG2JacScalarMultiplication(b *testing.B) {
var scalar big.Int
r := fr.Modulus()
scalar.SetString("5243587517512619047944770508185965837690552500527637822603658699938581184513", 10)
scalar.Add(&scalar, r)
var doubleAndAdd G2Jac
b.Run("double and add", func(b *testing.B) {
b.ResetTimer()
for j := 0; j < b.N; j++ {
doubleAndAdd.mulWindowed(&g2Gen, &scalar)
}
})
var glv G2Jac
b.Run("GLV", func(b *testing.B) {
b.ResetTimer()
for j := 0; j < b.N; j++ {
glv.mulGLV(&g2Gen, &scalar)
}
})
}
func BenchmarkG2AffineCofactorClearing(b *testing.B) {
var a G2Jac
a.Set(&g2Gen)
for i := 0; i < b.N; i++ {
a.ClearCofactor(&a)
}
}
func BenchmarkG2JacAdd(b *testing.B) {
var a G2Jac
a.Double(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.AddAssign(&g2Gen)
}
}
func BenchmarkG2JacAddMixed(b *testing.B) {
var a G2Jac
a.Double(&g2Gen)
var c G2Affine
c.FromJacobian(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.AddMixed(&c)
}
}
func BenchmarkG2JacDouble(b *testing.B) {
var a G2Jac
a.Set(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.DoubleAssign()
}
}
func BenchmarkG2JacExtAddMixed(b *testing.B) {
var a g2JacExtended
a.doubleMixed(&g2GenAff)
var c G2Affine
c.FromJacobian(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.addMixed(&c)
}
}
func BenchmarkG2JacExtSubMixed(b *testing.B) {
var a g2JacExtended
a.doubleMixed(&g2GenAff)
var c G2Affine
c.FromJacobian(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.subMixed(&c)
}
}
func BenchmarkG2JacExtDoubleMixed(b *testing.B) {
var a g2JacExtended
a.doubleMixed(&g2GenAff)
var c G2Affine
c.FromJacobian(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.doubleMixed(&c)
}
}
func BenchmarkG2JacExtDoubleNegMixed(b *testing.B) {
var a g2JacExtended
a.doubleMixed(&g2GenAff)
var c G2Affine
c.FromJacobian(&g2Gen)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.doubleNegMixed(&c)
}
}
func BenchmarkG2JacExtAdd(b *testing.B) {
var a, c g2JacExtended
a.doubleMixed(&g2GenAff)
c.double(&a)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.add(&c)
}
}
func BenchmarkG2JacExtDouble(b *testing.B) {
var a g2JacExtended
a.doubleMixed(&g2GenAff)
b.ResetTimer()
for i := 0; i < b.N; i++ {
a.double(&a)
}
}
func fuzzG2Jac(p *G2Jac, f fptower.E2) G2Jac {
var res G2Jac
res.X.Mul(&p.X, &f).Mul(&res.X, &f)
res.Y.Mul(&p.Y, &f).Mul(&res.Y, &f).Mul(&res.Y, &f)
res.Z.Mul(&p.Z, &f)
return res
}
func fuzzg2JacExtended(p *g2JacExtended, f fptower.E2) g2JacExtended {
var res g2JacExtended
var ff, fff fptower.E2
ff.Square(&f)
fff.Mul(&ff, &f)
res.X.Mul(&p.X, &ff)
res.Y.Mul(&p.Y, &fff)
res.ZZ.Mul(&p.ZZ, &ff)
res.ZZZ.Mul(&p.ZZZ, &fff)
return res
}