Switch crossgen2 to use SHA256 for PDB hash (#67305)
authorJan Kotas <jkotas@microsoft.com>
Wed, 30 Mar 2022 00:02:33 +0000 (17:02 -0700)
committerGitHub <noreply@github.com>
Wed, 30 Mar 2022 00:02:33 +0000 (17:02 -0700)
src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/DebugDirectoryEntryNode.cs

index 41bf7f7..b7ab72f 100644 (file)
@@ -341,11 +341,11 @@ namespace ILCompiler.DependencyAnalysis
                     if (nativeDebugDirectoryEntryNode is not null)
                     {
                         Debug.Assert(_generatePdbFile);
-                        // Compute MD5 hash of the output image and store that in the native DebugDirectory entry
-                        using (var md5Hash = MD5.Create())
+                        // Compute hash of the output image and store that in the native DebugDirectory entry
+                        using (var hashAlgorithm = SHA256.Create())
                         {
                             peStream.Seek(0, SeekOrigin.Begin);
-                            byte[] hash = md5Hash.ComputeHash(peStream);
+                            byte[] hash = hashAlgorithm.ComputeHash(peStream);
                             byte[] rsdsEntry = nativeDebugDirectoryEntryNode.GenerateRSDSEntryData(hash);
 
                             int offsetToUpdate = r2rPeBuilder.GetSymbolFilePosition(nativeDebugDirectoryEntryNode);
index 3780c4e..8099563 100644 (file)
@@ -180,7 +180,7 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun
             return builder.ToObjectData();
         }
 
-        public byte[] GenerateRSDSEntryData(byte[] md5Hash)
+        public byte[] GenerateRSDSEntryData(byte[] hash)
         {
             MemoryStream rsdsEntry = new MemoryStream(RSDSSize);
 
@@ -188,14 +188,8 @@ namespace ILCompiler.DependencyAnalysis.ReadyToRun
             {
                 writer.Write(RsdsMagic);
 
-                // The PDB signature will be the same as our NGEN signature.
-                // However we want the printed version of the GUID to be the same as the
-                // byte dump of the signature so we swap bytes to make this work.
-                Debug.Assert(md5Hash.Length == 16);
-                writer.Write((uint)((md5Hash[0] * 256 + md5Hash[1]) * 256 + md5Hash[2]) * 256 + md5Hash[3]);
-                writer.Write((ushort)(md5Hash[4] * 256 + md5Hash[5]));
-                writer.Write((ushort)(md5Hash[6] * 256 + md5Hash[7]));
-                writer.Write(md5Hash, 8, 8);
+                Debug.Assert(hash.Length >= 16);
+                writer.Write(hash, 0, 16);
 
                 // Age
                 writer.Write(1);