Skip to content

Commit 0e04025

Browse files
author
Wesley Chiu
committed
fix: replace weak hash functions with SHA-256
1 parent 7d883b5 commit 0e04025

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

gyp/pylib/gyp/MSVSNew.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def MakeGuid(name, seed="msvs_new"):
3434
3535
Args:
3636
name: Target name.
37-
seed: Seed for MD5 hash.
37+
seed: Seed for SHA-256 hash.
3838
Returns:
3939
A GUID-line string calculated from the name and seed.
4040
@@ -44,8 +44,8 @@ def MakeGuid(name, seed="msvs_new"):
4444
determine the GUID to refer to explicitly. It also means that the GUID will
4545
not change when the project for a target is rebuilt.
4646
"""
47-
# Calculate a MD5 signature for the seed and name.
48-
d = hashlib.md5((str(seed) + str(name)).encode("utf-8")).hexdigest().upper()
47+
# Calculate a SHA-256 signature for the seed and name.
48+
d = hashlib.sha256((str(seed) + str(name)).encode("utf-8")).hexdigest().upper()
4949
# Convert most of the signature to GUID form (discard the rest)
5050
guid = (
5151
"{"

gyp/pylib/gyp/generator/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ def WriteMakeRule(
21632163
# - The multi-output rule will have an do-nothing recipe.
21642164

21652165
# Hash the target name to avoid generating overlong filenames.
2166-
cmddigest = hashlib.sha1(
2166+
cmddigest = hashlib.sha256(
21672167
(command or self.target).encode("utf-8")
21682168
).hexdigest()
21692169
intermediate = "%s.intermediate" % cmddigest

gyp/pylib/gyp/generator/ninja.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ def cygwin_munge(path):
811811
if self.flavor == "win":
812812
# WriteNewNinjaRule uses unique_name to create a rsp file on win.
813813
extra_bindings.append(
814-
("unique_name", hashlib.md5(outputs[0]).hexdigest())
814+
("unique_name", hashlib.sha256(outputs[0].encode("utf-8")).hexdigest())
815815
)
816816

817817
self.ninja.build(
@@ -2811,7 +2811,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
28112811
build_file, name, toolset
28122812
)
28132813
qualified_target_for_hash = qualified_target_for_hash.encode("utf-8")
2814-
hash_for_rules = hashlib.md5(qualified_target_for_hash).hexdigest()
2814+
hash_for_rules = hashlib.sha256(qualified_target_for_hash).hexdigest()
28152815

28162816
base_path = os.path.dirname(build_file)
28172817
obj = "obj"

gyp/pylib/gyp/xcodeproj_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def _HashUpdate(hash, data):
431431
hash.update(data)
432432

433433
if seed_hash is None:
434-
seed_hash = hashlib.sha1()
434+
seed_hash = hashlib.sha256()
435435

436436
hash = seed_hash.copy()
437437

@@ -454,8 +454,8 @@ def _HashUpdate(hash, data):
454454
child.ComputeIDs(recursive, overwrite, child_hash)
455455

456456
if overwrite or self.id is None:
457-
# Xcode IDs are only 96 bits (24 hex characters), but a SHA-1 digest is
458-
# is 160 bits. Instead of throwing out 64 bits of the digest, xor them
457+
# Xcode IDs are only 96 bits (24 hex characters), but a SHA-256 digest is
458+
# is 256 bits. Instead of throwing out bits of the digest, xor them
459459
# into the portion that gets used.
460460
assert hash.digest_size % 4 == 0
461461
digest_int_count = hash.digest_size // 4

0 commit comments

Comments
 (0)