From ee8093c3d24334fcd1db91e1d6ae9fa51ab6973c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Jun 1996 03:08:31 +0000 Subject: [PATCH] add mdbinfile() which is like mdfile() but it returns a binary MD5 CVS patchset: 655 CVS date: 1996/06/20 03:08:31 --- lib/md5.h | 1 + lib/md5sum.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/md5.h b/lib/md5.h index b9035fd..2b4b2d9 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -20,6 +20,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *context); void MD5Transform(uint32 buf[4], uint32 const in[16]); int mdfile(char *fn, unsigned char *digest); +int mdbinfile(char *fn, unsigned char *bindigest); /* * This is needed to make RSAREF happy on some MS-DOS compilers. diff --git a/lib/md5sum.c b/lib/md5sum.c index 1743e7d..dd20b70 100644 --- a/lib/md5sum.c +++ b/lib/md5sum.c @@ -49,3 +49,28 @@ int mdfile(char *fn, unsigned char *digest) { return 0; } + +int mdbinfile(char *fn, unsigned char *bindigest) { + unsigned char buf[1024]; + FILE * fp; + MD5_CTX ctx; + int n; + + fp = fopen(fn, "r"); + if (!fp) { + return 1; + } + + MD5Init(&ctx); + while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) + MD5Update(&ctx, buf, n); + MD5Final(bindigest, &ctx); + if (ferror(fp)) { + fclose(fp); + return 1; + } + + fclose(fp); + + return 0; +} -- 2.7.4