X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d3187d77683cc7c81be53c12386630debeccb20b..4739c68a6cb81cae53cd7df694ecd6176d6f11f8:/hashsum.c diff --git a/hashsum.c b/hashsum.c index 0776ee8..a175397 100644 --- a/hashsum.c +++ b/hashsum.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: hashsum.c,v 1.7 2001/02/21 20:03:22 mdw Exp $ + * $Id: hashsum.c,v 1.10 2004/04/08 01:36:15 mdw Exp $ * * Hash files using some secure hash function * @@ -27,35 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: hashsum.c,v $ - * Revision 1.7 2001/02/21 20:03:22 mdw - * Added support for MD2 hash function. - * - * Revision 1.6 2001/01/25 21:40:14 mdw - * Support for new SHA variants added. - * - * Revision 1.5 2000/12/06 20:33:27 mdw - * Make flags be macros rather than enumerations, to ensure that they're - * unsigned. - * - * Revision 1.4 2000/08/04 23:23:44 mdw - * Various fixes. - * - * Revision 1.3 2000/07/29 17:02:43 mdw - * (checkhash): Be pettier about spaces between the hash and filename, for - * compatiblity with `md5sum'. - * - * Revision 1.2 2000/07/15 21:14:05 mdw - * Missed `-e' out of the usage string. - * - * Revision 1.1 2000/07/15 20:52:34 mdw - * Useful replacement for `md5sum' with support for many different hash - * functions and for reading filename lists from `find'. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "config.h" @@ -76,29 +47,8 @@ #include "ghash.h" -#include "md2.h" -#include "md4.h" -#include "md5.h" -#include "rmd128.h" -#include "rmd160.h" -#include "rmd256.h" -#include "rmd320.h" -#include "sha.h" -#include "sha256.h" -#include "sha384.h" -#include "sha512.h" -#include "tiger.h" - /*----- Static variables --------------------------------------------------*/ -static const gchash *hashtab[] = { - &md5, &md4, &md2, - &sha, &sha256, &sha384, &sha512, - &rmd128, &rmd160, &rmd256, &rmd320, - &tiger, - 0 -}; - #define f_binary 1u #define f_bogus 2u #define f_verbose 4u @@ -135,11 +85,11 @@ static int fhash(const char *file, unsigned f, const gchash *gch, void *buf) else if ((fp = fopen(file, f & f_binary ? "rb" : "r")) == 0) return (-1); - h = gch->init(); + h = GH_INIT(gch); while ((sz = fread(fbuf, 1, sizeof(fbuf), fp)) > 0) - h->ops->hash(h, fbuf, sz); - h->ops->done(h, buf); - h->ops->destroy(h); + GH_HASH(h, fbuf, sz); + GH_DONE(h, buf); + GH_DESTROY(h); e = ferror(fp); if (file) fclose(fp); @@ -208,9 +158,9 @@ static size_t gethex(const char *p, octet *q, size_t sz, char **pp) static const gchash *gethash(const char *name) { - const gchash **g, *gg = 0; + const gchash *const *g, *gg = 0; size_t sz = strlen(name); - for (g = hashtab; *g; g++) { + for (g = ghashtab; *g; g++) { if (strncmp(name, (*g)->name, sz) == 0) { if ((*g)->name[sz] == 0) { gg = *g; @@ -614,7 +564,7 @@ int main(int argc, char *argv[]) gch = gethash(q); } if (!gch) - gch = hashtab[0]; + gch = gethash("md5"); xfree(q); } @@ -662,10 +612,10 @@ int main(int argc, char *argv[]) break; case 'l': { unsigned j; - for (j = 0; hashtab[j]; j++) { + for (j = 0; ghashtab[j]; j++) { if (j) fputc(' ', stdout); - printf("%s", hashtab[j]->name); + printf("%s", ghashtab[j]->name); } fputc('\n', stdout); exit(0);