aboutsummaryrefslogtreecommitdiff
path: root/lib/curve25519-donna/test-curve25519.c
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2015-02-26 16:40:56 +0000
committerMark Haines <mjark@negativecurvature.net>2015-02-26 16:40:56 +0000
commit6c56bcf2fd3db38c679b9cf9345051a7309fa02f (patch)
treed587e9a7d8f7e0fc91d4d04b2e4903175a682a83 /lib/curve25519-donna/test-curve25519.c
parent09d8e84c7cbbf21195f3fd2eabbcff44042d5a4e (diff)
parente50ac707316ea6d8059f7036322450727773952d (diff)
Merge commit 'e50ac707316ea6d8059f7036322450727773952d' as 'lib/curve25519-donna'
Diffstat (limited to 'lib/curve25519-donna/test-curve25519.c')
-rw-r--r--lib/curve25519-donna/test-curve25519.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/curve25519-donna/test-curve25519.c b/lib/curve25519-donna/test-curve25519.c
new file mode 100644
index 0000000..591d871
--- /dev/null
+++ b/lib/curve25519-donna/test-curve25519.c
@@ -0,0 +1,54 @@
+/*
+test-curve25519 version 20050915
+D. J. Bernstein
+Public domain.
+
+Tiny modifications by agl
+*/
+
+#include <stdio.h>
+
+extern void curve25519_donna(unsigned char *output, const unsigned char *a,
+ const unsigned char *b);
+void doit(unsigned char *ek,unsigned char *e,unsigned char *k);
+
+void doit(unsigned char *ek,unsigned char *e,unsigned char *k)
+{
+ int i;
+
+ for (i = 0;i < 32;++i) printf("%02x",(unsigned int) e[i]); printf(" ");
+ for (i = 0;i < 32;++i) printf("%02x",(unsigned int) k[i]); printf(" ");
+ curve25519_donna(ek,e,k);
+ for (i = 0;i < 32;++i) printf("%02x",(unsigned int) ek[i]); printf("\n");
+}
+
+unsigned char e1k[32];
+unsigned char e2k[32];
+unsigned char e1e2k[32];
+unsigned char e2e1k[32];
+unsigned char e1[32] = {3};
+unsigned char e2[32] = {5};
+unsigned char k[32] = {9};
+
+int
+main()
+{
+ int loop;
+ int i;
+
+ for (loop = 0;loop < 10000;++loop) {
+ doit(e1k,e1,k);
+ doit(e2e1k,e2,e1k);
+ doit(e2k,e2,k);
+ doit(e1e2k,e1,e2k);
+ for (i = 0;i < 32;++i) if (e1e2k[i] != e2e1k[i]) {
+ printf("fail\n");
+ return 1;
+ }
+ for (i = 0;i < 32;++i) e1[i] ^= e2k[i];
+ for (i = 0;i < 32;++i) e2[i] ^= e1k[i];
+ for (i = 0;i < 32;++i) k[i] ^= e1e2k[i];
+ }
+
+ return 0;
+}