Mercurial > dropbear
comparison demos/test/test.c @ 143:5d99163f7e32 libtomcrypt-orig
import of libtomcrypt 0.99
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 19 Dec 2004 11:34:45 +0000 |
parents | 6362d3854bb4 |
children |
comparison
equal
deleted
inserted
replaced
15:6362d3854bb4 | 143:5d99163f7e32 |
---|---|
7 /* test name provides requires entry */ | 7 /* test name provides requires entry */ |
8 {"store_test", "a", "", store_test }, | 8 {"store_test", "a", "", store_test }, |
9 {"cipher_hash_test", "b", "a", cipher_hash_test }, | 9 {"cipher_hash_test", "b", "a", cipher_hash_test }, |
10 {"modes_test", "c", "b", modes_test }, | 10 {"modes_test", "c", "b", modes_test }, |
11 {"mac_test", "d", "c", mac_test }, | 11 {"mac_test", "d", "c", mac_test }, |
12 {"pkcs_1_test", "e", "b", pkcs_1_test }, | 12 {"der_test", "e", "", der_tests }, |
13 {"rsa_test", "f", "e", rsa_test }, | 13 |
14 {"ecc_test", "g", "a", ecc_tests }, | 14 {"pkcs_1_test", "f", "e", pkcs_1_test }, |
15 {"dsa_test", "h", "a", dsa_test }, | 15 {"rsa_test", "g", "e", rsa_test }, |
16 {"dh_test", "i", "a", dh_tests }, | 16 {"ecc_test", "h", "a", ecc_tests }, |
17 {"dsa_test", "i", "a", dsa_test }, | |
18 {"dh_test", "j", "a", dh_tests }, | |
17 | 19 |
18 {NULL, NULL, NULL, NULL} | 20 {NULL, NULL, NULL, NULL} |
19 }; | 21 }; |
20 | 22 |
21 prng_state test_yarrow; | 23 prng_state test_yarrow; |
29 } | 31 } |
30 } | 32 } |
31 | 33 |
32 void register_algs(void) | 34 void register_algs(void) |
33 { | 35 { |
36 int err; | |
37 | |
34 #ifdef RIJNDAEL | 38 #ifdef RIJNDAEL |
35 register_cipher (&aes_desc); | 39 register_cipher (&aes_desc); |
36 #endif | 40 #endif |
37 #ifdef BLOWFISH | 41 #ifdef BLOWFISH |
38 register_cipher (&blowfish_desc); | 42 register_cipher (&blowfish_desc); |
108 register_hash (&rmd160_desc); | 112 register_hash (&rmd160_desc); |
109 #endif | 113 #endif |
110 #ifdef WHIRLPOOL | 114 #ifdef WHIRLPOOL |
111 register_hash (&whirlpool_desc); | 115 register_hash (&whirlpool_desc); |
112 #endif | 116 #endif |
113 | 117 #ifdef CHC_HASH |
114 if (register_prng(&yarrow_desc) == -1) { | 118 register_hash(&chc_desc); |
115 printf("Error registering yarrow PRNG\n"); | 119 if ((err = chc_register(register_cipher(&aes_enc_desc))) != CRYPT_OK) { |
116 exit(-1); | 120 printf("chc_register error: %s\n", error_to_string(err)); |
117 } | 121 exit(EXIT_FAILURE); |
118 | 122 } |
119 if (register_prng(&sprng_desc) == -1) { | 123 #endif |
120 printf("Error registering sprng PRNG\n"); | 124 |
121 exit(-1); | 125 |
122 } | 126 #ifdef YARROW |
127 register_prng(&yarrow_desc); | |
128 #endif | |
129 #ifdef FORTUNA | |
130 register_prng(&fortuna_desc); | |
131 #endif | |
132 #ifdef RC4 | |
133 register_prng(&rc4_desc); | |
134 #endif | |
135 #ifdef SPRNG | |
136 register_prng(&sprng_desc); | |
137 #endif | |
138 #ifdef SOBER128 | |
139 register_prng(&sober128_desc); | |
140 #endif | |
123 } | 141 } |
124 | 142 |
125 /* sort tests based on their requirement/services. Helps make sure dependencies are tested first */ | 143 /* sort tests based on their requirement/services. Helps make sure dependencies are tested first */ |
126 void sort(void) | 144 void sort(void) |
127 { | 145 { |
151 } | 169 } |
152 } | 170 } |
153 } | 171 } |
154 } while (y == 1); | 172 } while (y == 1); |
155 } | 173 } |
156 | 174 |
175 #define STACKBLOCK 8 | |
176 #define STACK_EST_USAGE 32768 | |
177 | |
178 unsigned char stack_mask[STACKBLOCK]; | |
179 unsigned long stack_cur=0; | |
180 | |
181 void stack_masker(void) | |
182 { | |
183 #ifdef STACK_TEST | |
184 volatile unsigned char M[STACK_EST_USAGE]; | |
185 stack_cur = 0; | |
186 for (stack_cur = 0; stack_cur < STACK_EST_USAGE/STACKBLOCK; stack_cur++) { | |
187 memcpy(M+(stack_cur*STACKBLOCK), stack_mask, STACKBLOCK); | |
188 } | |
189 #endif | |
190 } | |
191 | |
192 void stack_check(void) | |
193 { | |
194 #ifdef STACK_TEST | |
195 unsigned char M[STACK_EST_USAGE]; | |
196 stack_cur = 0; | |
197 #ifdef STACK_DOWN | |
198 while (memcmp(M+(STACK_EST_USAGE-STACKBLOCK-stack_cur), stack_mask, STACKBLOCK) && | |
199 #else | |
200 while (memcmp(M+stack_cur, stack_mask, STACKBLOCK) && | |
201 #endif | |
202 stack_cur < (STACK_EST_USAGE - STACKBLOCK)) { | |
203 ++stack_cur; | |
204 } | |
205 #endif | |
206 } | |
207 | |
157 int main(void) | 208 int main(void) |
158 { | 209 { |
210 int x; | |
211 unsigned char buf[16]; | |
212 | |
213 /* setup stack checker */ | |
214 srand(time(NULL)); | |
215 for (x = 0; x < STACKBLOCK; x++) { | |
216 stack_mask[x] = rand() & 255; | |
217 } | |
218 stack_masker(); | |
219 | |
159 printf("Built with\n%s\n", crypt_build_settings); | 220 printf("Built with\n%s\n", crypt_build_settings); |
160 | 221 |
161 srand(time(NULL)); | |
162 sort(); | 222 sort(); |
163 register_algs(); | 223 register_algs(); |
164 | 224 |
165 // start dummy yarrow for internal use | 225 // start dummy yarrow for internal use |
166 DO(yarrow_start(&test_yarrow)); | 226 DO(yarrow_start(&test_yarrow)); |
167 DO(yarrow_add_entropy("test", 4, &test_yarrow)); | 227 sprng_read(buf, 16, NULL); |
228 DO(yarrow_add_entropy(buf, 16, &test_yarrow)); | |
168 DO(yarrow_ready(&test_yarrow)); | 229 DO(yarrow_ready(&test_yarrow)); |
169 | 230 |
231 // output sizes | |
232 printf("Sizes of objects (in bytes)\n"); | |
233 printf("\tsymmetric_key\t=\t%5lu\n", sizeof(symmetric_key)); | |
234 printf("\thash_state\t=\t%5lu\n", sizeof(hash_state)); | |
235 printf("\thmac_state\t=\t%5lu\n", sizeof(hmac_state)); | |
236 printf("\tomac_state\t=\t%5lu\n", sizeof(omac_state)); | |
237 printf("\tpmac_state\t=\t%5lu\n", sizeof(pmac_state)); | |
238 printf("\tocb_state\t=\t%5lu\n", sizeof(ocb_state)); | |
239 printf("\teax_state\t=\t%5lu\n", sizeof(eax_state)); | |
240 printf("\tmp_int\t\t=\t%5lu\n", sizeof(mp_int)); | |
241 #ifdef MRSA | |
242 printf("\trsa_key\t\t=\t%5lu\n", sizeof(rsa_key)); | |
243 #endif | |
244 #ifdef MDSA | |
245 printf("\tdsa_key\t\t=\t%5lu\n", sizeof(dsa_key)); | |
246 #endif | |
247 #ifdef MDH | |
248 printf("\tdh_key\t\t=\t%5lu\n", sizeof(dh_key)); | |
249 #endif | |
250 #ifdef MECC | |
251 printf("\tecc_key\t\t=\t%5lu\n", sizeof(ecc_key)); | |
252 #endif | |
253 | |
254 printf("\n\n"); | |
170 // do tests | 255 // do tests |
171 for (current_test = 0; tests[current_test].name != NULL; current_test++) { | 256 for (current_test = 0; tests[current_test].name != NULL; current_test++) { |
172 printf("[%-20s]: ", tests[current_test].name); fflush(stdout); | 257 printf("[%-20s]: ", tests[current_test].name); fflush(stdout); |
173 printf("\t%s\n", tests[current_test].entry()==0?"passed":"failed"); | 258 printf("\t%s\n", tests[current_test].entry()==0?"passed":"failed"); |
174 } | 259 } |