(self, name, allow_openssl, allow_builtin)
| 961 | ) |
| 962 | ) |
| 963 | def test_disable_hash(self, name, allow_openssl, allow_builtin): |
| 964 | # In FIPS mode, the function may be available but would still need |
| 965 | # to raise a ValueError, so we will test the helper separately. |
| 966 | self.skip_if_fips_mode() |
| 967 | flags = dict(allow_openssl=allow_openssl, allow_builtin=allow_builtin) |
| 968 | is_fully_disabled = not allow_builtin and not allow_openssl |
| 969 | |
| 970 | with hashlib_helper.block_algorithm(name, **flags): |
| 971 | # OpenSSL's blake2s and blake2b are unknown names |
| 972 | # when only the OpenSSL interface is available. |
| 973 | if allow_openssl and not allow_builtin: |
| 974 | aliases = {'blake2s': 'blake2s256', 'blake2b': 'blake2b512'} |
| 975 | name_for_hashlib_new = aliases.get(name, name) |
| 976 | else: |
| 977 | name_for_hashlib_new = name |
| 978 | |
| 979 | with self.check_context(is_fully_disabled): |
| 980 | _ = self.hashlib.new(name_for_hashlib_new) |
| 981 | |
| 982 | # Since _hashlib is present, explicit blake2b/blake2s constructors |
| 983 | # use the built-in implementation, while others (since we are not |
| 984 | # in FIPS mode and since _hashlib exists) use the OpenSSL function. |
| 985 | with self.check_context(is_fully_disabled): |
| 986 | _ = getattr(self.hashlib, name)() |
| 987 | |
| 988 | self.check_openssl_hash(name, disabled=not allow_openssl) |
| 989 | self.check_builtin_hash(name, disabled=not allow_builtin) |
| 990 | |
| 991 | if name not in hashlib_helper.NON_HMAC_DIGEST_NAMES: |
| 992 | with self.check_context(is_fully_disabled): |
| 993 | _ = self.hmac.new(b"", b"", name) |
| 994 | with self.check_context(is_fully_disabled): |
| 995 | _ = self.hmac.HMAC(b"", b"", name) |
| 996 | with self.check_context(is_fully_disabled): |
| 997 | _ = self.hmac.digest(b"", b"", name) |
| 998 | |
| 999 | self.check_openssl_hmac(name, disabled=not allow_openssl) |
| 1000 | self.check_builtin_hmac(name, disabled=not allow_builtin) |
| 1001 | |
| 1002 | @hashlib_helper.block_algorithm("md5") |
| 1003 | def test_disable_hash_md5_in_fips_mode(self): |
nothing calls this directly
no test coverage detected