]> gitweb.ps.run Git - matrix_esp_thesis/blob - ext/olm/lib/curve25519-donna/speed-curve25519.c
add dependencies to repo
[matrix_esp_thesis] / ext / olm / lib / curve25519-donna / speed-curve25519.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/time.h>
4 #include <time.h>
5 #include <stdint.h>
6
7 typedef uint8_t u8;
8
9 extern void curve25519_donna(u8 *output, const u8 *secret, const u8 *bp);
10
11 static uint64_t
12 time_now() {
13   struct timeval tv;
14   uint64_t ret;
15
16   gettimeofday(&tv, NULL);
17   ret = tv.tv_sec;
18   ret *= 1000000;
19   ret += tv.tv_usec;
20
21   return ret;
22 }
23
24 int
25 main() {
26   static const unsigned char basepoint[32] = {9};
27   unsigned char mysecret[32], mypublic[32];
28   unsigned i;
29   uint64_t start, end;
30
31   memset(mysecret, 42, 32);
32   mysecret[0] &= 248;
33   mysecret[31] &= 127;
34   mysecret[31] |= 64;
35
36   // Load the caches
37   for (i = 0; i < 1000; ++i) {
38     curve25519_donna(mypublic, mysecret, basepoint);
39   }
40
41   start = time_now();
42   for (i = 0; i < 30000; ++i) {
43     curve25519_donna(mypublic, mysecret, basepoint);
44   }
45   end = time_now();
46
47   printf("%luus\n", (unsigned long) ((end - start) / 30000));
48
49   return 0;
50 }