When I run the following on my Macbook, I get the error:
>>> import hashlib
>>> hashlib.md5(usedforsecurity=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: openssl_md5() takes no keyword arguments
But when I run it on my Linux box, it works!
>>> import hashlib
>>> hashlib.md5(usedforsecurity=False)
<md5 HASH object @ 0x7f763c1375d0>
My problem is, I need to run some safe, non-security related code on my FIPS enabled system (such as managing a cache of user requests which hashes the user query as an MD5 string). Using the usedforsecurity
flag prevents a FIPs exception.
This works fine, except when I want to test my code on my Macbook. My Macbook's "libcrypto" library apparently doesn't support this usedforsecurity
flag. Is there a good way to detect if the underlying C bindings behind hashlib.md5
support this flag or not?
If you use hashlib.new('md5', usedforsecurity=False)
instead of hashlib.md5(usedforsecurity=False)
it will not raise exception, even if the keyword argument is not supported.