Skip to content

Commit e7e59e9

Browse files
authored
Fix bug in file hashing on FIPS enabled system (#511)
Set `userforsecurity=False` on `hashlib` hashing algorithms to make FIPS enabled systems happy.
1 parent 27e3ab2 commit e7e59e9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pooch/hashes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ def file_hash(fname, alg="sha256"):
7878
)
7979
# Calculate the hash in chunks to avoid overloading the memory
8080
chunksize = 65536
81-
hasher = ALGORITHMS_AVAILABLE[alg]()
81+
# For hashlib algorithms, use usedforsecurity=False to support FIPS-enabled
82+
# systems. xxhash algorithms don't support this parameter.
83+
hasher = (
84+
ALGORITHMS_AVAILABLE[alg](usedforsecurity=False)
85+
if alg in hashlib.algorithms_available
86+
else ALGORITHMS_AVAILABLE[alg]()
87+
)
8288
with open(fname, "rb") as fin:
8389
buff = fin.read(chunksize)
8490
while buff:

pooch/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def unique_file_name(url: str) -> str:
347347
181a9d52e908219c2076f55145d6a344-data.txt.gz
348348
349349
"""
350-
md5 = hashlib.md5(url.encode()).hexdigest()
350+
md5 = hashlib.md5(url.encode(), usedforsecurity=False).hexdigest()
351351
fname = parse_url(url)["path"].split("/")[-1]
352352
# Crop the start of the file name to fit 255 characters including the hash
353353
# and the :

0 commit comments

Comments
 (0)