Skip to content
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

Fix md5 hashing with FIPS mode #6635

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions monai/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import math
import os
import sys
import pickle
from collections import abc, defaultdict
from collections.abc import Generator, Iterable, Mapping, Sequence, Sized
Expand Down Expand Up @@ -1370,7 +1371,11 @@ def json_hashing(item) -> bytes:

"""
# TODO: Find way to hash transforms content as part of the cache
cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8")).hexdigest()
cache_key = ""
if (sys.version_info.minor < 9):
cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8")).hexdigest()
else:
cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8"), usedforsecurity=False).hexdigest()
return f"{cache_key}".encode()


Expand All @@ -1385,7 +1390,11 @@ def pickle_hashing(item, protocol=pickle.HIGHEST_PROTOCOL) -> bytes:
Returns: the corresponding hash key

"""
cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest()
cache_key = ""
if (sys.version_info.minor < 9):
cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest()
else:
cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol), usedforsecurity=False).hexdigest()
return f"{cache_key}".encode()


Expand Down