-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.c
47 lines (32 loc) · 1003 Bytes
/
bench.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
// BENCHMARKING
static inline void delay(unsigned int count){ while (count--) {} }
int randombytes(unsigned char* random_array, unsigned long long nbytes)
{ // Generation of "nbytes" of random values
int r, n = (int)nbytes, count = 0;
if(lock == -1) {
do {
lock = open("/dev/urandom", O_RDONLY);
if (lock == -1) {
delay(0xFFFFF);
}
} while (lock == -1);
}
while(n > 0) {
do {
r = read(lock, random_array+count, n);
if (r == -1) {
delay(0xFFFF);
}
} while (r == -1);
count += r;
n -= r;
}
return 0;
}
void read_keys(char* keys_path, char* keys)
{ // Reads public and secret key from file saved in keys_path into the array pointed to by keys
FILE *fp = fopen(keys_path, "rb");
assert((fp != NULL) && "Error opening keys file");
assert( fread(keys, NBITS_FIELD * 2, 1, fp) != 0 );
fclose(fp);
}