diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-03-20 22:03:57 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-03-20 22:03:57 +0000 |
commit | 7bb90b847fdbd899c3e3adebf5afbc2ba83db4bb (patch) | |
tree | 7620d15df8417e302ada23371a2b2761e2ac2d9d /bin | |
parent | 550a28377381fac97a531ba75a0f61753df88db4 (diff) |
purge sum and sysvsum code. ok deraadt jmc lteo millert
a few initial leftovers spotted by naddy
Diffstat (limited to 'bin')
-rw-r--r-- | bin/md5/Makefile | 8 | ||||
-rw-r--r-- | bin/md5/cksum.1 | 114 | ||||
-rw-r--r-- | bin/md5/crc.c | 84 | ||||
-rw-r--r-- | bin/md5/crc.h | 30 | ||||
-rw-r--r-- | bin/md5/md5.c | 51 |
5 files changed, 18 insertions, 269 deletions
diff --git a/bin/md5/Makefile b/bin/md5/Makefile index 8a161cb6ca9..97603777432 100644 --- a/bin/md5/Makefile +++ b/bin/md5/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.13 2014/01/10 17:47:44 deraadt Exp $ +# $OpenBSD: Makefile,v 1.14 2014/03/20 22:03:56 tedu Exp $ PROG= md5 SRCS= crc.c md5.c @@ -6,10 +6,8 @@ MAN= cksum.1 md5.1 LINKS= ${BINDIR}/md5 ${BINDIR}/sha1 \ ${BINDIR}/md5 ${BINDIR}/sha256 \ ${BINDIR}/md5 ${BINDIR}/sha512 \ - ${BINDIR}/md5 ${BINDIR}/cksum \ - ${BINDIR}/md5 ${BINDIR}/sum -MLINKS= cksum.1 sum.1 -MLINKS+= md5.1 sha1.1 + ${BINDIR}/md5 ${BINDIR}/cksum +MLINKS= md5.1 sha1.1 MLINKS+= md5.1 sha256.1 MLINKS+= md5.1 sha512.1 diff --git a/bin/md5/cksum.1 b/bin/md5/cksum.1 index 8cc8c0c36d4..1a810f0b1df 100644 --- a/bin/md5/cksum.1 +++ b/bin/md5/cksum.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cksum.1,v 1.36 2014/03/20 20:32:42 naddy Exp $ +.\" $OpenBSD: cksum.1,v 1.37 2014/03/20 22:03:56 tedu Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -36,8 +36,7 @@ .Dt CKSUM 1 .Os .Sh NAME -.Nm cksum , -.Nm sum +.Nm cksum .Nd display file checksums and block counts .Sh SYNOPSIS .Nm cksum @@ -46,7 +45,6 @@ .Op Fl a Ar algorithms .Op Fl C Ar checklist .Op Fl h Ar hashfile -.Op Fl o Cm 1 | 2 .Op Fl s Ar string .Op Ar .Ek @@ -63,25 +61,13 @@ The .Nm cksum utility writes to the standard output a single line for each input file. The format of this line varies with the algorithm being used as follows: -.Bl -tag -width sysvsum +.Bl -tag -width allxothers .It cksum The output line consists of three whitespace separated fields: a CRC checksum, the number of octets in the input, and name of the file or string. If no file name is specified, the standard input is used and no file name is written. -.It sum -The output line consists of three whitespace separated fields: -a CRC checksum, the number of kilobytes in the input, -and name of the file or string. -If no file name is specified, the standard input is used and no file name -is written. -.It sysvsum -The output line consists of three whitespace separated fields: -a CRC checksum, the number of 512-byte blocks in the input, -and name of the file or string. -If no file name is specified, the standard input is used and no file name -is written. .It all others The output line consists of four whitespace separated fields: the name of the algorithm used, the name of the file or string in @@ -90,20 +76,12 @@ If no file name is specified, the standard input is used and only the cryptographic hash is output. .El .Pp -The -.Nm sum -utility is identical to the -.Nm cksum -utility, except that it defaults to using historic algorithm 1, as -described below. -It is provided for compatibility only. -.Pp The options are as follows: .Bl -tag -width Ds .It Fl a Ar algorithms Use the specified algorithm(s) instead of the default (cksum). Supported algorithms include cksum, md5, rmd160, sha1, -sha224, sha256, sha384, sha512, sum, and sysvsum. +sha224, sha256, sha384, and sha512. Multiple algorithms may be specified, separated by a comma or whitespace. Additionally, multiple .Fl a @@ -121,7 +99,7 @@ suffix, the checksum will be output in hex format. If an algorithm with the same output format is repeated, only the first instance is used. Note that output format suffixes are not supported -for the cksum, sum and sysvsum algorithms. +for the cksum algorithm. .It Fl b Output checksums in base64 notation, not hexadecimal by default. @@ -130,8 +108,7 @@ A or .Sq x suffix on the algorithm will override this default. -This option is ignored for the cksum, sum and sysvsum -algorithms, which do not use hexadecimal output. +This option is ignored for the cksum algorithm. .It Fl C Ar checklist Compare the checksum of each .Ar file @@ -161,9 +138,6 @@ option. Place the checksum into .Ar hashfile instead of stdout. -.It Fl o Cm 1 | 2 -Use historic algorithms instead of the (superior) default one -(see below). .It Fl p Echoes stdin to stdout and appends the checksum to stdout. @@ -187,80 +161,13 @@ by 10 for each additional flag. Runs a built-in test script. .El .Pp -Algorithm 1 (aka sum) -is the algorithm used by historic -.Bx -systems as the -.Nm sum -algorithm and by historic -.At V -systems as the -.Nm sum -algorithm when using the -.Fl r -option. -This is a 16-bit checksum, with a right rotation before each addition; -overflow is discarded. -.Pp -Algorithm 2 (aka sysvsum) is the algorithm used by historic -.At V -systems as the -default -.Nm sum -algorithm. -This is a 32-bit checksum, and is defined as follows: -.Bd -unfilled -offset indent -s = sum of all bytes; -r = s % 2^16 + (s % 2^32) / 2^16; -cksum = (r % 2^16) + r / 2^16; -.Ed -.Pp -Both algorithm 1 and 2 write to the standard output the same fields as -the default algorithm, except that the size of the file in bytes is -replaced with the size of the file in blocks. -For historic reasons, the block size is 1024 for algorithm 1 and 512 -for algorithm 2. -Partial blocks are rounded up. -.Pp The default CRC used is based on the polynomial used for CRC error checking in the networking standard ISO/IEC 8802-3:1996. -The CRC checksum encoding is defined by the generating polynomial: -.Bd -unfilled -offset indent -G(x) = x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + - x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 -.Ed -.Pp -Mathematically, the CRC value corresponding to a given file is defined by -the following procedure: -.Bd -filled -offset indent -The -.Ar n -bits to be evaluated are considered to be the coefficients of a mod 2 -polynomial M(x) of degree -.Ar n Ns \-1 . -These -.Ar n -bits are the bits from the file, with the most significant bit being the most -significant bit of the first octet of the file and the last bit being the least -significant bit of the last octet, padded with zero bits (if necessary) to -achieve an integral number of octets, followed by one or more octets -representing the length of the file as a binary value, least significant octet -first. -The smallest number of octets capable of representing this integer are used. -.Pp -M(x) is multiplied by x^32 (i.e., shifted left 32 bits) and divided by -G(x) using mod 2 division, producing a remainder R(x) of degree \*(Lt= 31. -.Pp -The coefficients of R(x) are considered to be a 32-bit sequence. -.Pp -The bit sequence is complemented and the result is the CRC. -.Ed -.Pp The other available algorithms are described in their respective man pages in section 3 of the manual. .Sh EXIT STATUS -.Ex -std cksum sum +.Ex -std cksum .Sh SEE ALSO .Xr md5 1 .Pp @@ -281,17 +188,12 @@ specification. .Pp All the flags are extensions to that specification. .Sh HISTORY -A -.Nm sum -command appeared in -.At v2 . The .Nm cksum utility appeared in .Bx 4.4 . .Sh CAVEATS -Do not use the cksum, md5, sum, or sysvsum -algorithms to verify file integrity. +Do not use the cksum or md5 algorithms to verify file integrity. An attacker can trivially produce modified payload that has the same checksum as the original version. Use a cryptographic checksum instead. diff --git a/bin/md5/crc.c b/bin/md5/crc.c index bb949b95c6e..05a253f46b1 100644 --- a/bin/md5/crc.c +++ b/bin/md5/crc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crc.c,v 1.3 2009/10/27 23:59:22 deraadt Exp $ */ +/* $OpenBSD: crc.c,v 1.4 2014/03/20 22:03:56 tedu Exp $ */ /* * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com> @@ -135,85 +135,3 @@ CKSUM_End(CKSUM_CTX *ctx, char *outstr) return (outstr); } - -void -SUM_Init(SUM_CTX *ctx) -{ - ctx->crc = 0; - ctx->len = 0; -} - -void -SUM_Update(SUM_CTX *ctx, const unsigned char *buf, size_t len) -{ - size_t i; - - for (i = 0; i < len; i++) { - ctx->crc = ((ctx->crc >> 1) + ((ctx->crc & 1) << 15) + buf[i]); - ctx->crc &= 0xffff; - } - ctx->len += len; -} - -void -SUM_Final(SUM_CTX *ctx) -{ - ctx->len = (ctx->len + 1023) / 1024; /* convert to 1KB blocks */ -} - -char * -SUM_End(SUM_CTX *ctx, char *outstr) -{ - SUM_Final(ctx); - - if (outstr == NULL) { - if (asprintf(&outstr, "%u %lld", ctx->crc, ctx->len) == -1) - return (NULL); - } else { - (void)snprintf(outstr, (size_t)SUM_DIGEST_STRING_LENGTH, - "%u %lld", ctx->crc, ctx->len); - } - - return (outstr); -} - -void -SYSVSUM_Init(SYSVSUM_CTX *ctx) -{ - ctx->crc = 0; - ctx->len = 0; -} - -void -SYSVSUM_Update(SYSVSUM_CTX *ctx, const unsigned char *buf, size_t len) -{ - size_t i; - - for (i = 0; i < len; i++) - ctx->crc += buf[i]; - ctx->len += len; -} - -void -SYSVSUM_Final(SYSVSUM_CTX *ctx) -{ - ctx->crc = (ctx->crc & 0xffff) + (ctx->crc >> 16); - ctx->crc = (ctx->crc & 0xffff) + (ctx->crc >> 16); - ctx->len = (ctx->len + 511) / 512; /* convert to 512 byte blocks */ -} - -char * -SYSVSUM_End(SYSVSUM_CTX *ctx, char *outstr) -{ - SYSVSUM_Final(ctx); - - if (outstr == NULL) { - if (asprintf(&outstr, "%u %lld", ctx->crc, ctx->len) == -1) - return (NULL); - } else { - (void)snprintf(outstr, (size_t)SYSVSUM_DIGEST_STRING_LENGTH, - "%u %lld", ctx->crc, ctx->len); - } - - return (outstr); -} diff --git a/bin/md5/crc.h b/bin/md5/crc.h index 1570d911639..d47eceb7841 100644 --- a/bin/md5/crc.h +++ b/bin/md5/crc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: crc.h,v 1.1 2004/05/02 17:53:29 millert Exp $ */ +/* $OpenBSD: crc.h,v 1.2 2014/03/20 22:03:56 tedu Exp $ */ /* * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com> @@ -24,36 +24,8 @@ typedef struct CKSUMContext { off_t len; } CKSUM_CTX; -#define SUM_DIGEST_LENGTH 4 -#define SUM_DIGEST_STRING_LENGTH (10 + 1 + 16) - -typedef struct SUMContext { - u_int32_t crc; - off_t len; -} SUM_CTX; - -#define SYSVSUM_DIGEST_LENGTH 4 -#define SYSVSUM_DIGEST_STRING_LENGTH (10 + 1 + 16) - -typedef struct SYSVSUMContext { - u_int32_t crc; - off_t len; -} SYSVSUM_CTX; - void CKSUM_Init(CKSUM_CTX *); void CKSUM_Update(CKSUM_CTX *, const u_int8_t *, size_t); void CKSUM_Final(CKSUM_CTX *); char *CKSUM_End(CKSUM_CTX *, char *); char *CKSUM_Data(const u_int8_t *, size_t, char *); - -void SUM_Init(SUM_CTX *); -void SUM_Update(SUM_CTX *, const u_int8_t *, size_t); -void SUM_Final(SUM_CTX *); -char *SUM_End(SUM_CTX *, char *); -char *SUM_Data(const u_int8_t *, size_t, char *); - -void SYSVSUM_Init(SYSVSUM_CTX *); -void SYSVSUM_Update(SYSVSUM_CTX *, const u_int8_t *, size_t); -void SYSVSUM_Final(SYSVSUM_CTX *); -char *SYSVSUM_End(SYSVSUM_CTX *, char *); -char *SYSVSUM_Data(const u_int8_t *, size_t, char *); diff --git a/bin/md5/md5.c b/bin/md5/md5.c index 9e95f3e7b2d..bd9fd597102 100644 --- a/bin/md5/md5.c +++ b/bin/md5/md5.c @@ -1,4 +1,4 @@ -/* $OpenBSD: md5.c,v 1.73 2014/03/20 20:32:42 naddy Exp $ */ +/* $OpenBSD: md5.c,v 1.74 2014/03/20 22:03:56 tedu Exp $ */ /* * Copyright (c) 2001,2003,2005-2007,2010,2013,2014 @@ -53,8 +53,6 @@ union ANY_CTX { #if !defined(SHA2_ONLY) - SUM_CTX sum; - SYSVSUM_CTX sysvsum; CKSUM_CTX cksum; MD5_CTX md5; RMD160_CTX rmd160; @@ -88,28 +86,6 @@ struct hash_function { (char *(*)(void *, char *))CKSUM_End }, { - "SUM", - SUM_DIGEST_LENGTH, - STYLE_CKSUM, - -1, - NULL, - (void (*)(void *))SUM_Init, - (void (*)(void *, const unsigned char *, unsigned int))SUM_Update, - (void (*)(unsigned char *, void *))SUM_Final, - (char *(*)(void *, char *))SUM_End - }, - { - "SYSVSUM", - SYSVSUM_DIGEST_LENGTH, - STYLE_CKSUM, - -1, - NULL, - (void (*)(void *))SYSVSUM_Init, - (void (*)(void *, const unsigned char *, unsigned int))SYSVSUM_Update, - (void (*)(unsigned char *, void *))SYSVSUM_Final, - (char *(*)(void *, char *))SYSVSUM_End - }, - { "MD5", MD5_DIGEST_LENGTH, STYLE_MD5, @@ -230,8 +206,8 @@ main(int argc, char **argv) error = bflag = cflag = pflag = qflag = rflag = tflag = xflag = 0; #if !defined(SHA2_ONLY) - if (strcmp(__progname, "cksum") == 0 || strcmp(__progname, "sum") == 0) - optstr = "a:bC:ch:o:pqrs:tx"; + if (strcmp(__progname, "cksum") == 0) + optstr = "a:bC:ch:pqrs:tx"; else #endif /* !defined(SHA2_ONLY) */ optstr = "bC:ch:pqrs:tx"; @@ -306,23 +282,6 @@ main(int argc, char **argv) case 'c': cflag = 1; break; - case 'o': - if (strcmp(optarg, "1") == 0) - hf = &functions[1]; - else if (strcmp(optarg, "2") == 0) - hf = &functions[2]; - else { - warnx("illegal argument to -o option"); - usage(); - } - /* Check for dupes. */ - TAILQ_FOREACH(hftmp, &hl, tailq) { - if (strcmp(hf->name, hftmp->name) == 0) - break; - } - if (hftmp == TAILQ_END(&hl)) - hash_insert(&hl, hf, 0); - break; #endif /* !defined(SHA2_ONLY) */ case 'p': pflag = 1; @@ -836,9 +795,9 @@ void usage(void) { #if !defined(SHA2_ONLY) - if (strcmp(__progname, "cksum") == 0 || strcmp(__progname, "sum") == 0) + if (strcmp(__progname, "cksum") == 0) fprintf(stderr, "usage: %s [-bcpqrtx] [-a algorithms] [-C checklist] " - "[-h hashfile] [-o 1 | 2]\n" + "[-h hashfile]\n" " [-s string] [file ...]\n", __progname); else |