Mercurial > dropbear
annotate testprof/ecc_test.c @ 230:809b681a9af5 libtomcrypt
- check for generic AES/TWOFISH settings from Dropbear, not AES128 etc
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 30 Aug 2005 17:40:30 +0000 |
parents | 39d5d58461d6 |
children |
rev | line source |
---|---|
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 #include <tomcrypt_test.h> |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 #ifdef MECC |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 |
209 | 5 static int sizes[] = { |
6 #ifdef ECC192 | |
7 24, | |
8 #endif | |
9 #ifdef ECC224 | |
10 28, | |
11 #endif | |
12 #ifdef ECC256 | |
13 32, | |
14 #endif | |
15 #ifdef ECC384 | |
16 48, | |
17 #endif | |
18 #ifdef ECC512 | |
19 65 | |
20 #endif | |
21 }; | |
22 | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 int ecc_tests (void) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 unsigned char buf[4][4096]; |
209 | 26 unsigned long x, y, z, s; |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 int stat, stat2; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 ecc_key usera, userb, pubKey, privKey; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 DO(ecc_test ()); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 |
209 | 32 for (s = 0; s < (int)(sizeof(sizes)/sizeof(sizes[0])); s++) { |
33 /* make up two keys */ | |
34 DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera)); | |
35 DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &userb)); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 |
209 | 37 /* make the shared secret */ |
38 x = 4096; | |
39 DO(ecc_shared_secret (&usera, &userb, buf[0], &x)); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 |
209 | 41 y = 4096; |
42 DO(ecc_shared_secret (&userb, &usera, buf[1], &y)); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 |
209 | 44 if (y != x) { |
45 fprintf(stderr, "ecc Shared keys are not same size."); | |
46 return 1; | |
47 } | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 |
209 | 49 if (memcmp (buf[0], buf[1], x)) { |
50 fprintf(stderr, "ecc Shared keys not same contents."); | |
51 return 1; | |
52 } | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 |
209 | 54 /* now export userb */ |
55 y = 4096; | |
56 DO(ecc_export (buf[1], &y, PK_PUBLIC, &userb)); | |
57 ecc_free (&userb); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 |
209 | 59 /* import and make the shared secret again */ |
60 DO(ecc_import (buf[1], y, &userb)); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 |
209 | 62 z = 4096; |
63 DO(ecc_shared_secret (&usera, &userb, buf[2], &z)); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 |
209 | 65 if (z != x) { |
66 fprintf(stderr, "failed. Size don't match?"); | |
67 return 1; | |
68 } | |
69 if (memcmp (buf[0], buf[2], x)) { | |
70 fprintf(stderr, "Failed. Contents didn't match."); | |
71 return 1; | |
72 } | |
73 ecc_free (&usera); | |
74 ecc_free (&userb); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 |
209 | 76 /* test encrypt_key */ |
77 DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera)); | |
78 | |
79 /* export key */ | |
80 x = sizeof(buf[0]); | |
81 DO(ecc_export(buf[0], &x, PK_PUBLIC, &usera)); | |
82 DO(ecc_import(buf[0], x, &pubKey)); | |
83 x = sizeof(buf[0]); | |
84 DO(ecc_export(buf[0], &x, PK_PRIVATE, &usera)); | |
85 DO(ecc_import(buf[0], x, &privKey)); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 |
209 | 87 for (x = 0; x < 32; x++) { |
88 buf[0][x] = x; | |
89 } | |
90 y = sizeof (buf[1]); | |
91 DO(ecc_encrypt_key (buf[0], 32, buf[1], &y, &yarrow_prng, find_prng ("yarrow"), find_hash ("sha256"), &pubKey)); | |
92 zeromem (buf[0], sizeof (buf[0])); | |
93 x = sizeof (buf[0]); | |
94 DO(ecc_decrypt_key (buf[1], y, buf[0], &x, &privKey)); | |
95 if (x != 32) { | |
96 fprintf(stderr, "Failed (length)"); | |
97 return 1; | |
98 } | |
99 for (x = 0; x < 32; x++) { | |
100 if (buf[0][x] != x) { | |
101 fprintf(stderr, "Failed (contents)"); | |
102 return 1; | |
103 } | |
104 } | |
105 /* test sign_hash */ | |
106 for (x = 0; x < 16; x++) { | |
107 buf[0][x] = x; | |
108 } | |
109 x = sizeof (buf[1]); | |
110 DO(ecc_sign_hash (buf[0], 16, buf[1], &x, &yarrow_prng, find_prng ("yarrow"), &privKey)); | |
111 DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &pubKey)); | |
112 buf[0][0] ^= 1; | |
113 DO(ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &privKey)); | |
114 if (!(stat == 1 && stat2 == 0)) { | |
115 fprintf(stderr, "ecc_verify_hash failed %d, %d, ", stat, stat2); | |
116 return 1; | |
117 } | |
118 ecc_free (&usera); | |
119 ecc_free (&pubKey); | |
120 ecc_free (&privKey); | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 return 0; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 #else |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 int ecc_tests(void) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 { |
209 | 129 fprintf(stderr, "NOP"); |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 return 0; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 #endif |
209 | 134 |
135 /* $Source: /cvs/libtom/libtomcrypt/testprof/ecc_test.c,v $ */ | |
136 /* $Revision: 1.9 $ */ | |
137 /* $Date: 2005/06/14 19:43:29 $ */ |