Instead of xxd, I guess it is possible to use perl oneliners:
checksum() {
perl -we "print pack 'H*', '$1'" |
openssl dgst -sha256 -binary |
openssl dgst -sha256 -binary |
perl -we 'print unpack q{H8}, join q{}, <>'
}
hash160() {
openssl dgst -sha256 -binary |
openssl dgst -rmd160 -binary |
perl -we 'print unpack q{H*}, join q{}, <>'
}
Perl is usually easy to install on systems where bash is installed.
Watch for the last lines of these two functions: they are actually different (H8 instead of H*), as the checksum function only needs the four first bytes.
THIS HAS NOT BEEN TESTED MUCH. Please test it thorously before actually using it.
Unless I'm missing something, it seems to me that simply doing
checksum() {
perl -we "print pack 'H*', '$1'" |
openssl dgst -sha256 -binary |
openssl dgst -sha256
}
hash160() {
openssl dgst -sha256 -binary |
openssl dgst -rmd160
}
would be sufficient in this case, since openssl outputs in hex by default.
Nice script by the way. I may make use of it to implement an idea that I've had for a while.