-
Notifications
You must be signed in to change notification settings - Fork 46
/
bench.c
105 lines (86 loc) · 2.79 KB
/
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
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <openssl/evp.h>
#include "fastpbkdf2.h"
#define PASSWORD (const void *) "password", 8
#define SALT (const void *) "saltsalt", 8
#define WARMUP 4096
#define ITERATIONS (1 << 22)
#include "benchutil.h"
static void sha1(uint32_t repeat, uint32_t iterations)
{
uint8_t out[20];
proctime end, start = cpu_now();
for (uint32_t i = 0; i < repeat; i++)
PKCS5_PBKDF2_HMAC_SHA1(PASSWORD, SALT,
iterations,
(int) sizeof(out), out);
end = cpu_now();
printf("openssl,sha1,%u,%u,%g\n", iterations, repeat, proctime2secs(start, end));
start = cpu_now();
for (uint32_t i = 0; i < repeat; i++)
fastpbkdf2_hmac_sha1(PASSWORD, SALT,
iterations,
out, sizeof out);
end = cpu_now();
printf("fastpbkdf2,sha1,%u,%u,%g\n", iterations, repeat, proctime2secs(start, end));
}
static void sha256(uint32_t repeat, uint32_t iterations)
{
uint8_t out[32];
proctime end, start = cpu_now();
for (uint32_t i = 0; i < repeat; i++)
PKCS5_PBKDF2_HMAC(PASSWORD, SALT,
iterations,
EVP_sha256(),
(int) sizeof(out), out);
end = cpu_now();
printf("openssl,sha256,%u,%u,%g\n", iterations, repeat, proctime2secs(start, end));
start = cpu_now();
for (uint32_t i = 0; i < repeat; i++)
fastpbkdf2_hmac_sha256(PASSWORD, SALT,
iterations,
out, sizeof out);
end = cpu_now();
printf("fastpbkdf2,sha256,%u,%u,%g\n", iterations, repeat, proctime2secs(start, end));
}
static void sha512(uint32_t repeat, uint32_t iterations)
{
uint8_t out[64];
proctime end, start = cpu_now();
for (uint32_t i = 0; i < repeat; i++)
PKCS5_PBKDF2_HMAC(PASSWORD, SALT,
iterations,
EVP_sha512(),
(int) sizeof(out), out);
end = cpu_now();
printf("openssl,sha512,%u,%u,%g\n", iterations, repeat, proctime2secs(start, end));
start = cpu_now();
for (uint32_t i = 0; i < repeat; i++)
fastpbkdf2_hmac_sha512(PASSWORD, SALT,
iterations,
out, sizeof out);
end = cpu_now();
printf("fastpbkdf2,sha512,%u,%u,%g\n", iterations, repeat, proctime2secs(start, end));
}
int main(int argc, char **argv)
{
unsigned total_iterations_log2 = 22;
if (argc == 2)
{
total_iterations_log2 = atoi(argv[1]);
assert(total_iterations_log2 > 12);
}
for (unsigned iterations = total_iterations_log2,
reps = 1;
iterations >= 12;
iterations -= 2, reps <<= 2)
{
sha1(reps, 1 << iterations);
sha256(reps, 1 << iterations);
sha512(reps, 1 << iterations);
}
return 0;
(void) wall_now;
}