Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any variable length hash functions available for Python?

Tags:

python

hash

I am looking for a hash function that can generate a digest of a specified bit-size for a cryptographic signature scheme. A related question (https://crypto.stackexchange.com/questions/3558/are-there-hash-algorithms-with-variable-length-output) on the Cryptography SE specifies that algorithms exist for this particular purpose.
Are there any Python libraries that I can use for this?

Currently, my scheme just pads a SHA-256 output to the desired size. I also have tried the Python SHA3 library - pysha3 1.0.2, however, it has a few predefined digest sizes that can be used.

I want a hashing function which can take in the desired digest size as a parameter and accordingly hashes a message (if possible)

like image 372
Tabish Mir Avatar asked Sep 13 '25 22:09

Tabish Mir


1 Answers

As a cursory answer: You might be interested in the inbuilt Blake2 function in hashlib in python 3.6+.

It only outputs up to 64 bytes, but is "faster than MD5, SHA-1, SHA-2, and SHA-3, yet is at least as secure as the latest standard SHA-3".

Hopefully this is long enough and you don't need external libraries!

like image 186
Seb Avatar answered Sep 15 '25 12:09

Seb