Skip to content

Commit 9dee7e3

Browse files
rpatel3001amykyta3
andauthored
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 <[email protected]>
1 parent ca6d1f9 commit 9dee7e3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

systemrdl/core/elaborate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,11 @@ def exit_Component(self, node: Node) -> None:
631631

632632
# <child_name>_<hash of child type name>
633633
if child.type_name is not None:
634-
norm_name = hashlib.md5(child.type_name.encode('utf-8')).hexdigest()[:8]
634+
norm_name = hashlib.new('md5', child.type_name.encode('utf-8'), usedforsecurity=False).hexdigest()[:8]
635635
else:
636636
# an external importer did not assign a type name.
637637
# Use the inst name instead
638-
norm_name = hashlib.md5(child.inst_name.encode('utf-8')).hexdigest()[:8]
638+
norm_name = hashlib.new('md5', child.inst_name.encode('utf-8'), usedforsecurity=False).hexdigest()[:8]
639639
extra_type_name_segments.append(child_name + "_" + norm_name)
640640

641641
# this component's DPAs

systemrdl/core/value_normalization.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def normalize_string(value: str) -> str:
7171
String values shall be rendered using the first eight characters of
7272
their md5 (Message-Digest Algorithm) checksum.
7373
"""
74-
md5 = hashlib.md5(value.encode('utf-8')).hexdigest()
74+
md5 = hashlib.new('md5', value.encode('utf-8'), usedforsecurity=False).hexdigest()
7575
return md5[:8]
7676

7777

@@ -101,7 +101,7 @@ def normalize_array(value: List[Any], owner_node: Optional[node.Node]=None) -> s
101101
norm_elements.append(normalize(element, owner_node))
102102

103103
norm_str = "_".join(norm_elements)
104-
md5 = hashlib.md5(norm_str.encode('utf-8')).hexdigest()
104+
md5 = hashlib.new('md5', norm_str.encode('utf-8'), usedforsecurity=False).hexdigest()
105105
return md5[:8]
106106

107107

@@ -125,7 +125,7 @@ def normalize_struct(value: rdltypes.UserStruct, owner_node: Optional[node.Node]
125125
norm_elements.append(f"{member_name}_{normalize(member_value, owner_node)}")
126126

127127
norm_str = "_".join(norm_elements)
128-
md5 = hashlib.md5(norm_str.encode('utf-8')).hexdigest()
128+
md5 = hashlib.new('md5', norm_str.encode('utf-8'), usedforsecurity=False).hexdigest()
129129
return md5[:8]
130130

131131

@@ -134,7 +134,7 @@ def normalize_component_ref(value: node.Node, owner_node: node.Node) -> str:
134134
Hash of relative path from owner of the property to the target component
135135
"""
136136
path = value.get_rel_path(owner_node)
137-
md5 = hashlib.md5(path.encode('utf-8')).hexdigest()
137+
md5 = hashlib.new('md5', path.encode('utf-8'), usedforsecurity=False).hexdigest()
138138
return md5[:8]
139139

140140

@@ -144,7 +144,7 @@ def normalize_property_ref(value: rdltypes.PropertyReference, owner_node: node.N
144144
property
145145
"""
146146
path = f"{value.node.get_rel_path(owner_node)}->{value.name}"
147-
md5 = hashlib.md5(path.encode('utf-8')).hexdigest()
147+
md5 = hashlib.new('md5', path.encode('utf-8'), usedforsecurity=False).hexdigest()
148148
return md5[:8]
149149

150150

0 commit comments

Comments
 (0)