15
|
1 #include "test.h" |
|
2 |
143
|
3 #ifdef MECC |
|
4 |
15
|
5 int ecc_tests (void) |
|
6 { |
|
7 unsigned char buf[4][4096]; |
|
8 unsigned long x, y, z; |
|
9 int stat, stat2; |
|
10 ecc_key usera, userb; |
|
11 |
|
12 DO(ecc_test ()); |
|
13 |
|
14 /* make up two keys */ |
143
|
15 DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &usera)); |
|
16 DO(ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &userb)); |
15
|
17 |
|
18 /* make the shared secret */ |
|
19 x = 4096; |
|
20 DO(ecc_shared_secret (&usera, &userb, buf[0], &x)); |
|
21 |
|
22 y = 4096; |
|
23 DO(ecc_shared_secret (&userb, &usera, buf[1], &y)); |
|
24 |
|
25 if (y != x) { |
|
26 printf ("ecc Shared keys are not same size."); |
|
27 return 1; |
|
28 } |
|
29 |
|
30 if (memcmp (buf[0], buf[1], x)) { |
|
31 printf ("ecc Shared keys not same contents."); |
|
32 return 1; |
|
33 } |
|
34 |
|
35 /* now export userb */ |
|
36 y = 4096; |
|
37 DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb)); |
|
38 ecc_free (&userb); |
|
39 |
|
40 /* import and make the shared secret again */ |
|
41 DO(ecc_import (buf[1], y, &userb)); |
|
42 |
|
43 z = 4096; |
|
44 DO(ecc_shared_secret (&usera, &userb, buf[2], &z)); |
|
45 |
|
46 if (z != x) { |
|
47 printf ("failed. Size don't match?"); |
|
48 return 1; |
|
49 } |
|
50 if (memcmp (buf[0], buf[2], x)) { |
|
51 printf ("Failed. Content didn't match."); |
|
52 return 1; |
|
53 } |
|
54 ecc_free (&usera); |
|
55 ecc_free (&userb); |
|
56 |
|
57 /* test encrypt_key */ |
143
|
58 ecc_make_key (&test_yarrow, find_prng ("yarrow"), 65, &usera); |
15
|
59 for (x = 0; x < 32; x++) { |
|
60 buf[0][x] = x; |
|
61 } |
|
62 y = sizeof (buf[1]); |
|
63 DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &test_yarrow, find_prng ("yarrow"), find_hash ("sha256"), &usera)); |
|
64 zeromem (buf[0], sizeof (buf[0])); |
|
65 x = sizeof (buf[0]); |
|
66 DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &usera)); |
|
67 if (x != 32) { |
|
68 printf ("Failed (length)"); |
|
69 return 1; |
|
70 } |
|
71 for (x = 0; x < 32; x++) |
|
72 if (buf[0][x] != x) { |
|
73 printf ("Failed (contents)"); |
|
74 return 1; |
|
75 } |
|
76 /* test sign_hash */ |
|
77 for (x = 0; x < 16; x++) { |
|
78 buf[0][x] = x; |
|
79 } |
|
80 x = sizeof (buf[1]); |
|
81 DO(ecc_sign_hash (buf[0], 16, buf[1], &x, &test_yarrow, find_prng ("yarrow"), &usera)); |
|
82 DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &usera)); |
|
83 buf[0][0] ^= 1; |
|
84 DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &usera)); |
|
85 if (!(stat == 1 && stat2 == 0)) { |
|
86 printf("ecc_verify_hash failed"); |
|
87 return 1; |
|
88 } |
|
89 ecc_free (&usera); |
|
90 return 0; |
|
91 } |
143
|
92 |
|
93 #else |
|
94 |
|
95 int ecc_tests(void) |
|
96 { |
|
97 printf("NOP"); |
|
98 return 0; |
|
99 } |
|
100 |
|
101 #endif |