summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/evp_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/evp_test.c')
-rw-r--r--src/lib/libcrypto/evp/evp_test.c34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c
index a624cfd248..28460173f7 100644
--- a/src/lib/libcrypto/evp/evp_test.c
+++ b/src/lib/libcrypto/evp/evp_test.c
@@ -136,7 +136,7 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
136 const unsigned char *iv,int in, 136 const unsigned char *iv,int in,
137 const unsigned char *plaintext,int pn, 137 const unsigned char *plaintext,int pn,
138 const unsigned char *ciphertext,int cn, 138 const unsigned char *ciphertext,int cn,
139 int encdec,int multiplier) 139 int encdec)
140 { 140 {
141 EVP_CIPHER_CTX ctx; 141 EVP_CIPHER_CTX ctx;
142 unsigned char out[4096]; 142 unsigned char out[4096];
@@ -162,25 +162,22 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
162 if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) 162 if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv))
163 { 163 {
164 fprintf(stderr,"EncryptInit failed\n"); 164 fprintf(stderr,"EncryptInit failed\n");
165 ERR_print_errors_fp(stderr);
166 test1_exit(10); 165 test1_exit(10);
167 } 166 }
168 EVP_CIPHER_CTX_set_padding(&ctx,0); 167 EVP_CIPHER_CTX_set_padding(&ctx,0);
169 168
170 if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn*multiplier)) 169 if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn))
171 { 170 {
172 fprintf(stderr,"Encrypt failed\n"); 171 fprintf(stderr,"Encrypt failed\n");
173 ERR_print_errors_fp(stderr);
174 test1_exit(6); 172 test1_exit(6);
175 } 173 }
176 if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) 174 if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2))
177 { 175 {
178 fprintf(stderr,"EncryptFinal failed\n"); 176 fprintf(stderr,"EncryptFinal failed\n");
179 ERR_print_errors_fp(stderr);
180 test1_exit(7); 177 test1_exit(7);
181 } 178 }
182 179
183 if(outl+outl2 != cn*multiplier) 180 if(outl+outl2 != cn)
184 { 181 {
185 fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", 182 fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n",
186 outl+outl2,cn); 183 outl+outl2,cn);
@@ -201,25 +198,22 @@ static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
201 if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) 198 if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv))
202 { 199 {
203 fprintf(stderr,"DecryptInit failed\n"); 200 fprintf(stderr,"DecryptInit failed\n");
204 ERR_print_errors_fp(stderr);
205 test1_exit(11); 201 test1_exit(11);
206 } 202 }
207 EVP_CIPHER_CTX_set_padding(&ctx,0); 203 EVP_CIPHER_CTX_set_padding(&ctx,0);
208 204
209 if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn*multiplier)) 205 if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn))
210 { 206 {
211 fprintf(stderr,"Decrypt failed\n"); 207 fprintf(stderr,"Decrypt failed\n");
212 ERR_print_errors_fp(stderr);
213 test1_exit(6); 208 test1_exit(6);
214 } 209 }
215 if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) 210 if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2))
216 { 211 {
217 fprintf(stderr,"DecryptFinal failed\n"); 212 fprintf(stderr,"DecryptFinal failed\n");
218 ERR_print_errors_fp(stderr);
219 test1_exit(7); 213 test1_exit(7);
220 } 214 }
221 215
222 if(outl+outl2 != cn*multiplier) 216 if(outl+outl2 != cn)
223 { 217 {
224 fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", 218 fprintf(stderr,"Plaintext length mismatch got %d expected %d\n",
225 outl+outl2,cn); 219 outl+outl2,cn);
@@ -244,7 +238,7 @@ static int test_cipher(const char *cipher,const unsigned char *key,int kn,
244 const unsigned char *iv,int in, 238 const unsigned char *iv,int in,
245 const unsigned char *plaintext,int pn, 239 const unsigned char *plaintext,int pn,
246 const unsigned char *ciphertext,int cn, 240 const unsigned char *ciphertext,int cn,
247 int encdec,int multiplier) 241 int encdec)
248 { 242 {
249 const EVP_CIPHER *c; 243 const EVP_CIPHER *c;
250 244
@@ -252,7 +246,7 @@ static int test_cipher(const char *cipher,const unsigned char *key,int kn,
252 if(!c) 246 if(!c)
253 return 0; 247 return 0;
254 248
255 test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec,multiplier); 249 test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec);
256 250
257 return 1; 251 return 1;
258 } 252 }
@@ -278,19 +272,16 @@ static int test_digest(const char *digest,
278 if(!EVP_DigestInit_ex(&ctx,d, NULL)) 272 if(!EVP_DigestInit_ex(&ctx,d, NULL))
279 { 273 {
280 fprintf(stderr,"DigestInit failed\n"); 274 fprintf(stderr,"DigestInit failed\n");
281 ERR_print_errors_fp(stderr);
282 EXIT(100); 275 EXIT(100);
283 } 276 }
284 if(!EVP_DigestUpdate(&ctx,plaintext,pn)) 277 if(!EVP_DigestUpdate(&ctx,plaintext,pn))
285 { 278 {
286 fprintf(stderr,"DigestUpdate failed\n"); 279 fprintf(stderr,"DigestUpdate failed\n");
287 ERR_print_errors_fp(stderr);
288 EXIT(101); 280 EXIT(101);
289 } 281 }
290 if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) 282 if(!EVP_DigestFinal_ex(&ctx,md,&mdn))
291 { 283 {
292 fprintf(stderr,"DigestFinal failed\n"); 284 fprintf(stderr,"DigestFinal failed\n");
293 ERR_print_errors_fp(stderr);
294 EXIT(101); 285 EXIT(101);
295 } 286 }
296 EVP_MD_CTX_cleanup(&ctx); 287 EVP_MD_CTX_cleanup(&ctx);
@@ -368,7 +359,6 @@ int main(int argc,char **argv)
368 unsigned char *iv,*key,*plaintext,*ciphertext; 359 unsigned char *iv,*key,*plaintext,*ciphertext;
369 int encdec; 360 int encdec;
370 int kn,in,pn,cn; 361 int kn,in,pn,cn;
371 int multiplier=1;
372 362
373 if(!fgets((char *)line,sizeof line,f)) 363 if(!fgets((char *)line,sizeof line,f))
374 break; 364 break;
@@ -393,15 +383,7 @@ int main(int argc,char **argv)
393 pn=convert(plaintext); 383 pn=convert(plaintext);
394 cn=convert(ciphertext); 384 cn=convert(ciphertext);
395 385
396 if(strchr(cipher,'*')) 386 if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec)
397 {
398 p=cipher;
399 sstrsep(&p,"*");
400 multiplier=atoi(sstrsep(&p,"*"));
401 }
402
403 if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec,
404 multiplier)
405 && !test_digest(cipher,plaintext,pn,ciphertext,cn)) 387 && !test_digest(cipher,plaintext,pn,ciphertext,cn))
406 { 388 {
407 fprintf(stderr,"Can't find %s\n",cipher); 389 fprintf(stderr,"Can't find %s\n",cipher);