Mercurial > dropbear
comparison demos/test/test.c @ 15:6362d3854bb4 libtomcrypt-orig
0.96 release of LibTomCrypt
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 15 Jun 2004 14:07:21 +0000 |
parents | |
children | 5d99163f7e32 |
comparison
equal
deleted
inserted
replaced
3:7faae8f46238 | 15:6362d3854bb4 |
---|---|
1 #include "test.h" | |
2 | |
3 test_entry tests[26]; | |
4 | |
5 test_entry test_list[26] = { | |
6 | |
7 /* test name provides requires entry */ | |
8 {"store_test", "a", "", store_test }, | |
9 {"cipher_hash_test", "b", "a", cipher_hash_test }, | |
10 {"modes_test", "c", "b", modes_test }, | |
11 {"mac_test", "d", "c", mac_test }, | |
12 {"pkcs_1_test", "e", "b", pkcs_1_test }, | |
13 {"rsa_test", "f", "e", rsa_test }, | |
14 {"ecc_test", "g", "a", ecc_tests }, | |
15 {"dsa_test", "h", "a", dsa_test }, | |
16 {"dh_test", "i", "a", dh_tests }, | |
17 | |
18 {NULL, NULL, NULL, NULL} | |
19 }; | |
20 | |
21 prng_state test_yarrow; | |
22 static int current_test; | |
23 | |
24 void run_cmd(int res, int line, char *file, char *cmd) | |
25 { | |
26 if (res != CRYPT_OK) { | |
27 fprintf(stderr, "[%s]: %s (%d)\n%s:%d:%s\n", tests[current_test].name, error_to_string(res), res, file, line, cmd); | |
28 exit(EXIT_FAILURE); | |
29 } | |
30 } | |
31 | |
32 void register_algs(void) | |
33 { | |
34 #ifdef RIJNDAEL | |
35 register_cipher (&aes_desc); | |
36 #endif | |
37 #ifdef BLOWFISH | |
38 register_cipher (&blowfish_desc); | |
39 #endif | |
40 #ifdef XTEA | |
41 register_cipher (&xtea_desc); | |
42 #endif | |
43 #ifdef RC5 | |
44 register_cipher (&rc5_desc); | |
45 #endif | |
46 #ifdef RC6 | |
47 register_cipher (&rc6_desc); | |
48 #endif | |
49 #ifdef SAFERP | |
50 register_cipher (&saferp_desc); | |
51 #endif | |
52 #ifdef TWOFISH | |
53 register_cipher (&twofish_desc); | |
54 #endif | |
55 #ifdef SAFER | |
56 register_cipher (&safer_k64_desc); | |
57 register_cipher (&safer_sk64_desc); | |
58 register_cipher (&safer_k128_desc); | |
59 register_cipher (&safer_sk128_desc); | |
60 #endif | |
61 #ifdef RC2 | |
62 register_cipher (&rc2_desc); | |
63 #endif | |
64 #ifdef DES | |
65 register_cipher (&des_desc); | |
66 register_cipher (&des3_desc); | |
67 #endif | |
68 #ifdef CAST5 | |
69 register_cipher (&cast5_desc); | |
70 #endif | |
71 #ifdef NOEKEON | |
72 register_cipher (&noekeon_desc); | |
73 #endif | |
74 #ifdef SKIPJACK | |
75 register_cipher (&skipjack_desc); | |
76 #endif | |
77 #ifdef TIGER | |
78 register_hash (&tiger_desc); | |
79 #endif | |
80 #ifdef MD2 | |
81 register_hash (&md2_desc); | |
82 #endif | |
83 #ifdef MD4 | |
84 register_hash (&md4_desc); | |
85 #endif | |
86 #ifdef MD5 | |
87 register_hash (&md5_desc); | |
88 #endif | |
89 #ifdef SHA1 | |
90 register_hash (&sha1_desc); | |
91 #endif | |
92 #ifdef SHA256 | |
93 register_hash (&sha256_desc); | |
94 #endif | |
95 #ifdef SHA224 | |
96 register_hash (&sha224_desc); | |
97 #endif | |
98 #ifdef SHA384 | |
99 register_hash (&sha384_desc); | |
100 #endif | |
101 #ifdef SHA512 | |
102 register_hash (&sha512_desc); | |
103 #endif | |
104 #ifdef RIPEMD128 | |
105 register_hash (&rmd128_desc); | |
106 #endif | |
107 #ifdef RIPEMD160 | |
108 register_hash (&rmd160_desc); | |
109 #endif | |
110 #ifdef WHIRLPOOL | |
111 register_hash (&whirlpool_desc); | |
112 #endif | |
113 | |
114 if (register_prng(&yarrow_desc) == -1) { | |
115 printf("Error registering yarrow PRNG\n"); | |
116 exit(-1); | |
117 } | |
118 | |
119 if (register_prng(&sprng_desc) == -1) { | |
120 printf("Error registering sprng PRNG\n"); | |
121 exit(-1); | |
122 } | |
123 } | |
124 | |
125 /* sort tests based on their requirement/services. Helps make sure dependencies are tested first */ | |
126 void sort(void) | |
127 { | |
128 unsigned x, y, z, a, pidx[26]; | |
129 | |
130 /* find out where things are provided */ | |
131 zeromem(pidx, sizeof(pidx)); | |
132 z = 0; | |
133 do { | |
134 y = 0; | |
135 for (x = 0; test_list[x].name != NULL; x++) { | |
136 if (test_list[x].entry == NULL) continue; | |
137 if (strlen(test_list[x].prov) == 0) { | |
138 y = 1; | |
139 tests[z++] = test_list[x]; test_list[x].entry = NULL; | |
140 pidx[test_list[x].prov[0]-'a'] = 1; | |
141 break; | |
142 } else { | |
143 for (a = 0; a < strlen(test_list[x].req); a++) { | |
144 if (pidx[test_list[x].req[a]-'a'] == 0) break; | |
145 } | |
146 if (a == strlen(test_list[x].req)) { | |
147 y = 1; | |
148 tests[z++] = test_list[x]; test_list[x].entry = NULL; | |
149 pidx[test_list[x].prov[0]-'a'] = 1; | |
150 break; | |
151 } | |
152 } | |
153 } | |
154 } while (y == 1); | |
155 } | |
156 | |
157 int main(void) | |
158 { | |
159 printf("Built with\n%s\n", crypt_build_settings); | |
160 | |
161 srand(time(NULL)); | |
162 sort(); | |
163 register_algs(); | |
164 | |
165 // start dummy yarrow for internal use | |
166 DO(yarrow_start(&test_yarrow)); | |
167 DO(yarrow_add_entropy("test", 4, &test_yarrow)); | |
168 DO(yarrow_ready(&test_yarrow)); | |
169 | |
170 // do tests | |
171 for (current_test = 0; tests[current_test].name != NULL; current_test++) { | |
172 printf("[%-20s]: ", tests[current_test].name); fflush(stdout); | |
173 printf("\t%s\n", tests[current_test].entry()==0?"passed":"failed"); | |
174 } | |
175 | |
176 return 0; | |
177 } |