Skip to content

Commit

Permalink
WASM: Add SHA* hash functions (#40486)
Browse files Browse the repository at this point in the history
This ports the managed SHA* hash functions from https://github.com/microsoft/referencesource so we can use them on Browser/WASM where we don't have OpenSSL.

Enables the System.Security.Cryptography.Algorithms tests for these classes: `Tests run: 271, Errors: 0, Failures: 0, Skipped: 1. Time: 11.857137s`

Resolves #40076
  • Loading branch information
akoeplinger authored Sep 2, 2020
1 parent 2d463ee commit 5183c6e
Show file tree
Hide file tree
Showing 85 changed files with 1,405 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class AesCipherTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public class AesContractTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class AesCornerTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public class AesModeTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class DecryptorReusabilty
{
// See https://github.com/dotnet/runtime/issues/21354 for details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace System.Security.Cryptography.Encryption.Des.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class DesCipherTests
{
// These are the expected output of many decryptions. Changing these values requires re-generating test input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace System.Security.Cryptography.Encryption.Des.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class DesContractTests
{
// cfb not available on windows 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Encryption.Des.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static partial class DesTests
{
private static readonly byte[] KnownWeakKey = "e0e0e0e0f1f1f1f1".HexToByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class DSAImportExport
{
public static bool SupportsFips186_3 => DSAFactory.SupportsFips186_3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class DSAKeyFileTests
{
public static bool SupportsFips186_3 => DSAFactory.SupportsFips186_3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class DSAKeyGeneration
{
public static bool SupportsKeyGeneration => DSAFactory.SupportsKeyGeneration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class DSAKeyPemTests
{
private const string AmbiguousExceptionMarker = "multiple keys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class DSASignVerify_Array : DSASignVerify
{
public override byte[] SignData(DSA dsa, byte[] data, HashAlgorithmName hashAlgorithm) =>
Expand Down Expand Up @@ -53,6 +54,7 @@ public void InvalidStreamArrayArguments_Throws()
}
}

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class DSASignVerify_Stream : DSASignVerify
{
public override byte[] SignData(DSA dsa, byte[] data, HashAlgorithmName hashAlgorithm) =>
Expand All @@ -74,6 +76,7 @@ public void InvalidArrayArguments_Throws()
}

#if NETCOREAPP
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class DSASignVerify_Span : DSASignVerify
{
public override byte[] SignData(DSA dsa, byte[] data, HashAlgorithmName hashAlgorithm) =>
Expand Down Expand Up @@ -106,6 +109,7 @@ private static byte[] TryWithOutputArray(Func<byte[], (bool, int)> func)
}
}
#endif
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract partial class DSASignVerify
{
public abstract byte[] SignData(DSA dsa, byte[] data, HashAlgorithmName hashAlgorithm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract class DSASignatureFormatTests : DsaFamilySignatureFormatTests
{
protected override bool SupportsSha2 => DSAFactory.SupportsFips186_3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class DSASignatureFormatterTests : AsymmetricSignatureFormatterTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Dsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class DSAXml
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace System.Security.Cryptography.Algorithms.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract class DsaFamilySignatureFormatTests
{
protected readonly struct KeyDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract partial class ECKeyFileTests<T> where T : AsymmetricAlgorithm
{
protected abstract T CreateKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract class ECKeyPemTests<TAlg> where TAlg : AsymmetricAlgorithm
{
private const string AmbiguousExceptionMarker = "multiple keys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Cryptography.Tests;
using Xunit;

namespace System.Security.Cryptography.EcDiffieHellman.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public class ECDhKeyFileTests : ECKeyFileTests<ECDiffieHellman>
{
protected override ECDiffieHellman CreateKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Cryptography.Tests;
using Xunit;

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class ECDiffieHellmanKeyPemTests : ECKeyPemTests<ECDiffieHellman>
{
protected override ECDiffieHellman CreateKey() => ECDiffieHellman.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace System.Security.Cryptography.EcDiffieHellman.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class ECDiffieHellmanTests : EccTestBase
{
private static List<object[]> s_everyKeysize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public class ECDsaImportExportTests : ECDsaTestsBase
{
#if NETCOREAPP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Cryptography.Tests;
using Xunit;

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public class ECDsaKeyFileTests : ECKeyFileTests<ECDsa>
{
protected override ECDsa CreateKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Cryptography.Tests;
using Xunit;

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class ECDsaKeyPemTests : ECKeyPemTests<ECDsa>
{
protected override ECDsa CreateKey() => ECDsa.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract class ECDsaSignatureFormatTests : DsaFamilySignatureFormatTests
{
protected override bool SupportsSha2 => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class ECDsaTests_Array : ECDsaTests
{
protected override bool VerifyData(ECDsa ecdsa, byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm) =>
Expand Down Expand Up @@ -86,6 +87,7 @@ public void VerifyHash_InvalidArguments_Throws(ECDsa ecdsa)
}
}

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class ECDsaTests_Stream : ECDsaTests
{
protected override bool VerifyData(ECDsa ecdsa, byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm)
Expand Down Expand Up @@ -123,6 +125,7 @@ public void VerifyData_InvalidArguments_Throws(ECDsa ecdsa)
}
}

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract partial class ECDsaTests : ECDsaTestsBase
{
protected bool VerifyData(ECDsa ecdsa, byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class ECDsaTests_Span : ECDsaTests
{
protected override bool VerifyData(ECDsa ecdsa, byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace System.Security.Cryptography.EcDsa.Tests
/// <summary>
/// Input and helper methods for ECDsa
/// </summary>
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract class ECDsaTestsBase : EccTestBase
{
#if NETCOREAPP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace System.Security.Cryptography.EcDsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class ECDsaXml : ECDsaTestsBase
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace System.Security.Cryptography.Encryption.RC2.Tests
{
using RC2 = System.Security.Cryptography.RC2;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class RC2CipherTests
{
// These are the expected output of many decryptions. Changing these values requires re-generating test input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace System.Security.Cryptography.Encryption.RC2.Tests
{
using RC2 = System.Security.Cryptography.RC2;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class RC2ContractTests
{
[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace System.Security.Cryptography.Encryption.RC2.Tests
{
using RC2 = System.Security.Cryptography.RC2;

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static partial class RC2Tests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void NullArray_Throws()
}
}

[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public abstract class EncryptDecrypt
{
public static bool SupportsSha2Oaep => RSAFactory.SupportsSha2Oaep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public sealed class EncryptDecrypt_Span : EncryptDecrypt
{
protected override byte[] Encrypt(RSA rsa, byte[] data, RSAEncryptionPadding padding) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class ImportExport
{
public static bool Supports16384 { get; } = TestRsa16384();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public class KeyGeneration
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class RSAKeyExchangeFormatterTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class RSAKeyFileTests
{
public static bool Supports384BitPrivateKey { get; } = RSAFactory.Supports384PrivateKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class RSAKeyPemTests
{
private const string AmbiguousExceptionMarker = "multiple keys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public partial class RSASignatureFormatterTests : AsymmetricSignatureFormatterTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace System.Security.Cryptography.Rsa.Tests
{
[SkipOnMono("Not supported on Browser", TestPlatforms.Browser)]
public static class RSAXml
{
[Fact]
Expand Down
Loading

0 comments on commit 5183c6e

Please sign in to comment.