Skip to content

Commit 70c8981

Browse files
edersondisouzakartben
authored andcommitted
scripts and soc: Mark MD5 and SHA1 usage as not for security
MD5 and SHA1 are not supposed to be used nowadays on security context. Some ancillary scripts in tree do use them, but for verification only - or where externally mandated, such the SPDX tool. This patch marks those usages as `usedforsecurity=False`, which helps clarify intent. Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
1 parent 0cce3dc commit 70c8981

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

scripts/pylib/twister/twisterlib/testinstance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _get_run_id(self):
152152
with open(run_id_file) as fp:
153153
run_id = fp.read()
154154
else:
155-
hash_object = hashlib.md5(self.name.encode())
155+
hash_object = hashlib.md5(self.name.encode(), usedforsecurity=False)
156156
random_str = f"{random.getrandbits(64)}".encode()
157157
hash_object.update(random_str)
158158
run_id = hash_object.hexdigest()

scripts/west_commands/runners/intel_adsp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def do_run(self, command, **kwargs):
9090

9191
def flash(self, **kwargs):
9292
'Generate a hash string for appending to the sending ri file'
93-
hash_object = hashlib.md5(self.bin_fw.encode())
93+
hash_object = hashlib.md5(self.bin_fw.encode(), usedforsecurity=False)
9494
random_str = f"{random.getrandbits(64)}".encode()
9595
hash_object.update(random_str)
9696
send_bin_fw = str(self.bin_fw + "." + hash_object.hexdigest())

scripts/west_commands/zspdx/scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def calculateVerificationCode(pkg):
115115
hashes.sort()
116116
filelist = "".join(hashes)
117117

118-
hSHA1 = hashlib.sha1()
118+
hSHA1 = hashlib.sha1(usedforsecurity=False)
119119
hSHA1.update(filelist.encode('utf-8'))
120120
return hSHA1.hexdigest()
121121

scripts/west_commands/zspdx/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def getHashes(filePath):
1616
Returns: tuple of (SHA1, SHA256, MD5) hashes for filePath, or
1717
None if file is not found.
1818
"""
19-
hSHA1 = hashlib.sha1()
19+
hSHA1 = hashlib.sha1(usedforsecurity=False)
2020
hSHA256 = hashlib.sha256()
21-
hMD5 = hashlib.md5()
21+
hMD5 = hashlib.md5(usedforsecurity=False)
2222

2323
log.dbg(f" - getting hashes for {filePath}")
2424

soc/intel/intel_adsp/tools/cavstool_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def uploading(self, filename):
6262
fname = os.path.basename(filename)
6363
fsize = os.path.getsize(filename)
6464

65-
md5_tx = hashlib.md5(open(filename,'rb').read()).hexdigest()
65+
md5_tx = hashlib.md5(open(filename,'rb').read(),
66+
usedforsecurity=False).hexdigest()
6667

6768
# Pack the header and the expecting packed size is 78 bytes.
6869
# The header by convention includes:

soc/intel/intel_adsp/tools/remote-fw-service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def receive_fw(self):
7777
return None
7878

7979
# Check the MD5 of the firmware
80-
md5_rx = hashlib.md5(total).hexdigest()
80+
md5_rx = hashlib.md5(total, usedforsecurity=False).hexdigest()
8181
md5_tx = md5_tx_b.decode('utf-8')
8282

8383
if md5_tx != md5_rx:

0 commit comments

Comments
 (0)