Hi,
find below (also attached) a very simple patch which adds a -r option to
the openssl 1.0 branch; the output is like this:

# ./openssl md5 openssl
MD5(openssl)= 4d184b33151ecde62657079a8b4c3e15
# ./openssl md5 -r openssl
4d184b33151ecde62657079a8b4c3e15 *openssl
# ./openssl sha1 openssl
SHA1(openssl)= f385aa365dcb11d6beef54eaef1f717c90b40a90
# ./openssl sha1 -r openssl
f385aa365dcb11d6beef54eaef1f717c90b40a90 *openssl
# ./openssl sha256 -r openssl
a2b3d8af6fc052626f13f740cad7aaadb2700ac6a331a876da2ecbcdeacc18d7 *openssl

and the check with coreutils tools succeeds:

# ./openssl md5 -r openssl | md5sum -c -
openssl: OK
# ./openssl sha1 -r openssl | sha1sum -c -
openssl: OK
# ./openssl sha256 -r openssl | sha256sum -c -
openssl: OK

--- dgst.c.orig 2009-04-26 14:16:12.000000000 +0200
+++ dgst.c      2009-09-29 01:19:39.000000000 +0200
@@ -155,6 +155,8 @@
                if ((*argv)[0] != '-') break;
                if (strcmp(*argv,"-c") == 0)
                        separator=1;
+               if (strcmp(*argv,"-r") == 0)
+                       separator=2;
                else if (strcmp(*argv,"-rand") == 0)
                        {
                        if (--argc < 1) break;
@@ -262,6 +264,7 @@
                BIO_printf(bio_err,"unknown option '%s'\n",*argv);
                BIO_printf(bio_err,"options are\n");
                BIO_printf(bio_err,"-c              to output the digest with
separating colons\n");
+               BIO_printf(bio_err,"-r              to output the digest in 
coreutils
format\n");
                BIO_printf(bio_err,"-d              to output debug info\n");
                BIO_printf(bio_err,"-hex            output as hex dump\n");
                BIO_printf(bio_err,"-binary         output in binary form\n");
@@ -602,6 +605,12 @@
                }

        if(binout) BIO_write(out, buf, len);
+       else if (sep == 2)
+               {
+               for (i=0; i<(int)len; i++)
+                       BIO_printf(out, "%02x",buf[i]);
+               BIO_printf(out, " *%s\n", file);
+               }
        else
                {
                if (sig_name)

as you see I have just re-used the separator / sep variables which
avoids adding another parameter to do_fp(); however if we do it that way
then we should probably rename it to something like optoutput / optout ...

Günter.

--- dgst.c.orig	2009-04-26 14:16:12.000000000 +0200
+++ dgst.c	2009-09-29 01:19:39.000000000 +0200
@@ -155,6 +155,8 @@
 		if ((*argv)[0] != '-') break;
 		if (strcmp(*argv,"-c") == 0)
 			separator=1;
+		if (strcmp(*argv,"-r") == 0)
+			separator=2;
 		else if (strcmp(*argv,"-rand") == 0)
 			{
 			if (--argc < 1) break;
@@ -262,6 +264,7 @@
 		BIO_printf(bio_err,"unknown option '%s'\n",*argv);
 		BIO_printf(bio_err,"options are\n");
 		BIO_printf(bio_err,"-c              to output the digest with separating colons\n");
+		BIO_printf(bio_err,"-r              to output the digest in coreutils format\n");
 		BIO_printf(bio_err,"-d              to output debug info\n");
 		BIO_printf(bio_err,"-hex            output as hex dump\n");
 		BIO_printf(bio_err,"-binary         output in binary form\n");
@@ -602,6 +605,12 @@
 		}
 
 	if(binout) BIO_write(out, buf, len);
+	else if (sep == 2)
+		{
+		for (i=0; i<(int)len; i++)
+			BIO_printf(out, "%02x",buf[i]);
+		BIO_printf(out, " *%s\n", file);
+		}
 	else 
 		{
 		if (sig_name)

Reply via email to