-
Notifications
You must be signed in to change notification settings - Fork 79
/
_tinysshd-speed.c
260 lines (238 loc) · 7.03 KB
/
_tinysshd-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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include "crypto.h"
static unsigned char sk[2560];
static unsigned char pk[2560];
static unsigned char a[16];
static unsigned char n[8];
static unsigned char k[64];
static unsigned char h[64];
static unsigned char space[10240];
static unsigned char m[51200];
static unsigned char sm[51200];
static unsigned long long smlen;
static unsigned long long mlen;
static const char *implementation, *version;
static int flagtimeout;
static void timeout(int x) {
flagtimeout = x = 1;
signal(SIGALRM, timeout);
}
int main(void) {
long long count;
signal(SIGALRM, timeout);
/* randombytes test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
randombytes(space, sizeof space);
++count;
}
printf("randombytes: %lld MB/s (%s)\n", count / 100, randombytes_source());
#ifdef crypto_hash_sha512_IMPLEMENTATION
implementation = crypto_hash_sha512_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_hash_sha512_VERSION
version = crypto_hash_sha512_VERSION;
#else
version = "unknown";
#endif
/* sha512 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_hash_sha512(h, space, sizeof space) != 0) return 111;
++count;
}
printf("crypto_hash_sha512: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_hash_sha256_IMPLEMENTATION
implementation = crypto_hash_sha256_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_hash_sha256_VERSION
version = crypto_hash_sha256_VERSION;
#else
version = "unknown";
#endif
/* sha256 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_hash_sha256(h, space, sizeof space) != 0) return 111;
++count;
}
printf("crypto_hash_sha256: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_stream_chacha20_IMPLEMENTATION
implementation = crypto_stream_chacha20_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_stream_chacha20_VERSION
version = crypto_stream_chacha20_VERSION;
#else
version = "unknown";
#endif
/* chacha20 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_stream_chacha20_xor(space, space, sizeof space, n, k) != 0)
return 111;
++count;
}
printf("crypto_stream_chacha20_xor: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_onetimeauth_poly1305_IMPLEMENTATION
implementation = crypto_onetimeauth_poly1305_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_onetimeauth_poly1305_VERSION
version = crypto_onetimeauth_poly1305_VERSION;
#else
version = "unknown";
#endif
/* onetimeauth test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_onetimeauth_poly1305(a, space, sizeof space, k) != 0)
return 111;
++count;
}
printf("crypto_onetimeauth_poly1305: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_scalarmult_curve25519_IMPLEMENTATION
implementation = crypto_scalarmult_curve25519_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_scalarmult_curve25519_VERSION
version = crypto_scalarmult_curve25519_VERSION;
#else
version = "unknown";
#endif
/* x25519 test */
randombytes(sk, crypto_scalarmult_curve25519_SCALARBYTES);
crypto_scalarmult_curve25519_base(pk, sk);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_scalarmult_curve25519(k, sk, pk) != 0) return 111;
++count;
}
printf("crypto_scalarmult_curve25519: %lld dh/s (%s, %s)\n", count,
implementation, version);
#ifdef crypto_sign_ed25519_IMPLEMENTATION
implementation = crypto_sign_ed25519_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_sign_ed25519_VERSION
version = crypto_sign_ed25519_VERSION;
#else
version = "unknown";
#endif
/* ed25519 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_sign_ed25519_keypair(pk, sk) != 0) return 111;
++count;
}
printf("crypto_sign_ed25519_keypair: %lld keypairs/s (%s, %s)\n", count,
implementation, version);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_sign_ed25519(sm, &smlen, m + crypto_sign_ed25519_BYTES,
sizeof(m) - crypto_sign_ed25519_BYTES, sk) != 0)
return 111;
++count;
}
printf("crypto_sign_ed25519: %lld sigs/s (%s, %s)\n", count, implementation,
version);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_sign_ed25519_open(m, &mlen, sm, sizeof sm, pk) != 0)
return 111;
++count;
}
printf("crypto_sign_ed25519_open: %lld sigs/s (%s, %s)\n", count,
implementation, version);
#ifdef crypto_kem_sntrup4591761_IMPLEMENTATION
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761_keypair(pk, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761_keypair: %lld keypairs/s (%s)\n", count,
crypto_kem_sntrup4591761_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761_enc(c, k, pk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761_enc: %lld encryptions/s (%s)\n", count,
crypto_kem_sntrup4591761_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761_dec(k, c, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761_dec: %lld decryptions/s (%s)\n", count,
crypto_kem_sntrup4591761_IMPLEMENTATION);
#endif
#ifdef crypto_kem_sntrup4591761x25519_IMPLEMENTATION
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761x25519_keypair(pk, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761x25519_keypair: %lld keypairs/s (%s)\n",
count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761x25519_enc(c, k, pk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761x25519_enc: %lld encryptions/s (%s)\n",
count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761x25519_dec(k, c, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761x25519_dec: %lld decryptions/s (%s)\n",
count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);
#endif
return 0;
}