summaryrefslogtreecommitdiffstats
path: root/crypto/openssl/apps/dgst.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssl/apps/dgst.c')
-rw-r--r--crypto/openssl/apps/dgst.c77
1 files changed, 37 insertions, 40 deletions
diff --git a/crypto/openssl/apps/dgst.c b/crypto/openssl/apps/dgst.c
index f8d9a70..c13535f 100644
--- a/crypto/openssl/apps/dgst.c
+++ b/crypto/openssl/apps/dgst.c
@@ -66,7 +66,6 @@
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
-#include <openssl/hmac.h>
#undef BUFSIZE
#define BUFSIZE 1024*8
@@ -74,11 +73,9 @@
#undef PROG
#define PROG dgst_main
-static HMAC_CTX hmac_ctx;
-
int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
- const char *file,BIO *bmd,const char *hmac_key);
+ const char *file);
int MAIN(int, char **);
@@ -103,10 +100,10 @@ int MAIN(int argc, char **argv)
EVP_PKEY *sigkey = NULL;
unsigned char *sigbuf = NULL;
int siglen = 0;
+ char *passargin = NULL, *passin = NULL;
#ifndef OPENSSL_NO_ENGINE
char *engine=NULL;
#endif
- char *hmac_key=NULL;
apps_startup();
@@ -149,6 +146,12 @@ int MAIN(int argc, char **argv)
if (--argc < 1) break;
keyfile=*(++argv);
}
+ else if (!strcmp(*argv,"-passin"))
+ {
+ if (--argc < 1)
+ break;
+ passargin=*++argv;
+ }
else if (strcmp(*argv,"-verify") == 0)
{
if (--argc < 1) break;
@@ -185,12 +188,6 @@ int MAIN(int argc, char **argv)
out_bin = 1;
else if (strcmp(*argv,"-d") == 0)
debug=1;
- else if (!strcmp(*argv,"-hmac"))
- {
- if (--argc < 1)
- break;
- hmac_key=*++argv;
- }
else if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
md=m;
else
@@ -232,10 +229,20 @@ int MAIN(int argc, char **argv)
LN_md4,LN_md4);
BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
LN_md2,LN_md2);
+#ifndef OPENSSL_NO_SHA
BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
LN_sha1,LN_sha1);
BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
LN_sha,LN_sha);
+#ifndef OPENSSL_NO_SHA256
+ BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
+ LN_sha256,LN_sha256);
+#endif
+#ifndef OPENSSL_NO_SHA512
+ BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
+ LN_sha512,LN_sha512);
+#endif
+#endif
BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
LN_mdc2,LN_mdc2);
BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
@@ -245,7 +252,7 @@ int MAIN(int argc, char **argv)
}
#ifndef OPENSSL_NO_ENGINE
- e = setup_engine(bio_err, engine, 0);
+ e = setup_engine(bio_err, engine, 0);
#endif
in=BIO_new(BIO_s_file());
@@ -257,6 +264,12 @@ int MAIN(int argc, char **argv)
BIO_set_callback_arg(in,bio_err);
}
+ if(!app_passwd(bio_err, passargin, NULL, &passin, NULL))
+ {
+ BIO_printf(bio_err, "Error getting password\n");
+ goto end;
+ }
+
if ((in == NULL) || (bmd == NULL))
{
ERR_print_errors(bio_err);
@@ -298,7 +311,7 @@ int MAIN(int argc, char **argv)
sigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL,
e, "key file");
else
- sigkey = load_key(bio_err, keyfile, keyform, 0, NULL,
+ sigkey = load_key(bio_err, keyfile, keyform, 0, passin,
e, "key file");
if (!sigkey)
{
@@ -328,6 +341,8 @@ int MAIN(int argc, char **argv)
goto end;
}
}
+
+
/* we use md as a filter, reading from 'in' */
if (!BIO_set_md(bmd,md))
@@ -343,7 +358,7 @@ int MAIN(int argc, char **argv)
{
BIO_set_fp(in,stdin,BIO_NOCLOSE);
err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
- siglen,"","(stdin)",bmd,hmac_key);
+ siglen,"","(stdin)");
}
else
{
@@ -361,15 +376,14 @@ int MAIN(int argc, char **argv)
}
if(!out_bin)
{
- size_t len = strlen(name)+strlen(argv[i])+(hmac_key ? 5 : 0)+5;
+ size_t len = strlen(name)+strlen(argv[i])+5;
tmp=tofree=OPENSSL_malloc(len);
- BIO_snprintf(tmp,len,"%s%s(%s)= ",
- hmac_key ? "HMAC-" : "",name,argv[i]);
+ BIO_snprintf(tmp,len,"%s(%s)= ",name,argv[i]);
}
else
tmp="";
r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
- siglen,tmp,argv[i],bmd,hmac_key);
+ siglen,tmp,argv[i]);
if(r)
err=r;
if(tofree)
@@ -384,6 +398,8 @@ end:
OPENSSL_free(buf);
}
if (in != NULL) BIO_free(in);
+ if (passin)
+ OPENSSL_free(passin);
BIO_free_all(out);
EVP_PKEY_free(sigkey);
if(sigbuf) OPENSSL_free(sigbuf);
@@ -394,21 +410,11 @@ end:
int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
EVP_PKEY *key, unsigned char *sigin, int siglen, const char *title,
- const char *file,BIO *bmd,const char *hmac_key)
+ const char *file)
{
- unsigned int len;
+ int len;
int i;
- EVP_MD_CTX *md_ctx;
- if (hmac_key)
- {
- EVP_MD *md;
-
- BIO_get_md(bmd,&md);
- HMAC_Init(&hmac_ctx,hmac_key,strlen(hmac_key),md);
- BIO_get_md_ctx(bmd,&md_ctx);
- BIO_set_md_ctx(bmd,&hmac_ctx.md_ctx);
- }
for (;;)
{
i=BIO_read(bp,(char *)buf,BUFSIZE);
@@ -451,11 +457,6 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
return 1;
}
}
- else if(hmac_key)
- {
- HMAC_Final(&hmac_ctx,buf,&len);
- HMAC_CTX_cleanup(&hmac_ctx);
- }
else
len=BIO_gets(bp,(char *)buf,BUFSIZE);
@@ -463,7 +464,7 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
else
{
BIO_write(out,title,strlen(title));
- for (i=0; (unsigned int)i<len; i++)
+ for (i=0; i<len; i++)
{
if (sep && (i != 0))
BIO_printf(out, ":");
@@ -471,10 +472,6 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
}
BIO_printf(out, "\n");
}
- if (hmac_key)
- {
- BIO_set_md_ctx(bmd,md_ctx);
- }
return 0;
}
OpenPOWER on IntegriCloud