]> gitweb.ps.run Git - matrix_esp_thesis/blob - ext/olm/lib/curve25519-donna/test-curve25519.c
add dependencies to repo
[matrix_esp_thesis] / ext / olm / lib / curve25519-donna / test-curve25519.c
1 /*
2 test-curve25519 version 20050915
3 D. J. Bernstein
4 Public domain.
5
6 Tiny modifications by agl
7 */
8
9 #include <stdio.h>
10
11 extern void curve25519_donna(unsigned char *output, const unsigned char *a,
12                              const unsigned char *b);
13 void doit(unsigned char *ek,unsigned char *e,unsigned char *k);
14
15 void doit(unsigned char *ek,unsigned char *e,unsigned char *k)
16 {
17   int i;
18
19   for (i = 0;i < 32;++i) printf("%02x",(unsigned int) e[i]); printf(" ");
20   for (i = 0;i < 32;++i) printf("%02x",(unsigned int) k[i]); printf(" ");
21   curve25519_donna(ek,e,k);
22   for (i = 0;i < 32;++i) printf("%02x",(unsigned int) ek[i]); printf("\n");
23 }
24
25 unsigned char e1k[32];
26 unsigned char e2k[32];
27 unsigned char e1e2k[32];
28 unsigned char e2e1k[32];
29 unsigned char e1[32] = {3};
30 unsigned char e2[32] = {5};
31 unsigned char k[32] = {9};
32
33 int
34 main()
35 {
36   int loop;
37   int i;
38
39   for (loop = 0;loop < 10000;++loop) {
40     doit(e1k,e1,k);
41     doit(e2e1k,e2,e1k);
42     doit(e2k,e2,k);
43     doit(e1e2k,e1,e2k);
44     for (i = 0;i < 32;++i) if (e1e2k[i] != e2e1k[i]) {
45       printf("fail\n");
46       return 1;
47     }
48     for (i = 0;i < 32;++i) e1[i] ^= e2k[i];
49     for (i = 0;i < 32;++i) e2[i] ^= e1k[i];
50     for (i = 0;i < 32;++i) k[i] ^= e1e2k[i];
51   }
52
53   return 0;
54 }