Commit Graph

63 Commits

Author SHA1 Message Date
Kyle Evans
8d78a0d331 md5: fix *sum -c with missing files
If we fail to open one of the files in the file listing, we still need
to advance `rec` along with `argv` so that the checksum we're checking
against lines up with the file we're hashing.

Tests added both for the -c flag, as well as the -b and -t modes of
the *sum programs.

PR:		267722
Reviewed by:	emaste (earlier version)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D37374
2023-02-13 00:32:38 -06:00
Dag-Erling Smørgrav
2768d70567 libmd / md5: Add SHA-512/224.
While there, remove .Tn from man pages.

Also remove an obsolete comment about the 80386.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	kevans, allanjude
Differential Revision:	https://reviews.freebsd.org/D38373
2023-02-06 18:03:04 +01:00
Stefan Eßer
9f3aa538e3 sbin/md5.c: fix -q -c for BSD style versions
The BSD style commands (with names not ending in "sum") ignored the -c
options and the passed digest value when invoked with -q.

The man page stated that -q causes only the calculated digest to be
printed, but did not consider the case of both the -q and -c being
used in combination.

Since there is no warning that -c will be ignored when the -q option
is used, users night (and did) expect that the exit code would reflect
the matching of the calculated digest and the argument passed with -c.

This update implements and documents this expected behavior.

PR:		265461
Reported by:	Dmitrij <bugs.freebsd@1fff.net>
MFC after:	2 weeks
2022-07-26 23:04:57 +02:00
Stefan Eßer
b33d1898c1 md5: Improve compatibility with coreutils and format fix
The previous changes that added support for the coreutils -c option
modified the output generated by passing -r to match that of the
coreutils versions. The difference is that coreutils separates the
hash from the file name by two blanks "  " (or a blank followed by
an asterisk " *" with the -b option denoting).

While most scripts or users will not notice the difference, it might
be considered a violation of POLA and this commit reverts the change
for the non-sum programs. These will print a single blank " " as the
separator, as they die before the previous commit.

In order to still generate output that is identical to that of the
coreutils programs, this commit generates the "  " or " *" separator
used by them for the -sum versions, depending on the presence of the
-b option.

MFC after:	3 days
2021-06-29 09:21:57 +02:00
Jessica Clarke
cab31e0e21 md5: Fix cross-build after c2870e576b
On macOS and Linux the current set of headers do not end up pulling in
sys/param.h, causing MAXPATHLEN to not be defined and the build to fail.
2021-06-25 22:00:11 +01:00
Stefan Eßer
c2870e576b sbin/md5: improve compatibility with coreutils -c option
The -c option expects a digest file in either BSD or coreutils format.

The output for matched and mismatched files is identical to that
of the coreutils version.

The review of these changes included test cases that have already
been committed for the functionality that existed before.
Another test script is added to cover the coreutils compatible
extension implemented by this patch.

This commit contains a tests/Makefile that has been cleaned up
compared to the review version, using an implicit rule to apply the
TESTBASE path at build time (and the scripts have been renamed to
have an extension of .SH instead of .sh to trigger this rule).

Reviewed by:    imp
Differential Revision:  https://reviews.freebsd.org/D30812
2021-06-25 08:54:36 +02:00
Warner Losh
d0ea5e467f md5: portability fix -- include stdbool.h explicitly
stdbool.h needs to be included to use type bool variables. Due to
namespace pollution, this gets brought in on FreeBSD, but not on
other systems. Include it explicilty.

Noticed by:		arichards@
Sponsored by:		Netflix
2021-05-20 11:28:18 -06:00
Warner Losh
086feed850 md5: Create md5sum, etc compatible programs
On Linux, there's a similar set of programs to ours, but that end in the
letters 'sum'. These act basically like FreeBSD versions run with the -r
option. Add code so that when the program ends in 'sum' you get the
linux -r behavior. This is enough to make most things that use sha*sum
work correctly (the -c / --check options, as well as the long args are
not implemented). When running with the -sum programs, ignore -t instead
of running internal speed tests and make -c an error.

Reviewed by:		sef, and kp and allanjude (earlier version)
Relnotes:		yes
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30309
2021-05-19 11:41:53 -06:00
Ed Maste
af9de844c4 md5: return non-zero if built-in tests (-x) fail
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2020-07-23 20:06:24 +00:00
Allan Jude
0bc6f34c3d md5(1): fix -c flag to work with input on stdin
Previously, the -p and -c flags were ignored when reading from stdin
Additionally, -s and -c can be used together now.

PR:		247295
Reviewed by:	kevans
MFC after:	2 weeks
Relnotes:	yes
Sponsored by:	Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D25362
2020-06-19 19:16:25 +00:00
Poul-Henning Kamp
5ddaf8458e Close filedescriptors when done with them. 2019-04-19 06:49:46 +00:00
Mariusz Zaborski
377421df96 capsicum: use a new capsicum helpers in tools
Use caph_{rights,ioctls,fcntls}_limit to simplify the code.
2018-11-04 19:24:49 +00:00
Alex Richardson
4635180ea7 Allow bootstrapping md5 on Linux, MacOS and FreeBSD < 12
In order to build on a Linux host we need to bootstrap md5 since the Linux
md5sum command produces output in a different format.

Reviewed By:	emaste
Approved By:	brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D16846
2018-08-23 18:19:01 +00:00
Conrad Meyer
8ff3cdd1b5 Integrate SHA2-224 with userspace components
The double compilation of the kernel sources in libmd and libcrypt is
baffling, but add yet another define hack to prevent duplicate symbols.

Add documentation and SHA2-224 test cases to libmd.

Integrate with the md5(1) command, document, and add more test cases;
self-tests pass.
2018-07-09 08:19:04 +00:00
Mariusz Zaborski
7672a0148f Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0.
No functional change intended.
2018-06-19 23:43:14 +00:00
Eitan Adler
aa677d07a1 md5: perform compare case-insenstive
md5 generates a md5 hash lowercase, but it might be provided in
uppercase. Allow this.

PR:		205598
Reported by:	ohauer
MFC After:	2 weeks
2018-05-23 11:45:46 +00:00
Ed Maste
2c81811986 md5: enter capability on last fd or when acting as a filter
Reviewed by:	allanjude, cem
MFC after:	2 months
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D8271
2016-10-19 21:07:17 +00:00
Allan Jude
b468a9ff1d Import the skein hashing algorithm, based on the threefish block cipher
Connect it to userland (libmd, libcrypt, sbin/md5) and kernel (crypto.ko)

Support for skein as a ZFS checksum algorithm was introduced in r289422
but is disconnected because FreeBSD lacked a Skein implementation.

A further commit will enable it in ZFS.

Reviewed by:	cem
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D6166
2016-05-29 01:15:36 +00:00
Allan Jude
1780e40715 Implement SHA-512 truncated (224 and 256 bits)
This implements SHA-512/256, which generates a 256 bit hash by
calculating the SHA-512 then truncating the result. A different initial
value is used, making the result different from the first 256 bits of
the SHA-512 of the same input. SHA-512 is ~50% faster than SHA-256 on
64bit platforms, so the result is a faster 256 bit hash.

The main goal of this implementation is to enable support for this
faster hashing algorithm in ZFS. The feature was introduced into ZFS
in r289422, but is disconnected because SHA-512/256 support was missing.
A further commit will enable it in ZFS.

This is the follow on to r292782

Reviewed by:	cem
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D6061
2016-05-28 16:06:07 +00:00
Allan Jude
7a3f5d11fb Replace sys/crypto/sha2/sha2.c with lib/libmd/sha512c.c
cperciva's libmd implementation is 5-30% faster

The same was done for SHA256 previously in r263218

cperciva's implementation was lacking SHA-384 which I implemented, validated against OpenSSL and the NIST documentation

Extend sbin/md5 to create sha384(1)

Chase dependancies on sys/crypto/sha2/sha2.{c,h} and replace them with sha512{c.c,.h}

Reviewed by:	cperciva, des, delphij
Approved by:	secteam, bapt (mentor)
MFC after:	2 weeks
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D3929
2015-12-27 17:33:59 +00:00
Xin LI
a2f9ce8a69 Constify.
Suggested by:	rdivacky
MFC after:	2 weeks
2015-03-31 19:12:13 +00:00
Xin LI
11500c4eaa Fix remaining warnings.
MFC after:	2 weeks
2015-03-27 18:23:06 +00:00
Xin LI
16945d8950 - Correct type for checkAgainst.
- Staticify flags that are not used outside the file scope.

PR:		bin/193471
Submitted by:	Robert Sprowson <webpages sprow.co.uk>
MFC after:	2 weeks
2015-03-26 22:34:27 +00:00
Xin LI
edd4c16f78 Teach md5(1) about sha512.
MFC after:	1 month
2012-08-01 00:36:12 +00:00
Eitan Adler
cf0badf098 Document the -c option in --help output
PR:		bin/167463
Submitted by:	"Bryan Drewery" <bryan@shatow.net>
Approved by:	cperciva
MFC after:	3 days
2012-05-09 17:32:10 +00:00
Eitan Adler
745253594b - add "check" option to MD5 and friends to compare files against known hash.
PR:		bin/146541
Submitted by:	eadler
Reviewed by:	jhell@dataix.net
Approved by:	secteam (cperciva)
Approved by:	cperciva
MFC after:	3 weeks
2011-11-13 16:35:47 +00:00
Kevin Lo
1f0e597d5a Use RUSAGE_SELF for the current process instead of hardcoded value 2008-09-02 02:59:13 +00:00
David E. O'Brien
9c6c6249d1 style(9) (verifed no-change in .o's) 2008-02-07 18:10:24 +00:00
Poul-Henning Kamp
25a14196dd Fix an 11 year old mistake: Let the hash functions take a void* instead
of unsigned char* argument.
2006-01-17 15:35:57 +00:00
Colin Percival
186c183c23 In light of the recent 2^69 operation collision-finding attack on SHA1,
add support for SHA256.

Tested on:	i386, sparc64
Tested using:	NIST test vectors, built-in tests
X-MFC-after:	5.4-RELEASE
2005-03-09 19:23:04 +00:00
Oliver Eikemeier
7b89c134f9 fix handling of an unknown progeam name
Noticed by:	Joshua Goodall <joshua@roughtrade.net>
Approved by:	ru
2004-06-22 09:18:50 +00:00
Oliver Eikemeier
cb49d42b60 Add sha1 and rmd160 checksum tools.
Since the algorithms are already supported in libmd,
the size increase is small when a dynamic root is used.

Approved by:	joerg, ru
MFC after:	2 weeks
2004-06-11 16:07:02 +00:00
Stefan Eßer
5758d949d5 Set exit code to 1 in case at least one of the input files
could not be opened.
2003-11-02 23:12:08 +00:00
David E. O'Brien
c69284ca08 Use __FBSDID() to quiet GCC 3.3 warnings. 2003-05-03 18:41:59 +00:00
Mike Silbersack
ed4edda03a Improvements to md5.c so that it uses getrusage to time
benchmarks, and prints out results in float format.
2003-02-14 04:48:06 +00:00
Mike Silbersack
bbe7088205 Change the -x option so that it does an actual REAL test of
the correctness of this program.  Previously, it printed out
the MD5 values of some test strings, but did not tell you
if they were correct or not!
2003-01-26 08:23:37 +00:00
Poul-Henning Kamp
dc015e16dc Fix
md5 -q -s foo
to not expect input on stdin after hashing the string.

MFC after:      1 week
2001-12-19 21:19:43 +00:00
Matthew Dillon
484a709abe Add missing cast for improper time_t use in computation. 2001-10-28 00:01:58 +00:00
Dag-Erling Smørgrav
40dbfd1a48 Fix include ordering breakage from rev. 1.23.
Please-read-style(9):	dd
2001-06-29 06:21:57 +00:00
Ruslan Ermilov
085d234587 Only checksum stdin if nothing has been checksummed yet.
PR:		bin/28386
2001-06-25 08:52:57 +00:00
Dima Dorfman
cafefe8c1b Include missing header files which define functions for which gcc has
builtins (e.g., exit, strcmp).
2001-06-24 23:04:23 +00:00
Ruslan Ermilov
05fe5d5620 Fix argument processing.
Make this compile with WARNS=2.

PR:		bin/27524
MFC after:	3 days
2001-05-22 10:33:43 +00:00
David E. O'Brien
42ea2a63f7 Update usage().
Submitted by:	nectar
2000-11-08 20:41:35 +00:00
David E. O'Brien
2963da13bf Add -q quite mode. 1999-12-04 01:29:43 +00:00
David E. O'Brien
73fd27179f Make `-r -s' also match the BSDI output. 1999-11-11 11:59:03 +00:00
David E. O'Brien
53151fddc0 Change the "-r" output format to match BSDI's default output format. 1999-11-09 17:28:47 +00:00
David E. O'Brien
9e18a3bdd2 Add a new "-r" (right) option that reverses the order a filename and the
hash is printed.  This aids visual diffs.
1999-11-07 04:14:55 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Bill Fumerola
b76bf6fc36 Since we are using strlen() let's assign it to the correct type and
include the proper header.
1999-07-21 00:51:14 +00:00
Kris Kennaway
93606d6ebb Fixes for -t option:
* Don't buffer "Digesting..." output - flush it immediately.
* Increase the number of repetitions by a factor of 100, and the block size by
  a factor of 10 so as to give meaningful results on modern machines (108
  seconds on my P120, and ~26 seconds on a P-II 350).

PR:		bin/10604
Submitted by:	Stanislav Shalunov <shalunov@lynxhub.lz.att.com>
1999-05-01 14:54:21 +00:00