|
45 | 45 | builtin_hashlib = None |
46 | 46 |
|
47 | 47 | try: |
48 | | - from _hashlib import HASH, HASHXOF, openssl_md_meth_names |
| 48 | + from _hashlib import HASH, HASHXOF, openssl_md_meth_names, get_fips_mode |
49 | 49 | except ImportError: |
50 | 50 | HASH = None |
51 | 51 | HASHXOF = None |
52 | 52 | openssl_md_meth_names = frozenset() |
53 | 53 |
|
| 54 | + def get_fips_mode(): |
| 55 | + return 0 |
| 56 | + |
54 | 57 | try: |
55 | 58 | import _blake2 |
56 | 59 | except ImportError: |
@@ -196,10 +199,7 @@ def hash_constructors(self): |
196 | 199 |
|
197 | 200 | @property |
198 | 201 | def is_fips_mode(self): |
199 | | - if hasattr(self._hashlib, "get_fips_mode"): |
200 | | - return self._hashlib.get_fips_mode() |
201 | | - else: |
202 | | - return None |
| 202 | + return get_fips_mode() |
203 | 203 |
|
204 | 204 | def test_hash_array(self): |
205 | 205 | a = array.array("b", range(10)) |
@@ -1013,7 +1013,7 @@ def _test_pbkdf2_hmac(self, pbkdf2, supported): |
1013 | 1013 | self.assertEqual(out, expected, |
1014 | 1014 | (digest_name, password, salt, rounds)) |
1015 | 1015 |
|
1016 | | - with self.assertRaisesRegex(ValueError, 'unsupported hash type'): |
| 1016 | + with self.assertRaisesRegex(ValueError, '.*unsupported.*'): |
1017 | 1017 | pbkdf2('unknown', b'pass', b'salt', 1) |
1018 | 1018 |
|
1019 | 1019 | if 'sha1' in supported: |
@@ -1050,6 +1050,7 @@ def test_pbkdf2_hmac_c(self): |
1050 | 1050 |
|
1051 | 1051 | @unittest.skipUnless(hasattr(hashlib, 'scrypt'), |
1052 | 1052 | ' test requires OpenSSL > 1.1') |
| 1053 | + @unittest.skipIf(get_fips_mode(), reason="scrypt is blocked in FIPS mode") |
1053 | 1054 | def test_scrypt(self): |
1054 | 1055 | for password, salt, n, r, p, expected in self.scrypt_test_vectors: |
1055 | 1056 | result = hashlib.scrypt(password, salt=salt, n=n, r=r, p=p) |
|
0 commit comments