** New Features
+ cksum -a now supports the "crc32b" option, which calculates the CRC
+ of the input as defined by ITU V.42, as used by gzip for example.
+
ls now supports the --sort=name option,
to explicitly select the default operation of sorting by file name.
config-h
configmake
copy-file-range
+ crc
crypto/md5
crypto/sha1
crypto/sha256
The 32-bit CRC used is based on the polynomial used
for CRC error checking in the ISO/IEC 8802-3:1996 standard (Ethernet).
Similar output formats are used for the other legacy checksums
-selectable with @option{--algorithm=sysv} or @option{--algorithm=bsd},
+selectable with @option{--algorithm=crc32b}, and
+@option{--algorithm=sysv} or @option{--algorithm=bsd}
detailed at @ref{sum invocation}.
@item Tagged output format
@samp{sysv} equivalent to @command{sum -s}
@samp{bsd} equivalent to @command{sum -r}
@samp{crc} equivalent to @command{cksum} (the default)
+@samp{crc32b} only available through @command{cksum}
@end example
Supported more modern digest algorithms are:
Print only the unencoded raw binary digest for a single input.
Do not output the file name or anything else.
Use network byte order (big endian) where applicable:
-for @samp{bsd}, @samp{crc}, and @samp{sysv}.
+for @samp{bsd}, @samp{crc}, @samp{crc32b}, and @samp{sysv}.
This option works only with a single input.
Unlike other output formats, @command{cksum} provides no way to
@option{--check} a @option{--raw} checksum.
line is found, @command{cksum} exits with nonzero status. Otherwise,
it exits successfully.
The @command{cksum} command does not support @option{--check}
-with the older @samp{sysv}, @samp{bsd}, or @samp{crc} algorithms.
+with the older @samp{sysv}, @samp{bsd}, @samp{crc} or @samp{crc32b} algorithms.
@item --ignore-missing
@opindex --ignore-missing
#else /* !CRCTAB */
# include "cksum.h"
+# include "crc.h"
/* Number of bytes to read at once. */
# define BUFLEN (1 << 16)
return 0;
}
+/* Calculate the crc32b checksum and length in bytes of stream STREAM.
+ Return -1 on error, 0 on success. */
+
+int
+crc32b_sum_stream (FILE *stream, void *resstream, uintmax_t *reslen)
+{
+ uint32_t buf[BUFLEN / sizeof (uint32_t)];
+ uint32_t crc = 0;
+ uintmax_t len = 0;
+ size_t bytes_read;
+
+ if (!stream || !resstream || !reslen)
+ return -1;
+
+ while ((bytes_read = fread (buf, 1, BUFLEN, stream)) > 0)
+ {
+ if (len + bytes_read < len)
+ {
+ errno = EOVERFLOW;
+ return -1;
+ }
+ len += bytes_read;
+
+ crc = crc32_update (crc, (char const *)buf, bytes_read);
+
+ if (feof (stream))
+ break;
+ }
+
+ unsigned int crc_out = crc;
+ memcpy (resstream, &crc_out, sizeof crc_out);
+
+ *reslen = len;
+
+ return ferror (stream) ? -1 : 0;
+}
+
/* Print the checksum and size to stdout.
If ARGS is true, also print the FILE name. */
extern int
crc_sum_stream (FILE *stream, void *resstream, uintmax_t *length);
+extern int
+crc32b_sum_stream (FILE *stream, void *resstream, uintmax_t *length);
+
extern void
output_crc (char const *file, int binary_file, void const *digest, bool raw,
bool tagged, unsigned char delim, bool args, uintmax_t length)
bsd,
sysv,
crc,
+ crc32b,
md5,
sha1,
sha224,
static char const *const algorithm_args[] =
{
- "bsd", "sysv", "crc", "md5", "sha1", "sha224",
+ "bsd", "sysv", "crc", "crc32b", "md5", "sha1", "sha224",
"sha256", "sha384", "sha512", "blake2b", "sm3", nullptr
};
static enum Algorithm const algorithm_types[] =
{
- bsd, sysv, crc, md5, sha1, sha224,
+ bsd, sysv, crc, crc32b, md5, sha1, sha224,
sha256, sha384, sha512, blake2b, sm3,
};
ARGMATCH_VERIFY (algorithm_args, algorithm_types);
static char const *const algorithm_tags[] =
{
- "BSD", "SYSV", "CRC", "MD5", "SHA1", "SHA224",
+ "BSD", "SYSV", "CRC", "CRC32B", "MD5", "SHA1", "SHA224",
"SHA256", "SHA384", "SHA512", "BLAKE2b", "SM3", nullptr
};
static int const algorithm_bits[] =
{
- 16, 16, 32, 128, 160, 224,
+ 16, 16, 32, 32, 128, 160, 224,
256, 384, 512, 512, 256, 0
};
bsd_sum_stream,
sysv_sum_stream,
crc_sum_stream,
+ crc32b_sum_stream,
md5_sum_stream,
sha1_sum_stream,
sha224_sum_stream,
output_bsd,
output_sysv,
output_crc,
+ output_crc,
output_file,
output_file,
output_file,
sysv (equivalent to sum -s)\n\
bsd (equivalent to sum -r)\n\
crc (equivalent to cksum)\n\
+ crc32b (only available through cksum)\n\
md5 (equivalent to md5sum)\n\
sha1 (equivalent to sha1sum)\n\
sha224 (equivalent to sha224sum)\n\
ptrdiff_t algo_tag = algorithm_from_tag (s + i);
if (algo_tag >= 0)
{
- if (algo_tag <= crc)
+ if (algo_tag <= crc32b)
return false; /* We don't support checking these older formats. */
cksum_algorithm = algo_tag;
}
case bsd:
case sysv:
case crc:
+ case crc32b:
if (do_check && algorithm_specified)
error (EXIT_FAILURE, 0,
- _("--check is not supported with --algorithm={bsd,sysv,crc}"));
+ _("--check is not supported with "
+ "--algorithm={bsd,sysv,crc,crc32b}"));
break;
default:
break;
bsd) ;;
sysv) ;;
crc) ;;
+ crc32b) ;;
*) cksum --check --algorithm=$algo out-c || fail=1 ;;
esac
['sysv', "0 0 f"],
['bsd', "00000 0 f"],
['crc', "4294967295 0 f"],
+ ['crc32b', "0 0 f"],
['md5', "1B2M2Y8AsgTpgAmY7PhCfg=="],
['sha1', "2jmj7l5rSw0yVb/vlWAYkK/YBwk="],
['sha224', "0UoCjCo6K8lHYQK7KII0xBWisB+CjqYqxbPkLw=="],
# Use the hard-coded "f" as file name.
sub fmt ($$) {
my ($h, $v) = @_;
- $h !~ m{^(sysv|bsd|crc)$} and $v = uc($h). " (f) = $v";
+ $h !~ m{^(sysv|bsd|crc|crc32b)$} and $v = uc($h). " (f) = $v";
# BLAKE2b is inconsistent:
$v =~ s{BLAKE2B}{BLAKE2b};
return "$v"
(map {my ($h,$v)= @$_; my $o=fmt $h,$v;
["chk-".$h, "--check --strict", {IN=>$o},
{AUX=>{f=>''}}, {OUT=>"f: OK\n"}]}
- grep { $_->[0] !~ m{^(sysv|bsd|crc)$} } @pairs),
+ grep { $_->[0] !~ m{^(sysv|bsd|crc|crc32b)$} } @pairs),
# For digests ending in "=", ensure --check fails if any "=" is removed.
(map {my ($h,$v)= @$_; my $o=fmt $h,$v;
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ cksum printf
+
returns_ 1 cksum missing || fail=1
+# Pass in expected crc and crc32b for file "in"
+# Sets fail=1 upon failure
+crc_check() {
+ for crct in crc crc32b; do
+ cksum -a $crct in > out || fail=1
+ case "$crct" in crc) crce="$1";; crc32b) crce="$2";; esac
+ size=$(stat -c %s in) || framework_failure_
+ printf '%s\n' "$crce $size in" > exp || framework_failure_
+ compare exp out || fail=1
+ done
+}
+
+
+# Check complete range of bytes
{
for offset in $(seq -1 6); do
env printf $(env printf '\\%03o' $(seq 0 $offset));
env printf $(env printf '\\%03o' $(seq 0 255));
done
} > in || framework_failure_
-
-cksum in > out || fail=1
-printf '%s\n' '4097727897 2077 in' > exp || framework_failure_
-compare exp out || fail=1
+crc_check 4097727897 559400337
# Make sure crc is correct for files larger than 128 bytes (4 fold pclmul)
{
env printf $(env printf '\\%03o' $(seq 0 130));
} > in || framework_failure_
-
-cksum in > out || fail=1
-printf '%s\n' '3800919234 131 in' > exp || framework_failure_
-compare exp out || fail=1
+crc_check 3800919234 3739179551
# Make sure crc is correct for files larger than 32 bytes
# but <128 bytes (1 fold pclmul)
{
env printf $(env printf '\\%03o' $(seq 0 64));
} > in || framework_failure_
-
-cksum in > out || fail=1
-printf '%s\n' '796287823 65 in' > exp || framework_failure_
-compare exp out || fail=1
+crc_check 796287823 1086353368
# Make sure crc is still handled correctly when next 65k buffer is read
# (>32 bytes more than 65k)
{
seq 1 12780
} > in || framework_failure_
-
-cksum in > out || fail=1
-printf '%s\n' '3720986905 65574 in' > exp || framework_failure_
-compare exp out || fail=1
+crc_check 3720986905 388883562
# Make sure crc is still handled correctly when next 65k buffer is read
# (>=128 bytes more than 65k)
{
seq 1 12795
} > in || framework_failure_
+crc_check 4278270357 2796628507
-cksum in > out || fail=1
-printf '%s\n' '4278270357 65664 in' > exp || framework_failure_
-compare exp out || fail=1
Exit $fail
cksum -a blake2b .
cksum -a bsd .
cksum -a crc .
+cksum -a crc32b .
cksum -a md5 .
cksum -a sha1 .
cksum -a sha224 .