Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,81 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.Primitives.Tests", "tests\System.Security.Cryptography.Primitives.Tests.csproj", "{101EB757-55A4-4F48-841C-C088640B8F57}"
ProjectSection(ProjectDependencies) = postProject
{DF73E985-E143-4BF5-9FA4-E199E7D36235} = {DF73E985-E143-4BF5-9FA4-E199E7D36235}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Security.Cryptography.Primitives", "src\System.Security.Cryptography.Primitives.csproj", "{DF73E985-E143-4BF5-9FA4-E199E7D36235}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DebugNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU
ReleaseNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU
DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{101EB757-55A4-4F48-841C-C088640B8F57}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = net463-Windows_NT-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.Build.0 = net463-Windows_NT-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = net463-Windows_NT-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp-Windows_NT|AnyCPU.Build.0 = net463-Windows_NT-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net463-Windows_NT-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = net463-Windows_NT-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net463-Windows_NT-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = net463-Windows_NT-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net463-Windows_NT-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = net463-Windows_NT-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net463-Windows_NT-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnet463-Windows_NTnetcoreapp|AnyCPU.Build.0 = net463-Windows_NT-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnetcoreappnetcoreapp-Windows_NT|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{DF73E985-E143-4BF5-9FA4-E199E7D36235}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<IsNETCoreApp>true</IsNETCoreApp>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
uap;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Security.Cryptography.Primitives.csproj" />
<Project Include="System.Security.Cryptography.Primitives.csproj">
<TargetGroup>netstandard</TargetGroup>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>

View File

@@ -0,0 +1,199 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Security.Cryptography.CryptographicException))]
namespace System.Security.Cryptography
{
public abstract partial class AsymmetricAlgorithm : System.IDisposable
{
protected int KeySizeValue;
protected System.Security.Cryptography.KeySizes[] LegalKeySizesValue;
protected AsymmetricAlgorithm() { }
public virtual string KeyExchangeAlgorithm { get { throw null; } }
public virtual int KeySize { get { throw null; } set { } }
public virtual System.Security.Cryptography.KeySizes[] LegalKeySizes { get { throw null; } }
public static System.Security.Cryptography.AsymmetricAlgorithm Create() { throw null; }
public static System.Security.Cryptography.AsymmetricAlgorithm Create(string algName) { throw null; }
public virtual string SignatureAlgorithm { get { throw null; } }
public void Clear() { }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public virtual void FromXmlString(string xmlString) { }
public virtual string ToXmlString(bool includePrivateParameters) { throw null; }
}
public enum CipherMode
{
CBC = 1,
[System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
CFB = 4,
CTS = 5,
ECB = 2,
[System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
OFB = 3,
}
public partial class CryptographicUnexpectedOperationException : System.Security.Cryptography.CryptographicException
{
public CryptographicUnexpectedOperationException() { }
protected CryptographicUnexpectedOperationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public CryptographicUnexpectedOperationException(string message) { }
public CryptographicUnexpectedOperationException(string message, System.Exception inner) { }
public CryptographicUnexpectedOperationException(string format, string insert) { }
}
public partial class CryptoStream : System.IO.Stream, System.IDisposable
{
public CryptoStream(System.IO.Stream stream, System.Security.Cryptography.ICryptoTransform transform, System.Security.Cryptography.CryptoStreamMode mode) { }
public CryptoStream(System.IO.Stream stream, System.Security.Cryptography.ICryptoTransform transform, System.Security.Cryptography.CryptoStreamMode mode, bool leaveOpen) { }
public override bool CanRead { get { throw null; } }
public override bool CanSeek { get { throw null; } }
public override bool CanWrite { get { throw null; } }
public void Clear() { }
public bool HasFlushedFinalBlock { get { throw null; } }
public override long Length { get { throw null; } }
public override long Position { get { throw null; } set { } }
protected override void Dispose(bool disposing) { }
public override void Flush() { }
public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; }
public void FlushFinalBlock() { }
public override int Read(byte[] buffer, int offset, int count) { throw null; }
public override System.Threading.Tasks.Task<int> ReadAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; }
public override int ReadByte() { throw null; }
public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; }
public override void SetLength(long value) { }
public override void Write(byte[] buffer, int offset, int count) { }
public override System.Threading.Tasks.Task WriteAsync(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) { throw null; }
public override void WriteByte(byte value) { }
}
public enum CryptoStreamMode
{
Read = 0,
Write = 1,
}
public abstract partial class HashAlgorithm : System.IDisposable, System.Security.Cryptography.ICryptoTransform
{
protected internal byte[] HashValue;
protected int HashSizeValue;
protected int State;
protected HashAlgorithm() { }
public virtual bool CanReuseTransform { get { throw null; } }
public virtual bool CanTransformMultipleBlocks { get { throw null; } }
public virtual byte[] Hash { get { throw null; } }
public virtual int HashSize { get { throw null; } }
public virtual int InputBlockSize { get { throw null; } }
public virtual int OutputBlockSize { get { throw null; } }
public void Clear() { }
public byte[] ComputeHash(byte[] buffer) { throw null; }
public byte[] ComputeHash(byte[] buffer, int offset, int count) { throw null; }
public byte[] ComputeHash(System.IO.Stream inputStream) { throw null; }
public static System.Security.Cryptography.HashAlgorithm Create() { throw null; }
public static System.Security.Cryptography.HashAlgorithm Create(string hashName) { throw null; }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
protected abstract void HashCore(byte[] array, int ibStart, int cbSize);
protected abstract byte[] HashFinal();
public abstract void Initialize();
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) { throw null; }
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount) { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct HashAlgorithmName : System.IEquatable<System.Security.Cryptography.HashAlgorithmName>
{
public HashAlgorithmName(string name) { throw null; }
public static System.Security.Cryptography.HashAlgorithmName MD5 { get { throw null; } }
public string Name { get { throw null; } }
public static System.Security.Cryptography.HashAlgorithmName SHA1 { get { throw null; } }
public static System.Security.Cryptography.HashAlgorithmName SHA256 { get { throw null; } }
public static System.Security.Cryptography.HashAlgorithmName SHA384 { get { throw null; } }
public static System.Security.Cryptography.HashAlgorithmName SHA512 { get { throw null; } }
public override bool Equals(object obj) { throw null; }
public bool Equals(System.Security.Cryptography.HashAlgorithmName other) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(System.Security.Cryptography.HashAlgorithmName left, System.Security.Cryptography.HashAlgorithmName right) { throw null; }
public static bool operator !=(System.Security.Cryptography.HashAlgorithmName left, System.Security.Cryptography.HashAlgorithmName right) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class HMAC : System.Security.Cryptography.KeyedHashAlgorithm
{
protected HMAC() { }
protected int BlockSizeValue { get { throw null; } set {} }
public string HashName { get { throw null; } set { } }
public override byte[] Key { get { throw null; } set { } }
public static new System.Security.Cryptography.HMAC Create() { throw null; }
public static new System.Security.Cryptography.HMAC Create(string algorithmName) { throw null; }
protected override void Dispose(bool disposing) { }
protected override void HashCore(byte[] rgb, int ib, int cb) { }
protected override byte[] HashFinal() { throw null; }
public override void Initialize() { }
}
public partial interface ICryptoTransform : System.IDisposable
{
bool CanReuseTransform { get; }
bool CanTransformMultipleBlocks { get; }
int InputBlockSize { get; }
int OutputBlockSize { get; }
int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset);
byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount);
}
public abstract partial class KeyedHashAlgorithm : System.Security.Cryptography.HashAlgorithm
{
protected byte[] KeyValue;
protected KeyedHashAlgorithm() { }
public virtual byte[] Key { get { throw null; } set { } }
public static new System.Security.Cryptography.KeyedHashAlgorithm Create() { throw null; }
public static new System.Security.Cryptography.KeyedHashAlgorithm Create(string algName) { throw null; }
protected override void Dispose(bool disposing) { }
}
public sealed partial class KeySizes
{
public KeySizes(int minSize, int maxSize, int skipSize) { }
public int MaxSize { get { throw null; } }
public int MinSize { get { throw null; } }
public int SkipSize { get { throw null; } }
}
public enum PaddingMode
{
None = 1,
PKCS7 = 2,
Zeros = 3,
ANSIX923 = 4,
ISO10126 = 5,
}
public abstract partial class SymmetricAlgorithm : System.IDisposable
{
protected int FeedbackSizeValue;
protected int BlockSizeValue;
protected byte[] IVValue;
protected int KeySizeValue;
protected byte[] KeyValue;
protected System.Security.Cryptography.KeySizes[] LegalBlockSizesValue;
protected System.Security.Cryptography.KeySizes[] LegalKeySizesValue;
protected System.Security.Cryptography.CipherMode ModeValue;
protected System.Security.Cryptography.PaddingMode PaddingValue;
protected SymmetricAlgorithm() { }
public virtual int FeedbackSize { get { throw null; } set { } }
public virtual int BlockSize { get { throw null; } set { } }
public virtual byte[] IV { get { throw null; } set { } }
public virtual byte[] Key { get { throw null; } set { } }
public virtual int KeySize { get { throw null; } set { } }
public virtual System.Security.Cryptography.KeySizes[] LegalBlockSizes { get { throw null; } }
public virtual System.Security.Cryptography.KeySizes[] LegalKeySizes { get { throw null; } }
public virtual System.Security.Cryptography.CipherMode Mode { get { throw null; } set { } }
public virtual System.Security.Cryptography.PaddingMode Padding { get { throw null; } set { } }
public static System.Security.Cryptography.SymmetricAlgorithm Create() { throw null; }
public static System.Security.Cryptography.SymmetricAlgorithm Create(string algName) { throw null; }
public virtual System.Security.Cryptography.ICryptoTransform CreateDecryptor() { throw null; }
public abstract System.Security.Cryptography.ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV);
public virtual System.Security.Cryptography.ICryptoTransform CreateEncryptor() { throw null; }
public abstract System.Security.Cryptography.ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV);
public void Clear() { }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
public abstract void GenerateIV();
public abstract void GenerateKey();
public bool ValidKeySize(int bitLength) { throw null; }
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.Security.Cryptography.Primitives.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.IO\ref\System.IO.csproj" />
<ProjectReference Include="..\..\System.Threading.Tasks\ref\System.Threading.Tasks.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
net463-Windows_NT;
netcoreapp;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,180 @@
<?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="Arg_CryptographyException" xml:space="preserve">
<value>Error occurred during a cryptographic operation.</value>
</data>
<data name="Argument_InvalidOffLen" xml:space="preserve">
<value>Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.</value>
</data>
<data name="Argument_InvalidValue" xml:space="preserve">
<value>Value was invalid.</value>
</data>
<data name="Argument_StreamNotReadable" xml:space="preserve">
<value>Stream was not readable.</value>
</data>
<data name="Argument_StreamNotWritable" xml:space="preserve">
<value>Stream was not writable.</value>
</data>
<data name="ArgumentOutOfRange_NeedNonNegNum" xml:space="preserve">
<value>Non-negative number required.</value>
</data>
<data name="Cryptography_BadHashState" xml:space="preserve">
<value>Hash not valid for use in specified state.</value>
</data>
<data name="Cryptography_CryptoStream_FlushFinalBlockTwice" xml:space="preserve">
<value>FlushFinalBlock() method was called twice on a CryptoStream. It can only be called once.</value>
</data>
<data name="Cryptography_HashNotYetFinalized" xml:space="preserve">
<value>Hash must be finalized before the hash value is retrieved.</value>
</data>
<data name="Cryptography_InvalidFeedbackSize" xml:space="preserve">
<value>Specified feedback size is not valid for this algorithm.</value>
</data>
<data name="Cryptography_InvalidBlockSize" xml:space="preserve">
<value>Specified block size is not valid for this algorithm.</value>
</data>
<data name="Cryptography_InvalidCipherMode" xml:space="preserve">
<value>Specified cipher mode is not valid for this algorithm.</value>
</data>
<data name="Cryptography_InvalidIVSize" xml:space="preserve">
<value>Specified initialization vector (IV) does not match the block size for this algorithm.</value>
</data>
<data name="Cryptography_InvalidKeySize" xml:space="preserve">
<value>Specified key is not a valid size for this algorithm.</value>
</data>
<data name="Cryptography_InvalidPaddingMode" xml:space="preserve">
<value>Specified padding mode is not valid for this algorithm.</value>
</data>
<data name="NotSupported_UnreadableStream" xml:space="preserve">
<value>Stream does not support reading.</value>
</data>
<data name="NotSupported_UnseekableStream" xml:space="preserve">
<value>Stream does not support seeking.</value>
</data>
<data name="NotSupported_UnwritableStream" xml:space="preserve">
<value>Stream does not support writing.</value>
</data>
<data name="HashNameMultipleSetNotSupported" xml:space="preserve">
<value>Setting the hashname after it's already been set is not supported on this platform.</value>
</data>
<data name="CryptoConfigNotSupported" xml:space="preserve">
<value>Accessing a hash algorithm by manipulating the HashName property is not supported on this platform. Instead, you must instantiate one of the supplied subtypes (such as HMACSHA1.)</value>
</data>
</root>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<ProjectGuid>{DF73E985-E143-4BF5-9FA4-E199E7D36235}</ProjectGuid>
<AssemblyName>System.Security.Cryptography.Primitives</AssemblyName>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<ResourcesSourceOutputDirectory Condition="'$(TargetGroup)' == 'net463'">None</ResourcesSourceOutputDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='net463-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netcoreapp-Release|AnyCPU'" />
<ItemGroup Condition="'$(TargetGroup)' == 'net463'">
<ContractProject Include="..\ref\System.Security.Cryptography.Primitives.csproj">
<TargetGroup>netcoreapp</TargetGroup>
</ContractProject>
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<Compile Include="System\Security\Cryptography\AsymmetricAlgorithm.cs" />
<Compile Include="System\Security\Cryptography\CipherMode.cs" />
<Compile Include="System\Security\Cryptography\CryptographicUnexpectedOperationException.cs" />
<Compile Include="System\Security\Cryptography\CryptoStream.cs" />
<Compile Include="System\Security\Cryptography\CryptoStreamMode.cs" />
<Compile Include="System\Security\Cryptography\HashAlgorithm.cs" />
<Compile Include="System\Security\Cryptography\HashAlgorithmName.cs" />
<Compile Include="System\Security\Cryptography\Helpers.cs" />
<Compile Include="System\Security\Cryptography\HMAC.cs" />
<Compile Include="System\Security\Cryptography\ICryptoTransform.cs" />
<Compile Include="System\Security\Cryptography\KeyedHashAlgorithm.cs" />
<Compile Include="System\Security\Cryptography\KeySizes.cs" />
<Compile Include="System\Security\Cryptography\PaddingMode.cs" />
<Compile Include="System\Security\Cryptography\SymmetricAlgorithm.cs" />
<Compile Include="$(CommonPath)\System\Threading\Tasks\ForceAsyncAwaiter.cs">
<Link>Common\System\Threading\Tasks\ForceAsyncAwaiter.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'net463'">
<TargetingPackReference Include="mscorlib" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Diagnostics.Contracts" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Resources.ResourceManager" />
<Reference Include="System.Runtime" />
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Tasks" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,91 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Security.Cryptography
{
public abstract class AsymmetricAlgorithm : IDisposable
{
protected int KeySizeValue;
protected KeySizes[] LegalKeySizesValue;
protected AsymmetricAlgorithm() { }
public static AsymmetricAlgorithm Create()
{
return Create("System.Security.Cryptography.AsymmetricAlgorithm");
}
public static AsymmetricAlgorithm Create(string algName)
{
throw new PlatformNotSupportedException();
}
public virtual int KeySize
{
get
{
return KeySizeValue;
}
set
{
if (!value.IsLegalSize(this.LegalKeySizes))
throw new CryptographicException(SR.Cryptography_InvalidKeySize);
KeySizeValue = value;
return;
}
}
public virtual KeySizes[] LegalKeySizes
{
get
{
// Desktop compat: No null check is performed
return (KeySizes[])LegalKeySizesValue.Clone();
}
}
public virtual string SignatureAlgorithm
{
get
{
throw new NotImplementedException();
}
}
public virtual string KeyExchangeAlgorithm
{
get
{
throw new NotImplementedException();
}
}
public virtual void FromXmlString(string xmlString)
{
throw new NotImplementedException();
}
public virtual string ToXmlString(bool includePrivateParameters)
{
throw new NotImplementedException();
}
public void Clear()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose()
{
Clear();
}
protected virtual void Dispose(bool disposing)
{
return;
}
}
}

View File

@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel;
namespace System.Security.Cryptography
{
// This enum represents supported cipher chaining modes:
// cipher block chaining (CBC),
// electronic code book (ECB),
// ciphertext-stealing (CTS).
// Not all implementations will support all modes.
[Serializable]
public enum CipherMode
{
CBC = 1,
ECB = 2,
[EditorBrowsable(EditorBrowsableState.Never)]OFB = 3,
[EditorBrowsable(EditorBrowsableState.Never)]CFB = 4,
CTS = 5
}
}

View File

@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
namespace System.Security.Cryptography
{
[Serializable]
public enum CryptoStreamMode
{
Read = 0,
Write = 1,
}
}

View File

@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Runtime.Serialization;
namespace System.Security.Cryptography
{
[Serializable]
public class CryptographicUnexpectedOperationException : CryptographicException
{
public CryptographicUnexpectedOperationException()
: base(SR.Arg_CryptographyException)
{
}
public CryptographicUnexpectedOperationException(string message)
: base(message)
{
}
public CryptographicUnexpectedOperationException(string message, Exception inner)
: base(message, inner)
{
}
public CryptographicUnexpectedOperationException(string format, string insert)
: base(string.Format(CultureInfo.CurrentCulture, format, insert))
{
}
protected CryptographicUnexpectedOperationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

View File

@@ -0,0 +1,93 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Security.Cryptography
{
public abstract class HMAC : KeyedHashAlgorithm
{
private int _blockSizeValue = 64;
protected int BlockSizeValue
{
get
{
return _blockSizeValue;
}
set
{
_blockSizeValue = value;
}
}
protected HMAC() { }
public static new HMAC Create()
{
return Create("System.Security.Cryptography.HMAC");
}
public static new HMAC Create(string algorithmName)
{
throw new PlatformNotSupportedException();
}
public String HashName
{
get
{
return _hashName;
}
set
{
// On the desktop, setting the HashName selects (or switches over to) a new hashing algorithm via CryptoConfig.
// Our intended refactoring turns HMAC back into an abstract class with no algorithm-specific implementation.
// Changing the HashName would not have the intended effect so throw a proper exception so the developer knows what's up.
//
// We still have to allow setting it the first time as the contract provides no other way to do so.
// Since the set is public, ensure that hmac.HashName = hmac.HashName works without throwing.
if (_hashName != null && value != _hashName)
throw new PlatformNotSupportedException(SR.HashNameMultipleSetNotSupported);
_hashName = value;
}
}
public override byte[] Key
{
get
{
return base.Key;
}
set
{
base.Key = value;
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
protected override void HashCore(byte[] rgb, int ib, int cb)
{
throw new PlatformNotSupportedException(SR.CryptoConfigNotSupported);
}
protected override byte[] HashFinal()
{
throw new PlatformNotSupportedException(SR.CryptoConfigNotSupported);
}
public override void Initialize()
{
throw new PlatformNotSupportedException(SR.CryptoConfigNotSupported);
}
private String _hashName;
}
}

View File

@@ -0,0 +1,202 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.IO;
namespace System.Security.Cryptography
{
public abstract class HashAlgorithm : IDisposable, ICryptoTransform
{
private bool _disposed;
protected int HashSizeValue;
protected internal byte[] HashValue;
protected int State = 0;
protected HashAlgorithm() { }
public static HashAlgorithm Create()
{
return Create("System.Security.Cryptography.HashAlgorithm");
}
public static HashAlgorithm Create(string hashName)
{
throw new PlatformNotSupportedException();
}
public virtual int HashSize => HashSizeValue;
public virtual byte[] Hash
{
get
{
if (_disposed)
throw new ObjectDisposedException(null);
if (State != 0)
throw new CryptographicUnexpectedOperationException(SR.Cryptography_HashNotYetFinalized);
return (byte[])HashValue.Clone();
}
}
public byte[] ComputeHash(byte[] buffer)
{
if (_disposed)
throw new ObjectDisposedException(null);
if (buffer == null)
throw new ArgumentNullException(nameof(buffer));
HashCore(buffer, 0, buffer.Length);
return CaptureHashCodeAndReinitialize();
}
public byte[] ComputeHash(byte[] buffer, int offset, int count)
{
if (buffer == null)
throw new ArgumentNullException(nameof(buffer));
if (offset < 0)
throw new ArgumentOutOfRangeException(nameof(offset), SR.ArgumentOutOfRange_NeedNonNegNum);
if (count < 0 || (count > buffer.Length))
throw new ArgumentException(SR.Argument_InvalidValue);
if ((buffer.Length - count) < offset)
throw new ArgumentException(SR.Argument_InvalidOffLen);
if (_disposed)
throw new ObjectDisposedException(null);
HashCore(buffer, offset, count);
return CaptureHashCodeAndReinitialize();
}
public byte[] ComputeHash(Stream inputStream)
{
if (_disposed)
throw new ObjectDisposedException(null);
// Default the buffer size to 4K.
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) > 0)
{
HashCore(buffer, 0, bytesRead);
}
return CaptureHashCodeAndReinitialize();
}
private byte[] CaptureHashCodeAndReinitialize()
{
HashValue = HashFinal();
// Clone the hash value prior to invoking Initialize in case the user-defined Initialize
// manipulates the array.
byte[] tmp = (byte[])HashValue.Clone();
Initialize();
return tmp;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Clear()
{
(this as IDisposable).Dispose();
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// Although we don't have any resources to dispose at this level,
// we need to continue to throw ObjectDisposedExceptions from CalculateHash
// for compatibility with the desktop framework.
_disposed = true;
}
return;
}
// ICryptoTransform methods
// We assume any HashAlgorithm can take input a byte at a time
public virtual int InputBlockSize
{
get { return (1); }
}
public virtual int OutputBlockSize
{
get { return (1); }
}
public virtual bool CanTransformMultipleBlocks
{
get { return true; }
}
public virtual bool CanReuseTransform
{
get { return true; }
}
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
ValidateTransformBlock(inputBuffer, inputOffset, inputCount);
// Change the State value
State = 1;
HashCore(inputBuffer, inputOffset, inputCount);
if ((outputBuffer != null) && ((inputBuffer != outputBuffer) || (inputOffset != outputOffset)))
{
// We let BlockCopy do the destination array validation
Buffer.BlockCopy(inputBuffer, inputOffset, outputBuffer, outputOffset, inputCount);
}
return inputCount;
}
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
ValidateTransformBlock(inputBuffer, inputOffset, inputCount);
HashCore(inputBuffer, inputOffset, inputCount);
HashValue = CaptureHashCodeAndReinitialize();
byte[] outputBytes;
if (inputCount != 0)
{
outputBytes = new byte[inputCount];
Buffer.BlockCopy(inputBuffer, inputOffset, outputBytes, 0, inputCount);
}
else
{
outputBytes = Array.Empty<byte>();
}
// Reset the State value
State = 0;
return outputBytes;
}
private void ValidateTransformBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
if (inputBuffer == null)
throw new ArgumentNullException(nameof(inputBuffer));
if (inputOffset < 0)
throw new ArgumentOutOfRangeException(nameof(inputOffset), SR.ArgumentOutOfRange_NeedNonNegNum);
if (inputCount < 0 || inputCount > inputBuffer.Length)
throw new ArgumentException(SR.Argument_InvalidValue);
if ((inputBuffer.Length - inputCount) < inputOffset)
throw new ArgumentException(SR.Argument_InvalidOffLen);
if (_disposed)
throw new ObjectDisposedException(null);
}
protected abstract void HashCore(byte[] array, int ibStart, int cbSize);
protected abstract byte[] HashFinal();
public abstract void Initialize();
}
}

View File

@@ -0,0 +1,107 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Security.Cryptography
{
// Strongly typed string representing the name of a hash algorithm.
// Open ended to allow extensibility while giving the discoverable feel of an enum for common values.
/// <summary>
/// Specifies the name of a cryptographic hash algorithm.
/// </summary>
/// Asymmetric Algorithms implemented using Microsoft's CNG (Cryptography Next Generation) API
/// will interpret the underlying string value as a CNG algorithm identifier:
/// * https://msdn.microsoft.com/en-us/library/windows/desktop/aa375534(v=vs.85).aspx
///
/// As with CNG, the names are case-sensitive.
///
/// Asymmetric Algorithms implemented using other technologies:
/// * Must recognize at least "MD5", "SHA1", "SHA256", "SHA384", and "SHA512".
/// * Should recognize additional CNG IDs for any other hash algorithms that they also support.
/// </remarks>
public struct HashAlgorithmName : IEquatable<HashAlgorithmName>
{
// Returning a new instance every time is free here since HashAlgorithmName is a struct with
// a single string field. The optimized codegen should be equivalent to return "MD5".
/// <summary>
/// Gets a <see cref="HashAlgorithmName" /> representing "MD5"
/// </summary>
public static HashAlgorithmName MD5 { get { return new HashAlgorithmName("MD5"); } }
/// <summary>
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA1"
/// </summary>
public static HashAlgorithmName SHA1 { get { return new HashAlgorithmName("SHA1"); } }
/// <summary>
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA256"
/// </summary>
public static HashAlgorithmName SHA256 { get { return new HashAlgorithmName("SHA256"); } }
/// <summary>
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA384"
/// </summary>
public static HashAlgorithmName SHA384 { get { return new HashAlgorithmName("SHA384"); } }
/// <summary>
/// Gets a <see cref="HashAlgorithmName" /> representing "SHA512"
/// </summary>
public static HashAlgorithmName SHA512 { get { return new HashAlgorithmName("SHA512"); } }
private readonly string _name;
/// <summary>
/// Gets a <see cref="HashAlgorithmName" /> representing a custom name.
/// </summary>
/// <param name="name">The custom hash algorithm name.</param>
public HashAlgorithmName(string name)
{
// Note: No validation because we have to deal with default(HashAlgorithmName) regardless.
_name = name;
}
/// <summary>
/// Gets the underlying string representation of the algorithm name.
/// </summary>
/// <remarks>
/// May be null or empty to indicate that no hash algorithm is applicable.
/// </remarks>
public string Name
{
get { return _name; }
}
public override string ToString()
{
return _name ?? String.Empty;
}
public override bool Equals(object obj)
{
return obj is HashAlgorithmName && Equals((HashAlgorithmName)obj);
}
public bool Equals(HashAlgorithmName other)
{
// NOTE: intentionally ordinal and case sensitive, matches CNG.
return _name == other._name;
}
public override int GetHashCode()
{
return _name == null ? 0 : _name.GetHashCode();
}
public static bool operator ==(HashAlgorithmName left, HashAlgorithmName right)
{
return left.Equals(right);
}
public static bool operator !=(HashAlgorithmName left, HashAlgorithmName right)
{
return !(left == right);
}
}
}

View File

@@ -0,0 +1,64 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Security.Cryptography;
namespace System.Security.Cryptography
{
internal static class Helpers
{
public static byte[] CloneByteArray(this byte[] src)
{
if (src == null)
{
return null;
}
return (byte[])(src.Clone());
}
public static bool IsLegalSize(this int size, KeySizes[] legalSizes)
{
bool dontCare;
return size.IsLegalSize(legalSizes, out dontCare);
}
public static bool IsLegalSize(this int size, KeySizes[] legalSizes, out bool validatedByZeroSkipSizeKeySizes)
{
validatedByZeroSkipSizeKeySizes = false;
for (int i = 0; i < legalSizes.Length; i++)
{
KeySizes currentSizes = legalSizes[i];
// If a cipher has only one valid key size, MinSize == MaxSize and SkipSize will be 0
if (currentSizes.SkipSize == 0)
{
if (currentSizes.MinSize == size)
{
// Signal that we were validated by a 0-skipsize KeySizes entry. Needed to preserve a very obscure
// piece of back-compat behavior.
validatedByZeroSkipSizeKeySizes = true;
return true;
}
}
else if (size >= currentSizes.MinSize && size <= currentSizes.MaxSize)
{
// If the number is in range, check to see if it's a legal increment above MinSize
int delta = size - currentSizes.MinSize;
// While it would be unusual to see KeySizes { 10, 20, 5 } and { 11, 14, 1 }, it could happen.
// So don't return false just because this one doesn't match.
if (delta % currentSizes.SkipSize == 0)
{
return true;
}
}
}
return false;
}
}
}

View File

@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
namespace System.Security.Cryptography
{
public interface ICryptoTransform : IDisposable
{
int InputBlockSize { get; }
int OutputBlockSize { get; }
// CanTransformMultipleBlocks == true implies that TransformBlock() can accept any number
// of whole blocks, not just a single block. If CanTransformMultipleBlocks is false, you have
// to feed blocks one at a time.
bool CanTransformMultipleBlocks { get; }
// If CanReuseTransform is true, then after a call to TransformFinalBlock() the transform
// resets its internal state to its initial configuration (with Key and IV loaded) and can
// be used to perform another encryption/decryption.
bool CanReuseTransform { get; }
// The return value of TransformBlock is the number of bytes returned to outputBuffer and is
// always <= OutputBlockSize. If CanTransformMultipleBlocks is true, then inputCount may be
// any positive multiple of InputBlockSize
int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset);
// Special function for transforming the last block or partial block in the stream. The
// return value is an array containing the remaining transformed bytes.
// We return a new array here because the amount of information we send back at the end could
// be larger than a single block once padding is accounted for.
byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount);
}
}

View File

@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
namespace System.Security.Cryptography
{
// This structure is used for returning the set of legal key sizes and
// block sizes of the symmetric algorithms.
public sealed class KeySizes
{
public KeySizes(int minSize, int maxSize, int skipSize)
{
MinSize = minSize;
MaxSize = maxSize;
SkipSize = skipSize;
}
public int MinSize { get; private set; }
public int MaxSize { get; private set; }
public int SkipSize { get; private set; }
}
}

Some files were not shown because too many files have changed in this diff Show More