Skip to content

Commit eb6680a

Browse files
Wesley Chiuguan404ming
authored andcommitted
fix: replace weak hash functions with SHA-256
1 parent 30cda26 commit eb6680a

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
@@ -2169,7 +2169,7 @@ def WriteMakeRule(
21692169
# - The multi-output rule will have an do-nothing recipe.
21702170

21712171
# Hash the target name to avoid generating overlong filenames.
2172-
cmddigest = hashlib.sha1(
2172+
cmddigest = hashlib.sha256(
21732173
(command or self.target).encode("utf-8")
21742174
).hexdigest()
21752175
intermediate = "%s.intermediate" % cmddigest

gyp/pylib/gyp/generator/ninja.py

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

816816
self.ninja.build(
@@ -2803,7 +2803,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
28032803
build_file, name, toolset
28042804
)
28052805
qualified_target_for_hash = qualified_target_for_hash.encode("utf-8")
2806-
hash_for_rules = hashlib.md5(qualified_target_for_hash).hexdigest()
2806+
hash_for_rules = hashlib.sha256(qualified_target_for_hash).hexdigest()
28072807

28082808
base_path = os.path.dirname(build_file)
28092809
obj = "obj"

gyp/pylib/gyp/xcodeproj_file.py

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

431431
if seed_hash is None:
432-
seed_hash = hashlib.sha1()
432+
seed_hash = hashlib.sha256()
433433

434434
hash = seed_hash.copy()
435435

@@ -452,8 +452,8 @@ def _HashUpdate(hash, data):
452452
child.ComputeIDs(recursive, overwrite, child_hash)
453453

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

0 commit comments

Comments
 (0)