提交 bb845ee0 编写于 作者: D Dr. Stephen Henson

Add -engine_impl option to dgst which will use an implementation of

an algorithm from the supplied engine instead of just the default one.
上级 b5cfc2f5
...@@ -103,7 +103,7 @@ int MAIN(int, char **); ...@@ -103,7 +103,7 @@ int MAIN(int, char **);
int MAIN(int argc, char **argv) int MAIN(int argc, char **argv)
{ {
ENGINE *e = NULL; ENGINE *e = NULL, *impl = NULL;
unsigned char *buf=NULL; unsigned char *buf=NULL;
int i,err=1; int i,err=1;
const EVP_MD *md=NULL,*m; const EVP_MD *md=NULL,*m;
...@@ -124,6 +124,7 @@ int MAIN(int argc, char **argv) ...@@ -124,6 +124,7 @@ int MAIN(int argc, char **argv)
char *passargin = NULL, *passin = NULL; char *passargin = NULL, *passin = NULL;
#ifndef OPENSSL_NO_ENGINE #ifndef OPENSSL_NO_ENGINE
char *engine=NULL; char *engine=NULL;
int engine_impl = 0;
#endif #endif
char *hmac_key=NULL; char *hmac_key=NULL;
char *mac_name=NULL; char *mac_name=NULL;
...@@ -208,6 +209,8 @@ int MAIN(int argc, char **argv) ...@@ -208,6 +209,8 @@ int MAIN(int argc, char **argv)
engine= *(++argv); engine= *(++argv);
e = setup_engine(bio_err, engine, 0); e = setup_engine(bio_err, engine, 0);
} }
else if (strcmp(*argv,"-engine_impl") == 0)
engine_impl = 1;
#endif #endif
else if (strcmp(*argv,"-hex") == 0) else if (strcmp(*argv,"-hex") == 0)
out_bin = 0; out_bin = 0;
...@@ -286,6 +289,11 @@ int MAIN(int argc, char **argv) ...@@ -286,6 +289,11 @@ int MAIN(int argc, char **argv)
goto end; goto end;
} }
#ifndef OPENSSL_NO_ENGINE
if (engine_impl)
impl = e;
#endif
in=BIO_new(BIO_s_file()); in=BIO_new(BIO_s_file());
bmd=BIO_new(BIO_f_md()); bmd=BIO_new(BIO_f_md());
if (debug) if (debug)
...@@ -363,7 +371,7 @@ int MAIN(int argc, char **argv) ...@@ -363,7 +371,7 @@ int MAIN(int argc, char **argv)
{ {
EVP_PKEY_CTX *mac_ctx = NULL; EVP_PKEY_CTX *mac_ctx = NULL;
int r = 0; int r = 0;
if (!init_gen_str(bio_err, &mac_ctx, mac_name,e, 0)) if (!init_gen_str(bio_err, &mac_ctx, mac_name, impl, 0))
goto mac_end; goto mac_end;
if (macopts) if (macopts)
{ {
...@@ -397,7 +405,7 @@ int MAIN(int argc, char **argv) ...@@ -397,7 +405,7 @@ int MAIN(int argc, char **argv)
if (hmac_key) if (hmac_key)
{ {
sigkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, e, sigkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, impl,
(unsigned char *)hmac_key, -1); (unsigned char *)hmac_key, -1);
if (!sigkey) if (!sigkey)
goto end; goto end;
...@@ -415,9 +423,9 @@ int MAIN(int argc, char **argv) ...@@ -415,9 +423,9 @@ int MAIN(int argc, char **argv)
goto end; goto end;
} }
if (do_verify) if (do_verify)
r = EVP_DigestVerifyInit(mctx, &pctx, md, e, sigkey); r = EVP_DigestVerifyInit(mctx, &pctx, md, impl, sigkey);
else else
r = EVP_DigestSignInit(mctx, &pctx, md, e, sigkey); r = EVP_DigestSignInit(mctx, &pctx, md, impl, sigkey);
if (!r) if (!r)
{ {
BIO_printf(bio_err, "Error setting context\n"); BIO_printf(bio_err, "Error setting context\n");
...@@ -444,9 +452,16 @@ int MAIN(int argc, char **argv) ...@@ -444,9 +452,16 @@ int MAIN(int argc, char **argv)
/* we use md as a filter, reading from 'in' */ /* we use md as a filter, reading from 'in' */
else else
{ {
EVP_MD_CTX *mctx = NULL;
if (!BIO_get_md_ctx(bmd, &mctx))
{
BIO_printf(bio_err, "Error getting context\n");
ERR_print_errors(bio_err);
goto end;
}
if (md == NULL) if (md == NULL)
md = EVP_md5(); md = EVP_md5();
if (!BIO_set_md(bmd,md)) if (!EVP_DigestInit_ex(mctx, md, impl))
{ {
BIO_printf(bio_err, "Error setting digest %s\n", pname); BIO_printf(bio_err, "Error setting digest %s\n", pname);
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册