From: zrj Date: Wed, 13 Dec 2017 07:39:00 +0000 (+0200) Subject: md5(1): Add support for sha512. X-Git-Tag: v5.3.0~672 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/82726bbd322006f03f0d48d15181ec652573e8cc md5(1): Add support for sha512. --- diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc index e2ecdb3aed..638ac0276b 100644 --- a/Makefile_upgrade.inc +++ b/Makefile_upgrade.inc @@ -3337,7 +3337,6 @@ TO_REMOVE+=/usr/share/man/man1/sess_id.1.gz TO_REMOVE+=/usr/share/man/man1/sha.1.gz TO_REMOVE+=/usr/share/man/man1/sha224.1.gz TO_REMOVE+=/usr/share/man/man1/sha384.1.gz -TO_REMOVE+=/usr/share/man/man1/sha512.1.gz TO_REMOVE+=/usr/share/man/man1/smime.1.gz TO_REMOVE+=/usr/share/man/man1/speed.1.gz TO_REMOVE+=/usr/share/man/man1/spkac.1.gz diff --git a/sbin/md5/Makefile b/sbin/md5/Makefile index ece6e10a9c..d5bb7dcb03 100644 --- a/sbin/md5/Makefile +++ b/sbin/md5/Makefile @@ -7,11 +7,13 @@ SRCS= md5.c sha1hl.c LINKS= ${BINDIR}/md5 ${BINDIR}/rmd160 \ ${BINDIR}/md5 ${BINDIR}/sha1 \ - ${BINDIR}/md5 ${BINDIR}/sha256 + ${BINDIR}/md5 ${BINDIR}/sha256 \ + ${BINDIR}/md5 ${BINDIR}/sha512 MLINKS= md5.1 rmd160.1 \ md5.1 sha1.1 \ - md5.1 sha256.1 + md5.1 sha256.1 \ + md5.1 sha512.1 DPADD= ${LIBMD} ${LIBRECRYPTO} LDADD= -lmd -lprivate_crypto diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1 index 0cf712f002..2f6ed7f76a 100644 --- a/sbin/md5/md5.1 +++ b/sbin/md5/md5.1 @@ -1,11 +1,12 @@ .\" $FreeBSD: src/sbin/md5/md5.1,v 1.24 2005/03/10 09:56:39 cperciva Exp $ -.Dd January 21, 2010 +.Dd December 17, 2017 .Dt MD5 1 .Os .Sh NAME .Nm md5 , .Nm sha1 , .Nm sha256 , +.Nm sha512 , .Nm rmd160 .Nd calculate a message-digest fingerprint (checksum) for a file .Sh SYNOPSIS @@ -37,7 +38,8 @@ The .Nm md5 , .Nm sha1 , -.Nm sha256 +.Nm sha256 , +.Nm sha512 and .Nm rmd160 utilities take as input a message of arbitrary length and produce as @@ -50,7 +52,7 @@ It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. The -.Tn MD5 , SHA-1, SHA-256 +.Tn MD5 , SHA-1, SHA-256, SHA-512 and .Tn RIPEMD-160 algorithms are intended for digital signature applications, where a @@ -61,16 +63,11 @@ in a secure manner before being encrypted with a private key under a public-key cryptosystem such as .Tn RSA . .Pp +The .Tn MD5 -has not yet (2001-09-03) been broken, but sufficient attacks have been -made that its security is in some doubt. -The attacks on -.Tn MD5 -are in the nature of finding -.Dq collisions -\(em that is, multiple -inputs which hash to the same value; it is still unlikely for an attacker -to be able to determine the exact original input given a hash value. +and +.Tn SHA-1 +algorithms are vulnerable to practical collision attacks. .Pp The following options may be used in any combination and must precede any files named on the command line. @@ -108,7 +105,7 @@ Print a checksum of the given .It Fl p Echo stdin to stdout and append the checksum to stdout. .It Fl q -Quiet mode - only the checksum is printed out. +Quiet mode \(em only the checksum is printed out. Overrides the .Fl r option. @@ -128,7 +125,8 @@ Run a built-in test script. The .Nm md5 , .Nm sha1 , -.Nm sha256 +.Nm sha256 , +.Nm sha512 and .Nm rmd160 utilities exit 0 on success, and @@ -142,7 +140,9 @@ A mistake with command line arguments results in .Xr mmap 2 , .Xr md5 3 , .Xr ripemd 3 , -.Xr sha 3 +.Xr sha 3 , +.Xr sha256 3 , +.Xr sha512 3 .Rs .%A R. Rivest .%T The MD5 Message-Digest Algorithm diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c index 758dd1376b..bca7672cc1 100644 --- a/sbin/md5/md5.c +++ b/sbin/md5/md5.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,7 @@ typedef char *(DIGEST_End)(void *, char *); extern const char *MD5TestOutput[MDTESTCOUNT]; extern const char *SHA1_TestOutput[MDTESTCOUNT]; extern const char *SHA256_TestOutput[MDTESTCOUNT]; +extern const char *SHA512_TestOutput[MDTESTCOUNT]; extern const char *RIPEMD160_TestOutput[MDTESTCOUNT]; typedef struct Algorithm_t { @@ -80,12 +82,14 @@ typedef union { MD5_CTX md5; SHA1_CTX sha1; SHA256_CTX sha256; + SHA512_CTX sha512; RIPEMD160_CTX ripemd160; } DIGEST_CTX; /* max(MD5_DIGEST_LENGTH, SHA_DIGEST_LENGTH, - SHA256_DIGEST_LENGTH, RIPEMD160_DIGEST_LENGTH)*2+1 */ -#define HEX_DIGEST_LENGTH 65 + SHA256_DIGEST_LENGTH, SHA512_DIGEST_LENGTH, + RIPEMD160_DIGEST_LENGTH)*2+1 */ +#define HEX_DIGEST_LENGTH 129 /* algorithm function table */ @@ -99,6 +103,9 @@ static const struct Algorithm_t Algorithm[] = { { "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init, (DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End, &SHA256_Data, &SHA256_File }, + { "sha512", "SHA512", &SHA512_TestOutput, (DIGEST_Init*)&SHA512_Init, + (DIGEST_Update*)&SHA512_Update, (DIGEST_End*)&SHA512_End, + &SHA512_Data, &SHA512_File }, { "rmd160", "RMD160", &RIPEMD160_TestOutput, (DIGEST_Init*)&RIPEMD160_Init, (DIGEST_Update*)&RIPEMD160_Update, (DIGEST_End*)&RIPEMD160_End, &RIPEMD160_Data, &RIPEMD160_File } @@ -453,6 +460,17 @@ const char *SHA256_TestOutput[MDTESTCOUNT] = { "e6eae09f10ad4122a0e2a4075761d185a272ebd9f5aa489e998ff2f09cbfdd9f" }; +const char *SHA512_TestOutput[MDTESTCOUNT] = { + "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", + "1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75", + "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", + "107dbf389d9e9f71a3a95f6c055b9251bc5268c2be16d6c13492ea45b0199f3309e16455ab1e96118e8a905d5597b72038ddb372a89826046de66687bb420e7c", + "4dbff86cc2ca1bae1e16468a05cb9881c97f1753bce3619034898faa1aabe429955a1bf8ec483d7421fe3c1646613a59ed5441fb0f321389f77f48a879c7b1f1", + "1e07be23c26a86ea37ea810c8ec7809352515a970e9253c26f536cfc7a9996c45c8370583e0a78fa4a90041d71a4ceab7423f19c71b9d5a3e01249f0bebd5894", + "72ec1ef1124a45b047e8b7c75a932195135bb61de24ec0d1914042246e0aec3a2354e093d76f3048b456764346900cb130d2a4fd5dd16abb5e30bcb850dee843", + "e8a835195e039708b13d9131e025f4441dbdc521ce625f245a436dcd762f54bf5cb298d96235e6c6a304e087ec8189b9512cbdf6427737ea82793460c367b9c3" +}; + const char *RIPEMD160_TestOutput[MDTESTCOUNT] = { "9c1185a5c5e9fc54612808977ee8f548b2258d31", "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",