From 9dee7e3ee5ecfe53c065409ccb22cea5d1715ad8 Mon Sep 17 00:00:00 2001 From: Rajan Patel Date: Mon, 9 Dec 2024 01:14:41 -0500 Subject: [PATCH] make FIPS happy (#219) * make FIPS happy * fix for py <3.9 and replace all instances of hashlib.md5 * actually add usedforsecurity=False --------- Co-authored-by: Alex Mykyta --- systemrdl/core/elaborate.py | 4 ++-- systemrdl/core/value_normalization.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/systemrdl/core/elaborate.py b/systemrdl/core/elaborate.py index e76e982..9724cee 100644 --- a/systemrdl/core/elaborate.py +++ b/systemrdl/core/elaborate.py @@ -631,11 +631,11 @@ def exit_Component(self, node: Node) -> None: # _ if child.type_name is not None: - norm_name = hashlib.md5(child.type_name.encode('utf-8')).hexdigest()[:8] + norm_name = hashlib.new('md5', child.type_name.encode('utf-8'), usedforsecurity=False).hexdigest()[:8] else: # an external importer did not assign a type name. # Use the inst name instead - norm_name = hashlib.md5(child.inst_name.encode('utf-8')).hexdigest()[:8] + norm_name = hashlib.new('md5', child.inst_name.encode('utf-8'), usedforsecurity=False).hexdigest()[:8] extra_type_name_segments.append(child_name + "_" + norm_name) # this component's DPAs diff --git a/systemrdl/core/value_normalization.py b/systemrdl/core/value_normalization.py index 63dc54a..8d5ebbf 100644 --- a/systemrdl/core/value_normalization.py +++ b/systemrdl/core/value_normalization.py @@ -71,7 +71,7 @@ def normalize_string(value: str) -> str: String values shall be rendered using the first eight characters of their md5 (Message-Digest Algorithm) checksum. """ - md5 = hashlib.md5(value.encode('utf-8')).hexdigest() + md5 = hashlib.new('md5', value.encode('utf-8'), usedforsecurity=False).hexdigest() return md5[:8] @@ -101,7 +101,7 @@ def normalize_array(value: List[Any], owner_node: Optional[node.Node]=None) -> s norm_elements.append(normalize(element, owner_node)) norm_str = "_".join(norm_elements) - md5 = hashlib.md5(norm_str.encode('utf-8')).hexdigest() + md5 = hashlib.new('md5', norm_str.encode('utf-8'), usedforsecurity=False).hexdigest() return md5[:8] @@ -125,7 +125,7 @@ def normalize_struct(value: rdltypes.UserStruct, owner_node: Optional[node.Node] norm_elements.append(f"{member_name}_{normalize(member_value, owner_node)}") norm_str = "_".join(norm_elements) - md5 = hashlib.md5(norm_str.encode('utf-8')).hexdigest() + md5 = hashlib.new('md5', norm_str.encode('utf-8'), usedforsecurity=False).hexdigest() return md5[:8] @@ -134,7 +134,7 @@ def normalize_component_ref(value: node.Node, owner_node: node.Node) -> str: Hash of relative path from owner of the property to the target component """ path = value.get_rel_path(owner_node) - md5 = hashlib.md5(path.encode('utf-8')).hexdigest() + md5 = hashlib.new('md5', path.encode('utf-8'), usedforsecurity=False).hexdigest() return md5[:8] @@ -144,7 +144,7 @@ def normalize_property_ref(value: rdltypes.PropertyReference, owner_node: node.N property """ path = f"{value.node.get_rel_path(owner_node)}->{value.name}" - md5 = hashlib.md5(path.encode('utf-8')).hexdigest() + md5 = hashlib.new('md5', path.encode('utf-8'), usedforsecurity=False).hexdigest() return md5[:8]