diff options
Diffstat (limited to 'src/lib/libcrypto/evp/evp_test.c')
-rw-r--r-- | src/lib/libcrypto/evp/evp_test.c | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c index 28460173f7..90294ef686 100644 --- a/src/lib/libcrypto/evp/evp_test.c +++ b/src/lib/libcrypto/evp/evp_test.c | |||
@@ -49,14 +49,8 @@ | |||
49 | 49 | ||
50 | #include <stdio.h> | 50 | #include <stdio.h> |
51 | #include <string.h> | 51 | #include <string.h> |
52 | |||
53 | #include "../e_os.h" | ||
54 | |||
55 | #include <openssl/evp.h> | 52 | #include <openssl/evp.h> |
56 | #ifndef OPENSSL_NO_ENGINE | ||
57 | #include <openssl/engine.h> | 53 | #include <openssl/engine.h> |
58 | #endif | ||
59 | #include <openssl/err.h> | ||
60 | #include <openssl/conf.h> | 54 | #include <openssl/conf.h> |
61 | 55 | ||
62 | static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) | 56 | static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) |
@@ -84,7 +78,7 @@ static int convert(unsigned char *s) | |||
84 | if(!s[1]) | 78 | if(!s[1]) |
85 | { | 79 | { |
86 | fprintf(stderr,"Odd number of hex digits!"); | 80 | fprintf(stderr,"Odd number of hex digits!"); |
87 | EXIT(4); | 81 | exit(4); |
88 | } | 82 | } |
89 | sscanf((char *)s,"%2x",&n); | 83 | sscanf((char *)s,"%2x",&n); |
90 | *d=(unsigned char)n; | 84 | *d=(unsigned char)n; |
@@ -126,12 +120,6 @@ static char *sstrsep(char **string, const char *delim) | |||
126 | static unsigned char *ustrsep(char **p,const char *sep) | 120 | static unsigned char *ustrsep(char **p,const char *sep) |
127 | { return (unsigned char *)sstrsep(p,sep); } | 121 | { return (unsigned char *)sstrsep(p,sep); } |
128 | 122 | ||
129 | static int test1_exit(int ec) | ||
130 | { | ||
131 | EXIT(ec); | ||
132 | return(0); /* To keep some compilers quiet */ | ||
133 | } | ||
134 | |||
135 | static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | 123 | static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, |
136 | const unsigned char *iv,int in, | 124 | const unsigned char *iv,int in, |
137 | const unsigned char *plaintext,int pn, | 125 | const unsigned char *plaintext,int pn, |
@@ -154,7 +142,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
154 | { | 142 | { |
155 | fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn, | 143 | fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn, |
156 | c->key_len); | 144 | c->key_len); |
157 | test1_exit(5); | 145 | exit(5); |
158 | } | 146 | } |
159 | EVP_CIPHER_CTX_init(&ctx); | 147 | EVP_CIPHER_CTX_init(&ctx); |
160 | if (encdec != 0) | 148 | if (encdec != 0) |
@@ -162,26 +150,26 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
162 | if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) | 150 | if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) |
163 | { | 151 | { |
164 | fprintf(stderr,"EncryptInit failed\n"); | 152 | fprintf(stderr,"EncryptInit failed\n"); |
165 | test1_exit(10); | 153 | exit(10); |
166 | } | 154 | } |
167 | EVP_CIPHER_CTX_set_padding(&ctx,0); | 155 | EVP_CIPHER_CTX_set_padding(&ctx,0); |
168 | 156 | ||
169 | if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) | 157 | if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) |
170 | { | 158 | { |
171 | fprintf(stderr,"Encrypt failed\n"); | 159 | fprintf(stderr,"Encrypt failed\n"); |
172 | test1_exit(6); | 160 | exit(6); |
173 | } | 161 | } |
174 | if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) | 162 | if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) |
175 | { | 163 | { |
176 | fprintf(stderr,"EncryptFinal failed\n"); | 164 | fprintf(stderr,"EncryptFinal failed\n"); |
177 | test1_exit(7); | 165 | exit(7); |
178 | } | 166 | } |
179 | 167 | ||
180 | if(outl+outl2 != cn) | 168 | if(outl+outl2 != cn) |
181 | { | 169 | { |
182 | fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", | 170 | fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", |
183 | outl+outl2,cn); | 171 | outl+outl2,cn); |
184 | test1_exit(8); | 172 | exit(8); |
185 | } | 173 | } |
186 | 174 | ||
187 | if(memcmp(out,ciphertext,cn)) | 175 | if(memcmp(out,ciphertext,cn)) |
@@ -189,7 +177,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
189 | fprintf(stderr,"Ciphertext mismatch\n"); | 177 | fprintf(stderr,"Ciphertext mismatch\n"); |
190 | hexdump(stderr,"Got",out,cn); | 178 | hexdump(stderr,"Got",out,cn); |
191 | hexdump(stderr,"Expected",ciphertext,cn); | 179 | hexdump(stderr,"Expected",ciphertext,cn); |
192 | test1_exit(9); | 180 | exit(9); |
193 | } | 181 | } |
194 | } | 182 | } |
195 | 183 | ||
@@ -198,26 +186,26 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
198 | if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) | 186 | if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) |
199 | { | 187 | { |
200 | fprintf(stderr,"DecryptInit failed\n"); | 188 | fprintf(stderr,"DecryptInit failed\n"); |
201 | test1_exit(11); | 189 | exit(11); |
202 | } | 190 | } |
203 | EVP_CIPHER_CTX_set_padding(&ctx,0); | 191 | EVP_CIPHER_CTX_set_padding(&ctx,0); |
204 | 192 | ||
205 | if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) | 193 | if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) |
206 | { | 194 | { |
207 | fprintf(stderr,"Decrypt failed\n"); | 195 | fprintf(stderr,"Decrypt failed\n"); |
208 | test1_exit(6); | 196 | exit(6); |
209 | } | 197 | } |
210 | if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) | 198 | if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) |
211 | { | 199 | { |
212 | fprintf(stderr,"DecryptFinal failed\n"); | 200 | fprintf(stderr,"DecryptFinal failed\n"); |
213 | test1_exit(7); | 201 | exit(7); |
214 | } | 202 | } |
215 | 203 | ||
216 | if(outl+outl2 != cn) | 204 | if(outl+outl2 != cn) |
217 | { | 205 | { |
218 | fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", | 206 | fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", |
219 | outl+outl2,cn); | 207 | outl+outl2,cn); |
220 | test1_exit(8); | 208 | exit(8); |
221 | } | 209 | } |
222 | 210 | ||
223 | if(memcmp(out,plaintext,cn)) | 211 | if(memcmp(out,plaintext,cn)) |
@@ -225,7 +213,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | |||
225 | fprintf(stderr,"Plaintext mismatch\n"); | 213 | fprintf(stderr,"Plaintext mismatch\n"); |
226 | hexdump(stderr,"Got",out,cn); | 214 | hexdump(stderr,"Got",out,cn); |
227 | hexdump(stderr,"Expected",plaintext,cn); | 215 | hexdump(stderr,"Expected",plaintext,cn); |
228 | test1_exit(9); | 216 | exit(9); |
229 | } | 217 | } |
230 | } | 218 | } |
231 | 219 | ||
@@ -272,24 +260,24 @@ static int test_digest(const char *digest, | |||
272 | if(!EVP_DigestInit_ex(&ctx,d, NULL)) | 260 | if(!EVP_DigestInit_ex(&ctx,d, NULL)) |
273 | { | 261 | { |
274 | fprintf(stderr,"DigestInit failed\n"); | 262 | fprintf(stderr,"DigestInit failed\n"); |
275 | EXIT(100); | 263 | exit(100); |
276 | } | 264 | } |
277 | if(!EVP_DigestUpdate(&ctx,plaintext,pn)) | 265 | if(!EVP_DigestUpdate(&ctx,plaintext,pn)) |
278 | { | 266 | { |
279 | fprintf(stderr,"DigestUpdate failed\n"); | 267 | fprintf(stderr,"DigestUpdate failed\n"); |
280 | EXIT(101); | 268 | exit(101); |
281 | } | 269 | } |
282 | if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) | 270 | if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) |
283 | { | 271 | { |
284 | fprintf(stderr,"DigestFinal failed\n"); | 272 | fprintf(stderr,"DigestFinal failed\n"); |
285 | EXIT(101); | 273 | exit(101); |
286 | } | 274 | } |
287 | EVP_MD_CTX_cleanup(&ctx); | 275 | EVP_MD_CTX_cleanup(&ctx); |
288 | 276 | ||
289 | if(mdn != cn) | 277 | if(mdn != cn) |
290 | { | 278 | { |
291 | fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); | 279 | fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); |
292 | EXIT(102); | 280 | exit(102); |
293 | } | 281 | } |
294 | 282 | ||
295 | if(memcmp(md,ciphertext,cn)) | 283 | if(memcmp(md,ciphertext,cn)) |
@@ -297,7 +285,7 @@ static int test_digest(const char *digest, | |||
297 | fprintf(stderr,"Digest mismatch\n"); | 285 | fprintf(stderr,"Digest mismatch\n"); |
298 | hexdump(stderr,"Got",md,cn); | 286 | hexdump(stderr,"Got",md,cn); |
299 | hexdump(stderr,"Expected",ciphertext,cn); | 287 | hexdump(stderr,"Expected",ciphertext,cn); |
300 | EXIT(103); | 288 | exit(103); |
301 | } | 289 | } |
302 | 290 | ||
303 | printf("\n"); | 291 | printf("\n"); |
@@ -315,7 +303,7 @@ int main(int argc,char **argv) | |||
315 | if(argc != 2) | 303 | if(argc != 2) |
316 | { | 304 | { |
317 | fprintf(stderr,"%s <test file>\n",argv[0]); | 305 | fprintf(stderr,"%s <test file>\n",argv[0]); |
318 | EXIT(1); | 306 | exit(1); |
319 | } | 307 | } |
320 | CRYPTO_malloc_debug_init(); | 308 | CRYPTO_malloc_debug_init(); |
321 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); | 309 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); |
@@ -327,20 +315,17 @@ int main(int argc,char **argv) | |||
327 | if(!f) | 315 | if(!f) |
328 | { | 316 | { |
329 | perror(szTestFile); | 317 | perror(szTestFile); |
330 | EXIT(2); | 318 | exit(2); |
331 | } | 319 | } |
332 | 320 | ||
333 | /* Load up the software EVP_CIPHER and EVP_MD definitions */ | 321 | /* Load up the software EVP_CIPHER and EVP_MD definitions */ |
334 | OpenSSL_add_all_ciphers(); | 322 | OpenSSL_add_all_ciphers(); |
335 | OpenSSL_add_all_digests(); | 323 | OpenSSL_add_all_digests(); |
336 | #ifndef OPENSSL_NO_ENGINE | ||
337 | /* Load all compiled-in ENGINEs */ | 324 | /* Load all compiled-in ENGINEs */ |
338 | ENGINE_load_builtin_engines(); | 325 | ENGINE_load_builtin_engines(); |
339 | #endif | ||
340 | #if 0 | 326 | #if 0 |
341 | OPENSSL_config(); | 327 | OPENSSL_config(); |
342 | #endif | 328 | #endif |
343 | #ifndef OPENSSL_NO_ENGINE | ||
344 | /* Register all available ENGINE implementations of ciphers and digests. | 329 | /* Register all available ENGINE implementations of ciphers and digests. |
345 | * This could perhaps be changed to "ENGINE_register_all_complete()"? */ | 330 | * This could perhaps be changed to "ENGINE_register_all_complete()"? */ |
346 | ENGINE_register_all_ciphers(); | 331 | ENGINE_register_all_ciphers(); |
@@ -349,7 +334,6 @@ int main(int argc,char **argv) | |||
349 | * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if | 334 | * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if |
350 | * they weren't already initialised. */ | 335 | * they weren't already initialised. */ |
351 | /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ | 336 | /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ |
352 | #endif | ||
353 | 337 | ||
354 | for( ; ; ) | 338 | for( ; ; ) |
355 | { | 339 | { |
@@ -387,13 +371,11 @@ int main(int argc,char **argv) | |||
387 | && !test_digest(cipher,plaintext,pn,ciphertext,cn)) | 371 | && !test_digest(cipher,plaintext,pn,ciphertext,cn)) |
388 | { | 372 | { |
389 | fprintf(stderr,"Can't find %s\n",cipher); | 373 | fprintf(stderr,"Can't find %s\n",cipher); |
390 | EXIT(3); | 374 | exit(3); |
391 | } | 375 | } |
392 | } | 376 | } |
393 | 377 | ||
394 | #ifndef OPENSSL_NO_ENGINE | ||
395 | ENGINE_cleanup(); | 378 | ENGINE_cleanup(); |
396 | #endif | ||
397 | EVP_cleanup(); | 379 | EVP_cleanup(); |
398 | CRYPTO_cleanup_all_ex_data(); | 380 | CRYPTO_cleanup_all_ex_data(); |
399 | ERR_remove_state(0); | 381 | ERR_remove_state(0); |