-
Notifications
You must be signed in to change notification settings - Fork 0
/
pair.cpp
83 lines (73 loc) · 3.06 KB
/
pair.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
#include <iostream>
//security define
#define AES_SECURITY 80
#define MR_PAIRING_SSP
//#define MR_PAIRING_SS2
#include "pairing_1.h"
#include <windows.h>
#pragma comment (lib, "miracl.lib")
using namespace std;
extern "C"
{
#include "miracl.h"
#include "mirdef.h"
#include <stdio.h>
}
int main() {
int k = 100;
double dTimeTake1=0, dTimeTake2=0, dTimeTake3=0, dTimeTake4 = 0, dTimeTake5 = 0;
LARGE_INTEGER fre = { 0 };//储存本机CPU时钟频率
LARGE_INTEGER startCount = { 0 };
LARGE_INTEGER endCount = { 0 };
QueryPerformanceFrequency(&fre);//获取本机cpu频率
miracl* mip = mirsys(1, 0); //初始化miracl系统
mip->IOBASE = 16;
PFC pfc(80);//big n = mirvar(8); //初始化n,必须有
Big a;//定义一个Big类型变量,默认初始化为0
big aa;
G1 P, Q;//乘法
G1 P1, Q1;//配对
GT ZT;
aa = mirvar(0);
for (int i = 0; i < k; i++) {
pfc.random(a);
pfc.random(P);
pfc.random(Q);
//pfc.precomp_for_mult(P);
QueryPerformanceCounter(&startCount);//计时开始
Q = pfc.mult(P, a); //Q=aP
QueryPerformanceCounter(&endCount);//计时结束
QueryPerformanceFrequency(&fre);//获取本机cpu频率
dTimeTake1 += ((double)endCount.QuadPart - (double)startCount.QuadPart) / (double)fre.QuadPart;
pfc.random(P1);
pfc.random(Q1);
//pfc.precomp_for_pairing(P1);
//pfc.precomp_for_pairing(Q1);
QueryPerformanceCounter(&startCount);//计时开始
ZT = pfc.pairing(P1, Q1); //Z=e(P,Q);
QueryPerformanceCounter(&endCount);//计时结束
QueryPerformanceFrequency(&fre);//获取本机cpu频率
dTimeTake2 += ((double)endCount.QuadPart - (double)startCount.QuadPart) / (double)fre.QuadPart;
QueryPerformanceCounter(&startCount);//计时开始
pfc.hash_and_map(P1, (char*)"Robert");
QueryPerformanceCounter(&endCount);//计时结束
QueryPerformanceFrequency(&fre);//获取本机cpu频率
dTimeTake3 += ((double)endCount.QuadPart - (double)startCount.QuadPart) / (double)fre.QuadPart;
QueryPerformanceCounter(&startCount);//计时开始
pfc.power(ZT,a);
QueryPerformanceCounter(&endCount);//计时结束
QueryPerformanceFrequency(&fre);//获取本机cpu频率
dTimeTake4 += ((double)endCount.QuadPart - (double)startCount.QuadPart) / (double)fre.QuadPart;
QueryPerformanceCounter(&startCount);//计时开始
P1 = P + Q;
QueryPerformanceCounter(&endCount);//计时结束
QueryPerformanceFrequency(&fre);//获取本机cpu频率
dTimeTake5 += ((double)endCount.QuadPart - (double)startCount.QuadPart) / (double)fre.QuadPart;
}
printf("mult %f ms!\n", dTimeTake1 * 1000 / k);
printf("pairing %f ms!\n", dTimeTake2 * 1000/k);
printf("hash_and_map %f ms!\n", dTimeTake3 * 1000/k);
printf("power %f ms!\n", dTimeTake4 * 1000 / k);
printf("add %f ms!\n", dTimeTake5 * 1000 / k);
return 0;
}