2020-09-24 15:18:23 +00:00
|
|
|
|
# Constantine
|
|
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
|
|
|
|
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
|
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
|
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
|
|
|
|
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
|
|
# ############################################################
|
|
|
|
|
#
|
|
|
|
|
# Benchmark of pairings
|
|
|
|
|
#
|
|
|
|
|
# ############################################################
|
|
|
|
|
|
|
|
|
|
import
|
|
|
|
|
# Internals
|
2022-02-27 00:49:08 +00:00
|
|
|
|
../constantine/platforms/abstractions,
|
|
|
|
|
../constantine/math/config/curves,
|
|
|
|
|
../constantine/math/arithmetic,
|
|
|
|
|
../constantine/math/extension_fields,
|
|
|
|
|
../constantine/math/ec_shortweierstrass,
|
|
|
|
|
../constantine/math/curves/zoo_subgroups,
|
|
|
|
|
../constantine/math/pairing/[
|
2022-02-20 19:15:20 +00:00
|
|
|
|
cyclotomic_subgroup,
|
|
|
|
|
lines_eval,
|
2020-09-25 19:58:20 +00:00
|
|
|
|
pairing_bls12,
|
|
|
|
|
pairing_bn
|
2020-09-24 15:18:23 +00:00
|
|
|
|
],
|
2022-02-27 00:49:08 +00:00
|
|
|
|
../constantine/math/curves/zoo_pairings,
|
2020-09-24 15:18:23 +00:00
|
|
|
|
# Helpers
|
2020-12-15 18:18:36 +00:00
|
|
|
|
../helpers/prng_unsafe,
|
|
|
|
|
./bench_blueprint
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
2021-02-14 12:06:57 +00:00
|
|
|
|
export zoo_pairings # generic sandwich https://github.com/nim-lang/Nim/issues/11225
|
2020-12-15 18:18:36 +00:00
|
|
|
|
export notes
|
2021-02-09 21:57:45 +00:00
|
|
|
|
proc separator*() = separator(132)
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
2020-12-15 18:18:36 +00:00
|
|
|
|
proc report(op, curve: string, startTime, stopTime: MonoTime, startClk, stopClk: int64, iters: int) =
|
|
|
|
|
let ns = inNanoseconds((stopTime-startTime) div iters)
|
2020-09-24 15:18:23 +00:00
|
|
|
|
let throughput = 1e9 / float64(ns)
|
|
|
|
|
when SupportsGetTicks:
|
2021-02-09 21:57:45 +00:00
|
|
|
|
echo &"{op:<40} {curve:<15} {throughput:>15.3f} ops/s {ns:>9} ns/op {(stopClk - startClk) div iters:>9} CPU cycles (approx)"
|
2020-09-24 15:18:23 +00:00
|
|
|
|
else:
|
2021-02-09 21:57:45 +00:00
|
|
|
|
echo &"{op:<40} {curve:<15} {throughput:>15.3f} ops/s {ns:>9} ns/op"
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
|
|
|
|
template bench(op: string, C: static Curve, iters: int, body: untyped): untyped =
|
2020-12-15 18:18:36 +00:00
|
|
|
|
measure(iters, startTime, stopTime, startClk, stopClk, body)
|
|
|
|
|
report(op, $C, startTime, stopTime, startClk, stopClk, iters)
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
2022-01-03 13:12:58 +00:00
|
|
|
|
func clearCofactor[F; G: static Subgroup](
|
2022-01-01 18:17:04 +00:00
|
|
|
|
ec: var ECP_ShortW_Aff[F, G]) =
|
2021-02-14 12:06:57 +00:00
|
|
|
|
# For now we don't have any affine operation defined
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var t {.noInit.}: ECP_ShortW_Prj[F, G]
|
2022-02-10 13:05:07 +00:00
|
|
|
|
t.fromAffine(ec)
|
2022-01-03 13:12:58 +00:00
|
|
|
|
t.clearCofactor()
|
2022-02-10 13:05:07 +00:00
|
|
|
|
ec.affine(t)
|
2021-02-14 12:06:57 +00:00
|
|
|
|
|
2020-09-24 15:18:23 +00:00
|
|
|
|
func random_point*(rng: var RngState, EC: typedesc): EC {.noInit.} =
|
|
|
|
|
result = rng.random_unsafe(EC)
|
2022-01-03 13:12:58 +00:00
|
|
|
|
result.clearCofactor()
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
|
|
|
|
proc lineDoubleBench*(C: static Curve, iters: int) =
|
2020-10-09 05:51:47 +00:00
|
|
|
|
var line: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2020-09-24 15:18:23 +00:00
|
|
|
|
bench("Line double", C, iters):
|
2021-02-14 12:06:57 +00:00
|
|
|
|
line.line_double(T, P)
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
|
|
|
|
proc lineAddBench*(C: static Curve, iters: int) =
|
2020-10-09 05:51:47 +00:00
|
|
|
|
var line: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
2020-09-24 15:18:23 +00:00
|
|
|
|
let
|
2022-01-01 18:17:04 +00:00
|
|
|
|
P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
|
|
|
|
Q = rng.random_point(ECP_ShortW_Aff[Fp2[C], G2])
|
2020-09-24 15:18:23 +00:00
|
|
|
|
bench("Line add", C, iters):
|
2021-02-14 12:06:57 +00:00
|
|
|
|
line.line_add(T, Q, P)
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
2020-09-25 19:58:20 +00:00
|
|
|
|
proc mulFp12byLine_xyz000_Bench*(C: static Curve, iters: int) =
|
2020-10-09 05:51:47 +00:00
|
|
|
|
var line: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
line.line_double(T, P)
|
2020-09-25 19:58:20 +00:00
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Mul 𝔽p12 by line xyz000", C, iters):
|
|
|
|
|
f.mul_sparse_by_line_xyz000(line)
|
|
|
|
|
|
|
|
|
|
proc mulFp12byLine_xy000z_Bench*(C: static Curve, iters: int) =
|
2020-10-09 05:51:47 +00:00
|
|
|
|
var line: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
line.line_double(T, P)
|
2020-09-24 15:18:23 +00:00
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Mul 𝔽p12 by line xy000z", C, iters):
|
|
|
|
|
f.mul_sparse_by_line_xy000z(line)
|
|
|
|
|
|
2021-02-14 12:06:57 +00:00
|
|
|
|
proc mulLinebyLine_xyz000_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var l0, l1: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
l0.line_double(T, P)
|
|
|
|
|
l1.line_double(T, P)
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Mul line xyz000 by line xyz000", C, iters):
|
2021-08-16 20:22:51 +00:00
|
|
|
|
f.prod_xyz000_xyz000_into_abcdefghij00(l0, l1)
|
2021-02-14 12:06:57 +00:00
|
|
|
|
|
|
|
|
|
proc mulLinebyLine_xy000z_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var l0, l1: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
l0.line_double(T, P)
|
|
|
|
|
l1.line_double(T, P)
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Mul line xy000z by line xy000z", C, iters):
|
2021-08-16 20:22:51 +00:00
|
|
|
|
f.prod_xy000z_xy000z_into_abcd00efghij(l0, l1)
|
2021-02-14 12:06:57 +00:00
|
|
|
|
|
|
|
|
|
proc mulFp12by_abcdefghij00_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
let g = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Mul 𝔽p12 by abcdefghij00", C, iters):
|
|
|
|
|
f.mul_sparse_by_abcdefghij00(g)
|
|
|
|
|
|
|
|
|
|
proc mulFp12by_abcd00efghij_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
let g = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Mul 𝔽p12 by abcd00efghij", C, iters):
|
|
|
|
|
f.mul_sparse_by_abcd00efghij(g)
|
|
|
|
|
|
|
|
|
|
proc mulFp12_by_2lines_v1_xyz000_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var l0, l1: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
l0.line_double(T, P)
|
|
|
|
|
l1.line_double(T, P)
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("mulFp12 by 2 lines v1", C, iters):
|
|
|
|
|
f.mul_sparse_by_line_xyz000(l0)
|
|
|
|
|
f.mul_sparse_by_line_xyz000(l1)
|
|
|
|
|
|
|
|
|
|
proc mulFp12_by_2lines_v2_xyz000_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var l0, l1: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
l0.line_double(T, P)
|
|
|
|
|
l1.line_double(T, P)
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("mulFp12 by 2 lines v2", C, iters):
|
|
|
|
|
var f2 {.noInit.}: Fp12[C]
|
2021-08-16 20:22:51 +00:00
|
|
|
|
f2.prod_xyz000_xyz000_into_abcdefghij00(l0, l1)
|
2021-02-14 12:06:57 +00:00
|
|
|
|
f.mul_sparse_by_abcdefghij00(f2)
|
|
|
|
|
|
|
|
|
|
proc mulFp12_by_2lines_v1_xy000z_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var l0, l1: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
l0.line_double(T, P)
|
|
|
|
|
l1.line_double(T, P)
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("mulFp12 by 2 lines v1", C, iters):
|
|
|
|
|
f.mul_sparse_by_line_xy000z(l0)
|
|
|
|
|
f.mul_sparse_by_line_xy000z(l1)
|
|
|
|
|
|
|
|
|
|
proc mulFp12_by_2lines_v2_xy000z_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var l0, l1: Line[Fp2[C]]
|
2022-01-01 18:17:04 +00:00
|
|
|
|
var T = rng.random_point(ECP_ShortW_Prj[Fp2[C], G2])
|
|
|
|
|
let P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
2021-02-14 12:06:57 +00:00
|
|
|
|
l0.line_double(T, P)
|
|
|
|
|
l1.line_double(T, P)
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("mulFp12 by 2 lines v2", C, iters):
|
|
|
|
|
var f2 {.noInit.}: Fp12[C]
|
2021-08-16 20:22:51 +00:00
|
|
|
|
f2.prod_xy000z_xy000z_into_abcd00efghij(l0, l1)
|
2021-02-14 12:06:57 +00:00
|
|
|
|
f.mul_sparse_by_abcd00efghij(f2)
|
|
|
|
|
|
2022-02-20 19:15:20 +00:00
|
|
|
|
proc mulBench*(C: static Curve, iters: int) =
|
|
|
|
|
var r: Fp12[C]
|
|
|
|
|
let x = rng.random_unsafe(Fp12[C])
|
|
|
|
|
let y = rng.random_unsafe(Fp12[C])
|
|
|
|
|
preventOptimAway(r)
|
|
|
|
|
bench("Multiplication 𝔽p12", C, iters):
|
|
|
|
|
r.prod(x, y)
|
|
|
|
|
|
|
|
|
|
proc sqrBench*(C: static Curve, iters: int) =
|
|
|
|
|
var r: Fp12[C]
|
|
|
|
|
let x = rng.random_unsafe(Fp12[C])
|
|
|
|
|
preventOptimAway(r)
|
|
|
|
|
bench("Squaring 𝔽p12", C, iters):
|
|
|
|
|
r.square(x)
|
|
|
|
|
|
|
|
|
|
proc cyclotomicSquare_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Squaring 𝔽p12 in cyclotomic subgroup", C, iters):
|
|
|
|
|
f.cyclotomic_square()
|
|
|
|
|
|
|
|
|
|
proc expCurveParamBench*(C: static Curve, iters: int) =
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
|
|
|
|
|
bench("Cyclotomic Exp by curve parameter", C, iters):
|
|
|
|
|
f.cycl_exp_by_curve_param(f)
|
|
|
|
|
|
|
|
|
|
proc cyclotomicSquareCompressed_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
var g: G2345[Fp2[C]]
|
|
|
|
|
g.fromFpk(f)
|
|
|
|
|
|
|
|
|
|
bench("Cyclotomic Compressed Squaring 𝔽p12", C, iters):
|
|
|
|
|
g.cyclotomic_square_compressed()
|
|
|
|
|
|
|
|
|
|
proc cyclotomicDecompression_Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var f = rng.random_unsafe(Fp12[C])
|
|
|
|
|
var gs: array[1, G2345[Fp2[C]]]
|
|
|
|
|
gs[0].fromFpk(f)
|
|
|
|
|
|
|
|
|
|
var g1s_ratio: array[1, tuple[g1_num, g1_den: Fp2[C]]]
|
|
|
|
|
var g0s, g1s: array[1, Fp2[C]]
|
|
|
|
|
|
|
|
|
|
bench("Cyclotomic Decompression 𝔽p12", C, iters):
|
|
|
|
|
recover_g1(g1s_ratio[0].g1_num, g1s_ratio[0].g1_den, gs[0])
|
|
|
|
|
g1s.batch_ratio_g1s(g1s_ratio)
|
|
|
|
|
g0s[0].recover_g0(g1s[0], gs[0])
|
|
|
|
|
|
2020-09-24 15:18:23 +00:00
|
|
|
|
proc millerLoopBLS12Bench*(C: static Curve, iters: int) =
|
|
|
|
|
let
|
2022-01-01 18:17:04 +00:00
|
|
|
|
P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
|
|
|
|
Q = rng.random_point(ECP_ShortW_Aff[Fp2[C], G2])
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
|
|
|
|
var f: Fp12[C]
|
|
|
|
|
bench("Miller Loop BLS12", C, iters):
|
2021-02-14 12:06:57 +00:00
|
|
|
|
f.millerLoopGenericBLS12(P, Q)
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
2020-09-25 19:58:20 +00:00
|
|
|
|
proc millerLoopBNBench*(C: static Curve, iters: int) =
|
|
|
|
|
let
|
2022-01-01 18:17:04 +00:00
|
|
|
|
P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
|
|
|
|
Q = rng.random_point(ECP_ShortW_Aff[Fp2[C], G2])
|
2020-09-25 19:58:20 +00:00
|
|
|
|
|
|
|
|
|
var f: Fp12[C]
|
|
|
|
|
bench("Miller Loop BN", C, iters):
|
2021-02-14 12:06:57 +00:00
|
|
|
|
f.millerLoopGenericBN(P, Q)
|
2020-09-25 19:58:20 +00:00
|
|
|
|
|
2020-09-24 15:18:23 +00:00
|
|
|
|
proc finalExpEasyBench*(C: static Curve, iters: int) =
|
|
|
|
|
var r = rng.random_unsafe(Fp12[C])
|
|
|
|
|
bench("Final Exponentiation Easy", C, iters):
|
|
|
|
|
r.finalExpEasy()
|
|
|
|
|
|
|
|
|
|
proc finalExpHardBLS12Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var r = rng.random_unsafe(Fp12[C])
|
|
|
|
|
r.finalExpEasy()
|
|
|
|
|
bench("Final Exponentiation Hard BLS12", C, iters):
|
|
|
|
|
r.finalExpHard_BLS12()
|
|
|
|
|
|
2020-09-25 19:58:20 +00:00
|
|
|
|
proc finalExpHardBNBench*(C: static Curve, iters: int) =
|
|
|
|
|
var r = rng.random_unsafe(Fp12[C])
|
|
|
|
|
r.finalExpEasy()
|
|
|
|
|
bench("Final Exponentiation Hard BN", C, iters):
|
|
|
|
|
r.finalExpHard_BN()
|
|
|
|
|
|
2020-09-24 15:18:23 +00:00
|
|
|
|
proc finalExpBLS12Bench*(C: static Curve, iters: int) =
|
|
|
|
|
var r = rng.random_unsafe(Fp12[C])
|
|
|
|
|
bench("Final Exponentiation BLS12", C, iters):
|
|
|
|
|
r.finalExpEasy()
|
|
|
|
|
r.finalExpHard_BLS12()
|
|
|
|
|
|
2020-09-25 19:58:20 +00:00
|
|
|
|
proc finalExpBNBench*(C: static Curve, iters: int) =
|
|
|
|
|
var r = rng.random_unsafe(Fp12[C])
|
|
|
|
|
bench("Final Exponentiation BN", C, iters):
|
|
|
|
|
r.finalExpEasy()
|
|
|
|
|
r.finalExpHard_BN()
|
|
|
|
|
|
2020-09-24 15:18:23 +00:00
|
|
|
|
proc pairingBLS12Bench*(C: static Curve, iters: int) =
|
|
|
|
|
let
|
2022-01-01 18:17:04 +00:00
|
|
|
|
P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
|
|
|
|
Q = rng.random_point(ECP_ShortW_Aff[Fp2[C], G2])
|
2020-09-24 15:18:23 +00:00
|
|
|
|
|
|
|
|
|
var f: Fp12[C]
|
|
|
|
|
bench("Pairing BLS12", C, iters):
|
|
|
|
|
f.pairing_bls12(P, Q)
|
2020-09-25 19:58:20 +00:00
|
|
|
|
|
2021-08-16 20:22:51 +00:00
|
|
|
|
proc pairing_multisingle_BLS12Bench*(C: static Curve, N: static int, iters: int) =
|
|
|
|
|
let
|
2022-01-01 18:17:04 +00:00
|
|
|
|
P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
|
|
|
|
Q = rng.random_point(ECP_ShortW_Aff[Fp2[C], G2])
|
2021-08-16 20:22:51 +00:00
|
|
|
|
|
|
|
|
|
var
|
2022-01-01 18:17:04 +00:00
|
|
|
|
Ps {.noInit.}: array[N, ECP_ShortW_Aff[Fp[C], G1]]
|
|
|
|
|
Qs {.noInit.}: array[N, ECP_ShortW_Aff[Fp2[C], G2]]
|
2021-08-16 20:22:51 +00:00
|
|
|
|
|
|
|
|
|
GTs {.noInit.}: array[N, Fp12[C]]
|
|
|
|
|
|
|
|
|
|
for i in 0 ..< N:
|
|
|
|
|
Ps[i] = rng.random_unsafe(typeof(Ps[0]))
|
|
|
|
|
Qs[i] = rng.random_unsafe(typeof(Qs[0]))
|
|
|
|
|
|
|
|
|
|
var f: Fp12[C]
|
2022-02-20 19:15:20 +00:00
|
|
|
|
bench("Pairing BLS12 non-batched: " & $N, C, iters):
|
2021-08-16 20:22:51 +00:00
|
|
|
|
for i in 0 ..< N:
|
|
|
|
|
GTs[i].pairing_bls12(Ps[i], Qs[i])
|
|
|
|
|
|
|
|
|
|
f = GTs[0]
|
|
|
|
|
for i in 1 ..< N:
|
|
|
|
|
f *= GTs[i]
|
|
|
|
|
|
|
|
|
|
proc pairing_multipairing_BLS12Bench*(C: static Curve, N: static int, iters: int) =
|
|
|
|
|
var
|
2022-01-01 18:17:04 +00:00
|
|
|
|
Ps {.noInit.}: array[N, ECP_ShortW_Aff[Fp[C], G1]]
|
|
|
|
|
Qs {.noInit.}: array[N, ECP_ShortW_Aff[Fp2[C], G2]]
|
2021-08-16 20:22:51 +00:00
|
|
|
|
|
|
|
|
|
for i in 0 ..< N:
|
|
|
|
|
Ps[i] = rng.random_unsafe(typeof(Ps[0]))
|
|
|
|
|
Qs[i] = rng.random_unsafe(typeof(Qs[0]))
|
|
|
|
|
|
|
|
|
|
var f: Fp12[C]
|
2022-02-20 19:15:20 +00:00
|
|
|
|
bench("Pairing BLS12 batched: " & $N, C, iters):
|
2021-08-16 20:22:51 +00:00
|
|
|
|
f.pairing_bls12(Ps, Qs)
|
|
|
|
|
|
2020-09-25 19:58:20 +00:00
|
|
|
|
proc pairingBNBench*(C: static Curve, iters: int) =
|
|
|
|
|
let
|
2022-01-01 18:17:04 +00:00
|
|
|
|
P = rng.random_point(ECP_ShortW_Aff[Fp[C], G1])
|
|
|
|
|
Q = rng.random_point(ECP_ShortW_Aff[Fp2[C], G2])
|
2020-09-25 19:58:20 +00:00
|
|
|
|
|
|
|
|
|
var f: Fp12[C]
|
|
|
|
|
bench("Pairing BN", C, iters):
|
|
|
|
|
f.pairing_bn(P, Q)
|