]> gitweb.ps.run Git - matrix_esp_thesis/blobdiff - ext/olm/lib/curve25519-donna/speed-curve25519.c
add dependencies to repo
[matrix_esp_thesis] / ext / olm / lib / curve25519-donna / speed-curve25519.c
diff --git a/ext/olm/lib/curve25519-donna/speed-curve25519.c b/ext/olm/lib/curve25519-donna/speed-curve25519.c
new file mode 100644 (file)
index 0000000..d945d48
--- /dev/null
@@ -0,0 +1,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;
+}