-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_speed.c
89 lines (69 loc) · 2.56 KB
/
test_speed.c
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
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "kyber-pake.h"
#include "params.h"
#include "indcpa.h"
#include "polyvec.h"
#include "poly.h"
#include "cpucycles.h"
#include "speed_print.h"
#include <sys/time.h>
#define NTESTS 1000
uint64_t t[NTESTS];
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
uint8_t sk[CRYPTO_SECRETKEYBYTES];
uint8_t ct[CRYPTO_CIPHERTEXTBYTES];
int i=0;
unsigned char pw[32] = "12345678";
unsigned char a_id[32] = "87654321";
unsigned char b_id[32] = "55555555";
const uint8_t ssid[ID_BYTES] = {0};
uint8_t k[CRYPTO_BYTES] = {0};
uint8_t auth_b[AUTH_SIZE];
uint8_t key_a[CRYPTO_BYTES] = {0};
uint8_t key_b[CRYPTO_BYTES] = {0};
uint8_t send_a0[PAKE_A0_SEND];
uint8_t send_b0[SHA3_256_HashSize];
int main()
{
unsigned int i;
struct timeval timeval_start, timeval_end;
polyvec gamma;
printf("\n--------------------\n");
gettimeofday(&timeval_start, NULL);
for(i=0;i<NTESTS;i++) {
t[i] = cpucycles();
pake_a0(pw, ssid, send_a0, pk, sk);
}
gettimeofday(&timeval_end, NULL);
printf("The average time of a0:\t %.3lf us \n", ((timeval_end.tv_usec + timeval_end.tv_sec * 1000000) - (timeval_start.tv_sec * 1000000 + timeval_start.tv_usec)) / (NTESTS * 1.0));
print_results("pake_a0: ", t, NTESTS);
gettimeofday(&timeval_start, NULL);
for(i=0;i<NTESTS;i++) {
t[i] = cpucycles();
pake_b0(pw, ssid, a_id, b_id, send_a0, send_b0, ct, k, auth_b);
}
gettimeofday(&timeval_end, NULL);
printf("The average time of b0:\t %.3lf us \n", ((timeval_end.tv_usec + timeval_end.tv_sec * 1000000) - (timeval_start.tv_sec * 1000000 + timeval_start.tv_usec)) / (NTESTS * 1.0));
print_results("pake_b0: ", t, NTESTS);
gettimeofday(&timeval_start, NULL);
for(i=0;i<NTESTS;i++) {
t[i] = cpucycles();
pake_a1(pw, pk, sk, send_a0, send_b0, ssid, a_id, b_id, ct, key_a);
}
gettimeofday(&timeval_end, NULL);
printf("The average time of a1:\t %.3lf us \n", ((timeval_end.tv_usec + timeval_end.tv_sec * 1000000) - (timeval_start.tv_sec * 1000000 + timeval_start.tv_usec)) / (NTESTS * 1.0));
print_results("pake_a1: ", t, NTESTS);
gettimeofday(&timeval_start, NULL);
for(i=0;i<NTESTS;i++) {
t[i] = cpucycles();
pake_b1(ssid,a_id,b_id,send_a0,ct,auth_b,k,key_b);
}
gettimeofday(&timeval_end, NULL);
printf("The average time of b1:\t %.3lf us \n", ((timeval_end.tv_usec + timeval_end.tv_sec * 1000000) - (timeval_start.tv_sec * 1000000 + timeval_start.tv_usec)) / (NTESTS * 1.0));
printf("\n--------------------\n");
print_results("pake_b1: ", t, NTESTS);
return 0;
}