1

Here's the code I tried in Python but I get AttributeError:

>>> import hmac
>>> import hashlib
>>> h=hashlib.new('ripemd160')
>>> hmac.new("bedford","Hello",hashlib.ripemd160)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: module 'hashlib' has no attribute 'ripemd160'

I have searched the Python documentation and lots of forums but do not find much on ripemd160 and Python.

Ajeet Shah
  • 18,551
  • 8
  • 57
  • 87
Sankar
  • 21
  • 1

3 Answers3

1

ripemd160 is not supported directly by the hashlib module:

>>> hashlib.algorithms 

A tuple providing the names of the hash algorithms guaranteed to be supported by this module.

The following are supported by the module: md5, sha1, sha224, sha256, sha384, sha512

So you need to use the new constructor again or pass the reference to the one you already created.

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
1

This would work:

hmac.new("bedford", "Hello", lambda: hashlib.new('ripemd160'))

or

h=hashlib.new('ripemd160')
hmac.new("bedford", "Hello", lambda: h)
Ajeet Shah
  • 18,551
  • 8
  • 57
  • 87
1

Firstly, the key needs to be binary (Python3) -> b"bedford".

Then, the message needs to be encoded if it's unicode etc (Python3) -> codecs.encode("Hello")

Finally, use lambda functions:

import codecs
import hmac
import hashlib
h=hashlib.new('ripemd160')
hmac.new(b"bedford", codecs.encode("Hello"), lambda: h)
DomTomCat
  • 8,189
  • 1
  • 49
  • 64