8000 bpo-40479: Fix hashlib's usedforsecurity for OpenSSL 3.0.0 (GH-30455) by tiran · Pull Request #30455 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-40479: Fix hashlib's usedforsecurity for OpenSSL 3.0.0 (GH-30455) #30455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 13, 2022
Prev Previous commit
Next Next commit
scrypt is blocked in FIPS mode
  • Loading branch information
tiran committed Jan 7, 2022
commit b58fde5755a6f1e3c8dd011f019adaae1e9d8097
11 changes: 6 additions & 5 deletions Lib/test/test_hashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@
builtin_hashlib = None

try:
from _hashlib import HASH, HASHXOF, openssl_md_meth_names
from _hashlib import HASH, HASHXOF, openssl_md_meth_names, get_fips_mode
except ImportError:
HASH = None
HASHXOF = None
openssl_md_meth_names = frozenset()

def get_fips_mode():
return 0

try:
import _blake2
except ImportError:
Expand Down Expand Up @@ -192,10 +195,7 @@ def hash_constructors(self):

@property
def is_fips_mode(self):
if hasattr(self._hashlib, "get_fips_mode"):
return self._hashlib.get_fips_mode()
else:
return None
return get_fips_mode()

def test_hash_array(self):
a = array.array("b", range(10))
Expand Down Expand Up @@ -1057,6 +1057,7 @@ def test_pbkdf2_hmac_c(self):

@unittest.skipUnless(hasattr(hashlib, 'scrypt'),
' test requires OpenSSL > 1.1')
@unittest.skipIf(get_fips_mode(), reason="scrypt is blocked in FIPS mode")
def test_scrypt(self):
for password, salt, n, r, p, expected in self.scrypt_test_vectors:
result = hashlib.scrypt(password, salt=salt, n=n, r=r, p=p)
Expand Down
0