The Unterminated String

Embedded Things and Software Stuff

Hashing With OpenSSL Dgst

Posted at — Jul 23, 2023

SQLite provides SHA3-256 hashes for the verification of the files available for download on its website.

Most Linux distributions I have used come with a collection of “*sum” commands (provided by coreutils) to generate hashes, e.g.:

However, there doesn’t seem to be a readily available “sha3sum” variant.

After searching around for ways of validating a SHA3-256 digest, I found that OpenSSL provides a wide selection of hashing algorithms to use via its dgst command.

It’s possible to list the supported algorithms with openssl dgst -list.

For example:

$ openssl dgst -list
Supported digests:
-blake2b512                -blake2s256                -md4
-md5                       -md5-sha1                  -ripemd
-ripemd160                 -rmd160                    -sha1
-sha224                    -sha256                    -sha3-224
-sha3-256                  -sha3-384                  -sha3-512
-sha384                    -sha512                    -sha512-224
-sha512-256                -shake128                  -shake256
-sm3                       -ssl3-md5                  -ssl3-sha1
-whirlpool

So, at the cost of slightly more typing, instead of:

sha256sum ${filename}

you can use:

openssl dgst -sha256 ${filename}

Calculating the SHA3-256 digest of an SQLite download then looks like:

$ wget https://www.sqlite.org/2023/sqlite-amalgamation-3420000.zip

$ openssl dgst -sha3-256 sqlite-amalgamation-3420000.zip
SHA3-256(sqlite-amalgamation-3420000.zip)= 436747dc8090d015b9869b96f5837f745e852d2ce73fd77410ed76ee51107a1f

The version of OpenSSL being used here was:

$ openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)