def testPairing(self):
        trials = 10
        trials2 = trials * 3
        group = PairingGroup("SS512")
        g = group.random(G1)
        h = group.random(G1)
        i = group.random(G2)

        self.assertTrue(group.InitBenchmark())
        group.StartBenchmark(["RealTime", "Exp", "Pair"])
        for a in range(trials):
            j = g * h
            k = i**group.random(ZR)
            t = (j**group.random(ZR)) / h
            n = pair(h, i)
        group.EndBenchmark()

        msmtDict = group.GetGeneralBenchmarks()
        self.assertTrue(isSaneBenchmark(msmtDict))

        self.assertTrue(group.InitBenchmark())

        group.StartBenchmark(["CpuTime", "Mul", "Pair"])
        for a in range(trials2):
            j = g * h
            k = i**group.random(ZR)
            n = pair(h, i)
        group.EndBenchmark()

        msmtDict = group.GetGeneralBenchmarks()
        del group
        self.assertTrue(isSaneBenchmark(msmtDict))
    def testInterleave(self):
        trials = 10
        trials2 = trials * 3
        group1 = PairingGroup("MNT224")
        group2 = PairingGroup("MNT224")

        g = group1.random(G1)
        h = group1.random(G1)
        i = group1.random(G2)

        self.assertTrue(group1.InitBenchmark())
        self.assertTrue(group2.InitBenchmark())
        group1.StartBenchmark(["RealTime", "Exp", "Pair", "Div", "Mul"])
        for a in range(trials):
            j = g * h
            k = i**group1.random(ZR)
            t = (j**group1.random(ZR)) / h
            n = pair(h, i)
        group1.EndBenchmark()
        msmtDict = group1.GetGeneralBenchmarks()
        del group1, group2
        self.assertTrue(isSaneBenchmark(msmtDict))
Пример #3
0
import time

from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair

trials = 100
group = PairingGroup("SS1024")
g = group.random(G1)
h = group.random(G1)
i = group.random(G2)

assert group.InitBenchmark(), "failed to initialize benchmark"
ts = time.time()
group.StartBenchmark(["CpuTime", "RealTime", "Mul", "Exp", "Pair", "Granular"])
for a in range(trials):
    j = g * h
    k = i**group.random(ZR)
    t = (j**group.random(ZR)) / h
    n = pair(h, i)
group.EndBenchmark()
print(time.time() - ts)

msmtDict = group.GetGeneralBenchmarks()
granDict = group.GetGranularBenchmarks()
print("<=== General Benchmarks ===>")
print("Results  := ", msmtDict)
print("<=== Granular Benchmarks ===>")
print("G1 mul   := ", granDict["Mul"][G1])
print("G2 exp   := ", granDict["Exp"][G2])