1*0Sstevel@tonic-gate /* Written by Ben Laurie, 2001 */ 2*0Sstevel@tonic-gate /* 3*0Sstevel@tonic-gate * Copyright (c) 2001 The OpenSSL Project. All rights reserved. 4*0Sstevel@tonic-gate * 5*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 6*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions 7*0Sstevel@tonic-gate * are met: 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 10*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 11*0Sstevel@tonic-gate * 12*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 13*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in 14*0Sstevel@tonic-gate * the documentation and/or other materials provided with the 15*0Sstevel@tonic-gate * distribution. 16*0Sstevel@tonic-gate * 17*0Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this 18*0Sstevel@tonic-gate * software must display the following acknowledgment: 19*0Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 20*0Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21*0Sstevel@tonic-gate * 22*0Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23*0Sstevel@tonic-gate * endorse or promote products derived from this software without 24*0Sstevel@tonic-gate * prior written permission. For written permission, please contact 25*0Sstevel@tonic-gate * openssl-core@openssl.org. 26*0Sstevel@tonic-gate * 27*0Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL" 28*0Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written 29*0Sstevel@tonic-gate * permission of the OpenSSL Project. 30*0Sstevel@tonic-gate * 31*0Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following 32*0Sstevel@tonic-gate * acknowledgment: 33*0Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project 34*0Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35*0Sstevel@tonic-gate * 36*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37*0Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38*0Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39*0Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40*0Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41*0Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42*0Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43*0Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44*0Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45*0Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46*0Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47*0Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE. 48*0Sstevel@tonic-gate */ 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate #include <stdio.h> 51*0Sstevel@tonic-gate #include <string.h> 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate #include "../e_os.h" 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate #include <openssl/evp.h> 56*0Sstevel@tonic-gate #ifndef OPENSSL_NO_ENGINE 57*0Sstevel@tonic-gate #include <openssl/engine.h> 58*0Sstevel@tonic-gate #endif 59*0Sstevel@tonic-gate #include <openssl/err.h> 60*0Sstevel@tonic-gate #include <openssl/conf.h> 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) 63*0Sstevel@tonic-gate { 64*0Sstevel@tonic-gate int n=0; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate fprintf(f,"%s",title); 67*0Sstevel@tonic-gate for( ; n < l ; ++n) 68*0Sstevel@tonic-gate { 69*0Sstevel@tonic-gate if((n%16) == 0) 70*0Sstevel@tonic-gate fprintf(f,"\n%04x",n); 71*0Sstevel@tonic-gate fprintf(f," %02x",s[n]); 72*0Sstevel@tonic-gate } 73*0Sstevel@tonic-gate fprintf(f,"\n"); 74*0Sstevel@tonic-gate } 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate static int convert(unsigned char *s) 77*0Sstevel@tonic-gate { 78*0Sstevel@tonic-gate unsigned char *d; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate for(d=s ; *s ; s+=2,++d) 81*0Sstevel@tonic-gate { 82*0Sstevel@tonic-gate unsigned int n; 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate if(!s[1]) 85*0Sstevel@tonic-gate { 86*0Sstevel@tonic-gate fprintf(stderr,"Odd number of hex digits!"); 87*0Sstevel@tonic-gate EXIT(4); 88*0Sstevel@tonic-gate } 89*0Sstevel@tonic-gate sscanf((char *)s,"%2x",&n); 90*0Sstevel@tonic-gate *d=(unsigned char)n; 91*0Sstevel@tonic-gate } 92*0Sstevel@tonic-gate return s-d; 93*0Sstevel@tonic-gate } 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate static char *sstrsep(char **string, const char *delim) 96*0Sstevel@tonic-gate { 97*0Sstevel@tonic-gate char isdelim[256]; 98*0Sstevel@tonic-gate char *token = *string; 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate if (**string == 0) 101*0Sstevel@tonic-gate return NULL; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate memset(isdelim, 0, 256); 104*0Sstevel@tonic-gate isdelim[0] = 1; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate while (*delim) 107*0Sstevel@tonic-gate { 108*0Sstevel@tonic-gate isdelim[(unsigned char)(*delim)] = 1; 109*0Sstevel@tonic-gate delim++; 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate while (!isdelim[(unsigned char)(**string)]) 113*0Sstevel@tonic-gate { 114*0Sstevel@tonic-gate (*string)++; 115*0Sstevel@tonic-gate } 116*0Sstevel@tonic-gate 117*0Sstevel@tonic-gate if (**string) 118*0Sstevel@tonic-gate { 119*0Sstevel@tonic-gate **string = 0; 120*0Sstevel@tonic-gate (*string)++; 121*0Sstevel@tonic-gate } 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate return token; 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate static unsigned char *ustrsep(char **p,const char *sep) 127*0Sstevel@tonic-gate { return (unsigned char *)sstrsep(p,sep); } 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate static int test1_exit(int ec) 130*0Sstevel@tonic-gate { 131*0Sstevel@tonic-gate EXIT(ec); 132*0Sstevel@tonic-gate return(0); /* To keep some compilers quiet */ 133*0Sstevel@tonic-gate } 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn, 136*0Sstevel@tonic-gate const unsigned char *iv,int in, 137*0Sstevel@tonic-gate const unsigned char *plaintext,int pn, 138*0Sstevel@tonic-gate const unsigned char *ciphertext,int cn, 139*0Sstevel@tonic-gate int encdec) 140*0Sstevel@tonic-gate { 141*0Sstevel@tonic-gate EVP_CIPHER_CTX ctx; 142*0Sstevel@tonic-gate unsigned char out[4096]; 143*0Sstevel@tonic-gate int outl,outl2; 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate printf("Testing cipher %s%s\n",EVP_CIPHER_name(c), 146*0Sstevel@tonic-gate (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)"))); 147*0Sstevel@tonic-gate hexdump(stdout,"Key",key,kn); 148*0Sstevel@tonic-gate if(in) 149*0Sstevel@tonic-gate hexdump(stdout,"IV",iv,in); 150*0Sstevel@tonic-gate hexdump(stdout,"Plaintext",plaintext,pn); 151*0Sstevel@tonic-gate hexdump(stdout,"Ciphertext",ciphertext,cn); 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate if(kn != c->key_len) 154*0Sstevel@tonic-gate { 155*0Sstevel@tonic-gate fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn, 156*0Sstevel@tonic-gate c->key_len); 157*0Sstevel@tonic-gate test1_exit(5); 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate EVP_CIPHER_CTX_init(&ctx); 160*0Sstevel@tonic-gate if (encdec != 0) 161*0Sstevel@tonic-gate { 162*0Sstevel@tonic-gate if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv)) 163*0Sstevel@tonic-gate { 164*0Sstevel@tonic-gate fprintf(stderr,"EncryptInit failed\n"); 165*0Sstevel@tonic-gate test1_exit(10); 166*0Sstevel@tonic-gate } 167*0Sstevel@tonic-gate EVP_CIPHER_CTX_set_padding(&ctx,0); 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn)) 170*0Sstevel@tonic-gate { 171*0Sstevel@tonic-gate fprintf(stderr,"Encrypt failed\n"); 172*0Sstevel@tonic-gate test1_exit(6); 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2)) 175*0Sstevel@tonic-gate { 176*0Sstevel@tonic-gate fprintf(stderr,"EncryptFinal failed\n"); 177*0Sstevel@tonic-gate test1_exit(7); 178*0Sstevel@tonic-gate } 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate if(outl+outl2 != cn) 181*0Sstevel@tonic-gate { 182*0Sstevel@tonic-gate fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n", 183*0Sstevel@tonic-gate outl+outl2,cn); 184*0Sstevel@tonic-gate test1_exit(8); 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate if(memcmp(out,ciphertext,cn)) 188*0Sstevel@tonic-gate { 189*0Sstevel@tonic-gate fprintf(stderr,"Ciphertext mismatch\n"); 190*0Sstevel@tonic-gate hexdump(stderr,"Got",out,cn); 191*0Sstevel@tonic-gate hexdump(stderr,"Expected",ciphertext,cn); 192*0Sstevel@tonic-gate test1_exit(9); 193*0Sstevel@tonic-gate } 194*0Sstevel@tonic-gate } 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate if (encdec <= 0) 197*0Sstevel@tonic-gate { 198*0Sstevel@tonic-gate if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv)) 199*0Sstevel@tonic-gate { 200*0Sstevel@tonic-gate fprintf(stderr,"DecryptInit failed\n"); 201*0Sstevel@tonic-gate test1_exit(11); 202*0Sstevel@tonic-gate } 203*0Sstevel@tonic-gate EVP_CIPHER_CTX_set_padding(&ctx,0); 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn)) 206*0Sstevel@tonic-gate { 207*0Sstevel@tonic-gate fprintf(stderr,"Decrypt failed\n"); 208*0Sstevel@tonic-gate test1_exit(6); 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2)) 211*0Sstevel@tonic-gate { 212*0Sstevel@tonic-gate fprintf(stderr,"DecryptFinal failed\n"); 213*0Sstevel@tonic-gate test1_exit(7); 214*0Sstevel@tonic-gate } 215*0Sstevel@tonic-gate 216*0Sstevel@tonic-gate if(outl+outl2 != cn) 217*0Sstevel@tonic-gate { 218*0Sstevel@tonic-gate fprintf(stderr,"Plaintext length mismatch got %d expected %d\n", 219*0Sstevel@tonic-gate outl+outl2,cn); 220*0Sstevel@tonic-gate test1_exit(8); 221*0Sstevel@tonic-gate } 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate if(memcmp(out,plaintext,cn)) 224*0Sstevel@tonic-gate { 225*0Sstevel@tonic-gate fprintf(stderr,"Plaintext mismatch\n"); 226*0Sstevel@tonic-gate hexdump(stderr,"Got",out,cn); 227*0Sstevel@tonic-gate hexdump(stderr,"Expected",plaintext,cn); 228*0Sstevel@tonic-gate test1_exit(9); 229*0Sstevel@tonic-gate } 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate EVP_CIPHER_CTX_cleanup(&ctx); 233*0Sstevel@tonic-gate 234*0Sstevel@tonic-gate printf("\n"); 235*0Sstevel@tonic-gate } 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate static int test_cipher(const char *cipher,const unsigned char *key,int kn, 238*0Sstevel@tonic-gate const unsigned char *iv,int in, 239*0Sstevel@tonic-gate const unsigned char *plaintext,int pn, 240*0Sstevel@tonic-gate const unsigned char *ciphertext,int cn, 241*0Sstevel@tonic-gate int encdec) 242*0Sstevel@tonic-gate { 243*0Sstevel@tonic-gate const EVP_CIPHER *c; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate c=EVP_get_cipherbyname(cipher); 246*0Sstevel@tonic-gate if(!c) 247*0Sstevel@tonic-gate return 0; 248*0Sstevel@tonic-gate 249*0Sstevel@tonic-gate test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec); 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate return 1; 252*0Sstevel@tonic-gate } 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate static int test_digest(const char *digest, 255*0Sstevel@tonic-gate const unsigned char *plaintext,int pn, 256*0Sstevel@tonic-gate const unsigned char *ciphertext, unsigned int cn) 257*0Sstevel@tonic-gate { 258*0Sstevel@tonic-gate const EVP_MD *d; 259*0Sstevel@tonic-gate EVP_MD_CTX ctx; 260*0Sstevel@tonic-gate unsigned char md[EVP_MAX_MD_SIZE]; 261*0Sstevel@tonic-gate unsigned int mdn; 262*0Sstevel@tonic-gate 263*0Sstevel@tonic-gate d=EVP_get_digestbyname(digest); 264*0Sstevel@tonic-gate if(!d) 265*0Sstevel@tonic-gate return 0; 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate printf("Testing digest %s\n",EVP_MD_name(d)); 268*0Sstevel@tonic-gate hexdump(stdout,"Plaintext",plaintext,pn); 269*0Sstevel@tonic-gate hexdump(stdout,"Digest",ciphertext,cn); 270*0Sstevel@tonic-gate 271*0Sstevel@tonic-gate EVP_MD_CTX_init(&ctx); 272*0Sstevel@tonic-gate if(!EVP_DigestInit_ex(&ctx,d, NULL)) 273*0Sstevel@tonic-gate { 274*0Sstevel@tonic-gate fprintf(stderr,"DigestInit failed\n"); 275*0Sstevel@tonic-gate EXIT(100); 276*0Sstevel@tonic-gate } 277*0Sstevel@tonic-gate if(!EVP_DigestUpdate(&ctx,plaintext,pn)) 278*0Sstevel@tonic-gate { 279*0Sstevel@tonic-gate fprintf(stderr,"DigestUpdate failed\n"); 280*0Sstevel@tonic-gate EXIT(101); 281*0Sstevel@tonic-gate } 282*0Sstevel@tonic-gate if(!EVP_DigestFinal_ex(&ctx,md,&mdn)) 283*0Sstevel@tonic-gate { 284*0Sstevel@tonic-gate fprintf(stderr,"DigestFinal failed\n"); 285*0Sstevel@tonic-gate EXIT(101); 286*0Sstevel@tonic-gate } 287*0Sstevel@tonic-gate EVP_MD_CTX_cleanup(&ctx); 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate if(mdn != cn) 290*0Sstevel@tonic-gate { 291*0Sstevel@tonic-gate fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn); 292*0Sstevel@tonic-gate EXIT(102); 293*0Sstevel@tonic-gate } 294*0Sstevel@tonic-gate 295*0Sstevel@tonic-gate if(memcmp(md,ciphertext,cn)) 296*0Sstevel@tonic-gate { 297*0Sstevel@tonic-gate fprintf(stderr,"Digest mismatch\n"); 298*0Sstevel@tonic-gate hexdump(stderr,"Got",md,cn); 299*0Sstevel@tonic-gate hexdump(stderr,"Expected",ciphertext,cn); 300*0Sstevel@tonic-gate EXIT(103); 301*0Sstevel@tonic-gate } 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate printf("\n"); 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gate EVP_MD_CTX_cleanup(&ctx); 306*0Sstevel@tonic-gate 307*0Sstevel@tonic-gate return 1; 308*0Sstevel@tonic-gate } 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate int main(int argc,char **argv) 311*0Sstevel@tonic-gate { 312*0Sstevel@tonic-gate const char *szTestFile; 313*0Sstevel@tonic-gate FILE *f; 314*0Sstevel@tonic-gate 315*0Sstevel@tonic-gate if(argc != 2) 316*0Sstevel@tonic-gate { 317*0Sstevel@tonic-gate fprintf(stderr,"%s <test file>\n",argv[0]); 318*0Sstevel@tonic-gate EXIT(1); 319*0Sstevel@tonic-gate } 320*0Sstevel@tonic-gate CRYPTO_malloc_debug_init(); 321*0Sstevel@tonic-gate CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL); 322*0Sstevel@tonic-gate CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate szTestFile=argv[1]; 325*0Sstevel@tonic-gate 326*0Sstevel@tonic-gate f=fopen(szTestFile,"r"); 327*0Sstevel@tonic-gate if(!f) 328*0Sstevel@tonic-gate { 329*0Sstevel@tonic-gate perror(szTestFile); 330*0Sstevel@tonic-gate EXIT(2); 331*0Sstevel@tonic-gate } 332*0Sstevel@tonic-gate 333*0Sstevel@tonic-gate /* Load up the software EVP_CIPHER and EVP_MD definitions */ 334*0Sstevel@tonic-gate OpenSSL_add_all_ciphers(); 335*0Sstevel@tonic-gate OpenSSL_add_all_digests(); 336*0Sstevel@tonic-gate #ifndef OPENSSL_NO_ENGINE 337*0Sstevel@tonic-gate /* Load all compiled-in ENGINEs */ 338*0Sstevel@tonic-gate ENGINE_load_builtin_engines(); 339*0Sstevel@tonic-gate #endif 340*0Sstevel@tonic-gate #if 0 341*0Sstevel@tonic-gate OPENSSL_config(); 342*0Sstevel@tonic-gate #endif 343*0Sstevel@tonic-gate #ifndef OPENSSL_NO_ENGINE 344*0Sstevel@tonic-gate /* Register all available ENGINE implementations of ciphers and digests. 345*0Sstevel@tonic-gate * This could perhaps be changed to "ENGINE_register_all_complete()"? */ 346*0Sstevel@tonic-gate ENGINE_register_all_ciphers(); 347*0Sstevel@tonic-gate ENGINE_register_all_digests(); 348*0Sstevel@tonic-gate /* If we add command-line options, this statement should be switchable. 349*0Sstevel@tonic-gate * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if 350*0Sstevel@tonic-gate * they weren't already initialised. */ 351*0Sstevel@tonic-gate /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ 352*0Sstevel@tonic-gate #endif 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gate for( ; ; ) 355*0Sstevel@tonic-gate { 356*0Sstevel@tonic-gate char line[4096]; 357*0Sstevel@tonic-gate char *p; 358*0Sstevel@tonic-gate char *cipher; 359*0Sstevel@tonic-gate unsigned char *iv,*key,*plaintext,*ciphertext; 360*0Sstevel@tonic-gate int encdec; 361*0Sstevel@tonic-gate int kn,in,pn,cn; 362*0Sstevel@tonic-gate 363*0Sstevel@tonic-gate if(!fgets((char *)line,sizeof line,f)) 364*0Sstevel@tonic-gate break; 365*0Sstevel@tonic-gate if(line[0] == '#' || line[0] == '\n') 366*0Sstevel@tonic-gate continue; 367*0Sstevel@tonic-gate p=line; 368*0Sstevel@tonic-gate cipher=sstrsep(&p,":"); 369*0Sstevel@tonic-gate key=ustrsep(&p,":"); 370*0Sstevel@tonic-gate iv=ustrsep(&p,":"); 371*0Sstevel@tonic-gate plaintext=ustrsep(&p,":"); 372*0Sstevel@tonic-gate ciphertext=ustrsep(&p,":"); 373*0Sstevel@tonic-gate if (p[-1] == '\n') { 374*0Sstevel@tonic-gate p[-1] = '\0'; 375*0Sstevel@tonic-gate encdec = -1; 376*0Sstevel@tonic-gate } else { 377*0Sstevel@tonic-gate encdec = atoi(sstrsep(&p,"\n")); 378*0Sstevel@tonic-gate } 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gate 381*0Sstevel@tonic-gate kn=convert(key); 382*0Sstevel@tonic-gate in=convert(iv); 383*0Sstevel@tonic-gate pn=convert(plaintext); 384*0Sstevel@tonic-gate cn=convert(ciphertext); 385*0Sstevel@tonic-gate 386*0Sstevel@tonic-gate if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec) 387*0Sstevel@tonic-gate && !test_digest(cipher,plaintext,pn,ciphertext,cn)) 388*0Sstevel@tonic-gate { 389*0Sstevel@tonic-gate fprintf(stderr,"Can't find %s\n",cipher); 390*0Sstevel@tonic-gate EXIT(3); 391*0Sstevel@tonic-gate } 392*0Sstevel@tonic-gate } 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gate #ifndef OPENSSL_NO_ENGINE 395*0Sstevel@tonic-gate ENGINE_cleanup(); 396*0Sstevel@tonic-gate #endif 397*0Sstevel@tonic-gate EVP_cleanup(); 398*0Sstevel@tonic-gate CRYPTO_cleanup_all_ex_data(); 399*0Sstevel@tonic-gate ERR_remove_state(0); 400*0Sstevel@tonic-gate ERR_free_strings(); 401*0Sstevel@tonic-gate CRYPTO_mem_leaks_fp(stderr); 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate return 0; 404*0Sstevel@tonic-gate } 405