diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/evp/evptest.c | 620 |
1 files changed, 296 insertions, 324 deletions
diff --git a/src/regress/lib/libcrypto/evp/evptest.c b/src/regress/lib/libcrypto/evp/evptest.c index de1bcce41d..c88bf130cd 100644 --- a/src/regress/lib/libcrypto/evp/evptest.c +++ b/src/regress/lib/libcrypto/evp/evptest.c | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | * are met: | 7 | * are met: |
| 8 | * | 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * | 11 | * |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
| @@ -58,398 +58,370 @@ | |||
| 58 | #include <openssl/err.h> | 58 | #include <openssl/err.h> |
| 59 | #include <openssl/conf.h> | 59 | #include <openssl/conf.h> |
| 60 | 60 | ||
| 61 | static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) | 61 | static void |
| 62 | { | 62 | hexdump(FILE *f, const char *title, const unsigned char *s, int l) |
| 63 | int n=0; | 63 | { |
| 64 | int n = 0; | ||
| 64 | 65 | ||
| 65 | fprintf(f,"%s",title); | 66 | fprintf(f, "%s",title); |
| 66 | for( ; n < l ; ++n) | 67 | for (; n < l; ++n) { |
| 67 | { | 68 | if ((n % 16) == 0) |
| 68 | if((n%16) == 0) | 69 | fprintf(f, "\n%04x",n); |
| 69 | fprintf(f,"\n%04x",n); | 70 | fprintf(f, " %02x",s[n]); |
| 70 | fprintf(f," %02x",s[n]); | ||
| 71 | } | 71 | } |
| 72 | fprintf(f,"\n"); | 72 | fprintf(f, "\n"); |
| 73 | } | 73 | } |
| 74 | |||
| 75 | static int convert(unsigned char *s) | ||
| 76 | { | ||
| 77 | unsigned char *d; | ||
| 78 | |||
| 79 | for(d=s ; *s ; s+=2,++d) | ||
| 80 | { | ||
| 81 | unsigned int n; | ||
| 82 | |||
| 83 | if(!s[1]) | ||
| 84 | { | ||
| 85 | fprintf(stderr,"Odd number of hex digits!"); | ||
| 86 | exit(4); | ||
| 87 | } | ||
| 88 | sscanf((char *)s,"%2x",&n); | ||
| 89 | *d=(unsigned char)n; | ||
| 90 | } | ||
| 91 | return s-d; | ||
| 92 | } | ||
| 93 | |||
| 94 | static char *sstrsep(char **string, const char *delim) | ||
| 95 | { | ||
| 96 | char isdelim[256]; | ||
| 97 | char *token = *string; | ||
| 98 | |||
| 99 | if (**string == 0) | ||
| 100 | return NULL; | ||
| 101 | 74 | ||
| 102 | memset(isdelim, 0, 256); | 75 | static int |
| 103 | isdelim[0] = 1; | 76 | convert(unsigned char *s) |
| 77 | { | ||
| 78 | unsigned char *d; | ||
| 104 | 79 | ||
| 105 | while (*delim) | 80 | for (d = s; *s; s += 2,++d) { |
| 106 | { | 81 | unsigned int n; |
| 107 | isdelim[(unsigned char)(*delim)] = 1; | ||
| 108 | delim++; | ||
| 109 | } | ||
| 110 | 82 | ||
| 111 | while (!isdelim[(unsigned char)(**string)]) | 83 | if (!s[1]) { |
| 112 | { | 84 | fprintf(stderr, "Odd number of hex digits!"); |
| 113 | (*string)++; | 85 | exit(4); |
| 114 | } | 86 | } |
| 87 | sscanf((char *)s, "%2x",&n); | ||
| 88 | *d = (unsigned char)n; | ||
| 89 | } | ||
| 90 | return s - d; | ||
| 91 | } | ||
| 115 | 92 | ||
| 116 | if (**string) | 93 | static char * |
| 117 | { | 94 | sstrsep(char **string, const char *delim) |
| 118 | **string = 0; | 95 | { |
| 119 | (*string)++; | 96 | char isdelim[256]; |
| 120 | } | 97 | char *token = *string; |
| 121 | 98 | ||
| 122 | return token; | 99 | if (**string == 0) |
| 123 | } | 100 | return NULL; |
| 124 | 101 | ||
| 125 | static unsigned char *ustrsep(char **p,const char *sep) | 102 | memset(isdelim, 0, 256); |
| 126 | { return (unsigned char *)sstrsep(p,sep); } | 103 | isdelim[0] = 1; |
| 127 | 104 | ||
| 128 | static int test1_exit(int ec) | 105 | while (*delim) { |
| 129 | { | 106 | isdelim[(unsigned char)(*delim)] = 1; |
| 130 | exit(ec); | 107 | delim++; |
| 131 | return(0); /* To keep some compilers quiet */ | ||
| 132 | } | 108 | } |
| 133 | 109 | ||
| 134 | static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, | 110 | while (!isdelim[(unsigned char)(**string)]) { |
| 135 | const unsigned char *iv,int in, | 111 | (*string)++; |
| 136 | const unsigned char *plaintext,int pn, | ||
| 137 | const unsigned char *ciphertext,int cn, | ||
| 138 | int encdec) | ||
| 139 | { | ||
| 140 | EVP_CIPHER_CTX ctx; | ||
| 141 | unsigned char out[4096]; | ||
| 142 | int outl,outl2; | ||
| 143 | |||
| 144 | printf("Testing cipher %s%s\n",EVP_CIPHER_name(c), | ||
| 145 | (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)"))); | ||
| 146 | hexdump(stdout,"Key",key,kn); | ||
| 147 | if(in) | ||
| 148 | hexdump(stdout,"IV",iv,in); | ||
| 149 | hexdump(stdout,"Plaintext",plaintext,pn); | ||
| 150 | hexdump(stdout,"Ciphertext",ciphertext,cn); | ||
| 151 | |||
| 152 | if(kn != c->key_len) | ||
| 153 | { | ||
| 154 | fprintf(stderr,"Key length doesn't match, got %d expected %lu\n",kn, | ||
| 155 | (unsigned long)c->key_len); | ||
| 156 | test1_exit(5); | ||
| 157 | } | ||
| 158 | EVP_CIPHER_CTX_init(&ctx); | ||
| 159 | if (encdec != 0) | ||
| 160 | { | ||
| 161 | if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) | ||
| 162 | { | ||
| 163 | fprintf(stderr,"EncryptInit failed\n"); | ||
| 164 | ERR_print_errors_fp(stderr); | ||
| 165 | test1_exit(10); | ||
| 166 | } | ||
| 167 | EVP_CIPHER_CTX_set_padding(&ctx,0); | ||
| 168 | |||
| 169 | if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) | ||
| 170 | { | ||
| 171 | fprintf(stderr,"Encrypt failed\n"); | ||
| 172 | ERR_print_errors_fp(stderr); | ||
| 173 | test1_exit(6); | ||
| 174 | } | ||
| 175 | if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) | ||
| 176 | { | ||
| 177 | fprintf(stderr,"EncryptFinal failed\n"); | ||
| 178 | ERR_print_errors_fp(stderr); | ||
| 179 | test1_exit(7); | ||
| 180 | } | ||
| 181 | |||
| 182 | if(outl+outl2 != cn) | ||
| 183 | { | ||
| 184 | fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", | ||
| 185 | outl+outl2,cn); | ||
| 186 | test1_exit(8); | ||
| 187 | } | ||
| 188 | |||
| 189 | if(memcmp(out,ciphertext,cn)) | ||
| 190 | { | ||
| 191 | fprintf(stderr,"Ciphertext mismatch\n"); | ||
| 192 | hexdump(stderr,"Got",out,cn); | ||
| 193 | hexdump(stderr,"Expected",ciphertext,cn); | ||
| 194 | test1_exit(9); | ||
| 195 | } | ||
| 196 | } | 112 | } |
| 197 | 113 | ||
| 198 | if (encdec <= 0) | 114 | if (**string) { |
| 199 | { | 115 | **string = 0; |
| 200 | if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) | 116 | (*string)++; |
| 201 | { | ||
| 202 | fprintf(stderr,"DecryptInit failed\n"); | ||
| 203 | ERR_print_errors_fp(stderr); | ||
| 204 | test1_exit(11); | ||
| 205 | } | ||
| 206 | EVP_CIPHER_CTX_set_padding(&ctx,0); | ||
| 207 | |||
| 208 | if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) | ||
| 209 | { | ||
| 210 | fprintf(stderr,"Decrypt failed\n"); | ||
| 211 | ERR_print_errors_fp(stderr); | ||
| 212 | test1_exit(6); | ||
| 213 | } | ||
| 214 | if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) | ||
| 215 | { | ||
| 216 | fprintf(stderr,"DecryptFinal failed\n"); | ||
| 217 | ERR_print_errors_fp(stderr); | ||
| 218 | test1_exit(7); | ||
| 219 | } | ||
| 220 | |||
| 221 | if(outl+outl2 != pn) | ||
| 222 | { | ||
| 223 | fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", | ||
| 224 | outl+outl2,pn); | ||
| 225 | test1_exit(8); | ||
| 226 | } | ||
| 227 | |||
| 228 | if(memcmp(out,plaintext,pn)) | ||
| 229 | { | ||
| 230 | fprintf(stderr,"Plaintext mismatch\n"); | ||
| 231 | hexdump(stderr,"Got",out,pn); | ||
| 232 | hexdump(stderr,"Expected",plaintext,pn); | ||
| 233 | test1_exit(9); | ||
| 234 | } | ||
| 235 | } | 117 | } |
| 236 | 118 | ||
| 237 | EVP_CIPHER_CTX_cleanup(&ctx); | 119 | return token; |
| 120 | } | ||
| 238 | 121 | ||
| 239 | printf("\n"); | 122 | static unsigned char * |
| 240 | } | 123 | ustrsep(char **p, const char *sep) |
| 124 | { | ||
| 125 | return (unsigned char *)sstrsep(p, sep); | ||
| 126 | } | ||
| 241 | 127 | ||
| 242 | static int test_cipher(const char *cipher,const unsigned char *key,int kn, | 128 | static int |
| 243 | const unsigned char *iv,int in, | 129 | test1_exit(int ec) |
| 244 | const unsigned char *plaintext,int pn, | 130 | { |
| 245 | const unsigned char *ciphertext,int cn, | 131 | exit(ec); |
| 246 | int encdec) | 132 | return(0); /* To keep some compilers quiet */ |
| 247 | { | 133 | } |
| 248 | const EVP_CIPHER *c; | 134 | |
| 135 | static void | ||
| 136 | test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | ||
| 137 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, | ||
| 138 | const unsigned char *ciphertext, int cn, int encdec) | ||
| 139 | { | ||
| 140 | EVP_CIPHER_CTX ctx; | ||
| 141 | unsigned char out[4096]; | ||
| 142 | int outl, outl2; | ||
| 143 | |||
| 144 | printf("Testing cipher %s%s\n", EVP_CIPHER_name(c), | ||
| 145 | (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)"))); | ||
| 146 | hexdump(stdout, "Key",key,kn); | ||
| 147 | if (in) | ||
| 148 | hexdump(stdout, "IV",iv,in); | ||
| 149 | hexdump(stdout, "Plaintext",plaintext,pn); | ||
| 150 | hexdump(stdout, "Ciphertext",ciphertext,cn); | ||
| 151 | |||
| 152 | if (kn != c->key_len) { | ||
| 153 | fprintf(stderr, "Key length doesn't match, got %d expected %lu\n",kn, | ||
| 154 | (unsigned long)c->key_len); | ||
| 155 | test1_exit(5); | ||
| 156 | } | ||
| 157 | EVP_CIPHER_CTX_init(&ctx); | ||
| 158 | if (encdec != 0) { | ||
| 159 | if (!EVP_EncryptInit_ex(&ctx, c,NULL, key, iv)) { | ||
| 160 | fprintf(stderr, "EncryptInit failed\n"); | ||
| 161 | ERR_print_errors_fp(stderr); | ||
| 162 | test1_exit(10); | ||
| 163 | } | ||
| 164 | EVP_CIPHER_CTX_set_padding(&ctx, 0); | ||
| 249 | 165 | ||
| 250 | c=EVP_get_cipherbyname(cipher); | 166 | if (!EVP_EncryptUpdate(&ctx, out, &outl, plaintext, pn)) { |
| 251 | if(!c) | 167 | fprintf(stderr, "Encrypt failed\n"); |
| 252 | return 0; | 168 | ERR_print_errors_fp(stderr); |
| 169 | test1_exit(6); | ||
| 170 | } | ||
| 171 | if (!EVP_EncryptFinal_ex(&ctx, out + outl, &outl2)) { | ||
| 172 | fprintf(stderr, "EncryptFinal failed\n"); | ||
| 173 | ERR_print_errors_fp(stderr); | ||
| 174 | test1_exit(7); | ||
| 175 | } | ||
| 253 | 176 | ||
| 254 | test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec); | 177 | if (outl + outl2 != cn) { |
| 178 | fprintf(stderr, "Ciphertext length mismatch got %d expected %d\n", | ||
| 179 | outl + outl2, cn); | ||
| 180 | test1_exit(8); | ||
| 181 | } | ||
| 182 | |||
| 183 | if (memcmp(out, ciphertext, cn)) { | ||
| 184 | fprintf(stderr, "Ciphertext mismatch\n"); | ||
| 185 | hexdump(stderr, "Got",out,cn); | ||
| 186 | hexdump(stderr, "Expected",ciphertext,cn); | ||
| 187 | test1_exit(9); | ||
| 188 | } | ||
| 189 | } | ||
| 255 | 190 | ||
| 256 | return 1; | 191 | if (encdec <= 0) { |
| 257 | } | 192 | if (!EVP_DecryptInit_ex(&ctx, c,NULL, key, iv)) { |
| 193 | fprintf(stderr, "DecryptInit failed\n"); | ||
| 194 | ERR_print_errors_fp(stderr); | ||
| 195 | test1_exit(11); | ||
| 196 | } | ||
| 197 | EVP_CIPHER_CTX_set_padding(&ctx, 0); | ||
| 258 | 198 | ||
| 259 | static int test_digest(const char *digest, | 199 | if (!EVP_DecryptUpdate(&ctx, out, &outl, ciphertext, cn)) { |
| 260 | const unsigned char *plaintext,int pn, | 200 | fprintf(stderr, "Decrypt failed\n"); |
| 261 | const unsigned char *ciphertext, unsigned int cn) | 201 | ERR_print_errors_fp(stderr); |
| 262 | { | 202 | test1_exit(6); |
| 263 | const EVP_MD *d; | 203 | } |
| 264 | EVP_MD_CTX ctx; | 204 | if (!EVP_DecryptFinal_ex(&ctx, out + outl, &outl2)) { |
| 265 | unsigned char md[EVP_MAX_MD_SIZE]; | 205 | fprintf(stderr, "DecryptFinal failed\n"); |
| 266 | unsigned int mdn; | 206 | ERR_print_errors_fp(stderr); |
| 207 | test1_exit(7); | ||
| 208 | } | ||
| 267 | 209 | ||
| 268 | d=EVP_get_digestbyname(digest); | 210 | if (outl + outl2 != pn) { |
| 269 | if(!d) | 211 | fprintf(stderr, "Plaintext length mismatch got %d expected %d\n", |
| 270 | return 0; | 212 | outl + outl2, pn); |
| 213 | test1_exit(8); | ||
| 214 | } | ||
| 271 | 215 | ||
| 272 | printf("Testing digest %s\n",EVP_MD_name(d)); | 216 | if (memcmp(out, plaintext, pn)) { |
| 273 | hexdump(stdout,"Plaintext",plaintext,pn); | 217 | fprintf(stderr, "Plaintext mismatch\n"); |
| 274 | hexdump(stdout,"Digest",ciphertext,cn); | 218 | hexdump(stderr, "Got",out,pn); |
| 219 | hexdump(stderr, "Expected",plaintext,pn); | ||
| 220 | test1_exit(9); | ||
| 221 | } | ||
| 222 | } | ||
| 275 | 223 | ||
| 276 | EVP_MD_CTX_init(&ctx); | 224 | EVP_CIPHER_CTX_cleanup(&ctx); |
| 277 | if(!EVP_DigestInit_ex(&ctx,d, NULL)) | 225 | |
| 278 | { | 226 | printf("\n"); |
| 279 | fprintf(stderr,"DigestInit failed\n"); | 227 | } |
| 280 | ERR_print_errors_fp(stderr); | 228 | |
| 281 | exit(100); | 229 | static int |
| 230 | test_cipher(const char *cipher, const unsigned char *key, int kn, | ||
| 231 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, | ||
| 232 | const unsigned char *ciphertext, int cn, int encdec) | ||
| 233 | { | ||
| 234 | const EVP_CIPHER *c; | ||
| 235 | |||
| 236 | c = EVP_get_cipherbyname(cipher); | ||
| 237 | if (!c) | ||
| 238 | return 0; | ||
| 239 | |||
| 240 | test1(c, key, kn, iv, in, plaintext, pn, ciphertext, cn, encdec); | ||
| 241 | |||
| 242 | return 1; | ||
| 243 | } | ||
| 244 | |||
| 245 | static int | ||
| 246 | test_digest(const char *digest, const unsigned char *plaintext, int pn, | ||
| 247 | const unsigned char *ciphertext, unsigned int cn) | ||
| 248 | { | ||
| 249 | const EVP_MD *d; | ||
| 250 | EVP_MD_CTX ctx; | ||
| 251 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
| 252 | unsigned int mdn; | ||
| 253 | |||
| 254 | d = EVP_get_digestbyname(digest); | ||
| 255 | if (!d) | ||
| 256 | return 0; | ||
| 257 | |||
| 258 | printf("Testing digest %s\n",EVP_MD_name(d)); | ||
| 259 | hexdump(stdout, "Plaintext",plaintext,pn); | ||
| 260 | hexdump(stdout, "Digest",ciphertext,cn); | ||
| 261 | |||
| 262 | EVP_MD_CTX_init(&ctx); | ||
| 263 | if (!EVP_DigestInit_ex(&ctx, d, NULL)) { | ||
| 264 | fprintf(stderr, "DigestInit failed\n"); | ||
| 265 | ERR_print_errors_fp(stderr); | ||
| 266 | exit(100); | ||
| 282 | } | 267 | } |
| 283 | if(!EVP_DigestUpdate(&ctx,plaintext,pn)) | 268 | if (!EVP_DigestUpdate(&ctx, plaintext, pn)) { |
| 284 | { | 269 | fprintf(stderr, "DigestUpdate failed\n"); |
| 285 | fprintf(stderr,"DigestUpdate failed\n"); | 270 | ERR_print_errors_fp(stderr); |
| 286 | ERR_print_errors_fp(stderr); | 271 | exit(101); |
| 287 | exit(101); | ||
| 288 | } | 272 | } |
| 289 | if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) | 273 | if (!EVP_DigestFinal_ex(&ctx, md, &mdn)) { |
| 290 | { | 274 | fprintf(stderr, "DigestFinal failed\n"); |
| 291 | fprintf(stderr,"DigestFinal failed\n"); | 275 | ERR_print_errors_fp(stderr); |
| 292 | ERR_print_errors_fp(stderr); | 276 | exit(101); |
| 293 | exit(101); | ||
| 294 | } | 277 | } |
| 295 | EVP_MD_CTX_cleanup(&ctx); | 278 | EVP_MD_CTX_cleanup(&ctx); |
| 296 | 279 | ||
| 297 | if(mdn != cn) | 280 | if (mdn != cn) { |
| 298 | { | 281 | fprintf(stderr, "Digest length mismatch, got %d expected %d\n",mdn,cn); |
| 299 | fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); | 282 | exit(102); |
| 300 | exit(102); | ||
| 301 | } | 283 | } |
| 302 | 284 | ||
| 303 | if(memcmp(md,ciphertext,cn)) | 285 | if (memcmp(md, ciphertext, cn)) { |
| 304 | { | 286 | fprintf(stderr, "Digest mismatch\n"); |
| 305 | fprintf(stderr,"Digest mismatch\n"); | 287 | hexdump(stderr, "Got",md,cn); |
| 306 | hexdump(stderr,"Got",md,cn); | 288 | hexdump(stderr, "Expected",ciphertext,cn); |
| 307 | hexdump(stderr,"Expected",ciphertext,cn); | 289 | exit(103); |
| 308 | exit(103); | ||
| 309 | } | 290 | } |
| 310 | 291 | ||
| 311 | printf("\n"); | 292 | printf("\n"); |
| 312 | 293 | ||
| 313 | EVP_MD_CTX_cleanup(&ctx); | 294 | EVP_MD_CTX_cleanup(&ctx); |
| 314 | 295 | ||
| 315 | return 1; | 296 | return 1; |
| 316 | } | 297 | } |
| 317 | 298 | ||
| 318 | int main(int argc,char **argv) | 299 | int |
| 319 | { | 300 | main(int argc, char **argv) |
| 320 | const char *szTestFile; | 301 | { |
| 321 | FILE *f; | 302 | const char *szTestFile; |
| 303 | FILE *f; | ||
| 322 | 304 | ||
| 323 | if(argc != 2) | 305 | if (argc != 2) { |
| 324 | { | 306 | fprintf(stderr, "%s <test file>\n",argv[0]); |
| 325 | fprintf(stderr,"%s <test file>\n",argv[0]); | 307 | exit(1); |
| 326 | exit(1); | ||
| 327 | } | 308 | } |
| 328 | CRYPTO_malloc_debug_init(); | 309 | CRYPTO_malloc_debug_init(); |
| 329 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); | 310 | CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); |
| 330 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | 311 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); |
| 331 | 312 | ||
| 332 | szTestFile=argv[1]; | 313 | szTestFile = argv[1]; |
| 333 | 314 | ||
| 334 | f=fopen(szTestFile,"r"); | 315 | f=fopen(szTestFile, "r"); |
| 335 | if(!f) | 316 | if (!f) { |
| 336 | { | 317 | perror(szTestFile); |
| 337 | perror(szTestFile); | 318 | exit(2); |
| 338 | exit(2); | ||
| 339 | } | 319 | } |
| 340 | 320 | ||
| 341 | /* Load up the software EVP_CIPHER and EVP_MD definitions */ | 321 | /* Load up the software EVP_CIPHER and EVP_MD definitions */ |
| 342 | OpenSSL_add_all_ciphers(); | 322 | OpenSSL_add_all_ciphers(); |
| 343 | OpenSSL_add_all_digests(); | 323 | OpenSSL_add_all_digests(); |
| 344 | #ifndef OPENSSL_NO_ENGINE | 324 | #ifndef OPENSSL_NO_ENGINE |
| 345 | /* Load all compiled-in ENGINEs */ | 325 | /* Load all compiled-in ENGINEs */ |
| 346 | ENGINE_load_builtin_engines(); | 326 | ENGINE_load_builtin_engines(); |
| 347 | #endif | 327 | #endif |
| 348 | #if 0 | 328 | #if 0 |
| 349 | OPENSSL_config(); | 329 | OPENSSL_config(); |
| 350 | #endif | 330 | #endif |
| 351 | #ifndef OPENSSL_NO_ENGINE | 331 | #ifndef OPENSSL_NO_ENGINE |
| 352 | /* Register all available ENGINE implementations of ciphers and digests. | 332 | /* Register all available ENGINE implementations of ciphers and digests. |
| 353 | * This could perhaps be changed to "ENGINE_register_all_complete()"? */ | 333 | * This could perhaps be changed to "ENGINE_register_all_complete()"? */ |
| 354 | ENGINE_register_all_ciphers(); | 334 | ENGINE_register_all_ciphers(); |
| 355 | ENGINE_register_all_digests(); | 335 | ENGINE_register_all_digests(); |
| 356 | /* If we add command-line options, this statement should be switchable. | 336 | /* If we add command-line options, this statement should be switchable. |
| 357 | * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if | 337 | * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if |
| 358 | * they weren't already initialised. */ | 338 | * they weren't already initialised. */ |
| 359 | /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ | 339 | /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ |
| 360 | #endif | 340 | #endif |
| 361 | 341 | ||
| 362 | for( ; ; ) | 342 | for (;;) { |
| 363 | { | 343 | char line[4096]; |
| 364 | char line[4096]; | 344 | char *p; |
| 365 | char *p; | 345 | char *cipher; |
| 366 | char *cipher; | 346 | unsigned char *iv, *key, *plaintext, *ciphertext; |
| 367 | unsigned char *iv,*key,*plaintext,*ciphertext; | 347 | int encdec; |
| 368 | int encdec; | 348 | int kn, in, pn, cn; |
| 369 | int kn,in,pn,cn; | 349 | |
| 370 | 350 | if (!fgets((char *)line, sizeof line, f)) | |
| 371 | if(!fgets((char *)line,sizeof line,f)) | 351 | break; |
| 372 | break; | 352 | if (line[0] == '#' || line[0] == '\n') |
| 373 | if(line[0] == '#' || line[0] == '\n') | 353 | continue; |
| 374 | continue; | 354 | p = line; |
| 375 | p=line; | 355 | cipher=sstrsep(&p, ":"); |
| 376 | cipher=sstrsep(&p,":"); | 356 | key=ustrsep(&p, ":"); |
| 377 | key=ustrsep(&p,":"); | 357 | iv=ustrsep(&p, ":"); |
| 378 | iv=ustrsep(&p,":"); | 358 | plaintext=ustrsep(&p, ":"); |
| 379 | plaintext=ustrsep(&p,":"); | 359 | ciphertext=ustrsep(&p, ":"); |
| 380 | ciphertext=ustrsep(&p,":"); | 360 | if (p[-1] == '\n') { |
| 381 | if (p[-1] == '\n') { | 361 | p[-1] = '\0'; |
| 382 | p[-1] = '\0'; | 362 | encdec = -1; |
| 383 | encdec = -1; | 363 | } else { |
| 384 | } else { | 364 | encdec = atoi(sstrsep(&p, "\n")); |
| 385 | encdec = atoi(sstrsep(&p,"\n")); | 365 | } |
| 386 | } | 366 | |
| 387 | |||
| 388 | 367 | ||
| 389 | kn=convert(key); | 368 | kn = convert(key); |
| 390 | in=convert(iv); | 369 | in = convert(iv); |
| 391 | pn=convert(plaintext); | 370 | pn = convert(plaintext); |
| 392 | cn=convert(ciphertext); | 371 | cn = convert(ciphertext); |
| 393 | 372 | ||
| 394 | if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec) | 373 | if (!test_cipher(cipher, key, kn, iv, in, plaintext, pn, ciphertext, cn, encdec) && |
| 395 | && !test_digest(cipher,plaintext,pn,ciphertext,cn)) | 374 | !test_digest(cipher, plaintext, pn, ciphertext, cn)) { |
| 396 | { | ||
| 397 | #ifdef OPENSSL_NO_AES | 375 | #ifdef OPENSSL_NO_AES |
| 398 | if (strstr(cipher, "AES") == cipher) | 376 | if (strstr(cipher, "AES") == cipher) { |
| 399 | { | 377 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); |
| 400 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | 378 | continue; |
| 401 | continue; | 379 | } |
| 402 | } | ||
| 403 | #endif | 380 | #endif |
| 404 | #ifdef OPENSSL_NO_DES | 381 | #ifdef OPENSSL_NO_DES |
| 405 | if (strstr(cipher, "DES") == cipher) | 382 | if (strstr(cipher, "DES") == cipher) { |
| 406 | { | 383 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); |
| 407 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | 384 | continue; |
| 408 | continue; | 385 | } |
| 409 | } | ||
| 410 | #endif | 386 | #endif |
| 411 | #ifdef OPENSSL_NO_RC4 | 387 | #ifdef OPENSSL_NO_RC4 |
| 412 | if (strstr(cipher, "RC4") == cipher) | 388 | if (strstr(cipher, "RC4") == cipher) { |
| 413 | { | 389 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); |
| 414 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | 390 | continue; |
| 415 | continue; | 391 | } |
| 416 | } | ||
| 417 | #endif | 392 | #endif |
| 418 | #ifdef OPENSSL_NO_CAMELLIA | 393 | #ifdef OPENSSL_NO_CAMELLIA |
| 419 | if (strstr(cipher, "CAMELLIA") == cipher) | 394 | if (strstr(cipher, "CAMELLIA") == cipher) { |
| 420 | { | 395 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); |
| 421 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | 396 | continue; |
| 422 | continue; | 397 | } |
| 423 | } | ||
| 424 | #endif | 398 | #endif |
| 425 | #ifdef OPENSSL_NO_SEED | 399 | #ifdef OPENSSL_NO_SEED |
| 426 | if (strstr(cipher, "SEED") == cipher) | 400 | if (strstr(cipher, "SEED") == cipher) { |
| 427 | { | 401 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); |
| 428 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | 402 | continue; |
| 429 | continue; | 403 | } |
| 430 | } | ||
| 431 | #endif | 404 | #endif |
| 432 | #ifdef OPENSSL_NO_CHACHA | 405 | #ifdef OPENSSL_NO_CHACHA |
| 433 | if (strstr(cipher, "ChaCha") == cipher) | 406 | if (strstr(cipher, "ChaCha") == cipher) { |
| 434 | { | 407 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); |
| 435 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | 408 | continue; |
| 436 | continue; | 409 | } |
| 437 | } | ||
| 438 | #endif | 410 | #endif |
| 439 | fprintf(stderr,"Can't find %s\n",cipher); | 411 | fprintf(stderr, "Can't find %s\n",cipher); |
| 440 | exit(3); | 412 | exit(3); |
| 441 | } | 413 | } |
| 442 | } | 414 | } |
| 443 | fclose(f); | 415 | fclose(f); |
| 444 | 416 | ||
| 445 | #ifndef OPENSSL_NO_ENGINE | 417 | #ifndef OPENSSL_NO_ENGINE |
| 446 | ENGINE_cleanup(); | 418 | ENGINE_cleanup(); |
| 447 | #endif | 419 | #endif |
| 448 | EVP_cleanup(); | 420 | EVP_cleanup(); |
| 449 | CRYPTO_cleanup_all_ex_data(); | 421 | CRYPTO_cleanup_all_ex_data(); |
| 450 | ERR_remove_thread_state(NULL); | 422 | ERR_remove_thread_state(NULL); |
| 451 | ERR_free_strings(); | 423 | ERR_free_strings(); |
| 452 | CRYPTO_mem_leaks_fp(stderr); | 424 | CRYPTO_mem_leaks_fp(stderr); |
| 453 | 425 | ||
| 454 | return 0; | 426 | return 0; |
| 455 | } | 427 | } |
