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