-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrwtest.c
75 lines (57 loc) · 2.03 KB
/
rwtest.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
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "api.h"
extern int crypto_sign_rwb0fuz1024_gmp_keypair(uint8_t *pk, uint8_t *sk);
extern int crypto_sign_rwb0fuz1024_gmp(uint8_t *sm, unsigned long long *smlen,
const uint8_t *m, unsigned long long mlen,
const uint8_t *sk);
extern int crypto_sign_rwb0fuz1024_gmp_open(unsigned char *m, unsigned long long *mlen,
const unsigned char *sm, unsigned long long smlen,
const unsigned char *pk);
static uint64_t
time_now() {
struct timeval tv;
gettimeofday(&tv, NULL);
uint64_t r = tv.tv_sec;
r *= 1000000;
r += tv.tv_usec;
return r;
}
#define N 64
int
main(int argc, char **argv) {
fprintf(stderr, "Generating keypair...\n");
uint8_t pk[crypto_sign_rwb0fuz1024_gmp_PUBLICKEYBYTES];
uint8_t sk[crypto_sign_rwb0fuz1024_gmp_SECRETKEYBYTES];
crypto_sign_rwb0fuz1024_gmp_keypair(pk, sk);
uint8_t input[N];
uint8_t result[N];
uint8_t output[N + crypto_sign_rwb0fuz1024_gmp_BYTES];
memset(input, 42, N);
fprintf(stderr, "Signing...\n");
unsigned i;
uint64_t start_time, end_time;
unsigned long long outputlen, inputlen;
static const unsigned sign_its = 500;
static const unsigned verify_its = 500000;
start_time = time_now();
for (i = 0; i < sign_its; ++i) {
crypto_sign_rwb0fuz1024_gmp(output, &outputlen,
input, sizeof(input), sk);
}
end_time = time_now();
fprintf(stderr, " time: %fus\n", ((double) (end_time - start_time)) / sign_its);
fprintf(stderr, "Verifying...\n");
start_time = time_now();
for (i = 0; i < verify_its; ++i) {
if (crypto_sign_rwb0fuz1024_gmp_open(result, &inputlen,
output, sizeof(output), pk))
abort();
}
end_time = time_now();
fprintf(stderr, " time: %fus\n", ((double) (end_time - start_time)) / verify_its);
return 0;
}