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 non-cryptographic hash algorithms #53623

Merged
merged 18 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 17 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
6 changes: 6 additions & 0 deletions src/libraries/System.IO.Hashing/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
</PropertyGroup>
</Project>
104 changes: 104 additions & 0 deletions src/libraries/System.IO.Hashing/System.IO.Hashing.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31320.298
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{F94DE827-A426-45CB-AE6E-4E1C154B5386}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj", "{38CB62AF-FD52-433E-AB63-CB07BA1D2CD8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Collections.Immutable", "..\System.Collections.Immutable\src\System.Collections.Immutable.csproj", "{B51B75BA-A1AF-42FB-9845-E9AAC42CFB22}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.Hashing", "ref\System.IO.Hashing.csproj", "{1548AC5C-27FD-4B46-A930-C168D622FAB0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.Hashing", "src\System.IO.Hashing.csproj", "{A078A4EB-27E8-42B1-BD44-3807732A4560}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.Hashing.Tests", "tests\System.IO.Hashing.Tests.csproj", "{2E6DAC1B-9054-40AF-AF72-4C2DD7BD9294}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Reflection.Metadata", "..\System.Reflection.Metadata\src\System.Reflection.Metadata.csproj", "{0E49FF32-6CC1-42B0-AF30-25098C7DA18F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\ref\System.Runtime.CompilerServices.Unsafe.csproj", "{696A5E1C-B7B4-4EA0-AE2A-3FDA1C50F4D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj", "{E5280823-9A9A-4314-B0C3-B983A7D50C85}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Security.AccessControl", "..\System.Security.AccessControl\ref\System.Security.AccessControl.csproj", "{A7AD2290-A979-4139-9C71-BBCD5594180D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Security.Principal.Windows", "..\System.Security.Principal.Windows\ref\System.Security.Principal.Windows.csproj", "{3A873063-B154-4186-914D-1F4F3236101E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{3A73868D-BC2F-483A-B51B-0F3C862BBE85}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{3F027944-9702-4DA5-A7E2-042D5037ABD3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BC246661-9887-4096-BF1A-AC25060547B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F94DE827-A426-45CB-AE6E-4E1C154B5386}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F94DE827-A426-45CB-AE6E-4E1C154B5386}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F94DE827-A426-45CB-AE6E-4E1C154B5386}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F94DE827-A426-45CB-AE6E-4E1C154B5386}.Release|Any CPU.Build.0 = Release|Any CPU
{38CB62AF-FD52-433E-AB63-CB07BA1D2CD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38CB62AF-FD52-433E-AB63-CB07BA1D2CD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38CB62AF-FD52-433E-AB63-CB07BA1D2CD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38CB62AF-FD52-433E-AB63-CB07BA1D2CD8}.Release|Any CPU.Build.0 = Release|Any CPU
{B51B75BA-A1AF-42FB-9845-E9AAC42CFB22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B51B75BA-A1AF-42FB-9845-E9AAC42CFB22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B51B75BA-A1AF-42FB-9845-E9AAC42CFB22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B51B75BA-A1AF-42FB-9845-E9AAC42CFB22}.Release|Any CPU.Build.0 = Release|Any CPU
{1548AC5C-27FD-4B46-A930-C168D622FAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1548AC5C-27FD-4B46-A930-C168D622FAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1548AC5C-27FD-4B46-A930-C168D622FAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1548AC5C-27FD-4B46-A930-C168D622FAB0}.Release|Any CPU.Build.0 = Release|Any CPU
{A078A4EB-27E8-42B1-BD44-3807732A4560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A078A4EB-27E8-42B1-BD44-3807732A4560}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A078A4EB-27E8-42B1-BD44-3807732A4560}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A078A4EB-27E8-42B1-BD44-3807732A4560}.Release|Any CPU.Build.0 = Release|Any CPU
{2E6DAC1B-9054-40AF-AF72-4C2DD7BD9294}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E6DAC1B-9054-40AF-AF72-4C2DD7BD9294}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E6DAC1B-9054-40AF-AF72-4C2DD7BD9294}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E6DAC1B-9054-40AF-AF72-4C2DD7BD9294}.Release|Any CPU.Build.0 = Release|Any CPU
{0E49FF32-6CC1-42B0-AF30-25098C7DA18F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E49FF32-6CC1-42B0-AF30-25098C7DA18F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E49FF32-6CC1-42B0-AF30-25098C7DA18F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E49FF32-6CC1-42B0-AF30-25098C7DA18F}.Release|Any CPU.Build.0 = Release|Any CPU
{696A5E1C-B7B4-4EA0-AE2A-3FDA1C50F4D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{696A5E1C-B7B4-4EA0-AE2A-3FDA1C50F4D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{696A5E1C-B7B4-4EA0-AE2A-3FDA1C50F4D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{696A5E1C-B7B4-4EA0-AE2A-3FDA1C50F4D9}.Release|Any CPU.Build.0 = Release|Any CPU
{E5280823-9A9A-4314-B0C3-B983A7D50C85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5280823-9A9A-4314-B0C3-B983A7D50C85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5280823-9A9A-4314-B0C3-B983A7D50C85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5280823-9A9A-4314-B0C3-B983A7D50C85}.Release|Any CPU.Build.0 = Release|Any CPU
{A7AD2290-A979-4139-9C71-BBCD5594180D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7AD2290-A979-4139-9C71-BBCD5594180D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7AD2290-A979-4139-9C71-BBCD5594180D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7AD2290-A979-4139-9C71-BBCD5594180D}.Release|Any CPU.Build.0 = Release|Any CPU
{3A873063-B154-4186-914D-1F4F3236101E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A873063-B154-4186-914D-1F4F3236101E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A873063-B154-4186-914D-1F4F3236101E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A873063-B154-4186-914D-1F4F3236101E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F94DE827-A426-45CB-AE6E-4E1C154B5386} = {3A73868D-BC2F-483A-B51B-0F3C862BBE85}
{38CB62AF-FD52-433E-AB63-CB07BA1D2CD8} = {3F027944-9702-4DA5-A7E2-042D5037ABD3}
{B51B75BA-A1AF-42FB-9845-E9AAC42CFB22} = {BC246661-9887-4096-BF1A-AC25060547B2}
{1548AC5C-27FD-4B46-A930-C168D622FAB0} = {3F027944-9702-4DA5-A7E2-042D5037ABD3}
{A078A4EB-27E8-42B1-BD44-3807732A4560} = {BC246661-9887-4096-BF1A-AC25060547B2}
{2E6DAC1B-9054-40AF-AF72-4C2DD7BD9294} = {3A73868D-BC2F-483A-B51B-0F3C862BBE85}
{0E49FF32-6CC1-42B0-AF30-25098C7DA18F} = {BC246661-9887-4096-BF1A-AC25060547B2}
{696A5E1C-B7B4-4EA0-AE2A-3FDA1C50F4D9} = {3F027944-9702-4DA5-A7E2-042D5037ABD3}
{E5280823-9A9A-4314-B0C3-B983A7D50C85} = {BC246661-9887-4096-BF1A-AC25060547B2}
{A7AD2290-A979-4139-9C71-BBCD5594180D} = {3F027944-9702-4DA5-A7E2-042D5037ABD3}
{3A873063-B154-4186-914D-1F4F3236101E} = {3F027944-9702-4DA5-A7E2-042D5037ABD3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4DF081FC-DC0D-4317-AB2C-4294B9FE6257}
EndGlobalSection
EndGlobal
78 changes: 78 additions & 0 deletions src/libraries/System.IO.Hashing/ref/System.IO.Hashing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ------------------------------------------------------------------------------
// Changes to this file must follow the https://aka.ms/api-review process.
// ------------------------------------------------------------------------------

namespace System.IO.Hashing
{
public sealed partial class Crc32 : System.IO.Hashing.NonCryptographicHashAlgorithm
{
public Crc32() : base (default(int)) { }
public override void Append(System.ReadOnlySpan<byte> source) { }
protected override void GetCurrentHashCore(System.Span<byte> destination) { }
protected override void GetHashAndResetCore(System.Span<byte> destination) { }
public static byte[] Hash(byte[] source) { throw null; }
public static byte[] Hash(System.ReadOnlySpan<byte> source) { throw null; }
public static int Hash(System.ReadOnlySpan<byte> source, System.Span<byte> destination) { throw null; }
public override void Reset() { }
public static bool TryHash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; }
}
public sealed partial class Crc64 : System.IO.Hashing.NonCryptographicHashAlgorithm
{
public Crc64() : base (default(int)) { }
public override void Append(System.ReadOnlySpan<byte> source) { }
protected override void GetCurrentHashCore(System.Span<byte> destination) { }
protected override void GetHashAndResetCore(System.Span<byte> destination) { }
public static byte[] Hash(byte[] source) { throw null; }
public static byte[] Hash(System.ReadOnlySpan<byte> source) { throw null; }
public static int Hash(System.ReadOnlySpan<byte> source, System.Span<byte> destination) { throw null; }
public override void Reset() { }
public static bool TryHash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; }
}
public abstract partial class NonCryptographicHashAlgorithm
{
protected NonCryptographicHashAlgorithm(int hashLengthInBytes) { }
public int HashLengthInBytes { get { throw null; } }
public void Append(byte[] source) { }
public void Append(System.IO.Stream stream) { }
public abstract void Append(System.ReadOnlySpan<byte> source);
public System.Threading.Tasks.Task AppendAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public byte[] GetCurrentHash() { throw null; }
public int GetCurrentHash(System.Span<byte> destination) { throw null; }
protected abstract void GetCurrentHashCore(System.Span<byte> destination);
public byte[] GetHashAndReset() { throw null; }
public int GetHashAndReset(System.Span<byte> destination) { throw null; }
protected virtual void GetHashAndResetCore(System.Span<byte> destination) { }
public override int GetHashCode() { throw null; }
public abstract void Reset();
public bool TryGetCurrentHash(System.Span<byte> destination, out int bytesWritten) { throw null; }
public bool TryGetHashAndReset(System.Span<byte> destination, out int bytesWritten) { throw null; }
}
public sealed partial class XxHash32 : System.IO.Hashing.NonCryptographicHashAlgorithm
{
public XxHash32() : base (default(int)) { }
public XxHash32(int seed) : base (default(int)) { }
public override void Append(System.ReadOnlySpan<byte> source) { }
protected override void GetCurrentHashCore(System.Span<byte> destination) { }
public static byte[] Hash(byte[] source) { throw null; }
public static byte[] Hash(byte[] source, int seed) { throw null; }
public static byte[] Hash(System.ReadOnlySpan<byte> source, int seed = 0) { throw null; }
public static int Hash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, int seed = 0) { throw null; }
public override void Reset() { }
public static bool TryHash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, int seed = 0) { throw null; }
}
public sealed partial class XxHash64 : System.IO.Hashing.NonCryptographicHashAlgorithm
{
public XxHash64() : base (default(int)) { }
public XxHash64(long seed) : base (default(int)) { }
public override void Append(System.ReadOnlySpan<byte> source) { }
protected override void GetCurrentHashCore(System.Span<byte> destination) { }
public static byte[] Hash(byte[] source) { throw null; }
public static byte[] Hash(byte[] source, long seed) { throw null; }
public static byte[] Hash(System.ReadOnlySpan<byte> source, long seed = (long)0) { throw null; }
public static int Hash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, long seed = (long)0) { throw null; }
public override void Reset() { }
public static bool TryHash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, long seed = (long)0) { throw null; }
}
}
126 changes: 126 additions & 0 deletions src/libraries/System.IO.Hashing/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Argument_DestinationTooShort" xml:space="preserve">
<value>Destination is too short.</value>
</data>
<data name="NotSupported_GetHashCode" xml:space="preserve">
<value>The GetHashCode method is not supported on this object. Use GetCurrentHash or GetHashAndReset to retrieve the hash code computed by this object.</value>
</data>
</root>
Loading