How can I generate SHA3 if there is no sha3sum command in coreutils?
Solution 1
You can use OpenSSL to do this. Run openssl list -digest-algorithms
to get a list of algorithms:
...
SHA3-224
SHA3-256
SHA3-384
SHA3-512
...
As you can see sha3-{224,256,384,512}
is supported by OpenSSL 1.1.1 (11 Sep 2018) from Ubuntu 18.10.
You can also run openssl
interactively:
OpenSSL> help
...
Message Digest commands (see the `dgst' command for more details)
blake2b512 blake2s256 gost md4
md5 rmd160 sha1 sha224
sha256 sha3-224 sha3-256 sha3-384
sha3-512 sha384 sha512 sha512-224
sha512-256 shake128 shake256 sm3
To checksum a file:
openssl dgst -sha3-512 /bin/echo
SHA3-512(/bin/echo)= c9a3baaa2aa3d667a4ff475d893b3e84eb588fb46adecd0af5f3cdd735be88c62e179f98dc8275955da4ee5ef1dc7968620686c6f7f63f5b80f10e43bc1f00fc
To checksum a string:
printf "foobar" | openssl dgst -sha3-512
You can change the output format with these options:
-
-c
Print out the digest in two digit groups separated by colons -
-r
Output the digest in the "coreutils" format, including newlines
Solution 2
There are a number of implementations, e.g. Mattias Andrée's sha3sum
, or the Perl Digest-SHA3 module. In Debian, install libdigest-sha3-perl
; in Fedora, install sha3sum
; both of these will provide a sha3sum
command based on the Perl module, which behaves in the same way as the binaries you're used to.
Solution 3
RHash application could do it:
rhash --sha3-256 yourfile
More info: rhash -h
it will work on Linux, BSD and Windows
Solution 4
For what it's worth, Busybox has had code for it since 2013.
Solution 5
If you're lazy like me and are used to md5sum, sha1sum, sha256sum:
Create the file /usr/local/bin/sha3256sum and make it executable with chmod +x sha3256sum.
#!/bin/bash
rhash --sha3-256 $1
Then you can run:
sha3256sum file
Related videos on Youtube
pepite
Updated on September 18, 2022Comments
-
pepite over 1 year
I have
sha1sum
orsha512sum
on an average Linux distro.But where is the
sha3sum
command that can generateSHA-3 commands? -
pepite about 7 yearsupdating the question, sha384 is sha2. sha3 is not sha2.
-
Patrick Mevzek about 7 yearsyes indeed, sorry for my mistake. Support for SHA3 in
openssl
is planned/in the work : github.com/openssl/openssl/issues/439 -
Stephen Kitt over 4 yearsWelcome! While this is a useful answer, it would be better if you indicated that you are the author of this particular
sha3sum
implementation. -
leberknecht about 4 yearsNote, for all the people who are using
echo
with this and are wondering why they cant get correct results: ensure to pass-n
to avoid the newline-pitfall -
lebed2045 almost 3 yearsI've tried "printf "foobar" | openssl dgst -sha3-512", got unknown option '-sha3-512'. openssl LibreSSL 2.8.3
-
Smeterlink over 2 years@lebed2045 LibreSSL does not support SHA-3.
-
telcoM about 2 yearsBut since the final SHA3 specification was not released by NIST until August 5 2015, Busybox's implementation must have been based on preliminary versions of the spec... and so Busybox needed a fix in 2016 in order to conform to the final version of the SHA3 algorithm specification.
-
Cristian Ciupitu about 2 years@lebed2045 LibreSSL issue for adding support for SHA-3