Make it possible to give digest names as -evp arguments.

This commit is contained in:
Richard Levitte 2001-11-15 20:19:40 +00:00
parent b5fe234588
commit 83c40e7fc0

View File

@ -357,6 +357,7 @@ int MAIN(int argc, char **argv)
#ifndef OPENSSL_NO_RSA #ifndef OPENSSL_NO_RSA
unsigned rsa_num; unsigned rsa_num;
#endif #endif
unsigned char md[EVP_MAX_MD_SIZE];
#ifndef OPENSSL_NO_MD2 #ifndef OPENSSL_NO_MD2
unsigned char md2[MD2_DIGEST_LENGTH]; unsigned char md2[MD2_DIGEST_LENGTH];
#endif #endif
@ -451,7 +452,8 @@ int MAIN(int argc, char **argv)
int dsa_doit[DSA_NUM]; int dsa_doit[DSA_NUM];
int doit[ALGOR_NUM]; int doit[ALGOR_NUM];
int pr_header=0; int pr_header=0;
const EVP_CIPHER *evp=NULL; const EVP_CIPHER *evp_cipher=NULL;
const EVP_MD *evp_md=NULL;
int decrypt=0; int decrypt=0;
#ifdef HAVE_FORK #ifdef HAVE_FORK
int multi=0; int multi=0;
@ -521,10 +523,14 @@ int MAIN(int argc, char **argv)
BIO_printf(bio_err,"no EVP given\n"); BIO_printf(bio_err,"no EVP given\n");
goto end; goto end;
} }
evp=EVP_get_cipherbyname(*argv); evp_cipher=EVP_get_cipherbyname(*argv);
if(!evp) if(!evp_cipher)
{ {
BIO_printf(bio_err,"%s is an unknown cipher\n",*argv); evp_md=EVP_get_digestbyname(*argv);
}
if(!evp_cipher && !evp_md)
{
BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
goto end; goto end;
} }
doit[D_EVP]=1; doit[D_EVP]=1;
@ -1235,18 +1241,21 @@ int MAIN(int argc, char **argv)
if (doit[D_EVP]) if (doit[D_EVP])
{ {
for (j=0; j<SIZE_NUM; j++) for (j=0; j<SIZE_NUM; j++)
{
if (evp_cipher)
{ {
EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX ctx;
int outl; int outl;
names[D_EVP]=OBJ_nid2ln(evp->nid); names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
print_message(names[D_EVP],save_count, print_message(names[D_EVP],save_count,
lengths[j]); lengths[j]);
EVP_CIPHER_CTX_init(&ctx); EVP_CIPHER_CTX_init(&ctx);
if(decrypt) if(decrypt)
EVP_DecryptInit_ex(&ctx,evp,NULL,key16,iv); EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
else else
EVP_EncryptInit_ex(&ctx,evp,NULL,key16,iv); EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
Time_F(START); Time_F(START);
if(decrypt) if(decrypt)
@ -1260,6 +1269,19 @@ int MAIN(int argc, char **argv)
else else
EVP_EncryptFinal_ex(&ctx,buf,&outl); EVP_EncryptFinal_ex(&ctx,buf,&outl);
d=Time_F(STOP); d=Time_F(STOP);
}
if (evp_md)
{
names[D_EVP]=OBJ_nid2ln(evp_md->type);
print_message(names[D_EVP],save_count,
lengths[j]);
Time_F(START);
for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
d=Time_F(STOP);
}
print_result(D_EVP,j,count,d); print_result(D_EVP,j,count,d);
} }
} }