Skip to content

Commit

Permalink
make FIPS happy (#219)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
rpatel3001 and amykyta3 authored Dec 9, 2024
1 parent ca6d1f9 commit 9dee7e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions systemrdl/core/elaborate.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,11 @@ def exit_Component(self, node: Node) -> None:

# <child_name>_<hash of child type name>
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
Expand Down
10 changes: 5 additions & 5 deletions systemrdl/core/value_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down Expand Up @@ -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]


Expand All @@ -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]


Expand All @@ -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]


Expand All @@ -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]


Expand Down

0 comments on commit 9dee7e3

Please sign in to comment.