@@ -50,6 +50,19 @@ func blsInitGurvy(b *testing.B) (*bls12381.G2Affine, *big.Int) {
5050 return g , x
5151}
5252
53+ func blsInitKilic (b * testing.B ) (* kilic.PointG2 , * big.Int ) {
54+ rng := rand .Reader
55+
56+ _g := kilic .NewG2 ()
57+ g2 := _g .One ()
58+ g := _g .New ()
59+
60+ _g .MulScalarBig (g , g2 , newRandZr (rng , fr .Modulus ()))
61+ x := newRandZr (rng , fr .Modulus ())
62+
63+ return g , x
64+ }
65+
5366func pokPedersenCommittmentInit (b * testing.B , curve * Curve ) (io.Reader , * G1 , * G1 , * Zr , error ) {
5467 rng , err := curve .Rand ()
5568 if err != nil {
@@ -299,47 +312,102 @@ func Benchmark_Parallel_BLSGurvy(b *testing.B) {
299312 })
300313}
301314
302- func Benchmark_Parallel_BLS (b * testing.B ) {
303- curve := Curves [BLS12_381_GURVY ]
304- g , x , err := blsInit (b , curve )
305- if err != nil {
306- panic (err )
307- }
308-
309- pk := g .Mul (x )
315+ func Benchmark_Parallel_BLSKilic (b * testing.B ) {
316+ g , x := blsInitKilic (b )
317+ _g := kilic .NewG2 ()
318+ pk := _g .New ()
319+ _g .MulScalarBig (pk , g , x )
310320
311321 b .ResetTimer ()
312322
313- var sig * G1
323+ var sig * kilic. PointG1
314324
315- b .Run (fmt . Sprintf ( "sign curve %s" , CurveIDToString ( curve . curveID )) , func (b * testing.B ) {
325+ b .Run ("sign curve BLS12_381_GURVY (direct)" , func (b * testing.B ) {
316326 b .RunParallel (func (pb * testing.PB ) {
327+ _g := kilic .NewG1 ()
317328 for pb .Next () {
318- h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
319- sig = h .Mul (x )
329+ g1 := kilic .NewG1 ()
330+ h , err := g1 .HashToCurve ([]byte ("msg" ), []byte ("context" ))
331+ if err != nil {
332+ panic (err )
333+ }
334+
335+ sig = _g .New ()
336+ _g .MulScalarBig (sig , h , x )
320337 }
321338 })
322339 })
323340
324- sig . Neg ()
341+ kilic . NewG1 (). Neg (sig , sig )
325342
326- b .Run (fmt .Sprintf ("verify curve %s" , CurveIDToString (curve .curveID )), func (b * testing.B ) {
343+ b .ResetTimer ()
344+
345+ b .Run ("verify curve BLS12_381_GURVY (direct)" , func (b * testing.B ) {
327346 b .RunParallel (func (pb * testing.PB ) {
328347 for pb .Next () {
329- h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
330-
331- p := curve .Pairing2 (g , sig , pk , h )
348+ g1 := kilic .NewG1 ()
349+ h , err := g1 .HashToCurve ([]byte ("msg" ), []byte ("context" ))
350+ if err != nil {
351+ panic (err )
352+ }
353+ bls := kilic .NewEngine ()
354+ bls .AddPair (sig , g )
355+ bls .AddPair (h , pk )
332356
333- p = curve .FExp (p )
334- if ! p .IsUnity () {
357+ if ! bls .Check () {
335358 panic ("invalid signature" )
336359 }
337360 }
338361 })
339362 })
340363}
341364
342- func Benchmark_Parallel_IndividualOps (b * testing.B ) {
365+ func Benchmark_Parallel_BLS (b * testing.B ) {
366+ for _ , curve := range Curves {
367+ if curve .curveID != BLS12_381 && curve .curveID != BLS12_381_GURVY {
368+ continue
369+ }
370+
371+ g , x , err := blsInit (b , curve )
372+ if err != nil {
373+ panic (err )
374+ }
375+
376+ pk := g .Mul (x )
377+
378+ b .ResetTimer ()
379+
380+ var sig * G1
381+
382+ b .Run (fmt .Sprintf ("sign curve %s" , CurveIDToString (curve .curveID )), func (b * testing.B ) {
383+ b .RunParallel (func (pb * testing.PB ) {
384+ for pb .Next () {
385+ h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
386+ sig = h .Mul (x )
387+ }
388+ })
389+ })
390+
391+ sig .Neg ()
392+
393+ b .Run (fmt .Sprintf ("verify curve %s" , CurveIDToString (curve .curveID )), func (b * testing.B ) {
394+ b .RunParallel (func (pb * testing.PB ) {
395+ for pb .Next () {
396+ h := curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
397+
398+ p := curve .Pairing2 (g , sig , pk , h )
399+
400+ p = curve .FExp (p )
401+ if ! p .IsUnity () {
402+ panic ("invalid signature" )
403+ }
404+ }
405+ })
406+ })
407+ }
408+ }
409+
410+ func Benchmark_Parallel_IndividualOpsGurvy (b * testing.B ) {
343411 curve := Curves [BLS12_381_GURVY ]
344412 g_gurv , x_gurv := blsInitGurvy (b )
345413 g_math , x_math , err := blsInit (b , curve )
@@ -415,3 +483,81 @@ func Benchmark_Parallel_IndividualOps(b *testing.B) {
415483 })
416484 })
417485}
486+
487+ func Benchmark_Parallel_IndividualOpsKilic (b * testing.B ) {
488+ curve := Curves [BLS12_381 ]
489+ g_kili , x_kili := blsInitKilic (b )
490+ g_math , x_math , err := blsInit (b , curve )
491+ if err != nil {
492+ panic (err )
493+ }
494+
495+ _g := kilic .NewG2 ()
496+ pk_kili := _g .New ()
497+ _g .MulScalarBig (pk_kili , g_kili , x_kili )
498+ pk_math := g_math .Mul (x_math )
499+
500+ var h_kili * kilic.PointG1
501+ var h_math * G1
502+
503+ var sig_kili * kilic.PointG1
504+ var sig_math * G1
505+
506+ var t_math * Gt
507+
508+ b .Run ("hash/kilic" , func (b * testing.B ) {
509+ b .RunParallel (func (pb * testing.PB ) {
510+ for pb .Next () {
511+ g1 := kilic .NewG1 ()
512+ h_kili , _ = g1 .HashToCurve ([]byte ("msg" ), []byte ("context" ))
513+ }
514+ })
515+ })
516+
517+ b .Run ("hash/mathlib" , func (b * testing.B ) {
518+ b .RunParallel (func (pb * testing.PB ) {
519+ for pb .Next () {
520+ h_math = curve .HashToG1WithDomain ([]byte ("msg" ), []byte ("context" ))
521+ }
522+ })
523+ })
524+
525+ b .Run ("sign/kilic" , func (b * testing.B ) {
526+ b .RunParallel (func (pb * testing.PB ) {
527+ _g := kilic .NewG1 ()
528+ for pb .Next () {
529+ sig_kili = _g .New ()
530+ _g .MulScalarBig (sig_kili , h_kili , x_kili )
531+ }
532+ })
533+ })
534+
535+ b .Run ("sign/mathlib" , func (b * testing.B ) {
536+ b .RunParallel (func (pb * testing.PB ) {
537+ for pb .Next () {
538+ sig_math = h_math .Mul (x_math )
539+ }
540+ })
541+ })
542+
543+ b .Run ("pairing2/kilic" , func (b * testing.B ) {
544+ b .RunParallel (func (pb * testing.PB ) {
545+ for pb .Next () {
546+ bls := kilic .NewEngine ()
547+ bls .AddPair (sig_kili , g_kili )
548+ bls .AddPair (h_kili , pk_kili )
549+ bls .Result ()
550+ }
551+ })
552+ })
553+
554+ b .Run ("pairing2/mathlib" , func (b * testing.B ) {
555+ b .RunParallel (func (pb * testing.PB ) {
556+ for pb .Next () {
557+ t_math = curve .Pairing2 (g_math , sig_math , pk_math , h_math )
558+
559+ t_math = curve .FExp (t_math )
560+ }
561+ })
562+ })
563+ }
0 commit comments