57 #ifndef OPENSSL_NO_ENGINE
63 static void hexdump(FILE *
f,
const char *title,
const unsigned char *s,
int l)
67 fprintf(f,
"%s",title);
71 fprintf(f,
"\n%04x",n);
72 fprintf(f,
" %02x",s[n]);
77 static int convert(
unsigned char *s)
81 for(d=s ; *s ; s+=2,++d)
87 fprintf(stderr,
"Odd number of hex digits!");
90 sscanf((
char *)s,
"%2x",&n);
96 static char *sstrsep(
char **
string,
const char *delim)
99 char *token = *string;
104 memset(isdelim, 0, 256);
109 isdelim[(
unsigned char)(*delim)] = 1;
113 while (!isdelim[(
unsigned char)(**string)])
127 static unsigned char *ustrsep(
char **
p,
const char *sep)
128 {
return (
unsigned char *)sstrsep(p,sep); }
130 static int test1_exit(
int ec)
136 static void test1(
const EVP_CIPHER *c,
const unsigned char *
key,
int kn,
137 const unsigned char *iv,
int in,
138 const unsigned char *plaintext,
int pn,
139 const unsigned char *ciphertext,
int cn,
143 unsigned char out[4096];
147 (encdec == 1 ?
"(encrypt)" : (encdec == 0 ?
"(decrypt)" :
"(encrypt/decrypt)")));
148 hexdump(stdout,
"Key",key,kn);
150 hexdump(stdout,
"IV",iv,in);
151 hexdump(stdout,
"Plaintext",plaintext,pn);
152 hexdump(stdout,
"Ciphertext",ciphertext,cn);
156 fprintf(stderr,
"Key length doesn't match, got %d expected %lu\n",kn,
165 fprintf(stderr,
"EncryptInit failed\n");
173 fprintf(stderr,
"Encrypt failed\n");
179 fprintf(stderr,
"EncryptFinal failed\n");
186 fprintf(stderr,
"Ciphertext length mismatch got %d expected %d\n",
191 if(memcmp(out,ciphertext,cn))
193 fprintf(stderr,
"Ciphertext mismatch\n");
194 hexdump(stderr,
"Got",out,cn);
195 hexdump(stderr,
"Expected",ciphertext,cn);
204 fprintf(stderr,
"DecryptInit failed\n");
212 fprintf(stderr,
"Decrypt failed\n");
218 fprintf(stderr,
"DecryptFinal failed\n");
225 fprintf(stderr,
"Plaintext length mismatch got %d expected %d\n",
230 if(memcmp(out,plaintext,pn))
232 fprintf(stderr,
"Plaintext mismatch\n");
233 hexdump(stderr,
"Got",out,pn);
234 hexdump(stderr,
"Expected",plaintext,pn);
244 static int test_cipher(
const char *cipher,
const unsigned char *key,
int kn,
245 const unsigned char *iv,
int in,
246 const unsigned char *plaintext,
int pn,
247 const unsigned char *ciphertext,
int cn,
256 test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec);
261 static int test_digest(
const char *digest,
262 const unsigned char *plaintext,
int pn,
263 const unsigned char *ciphertext,
unsigned int cn)
275 hexdump(stdout,
"Plaintext",plaintext,pn);
276 hexdump(stdout,
"Digest",ciphertext,cn);
281 fprintf(stderr,
"DigestInit failed\n");
287 fprintf(stderr,
"DigestUpdate failed\n");
293 fprintf(stderr,
"DigestFinal failed\n");
301 fprintf(stderr,
"Digest length mismatch, got %d expected %d\n",mdn,cn);
305 if(memcmp(md,ciphertext,cn))
307 fprintf(stderr,
"Digest mismatch\n");
308 hexdump(stderr,
"Got",md,cn);
309 hexdump(stderr,
"Expected",ciphertext,cn);
322 const char *szTestFile;
327 fprintf(stderr,
"%s <test file>\n",argv[0]);
336 f=fopen(szTestFile,
"r");
346 #ifndef OPENSSL_NO_ENGINE
353 #ifndef OPENSSL_NO_ENGINE
369 unsigned char *iv,*
key,*plaintext,*ciphertext;
373 if(!fgets((
char *)line,
sizeof line,f))
375 if(line[0] ==
'#' || line[0] ==
'\n')
378 cipher=sstrsep(&p,
":");
381 plaintext=ustrsep(&p,
":");
382 ciphertext=ustrsep(&p,
":");
387 encdec = atoi(sstrsep(&p,
"\n"));
393 pn=convert(plaintext);
394 cn=convert(ciphertext);
396 if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec)
397 && !test_digest(cipher,plaintext,pn,ciphertext,cn))
399 #ifdef OPENSSL_NO_AES
400 if (strstr(cipher,
"AES") == cipher)
402 fprintf(stdout,
"Cipher disabled, skipping %s\n", cipher);
406 #ifdef OPENSSL_NO_DES
407 if (strstr(cipher,
"DES") == cipher)
409 fprintf(stdout,
"Cipher disabled, skipping %s\n", cipher);
413 #ifdef OPENSSL_NO_RC4
414 if (strstr(cipher,
"RC4") == cipher)
416 fprintf(stdout,
"Cipher disabled, skipping %s\n", cipher);
420 #ifdef OPENSSL_NO_CAMELLIA
421 if (strstr(cipher,
"CAMELLIA") == cipher)
423 fprintf(stdout,
"Cipher disabled, skipping %s\n", cipher);
427 #ifdef OPENSSL_NO_SEED
428 if (strstr(cipher,
"SEED") == cipher)
430 fprintf(stdout,
"Cipher disabled, skipping %s\n", cipher);
434 fprintf(stderr,
"Can't find %s\n",cipher);
440 #ifndef OPENSSL_NO_ENGINE