-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeed.c
More file actions
63 lines (51 loc) · 1.31 KB
/
Copy pathspeed.c
File metadata and controls
63 lines (51 loc) · 1.31 KB
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
#include "api.h"
#include "stm32wrapper.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
static unsigned long long overflowcnt = 0;
void sys_tick_handler(void)
{
++overflowcnt;
}
static void printcycles(const char *s, unsigned long long c)
{
char outs[32];
send_USART_str(s);
snprintf(outs,sizeof(outs),"%llu\n",c);
send_USART_str(outs);
}
int main(void)
{
unsigned char ss[CRYPTO_BYTES];
unsigned char sk[CRYPTO_SECRETKEYBYTES];
unsigned char pk[CRYPTO_PUBLICKEYBYTES];
unsigned char ct[CRYPTO_CIPHERTEXTBYTES];
unsigned int t0, t1;
clock_setup(CLOCK_BENCHMARK);
gpio_setup();
usart_setup(115200);
systick_setup();
rng_enable();
send_USART_str("==========================");
// Key-pair generation
t0 = systick_get_value();
overflowcnt = 0;
crypto_kem_keypair(pk, sk);
t1 = systick_get_value();
printcycles("keypair cycles:", (t0+overflowcnt*2400000llu)-t1);
// Encapsulation
t0 = systick_get_value();
overflowcnt = 0;
crypto_kem_enc(ct, ss, pk);
t1 = systick_get_value();
printcycles("encaps cycles: ", (t0+overflowcnt*2400000llu)-t1);
// Decapsulation
t0 = systick_get_value();
overflowcnt = 0;
crypto_kem_dec(ss, ct, sk);
t1 = systick_get_value();
printcycles("decaps cycles: ", (t0+overflowcnt*2400000llu)-t1);
send_USART_str("#");
return 0;
}