-
Notifications
You must be signed in to change notification settings - Fork 12
/
poly1305.c
64 lines (52 loc) · 1.27 KB
/
poly1305.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
#include "bench.h"
#if __riscv_xlen != 32
#include "../thirdparty/rvv-chacha-poly/boring.h"
uint8_t *src;
uint8_t key[32], sig[16];
extern uint64_t
vector_poly1305(const uint8_t* in, size_t len,
const uint8_t key[32], uint8_t sig[16]);
static void
poly1305_boring(void const *src, size_t n) {
poly1305_state state;
boring_poly1305_init(&state, key);
boring_poly1305_update(&state, src, n);
boring_poly1305_finish(&state, sig);
}
static void
poly1305_rvv(void const *src, size_t n) {
vector_poly1305(src, n, key, sig);
}
typedef void *Func(void const *src, size_t n);
Impl impls[] = {
{ "boring", &poly1305_boring },
#if HAS_E64
{ "rvv", &poly1305_rvv },
#endif
};
void init(void) {
bench_memrand(key, sizeof key);
bench_memrand(sig, sizeof sig);
}
ux checksum(size_t n) {
ux sum = 0;
for (size_t i = 0; i < ARR_LEN(sig); ++i)
sum = uhash(sum) + sig[i];
return sum;
}
BENCH_BEG(aligned) {
for (size_t i = 0; i < 256; ++i)
mem[bench_urand()%n] = bench_urand();
n = (15+n) & -16;
TIME f(mem, n);
} BENCH_END
Bench benches[] = {
BENCH( impls, MAX_MEM, "poly1305 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