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