Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openssl removed ripemd160 support. Code using hashlib's 'ripemd160' algorithm may fail. #255

Open
cmdruid opened this issue Sep 4, 2022 · 4 comments

Comments

@cmdruid
Copy link

cmdruid commented Sep 4, 2022

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:

openssl/openssl#16994
bitcoin/bitcoin#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.

@cmdruid cmdruid changed the title Openssl removed ripemd160 support. Any code using hashlib's 'ripemd160' will fail. Openssl removed ripemd160 support. Code using hashlib's 'ripemd160' algorithm may fail. Sep 4, 2022
@vvronskyFX
Copy link

vvronskyFX commented Sep 9, 2022

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?

@cmdruid
Copy link
Author

cmdruid commented Sep 9, 2022

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.

@vvronskyFX
Copy link

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: #254

Thank you for sharing this information!

@gudnuf
Copy link

gudnuf commented Mar 14, 2023

You can change your openssl config to enable ripemd160.

https://stackoverflow.com/questions/72409563/unsupported-hash-type-ripemd160-with-hashlib-in-python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants