mirror of
https://github.com/openssl/openssl.git
synced 2024-11-24 02:23:51 +08:00
Better handling of EVP names, add EVP to speed.
This commit is contained in:
parent
0cc1115643
commit
646d56956b
92
apps/enc.c
92
apps/enc.c
@ -71,6 +71,7 @@
|
||||
#endif
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int set_hex(char *in,unsigned char *out,int size);
|
||||
#undef SIZE
|
||||
@ -81,6 +82,24 @@ int set_hex(char *in,unsigned char *out,int size);
|
||||
#define BSIZE (8*1024)
|
||||
#define PROG enc_main
|
||||
|
||||
void show_ciphers(const OBJ_NAME *name,void *bio_)
|
||||
{
|
||||
BIO *bio=bio_;
|
||||
static int n;
|
||||
|
||||
if(!islower(*name->name))
|
||||
return;
|
||||
|
||||
BIO_printf(bio,"-%-25s",name->name);
|
||||
if(++n == 3)
|
||||
{
|
||||
BIO_printf(bio,"\n");
|
||||
n=0;
|
||||
}
|
||||
else
|
||||
BIO_printf(bio," ");
|
||||
}
|
||||
|
||||
int MAIN(int, char **);
|
||||
|
||||
int MAIN(int argc, char **argv)
|
||||
@ -252,76 +271,11 @@ bad:
|
||||
BIO_printf(bio_err,"%-14s use engine e, possibly a hardware device.\n","-engine e");
|
||||
|
||||
BIO_printf(bio_err,"Cipher Types\n");
|
||||
BIO_printf(bio_err,"des : 56 bit key DES encryption\n");
|
||||
BIO_printf(bio_err,"des_ede :112 bit key ede DES encryption\n");
|
||||
BIO_printf(bio_err,"des_ede3:168 bit key ede DES encryption\n");
|
||||
#ifndef NO_IDEA
|
||||
BIO_printf(bio_err,"idea :128 bit key IDEA encryption\n");
|
||||
#endif
|
||||
#ifndef NO_RC4
|
||||
BIO_printf(bio_err,"rc2 :128 bit key RC2 encryption\n");
|
||||
#endif
|
||||
#ifndef NO_BF
|
||||
BIO_printf(bio_err,"bf :128 bit key Blowfish encryption\n");
|
||||
#endif
|
||||
#ifndef NO_RC4
|
||||
BIO_printf(bio_err," -%-5s :128 bit key RC4 encryption\n",
|
||||
LN_rc4);
|
||||
#endif
|
||||
OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH,
|
||||
show_ciphers,
|
||||
bio_err);
|
||||
BIO_printf(bio_err,"\n");
|
||||
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_des_ecb,LN_des_cbc,
|
||||
LN_des_cfb64,LN_des_ofb64);
|
||||
BIO_printf(bio_err," -%-4s (%s)\n",
|
||||
"des", LN_des_cbc);
|
||||
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_des_ede,LN_des_ede_cbc,
|
||||
LN_des_ede_cfb64,LN_des_ede_ofb64);
|
||||
BIO_printf(bio_err," -desx -none\n");
|
||||
|
||||
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_des_ede3,LN_des_ede3_cbc,
|
||||
LN_des_ede3_cfb64,LN_des_ede3_ofb64);
|
||||
BIO_printf(bio_err," -%-4s (%s)\n",
|
||||
"des3", LN_des_ede3_cbc);
|
||||
|
||||
#ifndef NO_IDEA
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_idea_ecb, LN_idea_cbc,
|
||||
LN_idea_cfb64, LN_idea_ofb64);
|
||||
BIO_printf(bio_err," -%-4s (%s)\n","idea",LN_idea_cbc);
|
||||
#endif
|
||||
#ifndef NO_RC2
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_rc2_ecb, LN_rc2_cbc,
|
||||
LN_rc2_cfb64, LN_rc2_ofb64);
|
||||
BIO_printf(bio_err," -%-4s (%s)\n","rc2", LN_rc2_cbc);
|
||||
#endif
|
||||
#ifndef NO_BF
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_bf_ecb, LN_bf_cbc,
|
||||
LN_bf_cfb64, LN_bf_ofb64);
|
||||
BIO_printf(bio_err," -%-4s (%s)\n","bf", LN_bf_cbc);
|
||||
#endif
|
||||
#ifndef NO_CAST
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_cast5_ecb, LN_cast5_cbc,
|
||||
LN_cast5_cfb64, LN_cast5_ofb64);
|
||||
BIO_printf(bio_err," -%-4s (%s)\n","cast", LN_cast5_cbc);
|
||||
#endif
|
||||
#ifndef NO_RC5
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s",
|
||||
LN_rc5_ecb, LN_rc5_cbc,
|
||||
LN_rc5_cfb64, LN_rc5_ofb64);
|
||||
BIO_printf(bio_err," -%-4s (%s)\n","rc5", LN_rc5_cbc);
|
||||
#endif
|
||||
#ifndef NO_RIJNDAEL
|
||||
BIO_printf(bio_err," -%-12s -%-12s -%-12s -%-12s\n",
|
||||
LN_rijndael_ecb_k128_b128,"","","","");
|
||||
#endif
|
||||
|
||||
goto end;
|
||||
}
|
||||
argc--;
|
||||
|
54
apps/speed.c
54
apps/speed.c
@ -82,6 +82,8 @@
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
# define USE_TOD
|
||||
@ -196,7 +198,7 @@
|
||||
int run=0;
|
||||
|
||||
static double Time_F(int s, int usertime);
|
||||
static void print_message(char *s,long num,int length);
|
||||
static void print_message(const char *s,long num,int length);
|
||||
static void pkey_print_message(char *str,char *str2,long num,int bits,int sec);
|
||||
#ifdef SIGALRM
|
||||
#if defined(__STDC__) || defined(sgi) || defined(_AIX)
|
||||
@ -314,11 +316,11 @@ int MAIN(int argc, char **argv)
|
||||
ENGINE *e;
|
||||
unsigned char *buf=NULL,*buf2=NULL;
|
||||
int mret=1;
|
||||
#define ALGOR_NUM 15
|
||||
#define ALGOR_NUM 16
|
||||
#define SIZE_NUM 5
|
||||
#define RSA_NUM 4
|
||||
#define DSA_NUM 3
|
||||
long count,rsa_count;
|
||||
long count,rsa_count,save_count=0;
|
||||
int i,j,k;
|
||||
unsigned rsa_num;
|
||||
#ifndef NO_MD2
|
||||
@ -384,10 +386,11 @@ int MAIN(int argc, char **argv)
|
||||
#define D_CBC_RC5 12
|
||||
#define D_CBC_BF 13
|
||||
#define D_CBC_CAST 14
|
||||
#define D_EVP 15
|
||||
double d,results[ALGOR_NUM][SIZE_NUM];
|
||||
static int lengths[SIZE_NUM]={8,64,256,1024,8*1024};
|
||||
long c[ALGOR_NUM][SIZE_NUM];
|
||||
static char *names[ALGOR_NUM]={
|
||||
static const char *names[ALGOR_NUM]={
|
||||
"md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
|
||||
"des cbc","des ede3","idea cbc",
|
||||
"rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc"};
|
||||
@ -420,6 +423,7 @@ int MAIN(int argc, char **argv)
|
||||
int doit[ALGOR_NUM];
|
||||
int pr_header=0;
|
||||
int usertime=1;
|
||||
const EVP_CIPHER *evp=NULL;
|
||||
|
||||
#ifndef TIMES
|
||||
usertime=-1;
|
||||
@ -472,6 +476,23 @@ int MAIN(int argc, char **argv)
|
||||
{
|
||||
if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
|
||||
usertime = 0;
|
||||
else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if(argc == 0)
|
||||
{
|
||||
BIO_printf(bio_err,"no EVP given\n");
|
||||
goto end;
|
||||
}
|
||||
evp=EVP_get_cipherbyname(*argv);
|
||||
if(!evp)
|
||||
{
|
||||
BIO_printf(bio_err,"%s is an unknown cipher\n",*argv);
|
||||
goto end;
|
||||
}
|
||||
doit[D_EVP]=1;
|
||||
}
|
||||
else
|
||||
if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
|
||||
{
|
||||
@ -804,6 +825,7 @@ int MAIN(int argc, char **argv)
|
||||
&(sch[0]),DES_ENCRYPT);
|
||||
d=Time_F(STOP,usertime);
|
||||
} while (d <3);
|
||||
save_count=count;
|
||||
c[D_MD2][0]=count/10;
|
||||
c[D_MDC2][0]=count/10;
|
||||
c[D_MD4][0]=count;
|
||||
@ -1160,6 +1182,28 @@ int MAIN(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (doit[D_EVP])
|
||||
{
|
||||
for (j=0; j<SIZE_NUM; j++)
|
||||
{
|
||||
EVP_CIPHER_CTX ctx;
|
||||
int outl;
|
||||
|
||||
names[D_EVP]=OBJ_nid2ln(evp->nid);
|
||||
print_message(names[D_EVP],save_count,
|
||||
lengths[j]);
|
||||
EVP_EncryptInit(&ctx,evp,key16,iv);
|
||||
Time_F(START,usertime);
|
||||
for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
|
||||
EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
|
||||
EVP_EncryptFinal(&ctx,buf,&outl);
|
||||
d=Time_F(STOP,usertime);
|
||||
BIO_printf(bio_err,"%ld %s's in %.2fs\n",
|
||||
count,names[D_EVP],d);
|
||||
results[D_EVP][j]=((double)count)/d*lengths[j];
|
||||
}
|
||||
}
|
||||
|
||||
RAND_pseudo_bytes(buf,36);
|
||||
#ifndef NO_RSA
|
||||
for (j=0; j<RSA_NUM; j++)
|
||||
@ -1429,7 +1473,7 @@ end:
|
||||
EXIT(mret);
|
||||
}
|
||||
|
||||
static void print_message(char *s, long num, int length)
|
||||
static void print_message(const char *s, long num, int length)
|
||||
{
|
||||
#ifdef SIGALRM
|
||||
BIO_printf(bio_err,"Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
|
||||
|
@ -14,9 +14,9 @@ static int names_type_num=OBJ_NAME_TYPE_NUM;
|
||||
|
||||
typedef struct name_funcs_st
|
||||
{
|
||||
unsigned long (*hash_func)();
|
||||
int (*cmp_func)();
|
||||
void (*free_func)();
|
||||
unsigned long (*hash_func)(const char *name);
|
||||
int (*cmp_func)(const char *a,const char *b);
|
||||
void (*free_func)(const char *, int, const char *);
|
||||
} NAME_FUNCS;
|
||||
|
||||
DECLARE_STACK_OF(NAME_FUNCS)
|
||||
@ -37,7 +37,7 @@ int OBJ_NAME_init(void)
|
||||
}
|
||||
|
||||
int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
|
||||
int (*cmp_func)(const void *, const void *),
|
||||
int (*cmp_func)(const char *, const char *),
|
||||
void (*free_func)(const char *, int, const char *))
|
||||
{
|
||||
int ret;
|
||||
@ -62,12 +62,12 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
|
||||
MemCheck_off();
|
||||
name_funcs = OPENSSL_malloc(sizeof(NAME_FUNCS));
|
||||
name_funcs->hash_func = lh_strhash;
|
||||
name_funcs->cmp_func = (int (*)())strcmp;
|
||||
name_funcs->cmp_func = strcmp;
|
||||
name_funcs->free_func = 0; /* NULL is often declared to
|
||||
* ((void *)0), which according
|
||||
* to Compaq C is not really
|
||||
* compatible with a function
|
||||
* pointer. -- Richard Levitte*/
|
||||
* ((void *)0), which according
|
||||
* to Compaq C is not really
|
||||
* compatible with a function
|
||||
* pointer. -- Richard Levitte*/
|
||||
sk_NAME_FUNCS_push(name_funcs_stack,name_funcs);
|
||||
MemCheck_on();
|
||||
}
|
||||
@ -132,7 +132,7 @@ const char *OBJ_NAME_get(const char *name, int type)
|
||||
on.type=type;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
{
|
||||
ret=(OBJ_NAME *)lh_retrieve(names_lh,&on);
|
||||
if (ret == NULL) return(NULL);
|
||||
if ((ret->alias) && !alias)
|
||||
@ -224,12 +224,80 @@ int OBJ_NAME_remove(const char *name, int type)
|
||||
return(0);
|
||||
}
|
||||
|
||||
struct doall
|
||||
{
|
||||
int type;
|
||||
void (*fn)(const OBJ_NAME *,void *arg);
|
||||
void *arg;
|
||||
};
|
||||
|
||||
static void do_all_fn(const OBJ_NAME *name,struct doall *d)
|
||||
{
|
||||
if(name->type == d->type)
|
||||
d->fn(name,d->arg);
|
||||
}
|
||||
|
||||
void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),void *arg)
|
||||
{
|
||||
struct doall d;
|
||||
|
||||
d.type=type;
|
||||
d.fn=fn;
|
||||
d.arg=arg;
|
||||
|
||||
lh_doall_arg(names_lh,do_all_fn,&d);
|
||||
}
|
||||
|
||||
struct doall_sorted
|
||||
{
|
||||
int type;
|
||||
int n;
|
||||
const OBJ_NAME **names;
|
||||
};
|
||||
|
||||
static void do_all_sorted_fn(const OBJ_NAME *name,void *d_)
|
||||
{
|
||||
struct doall_sorted *d=d_;
|
||||
|
||||
if(name->type != d->type)
|
||||
return;
|
||||
|
||||
d->names[d->n++]=name;
|
||||
}
|
||||
|
||||
static int do_all_sorted_cmp(const void *n1_,const void *n2_)
|
||||
{
|
||||
const OBJ_NAME * const *n1=n1_;
|
||||
const OBJ_NAME * const *n2=n2_;
|
||||
|
||||
return strcmp((*n1)->name,(*n2)->name);
|
||||
}
|
||||
|
||||
void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
|
||||
void *arg)
|
||||
{
|
||||
struct doall_sorted d;
|
||||
int n;
|
||||
|
||||
d.type=type;
|
||||
d.names=OPENSSL_malloc(lh_num_items(names_lh)*sizeof *d.names);
|
||||
d.n=0;
|
||||
OBJ_NAME_do_all(type,do_all_sorted_fn,&d);
|
||||
|
||||
qsort(d.names,d.n,sizeof *d.names,do_all_sorted_cmp);
|
||||
|
||||
for(n=0 ; n < d.n ; ++n)
|
||||
fn(d.names[n],arg);
|
||||
|
||||
OPENSSL_free(d.names);
|
||||
}
|
||||
|
||||
static int free_type;
|
||||
|
||||
static void names_lh_free(OBJ_NAME *onp, int type)
|
||||
{
|
||||
if(onp == NULL)
|
||||
return;
|
||||
return;
|
||||
|
||||
if ((free_type < 0) || (free_type == onp->type))
|
||||
{
|
||||
|
@ -985,12 +985,17 @@ typedef struct obj_name_st
|
||||
|
||||
|
||||
int OBJ_NAME_init(void);
|
||||
int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),int (*cmp_func)(const void *, const void *),
|
||||
void (*free_func)(const char *, int, const char *));
|
||||
int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
|
||||
int (*cmp_func)(const char *, const char *),
|
||||
void (*free_func)(const char *, int, const char *));
|
||||
const char *OBJ_NAME_get(const char *name,int type);
|
||||
int OBJ_NAME_add(const char *name,int type,const char *data);
|
||||
int OBJ_NAME_remove(const char *name,int type);
|
||||
void OBJ_NAME_cleanup(int type); /* -1 for everything */
|
||||
void OBJ_NAME_do_all(int type,void (*fn)(const OBJ_NAME *,void *arg),
|
||||
void *arg);
|
||||
void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
|
||||
void *arg);
|
||||
|
||||
ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o);
|
||||
ASN1_OBJECT * OBJ_nid2obj(int n);
|
||||
|
Loading…
Reference in New Issue
Block a user