aboutsummaryrefslogtreecommitdiff
path: root/speed-curve25519.c
blob: d945d4856242632d3f10d99d8011f1235f59d15c (plain)
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
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <stdint.h>

typedef uint8_t u8;

extern void curve25519_donna(u8 *output, const u8 *secret, const u8 *bp);

static uint64_t
time_now() {
  struct timeval tv;
  uint64_t ret;

  gettimeofday(&tv, NULL);
  ret = tv.tv_sec;
  ret *= 1000000;
  ret += tv.tv_usec;

  return ret;
}

int
main() {
  static const unsigned char basepoint[32] = {9};
  unsigned char mysecret[32], mypublic[32];
  unsigned i;
  uint64_t start, end;

  memset(mysecret, 42, 32);
  mysecret[0] &= 248;
  mysecret[31] &= 127;
  mysecret[31] |= 64;

  // Load the caches
  for (i = 0; i < 1000; ++i) {
    curve25519_donna(mypublic, mysecret, basepoint);
  }

  start = time_now();
  for (i = 0; i < 30000; ++i) {
    curve25519_donna(mypublic, mysecret, basepoint);
  }
  end = time_now();

  printf("%luus\n", (unsigned long) ((end - start) / 30000));

  return 0;
}