From: Adam Heath Date: Mon, 25 Dec 2000 05:50:15 +0000 (+0000) Subject: Moved md5 code into generic buffer_copy loop. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10a63dfaae1286c4830e8e70aaeafc0455d07234;p=dpkg Moved md5 code into generic buffer_copy loop. --- diff --git a/ChangeLog b/ChangeLog index e8656485..e72e33b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Dec 24 23:48:45 CST 2000 Adam Heath + + * include/dpkg.h.in, lib/Makefile.in, lib/mlib.c, utils/Makefile.in, + utils/md5sum.c: Moved md5 code into generic buffer_copy loop. + Sun Dec 24 13:59:36 CST 2000 Adam Heath * Use DESTDIR when installing /etc/dpkg/origins/dpkg diff --git a/include/dpkg.h.in b/include/dpkg.h.in index 4b130184..ec62138f 100644 --- a/include/dpkg.h.in +++ b/include/dpkg.h.in @@ -202,6 +202,7 @@ void waitsubproc(pid_t pid, const char *description, int sigpipeok); #define BUFFER_WRITE_FD 2 #define BUFFER_WRITE_NULL 3 #define BUFFER_WRITE_STREAM 4 +#define BUFFER_WRITE_MD5 5 #define BUFFER_READ_FD 0 #define BUFFER_READ_STREAM 1 @@ -213,6 +214,13 @@ struct buffer_data { int type; }; +#define fd_md5(fd, hash, limit, desc...)\ + buffer_md5_setup((void *)fd, BUFFER_READ_FD, NULL, \ + hash, limit, desc) +#define stream_md5(file, hash, limit, desc...)\ + buffer_md5_setup((void *)file, BUFFER_READ_STREAM, NULL, \ + hash, limit, desc) + #define fd_fd_copy(fd1, fd2, limit, desc...)\ buffer_copy_setup((void *)fd1, BUFFER_READ_FD, NULL, \ (void *)fd2, BUFFER_WRITE_FD, NULL, \ @@ -246,6 +254,8 @@ struct buffer_data { ssize_t buffer_copy_setup(void *argIn, int typeIn, void *procIn, void *argOut, int typeOut, void *procOut, ssize_t limit, const char *desc, ...); +ssize_t buffer_md5_setup(void *argIn, int typeIn, void *procIn, + unsigned char hash[33], ssize_t limit, const char *desc, ...); ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, char *desc); extern volatile int onerr_abort; diff --git a/lib/Makefile.in b/lib/Makefile.in index 4ec7da80..6b6bfe2f 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -7,7 +7,7 @@ include ../Makefile.conf SOURCES = compat.c database.c dbmodify.c dump.c ehandle.c fields.c \ lock.c mlib.c myopt.c nfmalloc.c parse.c parsehelp.c \ - showcright.c tarfn.c varbuf.c vercmp.c + showcright.c tarfn.c varbuf.c vercmp.c md5.c OBJECTS = $(patsubst %.c, %.o, $(SOURCES)) GENFILES = $(OBJECTS) libdpkg.a diff --git a/lib/mlib.c b/lib/mlib.c index 2392b638..61f80c52 100644 --- a/lib/mlib.c +++ b/lib/mlib.c @@ -31,6 +31,7 @@ #include #include #include +#include /* Incremented when we do some kind of generally necessary operation, so that * loops &c know to quit if we take an error exit. Decremented again afterwards. @@ -147,6 +148,9 @@ ssize_t buffer_write(buffer_data_t data, void *buf, ssize_t length, char *desc) if(ferror((FILE *)data->data)) ohshite(_("error in buffer_write(stream): %s"), desc); break; + case BUFFER_WRITE_MD5: + MD5Update((struct MD5Context *)data->data, buf, length); + break; default: fprintf(stderr, _("unknown data type `%i' in buffer_write\n"), data->type); } @@ -163,7 +167,7 @@ ssize_t buffer_read(buffer_data_t data, void *buf, ssize_t length, char *desc) { case BUFFER_READ_STREAM: ret= fread(buf, 1, length, (FILE *)data->data); if(feof((FILE *)data->data)) - ohshite(_("eof in buffer_read(stream): %s"), desc); + return ret; if(ferror((FILE *)data->data)) ohshite(_("error in buffer_read(stream): %s"), desc); break; @@ -198,6 +202,36 @@ ssize_t buffer_copy_setup(void *argIn, int typeIn, void *procIn, return ret; } +ssize_t buffer_md5_setup(void *argIn, int typeIn, void *procIn, + unsigned char hash[33], ssize_t limit, const char *desc, ...) +{ + struct MD5Context ctx; + struct buffer_data read_data = { procIn, argIn, typeIn }, + write_data = { buffer_write, &ctx, BUFFER_WRITE_MD5 }; + va_list al; + struct varbuf v; + int ret, i; + unsigned char digest[16], *p = digest; + + varbufinit(&v); + + va_start(al,desc); + varbufvprintf(&v, desc, al); + va_end(al); + + if ( procIn == NULL ) + read_data.proc = buffer_read; + MD5Init(&ctx); + ret = buffer_copy(&read_data, &write_data, limit, v.buf); + MD5Final(digest, &ctx); + for (i = 0; i < 16; ++i) { + sprintf(hash, "%02x", *p++); + hash += 2; + } + varbuffree(&v); + return ret; +} + ssize_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, ssize_t limit, char *desc) { char *buf, *writebuf; diff --git a/po/dpkg.pot b/po/dpkg.pot index 5f46b912..031109be 100644 --- a/po/dpkg.pot +++ b/po/dpkg.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2000-12-24 05:57-0600\n" +"POT-Creation-Date: 2000-12-24 23:33-0600\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -399,105 +399,105 @@ msgstr "" msgid "unable to lock dpkg status database" msgstr "" -#: lib/mlib.c:48 +#: lib/mlib.c:49 #, c-format msgid "malloc failed (%ld bytes)" msgstr "" -#: lib/mlib.c:61 +#: lib/mlib.c:62 #, c-format msgid "realloc failed (%ld bytes)" msgstr "" -#: lib/mlib.c:68 +#: lib/mlib.c:69 #, c-format msgid "%s (subprocess): %s\n" msgstr "" -#: lib/mlib.c:81 +#: lib/mlib.c:82 msgid "fork failed" msgstr "" -#: lib/mlib.c:94 +#: lib/mlib.c:95 #, c-format msgid "failed to dup for std%s" msgstr "" -#: lib/mlib.c:95 +#: lib/mlib.c:96 #, c-format msgid "failed to dup for fd %d" msgstr "" -#: lib/mlib.c:101 +#: lib/mlib.c:102 msgid "failed to create pipe" msgstr "" -#: lib/mlib.c:108 +#: lib/mlib.c:109 #, c-format msgid "subprocess %s returned error exit status %d" msgstr "" -#: lib/mlib.c:111 +#: lib/mlib.c:112 #, c-format msgid "subprocess %s killed by signal (%s)%s" msgstr "" -#: lib/mlib.c:114 +#: lib/mlib.c:115 #, c-format msgid "subprocess %s failed with wait status code %d" msgstr "" -#: lib/mlib.c:123 main/help.c:367 +#: lib/mlib.c:124 main/help.c:367 #, c-format msgid "wait for %s failed" msgstr "" -#: lib/mlib.c:139 +#: lib/mlib.c:140 #, c-format msgid "failed in buffer_write(fd) (%i, ret=%i, %s)" msgstr "" -#: lib/mlib.c:146 +#: lib/mlib.c:147 #, c-format msgid "eof in buffer_write(stream): %s" msgstr "" -#: lib/mlib.c:148 +#: lib/mlib.c:149 #, c-format msgid "error in buffer_write(stream): %s" msgstr "" -#: lib/mlib.c:151 +#: lib/mlib.c:155 #, c-format msgid "unknown data type `%i' in buffer_write\n" msgstr "" -#: lib/mlib.c:161 +#: lib/mlib.c:165 #, c-format msgid "failed in buffer_read(fd): %s" msgstr "" -#: lib/mlib.c:166 +#: lib/mlib.c:171 #, c-format msgid "eof in buffer_read(stream): %s" msgstr "" -#: lib/mlib.c:168 +#: lib/mlib.c:173 #, c-format msgid "error in buffer_read(stream): %s" msgstr "" -#: lib/mlib.c:171 +#: lib/mlib.c:176 #, c-format msgid "unknown data type `%i' in buffer_read\n" msgstr "" -#: lib/mlib.c:209 +#: lib/mlib.c:244 #, c-format msgid "failed to allocate buffer in buffer_copy (%s)" msgstr "" -#: lib/mlib.c:240 +#: lib/mlib.c:275 #, c-format msgid "failed in buffer_copy (%s)" msgstr "" @@ -1299,32 +1299,11 @@ msgid "" "`%s')\n" msgstr "" -#: main/configure.c:551 -msgid "failed to exec md5sum" -msgstr "" - -#: main/configure.c:556 -#, c-format -msgid "unable to fdopen for md5sum of `%.250s'" -msgstr "" - -#: main/configure.c:564 -msgid "error reading pipe from md5sum" -msgstr "" - -#: main/configure.c:565 -msgid "error closing pipe from md5sum" -msgstr "" - -#. file= fdopen(p1[0]) -#. m_pipe() -#. fd= open(cdr.buf) -#: main/configure.c:569 -#, c-format -msgid "md5sum gave malformatted output `%.250s'" +#: main/configure.c:545 +msgid "md5hash" msgstr "" -#: main/configure.c:573 +#: main/configure.c:551 #, c-format msgid "dpkg: %s: warning - unable to open conffile %s for hash: %s\n" msgstr "" @@ -3549,17 +3528,21 @@ msgstr "" msgid "unable to exec mksplit" msgstr "" -#: utils/md5sum.c:106 +#: utils/md5sum.c:59 +msgid "Type md5sum --help for help." +msgstr "" + +#: utils/md5sum.c:110 #, c-format msgid "%s: read error on stdin\n" msgstr "" -#: utils/md5sum.c:124 utils/md5sum.c:250 +#: utils/md5sum.c:127 utils/md5sum.c:237 #, c-format msgid "%s: error reading %s\n" msgstr "" -#: utils/md5sum.c:138 +#: utils/md5sum.c:140 msgid "" "usage: md5sum [-bv] [-c [file]] | [file...]\n" "Generates or checks MD5 Message Digests\n" @@ -3570,35 +3553,39 @@ msgid "" "that is printed on stdout by this program when it generates digests.\n" msgstr "" -#: utils/md5sum.c:211 +#: utils/md5sum.c:153 +msgid "mdfile" +msgstr "" + +#: utils/md5sum.c:198 #, c-format msgid "%s: unrecognized line: %s" msgstr "" -#: utils/md5sum.c:245 +#: utils/md5sum.c:232 #, c-format msgid "%s: can't open %s\n" msgstr "" -#: utils/md5sum.c:258 +#: utils/md5sum.c:245 msgid "FAILED\n" msgstr "" -#: utils/md5sum.c:260 +#: utils/md5sum.c:247 #, c-format msgid "%s: MD5 check failed for '%s'\n" msgstr "" -#: utils/md5sum.c:263 +#: utils/md5sum.c:250 msgid "OK\n" msgstr "" -#: utils/md5sum.c:267 +#: utils/md5sum.c:254 #, c-format msgid "%s: %d of %d file(s) failed MD5 check\n" msgstr "" -#: utils/md5sum.c:269 +#: utils/md5sum.c:256 #, c-format msgid "%s: no files checked\n" msgstr "" @@ -3868,113 +3855,115 @@ msgstr "" msgid "Quit without changing selected access method" msgstr "" -#: dselect/main.cc:53 +#: dselect/main.cc:54 msgid "Type dselect --help for help." msgstr "" -#: dselect/main.cc:70 +#: dselect/main.cc:72 msgid "a" msgstr "" -#: dselect/main.cc:70 +#: dselect/main.cc:72 msgid "[A]ccess" msgstr "" -#: dselect/main.cc:70 +#: dselect/main.cc:72 msgid "Choose the access method to use." msgstr "" -#: dselect/main.cc:71 +#: dselect/main.cc:73 msgid "u" msgstr "" -#: dselect/main.cc:71 +#: dselect/main.cc:73 msgid "[U]pdate" msgstr "" -#: dselect/main.cc:71 +#: dselect/main.cc:73 msgid "Update list of available packages, if possible." msgstr "" -#: dselect/main.cc:72 +#: dselect/main.cc:74 msgid "s" msgstr "" -#: dselect/main.cc:72 +#: dselect/main.cc:74 msgid "[S]elect" msgstr "" -#: dselect/main.cc:72 +#: dselect/main.cc:74 msgid "Request which packages you want on your system." msgstr "" -#: dselect/main.cc:73 +#: dselect/main.cc:75 msgid "i" msgstr "" -#: dselect/main.cc:73 +#: dselect/main.cc:75 msgid "[I]nstall" msgstr "" -#: dselect/main.cc:73 +#: dselect/main.cc:75 msgid "Install and upgrade wanted packages." msgstr "" -#: dselect/main.cc:74 +#: dselect/main.cc:76 msgid "c" msgstr "" -#: dselect/main.cc:74 +#: dselect/main.cc:76 msgid "[C]onfig" msgstr "" -#: dselect/main.cc:74 +#: dselect/main.cc:76 msgid "Configure any packages that are unconfigured." msgstr "" -#: dselect/main.cc:75 +#: dselect/main.cc:77 msgid "r" msgstr "" -#: dselect/main.cc:75 +#: dselect/main.cc:77 msgid "[R]emove" msgstr "" -#: dselect/main.cc:75 +#: dselect/main.cc:77 msgid "Remove unwanted software." msgstr "" -#: dselect/main.cc:76 +#: dselect/main.cc:78 msgid "q" msgstr "" -#: dselect/main.cc:76 +#: dselect/main.cc:78 msgid "[Q]uit" msgstr "" -#: dselect/main.cc:76 +#: dselect/main.cc:78 msgid "Quit dselect." msgstr "" -#: dselect/main.cc:77 +#: dselect/main.cc:79 msgid "menu" msgstr "" -#: dselect/main.cc:82 +#: dselect/main.cc:84 #, c-format -msgid "Debian GNU/Linux `%s' package handling frontend." +msgid "Debian `%s' package handling frontend." msgstr "" -#: dselect/main.cc:85 +#: dselect/main.cc:87 #, c-format msgid "" -"Version %s. Copyright (C) 1994-1996 Ian Jackson. This is\n" -"free software; see the GNU General Public Licence version 2 or later for\n" -"copying conditions. There is NO warranty. See dselect --licence for " -"details.\n" +"Version %s.\n" +"Copyright (C) 1994-1996 Ian Jackson.\n" +"Copyright (C) 2000 Wichert Akkerman.\n" +"This is free software; see the GNU General Public Licence version 2\n" +"or later for copying conditions. There is NO warranty. See\n" +"dselect --licence for details.\n" msgstr "" -#: dselect/main.cc:97 +#: dselect/main.cc:102 msgid "" "Usage: dselect [options]\n" " dselect [options] action ...\n" @@ -3983,30 +3972,30 @@ msgid "" "Actions: access update select install config remove quit menu\n" msgstr "" -#: dselect/main.cc:117 +#: dselect/main.cc:122 #, c-format msgid "couldn't open debug file `%.255s'\n" msgstr "" -#: dselect/main.cc:148 +#: dselect/main.cc:153 msgid "Terminal does not appear to support cursor addressing.\n" msgstr "" -#: dselect/main.cc:150 +#: dselect/main.cc:155 msgid "Terminal does not appear to support highlighting.\n" msgstr "" -#: dselect/main.cc:151 +#: dselect/main.cc:156 msgid "" "Set your TERM variable correctly, use a better terminal,\n" "or make do with the per-package management tool " msgstr "" -#: dselect/main.cc:154 +#: dselect/main.cc:159 msgid "terminal lacks necessary features, giving up" msgstr "" -#: dselect/main.cc:232 +#: dselect/main.cc:237 msgid "" "\n" "\n" @@ -4015,18 +4004,18 @@ msgid "" "\n" msgstr "" -#: dselect/main.cc:246 +#: dselect/main.cc:251 msgid "" "\n" "\n" "Read-only access: only preview of selections is available!" msgstr "" -#: dselect/main.cc:260 +#: dselect/main.cc:265 msgid "failed to getch in main menu" msgstr "" -#: dselect/main.cc:327 +#: dselect/main.cc:332 #, c-format msgid "unknown action string `%.50s'" msgstr "" diff --git a/utils/Makefile.in b/utils/Makefile.in index c95ded66..aca2e482 100644 --- a/utils/Makefile.in +++ b/utils/Makefile.in @@ -11,7 +11,7 @@ SSD_SOURCES = start-stop-daemon.c SSD_OBJECTS = $(patsubst %.c, %.o, $(SSD_SOURCES)) SSD_MANPAGES = start-stop-daemon.8 -MD5_SOURCES = md5sum.c md5.c +MD5_SOURCES = md5sum.c MD5_OBJECTS = $(patsubst %.c, %.o, $(MD5_SOURCES)) MD5_MANPAGES = md5sum.1 @@ -62,6 +62,5 @@ endif start-stop-daemon: $(SSD_OBJECTS) ../optlib/libopt.a $(CC) $(LDFLAGS) -o $@ $^ $(SSD_LIBS) -md5sum: $(MD5_OBJECTS) ../optlib/libopt.a +md5sum: $(MD5_OBJECTS) ../optlib/libopt.a ../lib/libdpkg.a $(CC) $(LDFLAGS) -o $@ $^ $(NLS_LIBS) - diff --git a/utils/md5.c b/utils/md5.c deleted file mode 100644 index 0ac9d192..00000000 --- a/utils/md5.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - * - * Changed so as no longer to depend on Colin Plumb's `usual.h' header - * definitions; now uses stuff from dpkg's config.h. - * - Ian Jackson . - * Still in the public domain. - */ - -#include /* for memcpy() */ -#include /* for stupid systems */ -#include /* for ntohl() */ - -#include "config.h" -#include "md5.h" - -#ifdef WORDS_BIGENDIAN -void -byteSwap(UWORD32 *buf, unsigned words) -{ - md5byte *p = (md5byte *)buf; - - do { - *buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 | - ((unsigned)p[1] << 8 | p[0]); - p += 4; - } while (--words); -} -#else -#define byteSwap(buf,words) -#endif - -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void -MD5Init(struct MD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bytes[0] = 0; - ctx->bytes[1] = 0; -} - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -void -MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len) -{ - UWORD32 t; - - /* Update byte count */ - - t = ctx->bytes[0]; - if ((ctx->bytes[0] = t + len) < t) - ctx->bytes[1]++; /* Carry from low to high */ - - t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */ - if (t > len) { - memcpy((md5byte *)ctx->in + 64 - t, buf, len); - return; - } - /* First chunk is an odd size */ - memcpy((md5byte *)ctx->in + 64 - t, buf, t); - byteSwap(ctx->in, 16); - MD5Transform(ctx->buf, ctx->in); - buf += t; - len -= t; - - /* Process data in 64-byte chunks */ - while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteSwap(ctx->in, 16); - MD5Transform(ctx->buf, ctx->in); - buf += 64; - len -= 64; - } - - /* Handle any remaining bytes of data. */ - memcpy(ctx->in, buf, len); -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void -MD5Final(md5byte digest[16], struct MD5Context *ctx) -{ - int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */ - md5byte *p = (md5byte *)ctx->in + count; - - /* Set the first char of padding to 0x80. There is always room. */ - *p++ = 0x80; - - /* Bytes of padding needed to make 56 bytes (-8..55) */ - count = 56 - 1 - count; - - if (count < 0) { /* Padding forces an extra block */ - memset(p, 0, count + 8); - byteSwap(ctx->in, 16); - MD5Transform(ctx->buf, ctx->in); - p = (md5byte *)ctx->in; - count = 56; - } - memset(p, 0, count); - byteSwap(ctx->in, 14); - - /* Append length in bits and transform */ - ctx->in[14] = ctx->bytes[0] << 3; - ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29; - MD5Transform(ctx->buf, ctx->in); - - byteSwap(ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ -} - -#ifndef ASM_MD5 - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f,w,x,y,z,in,s) \ - (w += f(x,y,z) + in, w = (w<>(32-s)) + x) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -void -MD5Transform(UWORD32 buf[4], UWORD32 const in[16]) -{ - register UWORD32 a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} - -#endif diff --git a/utils/md5.h b/utils/md5.h deleted file mode 100644 index 021766c1..00000000 --- a/utils/md5.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This is the header file for the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - * - * Changed so as no longer to depend on Colin Plumb's `usual.h' - * header definitions; now uses stuff from dpkg's config.h - * - Ian Jackson . - * Still in the public domain. - */ - -#ifndef MD5_H -#define MD5_H - -#define md5byte unsigned char - -struct MD5Context { - UWORD32 buf[4]; - UWORD32 bytes[2]; - UWORD32 in[16]; -}; - -void MD5Init(struct MD5Context *context); -void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len); -void MD5Final(unsigned char digest[16], struct MD5Context *context); -void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]); - -#endif /* !MD5_H */ diff --git a/utils/md5sum.c b/utils/md5sum.c index 2d103676..de39960d 100644 --- a/utils/md5sum.c +++ b/utils/md5sum.c @@ -16,8 +16,8 @@ #include #include #include + #include "config.h" -#include "md5.h" /* Take care of NLS matters. */ @@ -39,6 +39,8 @@ # define _(Text) Text #endif +#include + #ifdef UNIX #define FOPRTXT "r" #define FOPRBIN "r" @@ -54,6 +56,8 @@ extern char *optarg; extern int optind; +const char printforhelp[]= N_("Type md5sum --help for help."); +const char thisname[]= MD5SUM; void usage(void); void print_digest(unsigned char *p); @@ -106,8 +110,7 @@ main(int argc, char **argv) fprintf(stderr, _("%s: read error on stdin\n"), progname); exit(2); } - print_digest(digest); - printf("\n"); + printf("%s\n", digest); exit(0); } for ( ; argc > 0; --argc, ++argv) { @@ -124,8 +127,7 @@ main(int argc, char **argv) fprintf(stderr, _("%s: error reading %s\n"), progname, *argv); rc = 2; } else { - print_digest(digest); - printf(" %c%s\n", bin_mode ? '*' : ' ', *argv); + printf("%s %c%s\n", digest, bin_mode ? '*' : ' ', *argv); } fclose(fp); } @@ -148,26 +150,11 @@ that is printed on stdout by this program when it generates digests.\n"), stderr int mdfile(FILE *fp, unsigned char *digest) { - unsigned char buf[1024]; - struct MD5Context ctx; - int n; - - MD5Init(&ctx); - while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) - MD5Update(&ctx, buf, n); - MD5Final(digest, &ctx); - if (ferror(fp)) - return -1; - return 0; -} - -void -print_digest(unsigned char *p) -{ - int i; - - for (i = 0; i < 16; ++i) - printf("%02x", *p++); + ssize_t ret = stream_md5(fp, digest, -1, _("mdfile")); + if ( ret >= 0 ) + return 0; + else + return ret; } int