programmingbitcoin
programmingbitcoin copied to clipboard
Openssl removed ripemd160 support. Code using hashlib's 'ripemd160' algorithm may fail.
I'm posting this issue in order to help anyone who comes across this problem.
If you try to use the code:
hashlib.new('ripemd160', thingtobehashed).digest()
and you receive this error:
ValueError: unsupported hash type ripemd160
It is because Hashlib uses openssl under the hood, and openssl has recently decided to depreciate support for the ripemd160 algorithm. See the relevant issues below:
https://github.com/openssl/openssl/issues/16994 https://github.com/bitcoin/bitcoin/issues/23710
There may be some way to re-enable support for ripemd160 under the hood, but I think an easier solution is to just copy/paste the pure python implementation of ripemd160 and use that instead. See the link below (code courtesy of the legend Pieter Wuille):
https://github.com/bitcoin/bitcoin/blob/master/test/functional/test_framework/ripemd160.py
If you would like, I can submit a PR that adds this file to the chapters and updates the existing hash160 function (with notes explaining the issue). But maybe there's a cleaner way to fix this, I don't know.
Nice catch @cmdruid can you specify which chapter we will encounter this on?
Also, should we create a separate file that includes the entire "ripemd160.py" and import that file into our scripts?
Nice catch @cmdruid can you specify which chapter we will encounter this on?
Starting from chapter 4, it is used in the helper.py file. So the issue would be addressing chapters 4-13.
Also, should we create a separate file that includes the entire "ripemd160.py" and import that file into our scripts?
Yes that is correct. The ripemd160.py seems to work just fine as a replacement.
Thanks @cmdruid - so far I haven't ran into any issues using "hash160".
So far the only big issue I had was on this problem: https://github.com/jimmysong/programmingbitcoin/issues/254
Thank you for sharing this information!
You can change your openssl config to enable ripemd160.
https://stackoverflow.com/questions/72409563/unsupported-hash-type-ripemd160-with-hashlib-in-python