14

After a thorough search, I have not found a complete explanation and solution to this very common problem on the entire web. All scripts that need to encode with hashlib give me error:

Python 3.10

import hashlib
h = hashlib.new('ripemd160')

return:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/hashlib.py", line 166, in __hash_new
    return __get_builtin_constructor(name)(data)
  File "/usr/lib/python3.10/hashlib.py", line 123, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type ripemd160

I already tried to check if that hash exists in the library, and if I have it:

print(hashlib.algorithms_available): {'md5', 'sm3', 'sha3_512', 'sha384', 'sha256', 'sha1', 'shake_128', 'sha224', 'sha512_224', 'sha512_256', 'blake2b', 'ripemd160', 'md5-sha1', 'sha512', 'sha3_256', 'shake_256', 'sha3_384', 'whirlpool', 'md4', 'blake2s', 'sha3_224'}

I am having this problem in a vps with linux, but in my pc I use Windows and I don't have this problem.

I sincerely appreciate any help or suggestion.

1
  • Any others missing? Could you run this and share your output? Commented May 27, 2022 at 18:26

2 Answers 2

30

Hashlib uses OpenSSL for ripemd160 and apparently OpenSSL disabled some older crypto algos around version 3.0 in November 2021. All the functions are still there but require manual enabling. See issue 16994 of OpenSSL github project for details.

To quickly enable it, find the directory that holds your OpenSSL config file or a symlink to it, by running the below command:

openssl version -d

You can now go to the directory and edit the config file (it may be necessary to use sudo):

nano openssl.cnf

Make sure that the config file contains following lines:

openssl_conf = openssl_init

[openssl_init]
providers = provider_sect

[provider_sect]
default = default_sect
legacy = legacy_sect

[default_sect]
activate = 1

[legacy_sect]
activate = 1

Tested on: OpenSSL 3.0.2, Python 3.10.4, Linux Ubuntu 22.04 LTS aarch64, I have no access to other platforms at the moment.

Sign up to request clarification or add additional context in comments.

3 Comments

Well done. I had solved in this way an error in Zeronet.
its great. the release notes bold sections said 'Added RIPEMD160 to the default provider' in nov'22 and in Dec'21 it says its moved and 'All of the low-level MD2, MD4, MD5, MDC2, RIPEMD160, SHA1, SHA224, SHA256, SHA384, SHA512 and Whirlpool digest functions have been deprecated.' - clearly deprecated.
Actually you do not need sudo. You can run python with env variable: OPENSSL_CONF=openssl.cnf python3 some_script.py
0

With openssl 3.5.0-1 and python3.13.2 (as provided by Debian trixie), I have:

$ python3
Python 3.13.2 (main, Mar 29 2025, 10:04:43) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> hashlib.new('ripemd160', b'lala').hexdigest()
'3e72844027d4e2aa163c0ef7faea8ff9d831bae2'

and it works just fine using openssl, too:

$ echo -n lala | openssl ripemd160
RIPEMD-160(stdin)= 3e72844027d4e2aa163c0ef7faea8ff9d831bae2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.