-
Notifications
You must be signed in to change notification settings - Fork 1
/
linkpcsig_bench.cpp
130 lines (102 loc) · 3.76 KB
/
linkpcsig_bench.cpp
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
#include "linkpcsig.h"
#if curveid == 1
#include <mcl/bn256.hpp>
using namespace mcl::bn256;
#elif curveid == 2
#include <mcl/bn384.hpp>
using namespace mcl::bn384;
#elif curveid == 3
#include <mcl/bn512.hpp>
using namespace mcl::bn512;
#elif curveid == 4
#include <mcl/bls12_381.hpp>
using namespace mcl::bls12;
#else
#error "Invalid choice for curve."
#endif
#include <iostream>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main(int argc, char** argv){
int N = 100; //Number of iterations to average over
if(argc>1)
N = atoi(argv[1]);
cout<<"Averaging over "<<N<<" iterations"<<endl;
switch(curveid) {
case 1:
cout<<"Using curve BN254"<<endl;
initPairing(mcl::BN254); //Assuming SXDH holds in BN254
break;
case 2:
cout<<"Using curve BN381_1"<<endl;
initPairing(mcl::BN381_1); //Assuming SXDH holds in BN381_1
break;
case 3:
cout<<"Using curve BN462"<<endl;
initPairing(mcl::BN462); //Assuming SXDH holds in BN462
break;
default:
std::perror("Invalid choice for curve.");
}
proof p;
secrets s;
publicparam pp;
G1 pkopen1, pkopen2;
if(argc>2)
pp.m = argv[2];
else
pp.m = "hello world";
cout<<"Creating an SPC group signature on \""<<pp.m<<"\""<<endl;
//Setup
setup(pp);
//Creating client's public and secret key
s.sk.setRand();
s.pk = pp.G*s.sk; // pk = G^sk
//ApplePSI secretkey
Fr alpha;
alpha.setRand();
pp.L = pp.G*alpha; //L = G^alpha
auto startenc = high_resolution_clock::now(), stopenc = high_resolution_clock::now(),
startprove = high_resolution_clock::now(), stopprove = high_resolution_clock::now(),
startver = high_resolution_clock::now(), stopver = high_resolution_clock::now(),
startopen = high_resolution_clock::now(), endopen = high_resolution_clock::now();
double enctotal = 0, provetotal = 0, verifytotal = 0, opentotal = 0;
auto encduration = duration_cast<microseconds>(endopen - startopen),
proveduration = duration_cast<microseconds>(stopprove - startprove),
verduration = duration_cast<microseconds>(stopver - startver),
openduration = duration_cast<microseconds>(endopen - startopen);
bool flag=false;
for(int i = 0; i<N;i++){ //Benchmarking loop
startenc = high_resolution_clock::now();
SPCEnc(p,s,pp);
stopenc = high_resolution_clock::now();
//Proving
startprove = high_resolution_clock::now();
SPCsign(p, s, pp);
stopprove = high_resolution_clock::now();
//Verification
startver = high_resolution_clock::now();
flag = SPCver(p, pp);
stopver = high_resolution_clock::now();
if(flag)
cout<<"fail"<<endl;
//Opening
startopen = high_resolution_clock::now();
pkopen1 = pp.ct1 - (pp.Q1*alpha);
pkopen2 = pp.ct2 - (pp.Q2*alpha);
endopen = high_resolution_clock::now();
encduration = duration_cast<microseconds>(stopenc - startenc);
proveduration = duration_cast<microseconds>(stopprove - startprove);
verduration = duration_cast<microseconds>(stopver - startver);
openduration = duration_cast<microseconds>(endopen - startopen);
enctotal = enctotal + encduration.count();
provetotal = provetotal + proveduration.count();
verifytotal = verifytotal + verduration.count();
opentotal = opentotal + openduration.count();
}
cout<< "Mean enc time (\u03BCs):"<<enctotal/N<<endl;
cout<< "Mean prove time (\u03BCs):"<<provetotal/N<<endl;
cout<< "Mean verify time (\u03BCs):"<<verifytotal/N<<endl;
cout<< "Mean open time (\u03BCs):"<<opentotal/N<<endl;
}