Prepend signature name in dgst output.
authorDr. Stephen Henson <steve@openssl.org>
Thu, 17 May 2007 16:19:17 +0000 (16:19 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Thu, 17 May 2007 16:19:17 +0000 (16:19 +0000)
apps/dgst.c
crypto/asn1/ameth_lib.c
crypto/evp/evp.h

index deb829a..312d880 100644 (file)
@@ -75,7 +75,8 @@
 #define PROG   dgst_main
 
 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,
+         EVP_PKEY *key, unsigned char *sigin, int siglen,
+         const char *sig_name, const char *md_name,
          const char *file,BIO *bmd);
 
 int MAIN(int, char **);
@@ -89,7 +90,6 @@ int MAIN(int argc, char **argv)
        BIO *in=NULL,*inp;
        BIO *bmd=NULL;
        BIO *out = NULL;
-       const char *name;
 #define PROG_NAME_SIZE  39
        char pname[PROG_NAME_SIZE+1];
        int separator=0;
@@ -490,37 +490,42 @@ 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);
+                         siglen,NULL,NULL,"stdin",bmd);
                }
        else
                {
-               name=OBJ_nid2sn(md->type);
+               const char *md_name, *sig_name;
+               if(out_bin)
+                       {
+                       md_name = NULL;
+                       sig_name = NULL;
+                       }
+               else
+                       {
+                       if (sigkey)
+                               {
+                               const EVP_PKEY_ASN1_METHOD *ameth;
+                               ameth = EVP_PKEY_get0_asn1(sigkey);
+                               if (ameth)
+                                       EVP_PKEY_asn1_get0_info(NULL, NULL,
+                                               NULL, NULL, &sig_name, ameth);
+                               }
+                       md_name = EVP_MD_name(md);
+                       }
                for (i=0; i<argc; i++)
                        {
-                       char *tmp,*tofree=NULL;
                        int r;
-
                        if (BIO_read_filename(in,argv[i]) <= 0)
                                {
                                perror(argv[i]);
                                err++;
                                continue;
                                }
-                       if(!out_bin)
-                               {
-                               size_t len = strlen(name)+strlen(argv[i])+(hmac_key ? 5 : 0)+5;
-                               tmp=tofree=OPENSSL_malloc(len);
-                               BIO_snprintf(tmp,len,"%s%s(%s)= ",
-                                                        hmac_key ? "HMAC-" : "",name,argv[i]);
-                               }
                        else
-                               tmp="";
                        r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
-                               siglen,tmp,argv[i],bmd);
+                               siglen,sig_name,md_name, argv[i],bmd);
                        if(r)
                            err=r;
-                       if(tofree)
-                               OPENSSL_free(tofree);
                        (void)BIO_reset(bmd);
                        }
                }
@@ -546,7 +551,8 @@ 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,
+         EVP_PKEY *key, unsigned char *sigin, int siglen,
+         const char *sig_name, const char *md_name,
          const char *file,BIO *bmd)
        {
        size_t len;
@@ -600,7 +606,12 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout,
        if(binout) BIO_write(out, buf, len);
        else 
                {
-               BIO_write(out,title,strlen(title));
+               if (sig_name)
+                       BIO_printf(out, "%s-%s(%s)=", sig_name, md_name, file);
+               else if (md_name)
+                       BIO_printf(out, "%s(%s)=", md_name, file);
+               else
+                       BIO_printf(out, "(%s)=", file);
                for (i=0; i<(int)len; i++)
                        {
                        if (sep && (i != 0))
index 13129bc..7c385f6 100644 (file)
@@ -276,6 +276,11 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
        return 1;
        }
 
+const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey)
+       {
+       return pkey->ameth;
+       }
+
 EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
                                        const char *pem_str, const char *info)
        {
index 6c65f5a..65538d4 100644 (file)
@@ -939,6 +939,7 @@ int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *pkey_base_id, int *ppkey_flags,
                                const char **pinfo, const char **ppem_str,
                                        const EVP_PKEY_ASN1_METHOD *ameth);
 
+const EVP_PKEY_ASN1_METHOD* EVP_PKEY_get0_asn1(EVP_PKEY *pkey);
 EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
                                        const char *pem_str, const char *info);
 void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,