[Midnightbsd-cvs] src [11113] trunk/sbin/md5/md5.c: sync md5 with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Jun 19 15:00:23 EDT 2018
Revision: 11113
http://svnweb.midnightbsd.org/src/?rev=11113
Author: laffer1
Date: 2018-06-19 15:00:22 -0400 (Tue, 19 Jun 2018)
Log Message:
-----------
sync md5 with freebsd
Modified Paths:
--------------
trunk/sbin/md5/Makefile
trunk/sbin/md5/md5.1
trunk/sbin/md5/md5.c
Property Changed:
----------------
trunk/sbin/md5/md5.1
Modified: trunk/sbin/md5/Makefile
===================================================================
--- trunk/sbin/md5/Makefile 2018-06-19 18:59:04 UTC (rev 11112)
+++ trunk/sbin/md5/Makefile 2018-06-19 19:00:22 UTC (rev 11113)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
# @(#)Makefile 8.1 (Berkeley) 6/9/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/sbin/md5/Makefile 314332 2017-02-27 10:40:39Z avg $
PROG= md5
@@ -6,15 +7,17 @@
LINKS= ${BINDIR}/md5 ${BINDIR}/rmd160 \
${BINDIR}/md5 ${BINDIR}/sha1 \
${BINDIR}/md5 ${BINDIR}/sha256 \
- ${BINDIR}/md5 ${BINDIR}/sha512
+ ${BINDIR}/md5 ${BINDIR}/sha384 \
+ ${BINDIR}/md5 ${BINDIR}/sha512 \
+ ${BINDIR}/md5 ${BINDIR}/sha512t256
MLINKS= md5.1 rmd160.1 \
md5.1 sha1.1 \
md5.1 sha256.1 \
- md5.1 sha512.1
+ md5.1 sha384.1 \
+ md5.1 sha512.1 \
+ md5.1 sha512t256.1
-WFORMAT?= 1
-
DPADD= ${LIBMD}
LDADD= -lmd
Modified: trunk/sbin/md5/md5.1
===================================================================
--- trunk/sbin/md5/md5.1 2018-06-19 18:59:04 UTC (rev 11112)
+++ trunk/sbin/md5/md5.1 2018-06-19 19:00:22 UTC (rev 11113)
@@ -1,9 +1,10 @@
.\" $MidnightBSD$
-.Dd July 31, 2012
+.\" $FreeBSD: stable/10/sbin/md5/md5.1 315150 2017-03-12 13:20:07Z des $
+.Dd April 22, 2016
.Dt MD5 1
.Os
.Sh NAME
-.Nm md5 , sha1 , sha256 , sha512, rmd160
+.Nm md5 , sha1 , sha256 , sha384 , sha512, sha512t256, rmd160
.Nd calculate a message-digest fingerprint (checksum) for a file
.Sh SYNOPSIS
.Nm md5
@@ -21,11 +22,21 @@
.Op Fl c Ar string
.Op Fl s Ar string
.Op Ar
+.Nm sha384
+.Op Fl pqrtx
+.Op Fl c Ar string
+.Op Fl s Ar string
+.Op Ar
.Nm sha512
.Op Fl pqrtx
.Op Fl c Ar string
.Op Fl s Ar string
.Op Ar
+.Nm sha512t256
+.Op Fl pqrtx
+.Op Fl c Ar string
+.Op Fl s Ar string
+.Op Ar
.Nm rmd160
.Op Fl pqrtx
.Op Fl c Ar string
@@ -33,7 +44,7 @@
.Op Ar
.Sh DESCRIPTION
The
-.Nm md5 , sha1 , sha256 , sha512
+.Nm md5 , sha1 , sha256 , sha384 , sha512, sha512t256
and
.Nm rmd160
utilities take as input a message of arbitrary length and produce as
@@ -46,7 +57,7 @@
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 , SHA-512
+.Tn MD5 , SHA-1 , SHA-256 , SHA-384 , SHA-512
and
.Tn RIPEMD-160
algorithms are intended for digital signature applications, where a
@@ -57,24 +68,29 @@
key under a public-key cryptosystem such as
.Tn RSA .
.Pp
+The
.Tn MD5
-has been completely broken as far as finding collisions is
-concerned, and should not be relied upon to produce unique outputs.
-This also means that
-.Tn MD5
-should not be used as part of a cryptographic signature scheme.
-At the current time (2009-01-06) there is no publicly known method to
-.Dq reverse
-MD5, i.e., to find an input given a hash value.
-.Pp
+and
.Tn SHA-1
-currently (2009-01-06) has no known collisions, but an attack has been
-found which is faster than a brute-force search, placing the security of
-.Tn SHA-1
-in doubt.
+algorithms have been proven to be vulnerable to practical collision
+attacks and should not be relied upon to produce unique outputs, nor
+should they be used as part of a cryptographic signature scheme.
+As of 2017-03-02, there is no publicly known method to
+.Em reverse
+either algorithm, i.e. to find an input that produces a specific
+output.
.Pp
+.Tn SHA-512t256
+is a version of
+.Tn SHA-512
+truncated to only 256 bits.
+On 64-bit hardware, this algorithm is approximately 50% faster than
+.Tn SHA-256
+but with the same level of security.
+The hashes are not interchangeable.
+.Pp
It is recommended that all new applications use
-.Tn SHA-256
+.Tn SHA-512
instead of one of the other hash functions.
.Pp
The following options may be used in any combination and must
@@ -83,8 +99,8 @@
after the options are processed.
.Bl -tag -width indent
.It Fl c Ar string
-Compare files to this md5 string.
-(Note that this option is not yet useful if multiple files are specified.)
+Compare the digest of the file against this string.
+.Pq Note that this option is not yet useful if multiple files are specified.
.It Fl s Ar string
Print a checksum of the given
.Ar string .
@@ -91,7 +107,7 @@
.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.
@@ -109,12 +125,14 @@
.El
.Sh EXIT STATUS
The
-.Nm md5 , sha1 , sha256 , sha512
+.Nm md5 , sha1 , sha256 , sha512, sha512t256
and
.Nm rmd160
utilities exit 0 on success,
1 if at least one of the input files could not be read,
-and 2 if at least one file does not have the same hash as the -c option.
+and 2 if at least one file does not have the same hash as the
+.Fl c
+option.
.Sh SEE ALSO
.Xr cksum 1 ,
.Xr md5 3 ,
@@ -121,6 +139,7 @@
.Xr ripemd 3 ,
.Xr sha 3 ,
.Xr sha256 3 ,
+.Xr sha384 3 ,
.Xr sha512 3
.Rs
.%A R. Rivest
@@ -152,4 +171,4 @@
RSA Data Security.
.Pp
Support for SHA-1 and RIPEMD-160 has been added by
-.An Oliver Eikemeier Aq eik at FreeBSD.org .
+.An Oliver Eikemeier Aq Mt eik at FreeBSD.org .
Property changes on: trunk/sbin/md5/md5.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/md5/md5.c
===================================================================
--- trunk/sbin/md5/md5.c 2018-06-19 18:59:04 UTC (rev 11112)
+++ trunk/sbin/md5/md5.c 2018-06-19 19:00:22 UTC (rev 11113)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Derived from:
*
@@ -18,7 +19,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/md5/md5.c 314332 2017-02-27 10:40:39Z avg $");
#include <sys/types.h>
#include <sys/time.h>
@@ -28,7 +29,9 @@
#include <ripemd.h>
#include <sha.h>
#include <sha256.h>
+#include <sha384.h>
#include <sha512.h>
+#include <sha512t.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -42,11 +45,11 @@
#define TEST_BLOCK_COUNT 100000
#define MDTESTCOUNT 8
-int qflag;
-int rflag;
-int sflag;
-unsigned char* checkAgainst;
-int checksFailed;
+static int qflag;
+static int rflag;
+static int sflag;
+static char* checkAgainst;
+static int checksFailed;
typedef void (DIGEST_Init)(void *);
typedef void (DIGEST_Update)(void *, const unsigned char *, size_t);
@@ -55,7 +58,9 @@
extern const char *MD5TestOutput[MDTESTCOUNT];
extern const char *SHA1_TestOutput[MDTESTCOUNT];
extern const char *SHA256_TestOutput[MDTESTCOUNT];
+extern const char *SHA384_TestOutput[MDTESTCOUNT];
extern const char *SHA512_TestOutput[MDTESTCOUNT];
+extern const char *SHA512t256_TestOutput[MDTESTCOUNT];
extern const char *RIPEMD160_TestOutput[MDTESTCOUNT];
typedef struct Algorithm_t {
@@ -70,16 +75,17 @@
} Algorithm_t;
static void MD5_Update(MD5_CTX *, const unsigned char *, size_t);
-static void MDString(Algorithm_t *, const char *);
-static void MDTimeTrial(Algorithm_t *);
-static void MDTestSuite(Algorithm_t *);
-static void MDFilter(Algorithm_t *, int);
-static void usage(Algorithm_t *);
+static void MDString(const Algorithm_t *, const char *);
+static void MDTimeTrial(const Algorithm_t *);
+static void MDTestSuite(const Algorithm_t *);
+static void MDFilter(const Algorithm_t *, int);
+static void usage(const Algorithm_t *);
typedef union {
MD5_CTX md5;
SHA1_CTX sha1;
SHA256_CTX sha256;
+ SHA384_CTX sha384;
SHA512_CTX sha512;
RIPEMD160_CTX ripemd160;
} DIGEST_CTX;
@@ -91,7 +97,7 @@
/* algorithm function table */
-struct Algorithm_t Algorithm[] = {
+static const struct Algorithm_t Algorithm[] = {
{ "md5", "MD5", &MD5TestOutput, (DIGEST_Init*)&MD5Init,
(DIGEST_Update*)&MD5_Update, (DIGEST_End*)&MD5End,
&MD5Data, &MD5File },
@@ -101,9 +107,15 @@
{ "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init,
(DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End,
&SHA256_Data, &SHA256_File },
+ { "sha384", "SHA384", &SHA384_TestOutput, (DIGEST_Init*)&SHA384_Init,
+ (DIGEST_Update*)&SHA384_Update, (DIGEST_End*)&SHA384_End,
+ &SHA384_Data, &SHA384_File },
{ "sha512", "SHA512", &SHA512_TestOutput, (DIGEST_Init*)&SHA512_Init,
(DIGEST_Update*)&SHA512_Update, (DIGEST_End*)&SHA512_End,
&SHA512_Data, &SHA512_File },
+ { "sha512t256", "SHA512t256", &SHA512t256_TestOutput, (DIGEST_Init*)&SHA512_256_Init,
+ (DIGEST_Update*)&SHA512_256_Update, (DIGEST_End*)&SHA512_256_End,
+ &SHA512_256_Data, &SHA512_256_File },
{ "rmd160", "RMD160", &RIPEMD160_TestOutput,
(DIGEST_Init*)&RIPEMD160_Init, (DIGEST_Update*)&RIPEMD160_Update,
(DIGEST_End*)&RIPEMD160_End, &RIPEMD160_Data, &RIPEMD160_File }
@@ -216,7 +228,7 @@
* Digests a string and prints the result.
*/
static void
-MDString(Algorithm_t *alg, const char *string)
+MDString(const Algorithm_t *alg, const char *string)
{
size_t len = strlen(string);
char buf[HEX_DIGEST_LENGTH];
@@ -240,7 +252,7 @@
* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
*/
static void
-MDTimeTrial(Algorithm_t *alg)
+MDTimeTrial(const Algorithm_t *alg)
{
DIGEST_CTX context;
struct rusage before, after;
@@ -282,7 +294,7 @@
* Digests a reference suite of strings and prints the results.
*/
-const char *MDTestInput[MDTESTCOUNT] = {
+static const char *MDTestInput[MDTESTCOUNT] = {
"",
"a",
"abc",
@@ -327,6 +339,17 @@
"e6eae09f10ad4122a0e2a4075761d185a272ebd9f5aa489e998ff2f09cbfdd9f"
};
+const char *SHA384_TestOutput[MDTESTCOUNT] = {
+ "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b",
+ "54a59b9f22b0b80880d8427e548b7c23abd873486e1f035dce9cd697e85175033caa88e6d57bc35efae0b5afd3145f31",
+ "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
+ "473ed35167ec1f5d8e550368a3db39be54639f828868e9454c239fc8b52e3c61dbd0d8b4de1390c256dcbb5d5fd99cd5",
+ "feb67349df3db6f5924815d6c3dc133f091809213731fe5c7b5f4999e463479ff2877f5f2936fa63bb43784b12f3ebb4",
+ "1761336e3f7cbfe51deb137f026f89e01a448e3b1fafa64039c1464ee8732f11a5341a6f41e0c202294736ed64db1a84",
+ "b12932b0627d1c060942f5447764155655bd4da0c9afa6dd9b9ef53129af1b8fb0195996d2de9ca0df9d821ffee67026",
+ "99428d401bf4abcd4ee0695248c9858b7503853acfae21a9cffa7855f46d1395ef38596fcd06d5a8c32d41a839cc5dfb"
+};
+
const char *SHA512_TestOutput[MDTESTCOUNT] = {
"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e",
"1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75",
@@ -338,6 +361,17 @@
"e8a835195e039708b13d9131e025f4441dbdc521ce625f245a436dcd762f54bf5cb298d96235e6c6a304e087ec8189b9512cbdf6427737ea82793460c367b9c3"
};
+const char *SHA512t256_TestOutput[MDTESTCOUNT] = {
+ "c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a",
+ "455e518824bc0601f9fb858ff5c37d417d67c2f8e0df2babe4808858aea830f8",
+ "53048e2681941ef99b2e29b76b4c7dabe4c2d0c634fc6d46e0e2f13107e7af23",
+ "0cf471fd17ed69d990daf3433c89b16d63dec1bb9cb42a6094604ee5d7b4e9fb",
+ "fc3189443f9c268f626aea08a756abe7b726b05f701cb08222312ccfd6710a26",
+ "cdf1cc0effe26ecc0c13758f7b4a48e000615df241284185c39eb05d355bb9c8",
+ "2c9fdbc0c90bdd87612ee8455474f9044850241dc105b1e8b94b8ddf5fac9148",
+ "dd095fc859b336c30a52548b3dc59fcc0d1be8616ebcf3368fad23107db2d736"
+};
+
const char *RIPEMD160_TestOutput[MDTESTCOUNT] = {
"9c1185a5c5e9fc54612808977ee8f548b2258d31",
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
@@ -350,7 +384,7 @@
};
static void
-MDTestSuite(Algorithm_t *alg)
+MDTestSuite(const Algorithm_t *alg)
{
int i;
char buffer[HEX_DIGEST_LENGTH];
@@ -370,7 +404,7 @@
* Digests the standard input and prints the result.
*/
static void
-MDFilter(Algorithm_t *alg, int tee)
+MDFilter(const Algorithm_t *alg, int tee)
{
DIGEST_CTX context;
unsigned int len;
@@ -387,7 +421,7 @@
}
static void
-usage(Algorithm_t *alg)
+usage(const Algorithm_t *alg)
{
fprintf(stderr, "usage: %s [-pqrtx] [-c string] [-s string] [files ...]\n", alg->progname);
More information about the Midnightbsd-cvs
mailing list