Subject: Re: new message digest support in pkgsrc
To: Alistair Crooks <agc@pkgsrc.org>
From: Andrew Brown <atatat@atatdot.net>
List: tech-pkg
Date: 03/14/2001 13:52:06
--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

(catching up)

>I considered modifying the existing cksum(1) utility, but thought
>that it wasn't scalable enough, and I considered using openssl, but
>didn't want pkgsrc to be dependent on openssl being installed, and
>because the output format isn't the same as md5(1).

i have patches to cksum that i did last week (before i read this) to
add md4 (a no brainer, even if it is unused), sha1 (although not the
large sha variants), and rmd160.  a few minor changes to cksum.c and
md5.c and a few new little files (eg sha1.c into which md5.c is simply
included) made it rather easy.  should i throw it away?

i've also attached a small patch that seems to me to be rather useful
in the face of the multiple algorithms that digest supports.  it
basically adds a "help" hash that prints the other hash names, and a
-h option that does the same thing.

i'd also like to note that the use of sha1 (although not sha256,
sha384, or sha512) on alpha spews a lot of messages of the form:

pid 18514 (digest): unaligned access: va=0x12012275f pc=0x120004eb4 ra=0x12012275f op=stl

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
andrew@crossbar.com       * "information is power -- share the wealth."

--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="digest.c.patch"

--- digest.c.orig	Wed Mar 14 13:11:49 2001
+++ digest.c	Wed Mar 14 13:12:54 2001
@@ -51,6 +51,8 @@
 #include <string.h>
 #include <unistd.h>
 
+static int help_digest_file(char *fn);
+
 /* perform an md5 digest, and print the results if successful */
 static int
 md5_digest_file(char *fn)
@@ -203,6 +205,7 @@
 
 /* list of supported message digest algorithms */
 static alg_t algorithms[] = {
+	{ "help",	help_digest_file	},
 	{ "md5",	md5_digest_file		},
 	{ "rmd160",	rmd160_digest_file	},
 	{ "sha1",	sha1_digest_file	},
@@ -212,6 +215,20 @@
 	{ NULL	}
 };
 
+/* print a list of supported hashes and exit */
+static int
+help_digest_file(char *fn)
+{
+	alg_t	*alg;
+
+	printf("supported hashes:\n");
+	for (alg = algorithms ; alg->name ; alg++)
+		if (strcasecmp("help", alg->name) != 0)
+			printf("\t%s\n", alg->name);
+
+	exit(0);
+}
+
 /* find an algorithm, given a name */
 static alg_t *
 find_algorithm(const char *a)
@@ -231,11 +248,14 @@
 	int	i;
 
 	(void) setlocale(LC_ALL, "");
-	while ((i = getopt(argc, argv, "V")) != -1) {
+	while ((i = getopt(argc, argv, "Vh")) != -1) {
 		switch(i) {
 		case 'V':
 			printf("%d\n", VERSION);
 			return EXIT_SUCCESS;
+		case 'h':
+			help_digest_file(NULL);
+			break;
 		}
 	}
 	if (argc == optind) {

--tThc/1wpZn/ma/RB--