-
Notifications
You must be signed in to change notification settings - Fork 12
/
chacha20.c
61 lines (48 loc) · 1.3 KB
/
chacha20.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
#include "bench.h"
#if __riscv_xlen != 32
#include "../thirdparty/rvv-chacha-poly/boring.h"
uint8_t *dest, *src;
uint8_t key[32], nonce[12];
uint32_t counter;
extern void vector_chacha20(
uint8_t *out, const uint8_t *in,
size_t in_len, const uint8_t key[32],
const uint8_t nonce[12], uint32_t counter);
static void
chacha20_boring(void *restrict dest, void const *restrict src, size_t n) {
boring_chacha20(dest, src, n, key, nonce, counter);
}
static void
chacha20_rvv(void *restrict dest, void const *restrict src, size_t n) {
vector_chacha20(dest, src, n, key, nonce, counter);
}
typedef void *Func(void *restrict dest, void const *restrict src, size_t n);
Impl impls[] = {
{ "boring", &chacha20_boring },
{ "rvv", &chacha20_rvv },
};
void init(void) {
bench_memrand(key, sizeof key);
bench_memrand(nonce, sizeof nonce);
counter = 0;
}
ux checksum(size_t n) {
ux sum = 0;
for (size_t i = 0; i < n+16; ++i)
sum = uhash(sum) + mem[i];
return sum;
}
BENCH_BEG(aligned) {
memset(mem, 0, n+16);
TIME f(mem, mem + MAX_MEM/2 + 16, n);
} BENCH_END
Bench benches[] = {
BENCH( impls, MAX_MEM/2 - 16, "chacha20 aligned", bench_aligned )
}; BENCH_MAIN(benches)
#include "../thirdparty/rvv-chacha-poly/boring.c"
#else
void init(void) {}
Impl impls[] = {};
Bench benches[] = {};
BENCH_MAIN(benches)
#endif