-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurveX.c
68 lines (54 loc) · 1.24 KB
/
CurveX.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* CurveX.c
*
* Created: 9/28/2015 4:23:21 PM
* Author: TestPower
*/
#include <avr/io.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 printhex(unsigned int val)
{
return;
}
void printtext(char *text)
{
return;
}
void doit(unsigned char *ek,unsigned char *e,unsigned char *k)
{
int i;
for (i = 0;i < 32;++i) printhex((unsigned int) e[i]);
for (i = 0;i < 32;++i) printhex((unsigned int) k[i]);
curve25519_donna(ek,e,k);
for (i = 0;i < 32;++i) printhex((unsigned int) ek[i]);
}
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(void)
{
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]) {
printtext("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];
}
while(1)
{
//TODO:: Please write your application code
}
}