Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sha256 support. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions System.Compiler/Nodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,10 @@ public enum AssemblyFlags{
public enum AssemblyHashAlgorithm{
None = 0x0000,
MD5 = 0x8003,
SHA1 = 0x8004
SHA1 = 0x8004,
SHA256 = 0x800c,
SHA384 = 0x800d,
SHA512 = 0x800e
}
[Flags]
public enum CallingConventionFlags{
Expand Down Expand Up @@ -5481,7 +5484,7 @@ public string Directory{
get{return this.directory;}
set{this.directory = value;}
}
private AssemblyHashAlgorithm hashAlgorithm = AssemblyHashAlgorithm.SHA1;
private AssemblyHashAlgorithm hashAlgorithm = AssemblyHashAlgorithm.SHA256;
public AssemblyHashAlgorithm HashAlgorithm{
get{return this.hashAlgorithm;}
set{this.hashAlgorithm = value;}
Expand Down Expand Up @@ -6701,7 +6704,7 @@ private static string GetKeyString(byte[] publicKey){
StringBuilder str;
if (n > 8){
#if !ROTOR
var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
var sha = new System.Security.Cryptography.SHA256CryptoServiceProvider();
publicKey = sha.ComputeHash(publicKey);
byte[] token = new byte[8];
for (int i = 0, m = publicKey.Length-1; i < 8; i++)
Expand Down Expand Up @@ -6822,7 +6825,7 @@ public virtual byte[] PublicKeyToken{
if (this.PublicKeyOrToken == null || this.PublicKeyOrToken.Length == 0) return null;
if (this.PublicKeyOrToken.Length == 8) return this.token = this.PublicKeyOrToken;
#if !ROTOR
var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
var sha = new System.Security.Cryptography.SHA256CryptoServiceProvider();
byte[] hashedKey = sha.ComputeHash(this.PublicKeyOrToken);
byte[] token = new byte[8];
for (int i = 0, n = hashedKey.Length-1; i < 8; i++) token[i] = hashedKey[n-i];
Expand Down Expand Up @@ -7104,9 +7107,9 @@ public byte[] PublicKeyToken{
if (this.PublicKeyOrToken == null || this.PublicKeyOrToken.Length == 0) return null;
if (this.PublicKeyOrToken.Length == 8) return this.token = this.PublicKeyOrToken;
#if !ROTOR
System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] hashedKey1 = sha1.ComputeHash(this.PublicKeyOrToken);
var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
System.Security.Cryptography.SHA256 sha256 = new System.Security.Cryptography.SHA256CryptoServiceProvider();
byte[] hashedKey1 = sha256.ComputeHash(this.PublicKeyOrToken);
var sha = new System.Security.Cryptography.SHA256CryptoServiceProvider();
byte[] hashedKey = sha.ComputeHash(this.PublicKeyOrToken);
byte[] token = new byte[8];
for (int i = 0, n = hashedKey.Length-1; i < 8; i++) token[i] = hashedKey[n-i];
Expand Down
4 changes: 2 additions & 2 deletions System.Compiler/Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ void PopulateAssemblyTable()
{
AssemblyNode assembly = this.assembly;
AssemblyRow[] assemblyTable = this.writer.assemblyTable = new AssemblyRow[1];
assemblyTable[0].HashAlgId = (int)AssemblyHashAlgorithm.SHA1;
assemblyTable[0].HashAlgId = (int)AssemblyHashAlgorithm.SHA256;
assemblyTable[0].Flags = (int)assembly.Flags;
if (assembly.Version == null) assembly.Version = new Version(1,0,0,0);
assemblyTable[0].MajorVersion = assembly.Version.Major;
Expand Down Expand Up @@ -1864,7 +1864,7 @@ void PopulateFileTable(){
long size = fs.Length;
byte[] buffer = new byte[size];
fs.Read(buffer, 0, (int)size);
var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
var sha = new System.Security.Cryptography.SHA256CryptoServiceProvider();
byte[] hash = sha.ComputeHash(buffer);
ftr[i].HashValue = this.GetBlobIndex(hash);
}catch{}
Expand Down