#!/bin/sh -e # Autodetect possible commandlines for various hashes. Example usage: # meta4ra-{create,check} -hashes "$(meta4ra-hashes-detect)" ... hw="hello world" hashes="" desired="$1" check() { local name="$1" if [ -n "$desired" ] && [ $desired != "$name" ] ; then return 1 ; fi local cmd="$2" local cmdline="$cmd" [ "$cmd" != "builtin" ] || cmd="meta4ra-hash -hashes $name:builtin" our=$(echo -n hello world | sh -e -c "$cmd" | { read h rem ; printf %s "$h"; }) [ $HSH = "$our" ] && hashes="$hashes,$name:$cmdline" } HSH=d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24 check blake3-256 b3sum || # https://github.com/BLAKE3-team/BLAKE3 check blake3-256 builtin || : HSH=021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbcc05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0 check blake2b-512 b2sum || # https://blake2.net/, GNU Coreutils check blake2b-512 "openssl blake2b512 -r" || check blake2b-512 builtin || : HSH=256c83b297114d201b30179f3f0ef0cace9783622da5974326b436178aeef610 check blake2b-256 "b2sum -l 256" || check blake2b-512 builtin || : HSH=8b4830244fc36daa11177311dc6bf7636376180dce2d29193335878142e7d6f5e9016beba729e0a353dd2fd421c8b2022ee8927f0bce6b88631bb01be2e0f5ba check skein-512 skein512 || # FreeBSD's out-of-box command check skein-512 builtin || : HSH=3a9159f071e4dd1c8c4f968607c30942e120d8156b8b1e72e0d376e8871cb8b8 check shake128 goshake128 || # go.stargrave.org/gosha3 check shake128 "sha3sum -a 128000 | dd bs=1 count=64 2>/dev/null" || # p5-Digest-SHA3 check shake128 builtin || : # openssl shake128 -- useless, as it outputs only 128 bits HSH=369771bb2cb9d2b04c1d54cca487e372d9f187f73f7ba3f65b95c8ee7798c527f4f3c2d55c2d46a29f2e945d469c3df27853a8735271f5cc2d9e889544357116 check shake256 goshake256 || check shake256 "sha3sum -a 256000 | dd bs=1 count=128 2>/dev/null" || check shake256 builtin || : HSH=309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f check sha-512 sha512 || check sha-512 sha512sum || check sha-512 "libressl dgst -sha512" || check sha-512 "openssl sha512 -r" || check sha-512 builtin || : HSH=b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 check sha-256 sha256 || check sha-256 sha256sum || check sha-256 "libressl dgst -sha256" || check sha-256 "openssl sha256 -r" || check sha-256 builtin || : unxxd="xxd -c 0 -p" unhexdump="hexdump -v -e '/1 \"%02x\"' ; echo" HSH=84d883ede9fa6ce855d82d8c278ecd9f5fc88bf0602831ae0c38b9b506ea3cb02f3fa076b8f5664adf1ff862c0157da4cc9a83e141b738ff9268a9ba3ed6f563 check streebog-512 streebog512 $hsh || # go.cypherpunks.su/gogost check streebog-512 "nettle-hash --algorithm=streebog512 --raw | $unxxd" || check streebog-512 "nettle-hash --algorithm=streebog512 --raw | $unhexdump" || check streebog-512 "libressl dgst -streebog512" || check streebog-512 builtin || : HSH=c600fd9dd049cf8abd2f5b32e840d2cb0e41ea44de1c155dcd88dc84fe58a855 check streebog-256 streebog256 || check streebog-256 "nettle-hash --algorithm=streebog256 --raw | $unxxd" || check streebog-256 "nettle-hash --algorithm=streebog256 --raw | $unhexdump" || check streebog-256 "libressl dgst -streebog256" || check streebog-256 builtin || : HSH=df8d09e93f874900a99b8775cc15b6c7 check xxh3-128 "xxhsum -H128" || # https://cyan4973.github.io/xxHash/ check xxh3-128 builtin || : [ -n "$hashes" ] echo ${hashes#,}