2

When I try to use ripemd160 with hashlib it says it can't find it.

I used easy_install hashlib which installed hashlib but it still can't find ripemd160.

I'm using Ubuntu and python2.7

def hexHash(str, withHash = None):
    h = hashlib.new('ripemd160')
    h.update(str)
    if withHash != None:
        return h.hexdigest()[0:6]
    else:
        return '#'+h.hexdigest()[0:6]

ValueError: unsupported hash type

wizardzeb
  • 1,546
  • 2
  • 14
  • 30

1 Answers1

4

Hashlib is part of Python's standard library, so you don't have to install it.

However, the only hash algorithms that are guaranteed to be available are md5, sha1, sha224, sha256, sha384, and sha512.

Others may be available depending on the SSL library that is used on your platform.

You can run openssl list-message-digest-algorithms in a terminal to see which algorithms are available.

(Note: as of openssl 1.1.1, the above command doesn't work. Try openssl dgst -list)

The above assumes that Python uses the system's SSL library, which might not be the case.

Or (better) from Python:

import hashlib

print(hashlib.algorithms_available)

If ripemd160 isn't available, you should probably look into re-installing your SSL library with different options. (Assuming Python uses the system's SSL)

If you are changing your SSL library to one with a different version number, you will have to rebuild anything that depends on it as well.

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • 1
    python 3.10 under termux shows ripemd160 available, but gives the above error when attempting `hashlib.new('ripemd160')` – jcomeau_ictx Apr 28 '22 at 00:46
  • 1
    hmm, openssl shows `rmd160` available, I wonder if it's the same and if the python module doesn't know of the name change. – jcomeau_ictx Apr 28 '22 at 00:51
  • 1
    @jcomeau_ictx OpenSSL3 disabled ripemd160, it must be manually enabled now, see https://stackoverflow.com/a/72508879/2922723 – streamofstars Jun 05 '22 at 16:07
  • @jcomeau_ictx On FreeBSD 13, using OpenSSL 1.1.1 and Python 3.9 & 3.11, `hashlib.new('ripemd160')` works. Verify that your Python is actually linked against openssl. – Roland Smith Nov 26 '22 at 12:33