Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eng/liveBuilds.targets1
-rw-r--r--src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props2
-rw-r--r--src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs1
-rw-r--r--src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs67
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/Helpers.cs2
-rw-r--r--src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs50
-rw-r--r--src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs1050
-rw-r--r--src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherTests.cs70
-rw-r--r--src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesContractTests.cs41
-rw-r--r--src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCornerTests.cs1
-rw-r--r--src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesModeTests.cs5
-rw-r--r--src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/DecryptorReusability.cs1
-rw-r--r--src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/Symmetric/SymmetricOneShotBase.cs4
-rw-r--r--src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs5
-rw-r--r--src/libraries/System.Security.Cryptography/src/Resources/Strings.resx6
-rw-r--r--src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj11
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs5
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesCryptoServiceProvider.cs2
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.Browser.cs64
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NonBrowser.cs10
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NotSupported.cs35
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManaged.cs2
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManagedTransform.Browser.cs1015
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesSubtleCryptoTransform.Browser.cs171
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoConfig.cs14
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HMACHashProvider.Browser.Native.cs94
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderDispenser.Browser.cs34
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Pbkdf2Implementation.Browser.cs38
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Rijndael.cs2
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelImplementation.cs2
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelManaged.cs2
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SHAHashProvider.Browser.Native.cs98
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs2
-rw-r--r--src/libraries/System.Security.Cryptography/tests/AesManagedTests.cs2
-rw-r--r--src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs75
-rw-r--r--src/libraries/System.Security.Cryptography/tests/AesTests.cs1
-rw-r--r--src/libraries/System.Security.Cryptography/tests/CryptoConfigTests.cs58
-rw-r--r--src/libraries/System.Security.Cryptography/tests/PaddingModeTests.cs1
-rw-r--r--src/libraries/System.Security.Cryptography/tests/RijndaelTests.cs3
-rw-r--r--src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj7
-rw-r--r--src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt8
-rw-r--r--src/mono/wasi/mono-wasi-driver/driver.c11
-rw-r--r--src/mono/wasm/build/WasmApp.Native.targets1
-rw-r--r--src/mono/wasm/build/WasmApp.targets2
-rw-r--r--src/mono/wasm/runtime/CMakeLists.txt3
-rw-r--r--src/mono/wasm/runtime/assets.ts3
-rw-r--r--src/mono/wasm/runtime/dotnet.d.ts2
-rw-r--r--src/mono/wasm/runtime/es6/dotnet.es6.lib.js7
-rw-r--r--src/mono/wasm/runtime/exports-linker.ts10
-rw-r--r--src/mono/wasm/runtime/startup.ts2
-rw-r--r--src/mono/wasm/runtime/subtle-crypto.ts412
-rw-r--r--src/mono/wasm/runtime/types.ts1
-rw-r--r--src/mono/wasm/runtime/workers/dotnet-crypto-worker.ts404
-rw-r--r--src/mono/wasm/wasm.proj3
-rw-r--r--src/native/libs/CMakeLists.txt2
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt14
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h18
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c99
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h55
-rw-r--r--src/tasks/WasmAppBuilder/WasmAppBuilder.cs6
-rw-r--r--src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs3
-rw-r--r--src/tests/BuildWasmApps/Wasm.Build.Tests/NativeLibraryTests.cs2
62 files changed, 680 insertions, 3442 deletions
diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets
index 5802882a82a..5a3bf10c3e0 100644
--- a/eng/liveBuilds.targets
+++ b/eng/liveBuilds.targets
@@ -179,7 +179,6 @@
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'Browser'"
Include="
$(LibrariesNativeArtifactsPath)dotnet.js;
- $(LibrariesNativeArtifactsPath)src\dotnet-crypto-worker.js;
$(LibrariesNativeArtifactsPath)dotnet.d.ts;
$(LibrariesNativeArtifactsPath)dotnet-legacy.d.ts;
$(LibrariesNativeArtifactsPath)package.json;
diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
index 0bb1a67b032..61f577981d1 100644
--- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
+++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
@@ -95,7 +95,6 @@
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Apple.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Android.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Android.so" IsNative="true" />
- <PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Browser.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.so" IsNative="true" />
@@ -220,7 +219,6 @@
<PlatformManifestFileEntry Include="libmono-profiler-aot.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-wasm-eh-js.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-wasm-eh-wasm.a" IsNative="true" />
- <PlatformManifestFileEntry Include="dotnet-crypto-worker.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.worker.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.js.symbols" IsNative="true" />
diff --git a/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs
index b28d723f0bf..df7bdb4b890 100644
--- a/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs
+++ b/src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs
@@ -7,6 +7,5 @@ internal static partial class Interop
{
// Shims
internal const string SystemNative = "libSystem.Native";
- internal const string CryptoNative = "libSystem.Security.Cryptography.Native.Browser";
}
}
diff --git a/src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs b/src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs
deleted file mode 100644
index 1e6ea5c2821..00000000000
--- a/src/libraries/Common/src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SubtleCrypto.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static partial class BrowserCrypto
- {
- // These values are also defined in the pal_crypto_webworker header file, and utilized in the dotnet-crypto-worker in the wasm runtime.
- internal enum SimpleDigest
- {
- Sha1,
- Sha256,
- Sha384,
- Sha512,
- };
-
- internal static readonly bool CanUseSubtleCrypto = CanUseSubtleCryptoImpl() == 1;
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_CanUseSubtleCryptoImpl")]
- private static partial int CanUseSubtleCryptoImpl();
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_SimpleDigestHash")]
- internal static unsafe partial int SimpleDigestHash(
- SimpleDigest hash,
- byte* input_buffer,
- int input_len,
- byte* output_buffer,
- int output_len);
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_Sign")]
- internal static unsafe partial int Sign(
- SimpleDigest hashAlgorithm,
- byte* key_buffer,
- int key_len,
- byte* input_buffer,
- int input_len,
- byte* output_buffer,
- int output_len);
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_EncryptDecrypt")]
- internal static unsafe partial int EncryptDecrypt(
- int encrypting,
- byte* key_buffer,
- int key_len,
- byte* iv_buffer,
- int iv_len,
- byte* input_buffer,
- int input_len,
- byte* output_buffer,
- int output_len);
-
- [LibraryImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_DeriveBits")]
- internal static unsafe partial int DeriveBits(
- byte* password_buffer,
- int password_len,
- byte* salt_buffer,
- int salt_len,
- int iterations,
- SimpleDigest hashAlgorithm,
- byte* output_buffer,
- int output_len);
- }
-}
diff --git a/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs b/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs
index 685a7e1beed..b1dc4d1de9a 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/Helpers.cs
@@ -11,7 +11,7 @@ namespace Internal.Cryptography
internal static partial class Helpers
{
[UnsupportedOSPlatformGuard("browser")]
- internal static bool HasNonAesSymmetricEncryption =>
+ internal static bool HasSymmetricEncryption { get; } =
#if NETCOREAPP
!OperatingSystem.IsBrowser();
#else
diff --git a/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs b/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs
index 185eb3fcf2b..800b4f335e8 100644
--- a/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs
+++ b/src/libraries/Common/src/System/Security/Cryptography/PasswordBasedEncryption.cs
@@ -74,20 +74,7 @@ namespace System.Security.Cryptography
{
Debug.Assert(destination.Length >= encryptedData.Length);
- // Don't check that algorithmIdentifier.Parameters is set here.
- // Maybe some future PBES3 will have one with a default.
-
- if (algorithmIdentifier.Algorithm == Oids.PasswordBasedEncryptionScheme2)
- {
- return Pbes2Decrypt(
- algorithmIdentifier.Parameters,
- password,
- passwordBytes,
- encryptedData,
- destination);
- }
-
- if (!Helpers.HasNonAesSymmetricEncryption)
+ if (!Helpers.HasSymmetricEncryption)
{
throw new CryptographicException(
SR.Format(
@@ -95,8 +82,11 @@ namespace System.Security.Cryptography
algorithmIdentifier.Algorithm));
}
+ // Don't check that algorithmIdentifier.Parameters is set here.
+ // Maybe some future PBES3 will have one with a default.
+
HashAlgorithmName digestAlgorithmName;
- SymmetricAlgorithm cipher;
+ SymmetricAlgorithm? cipher = null;
bool pkcs12 = false;
@@ -141,6 +131,13 @@ namespace System.Security.Cryptography
cipher.KeySize = 40;
pkcs12 = true;
break;
+ case Oids.PasswordBasedEncryptionScheme2:
+ return Pbes2Decrypt(
+ algorithmIdentifier.Parameters,
+ password,
+ passwordBytes,
+ encryptedData,
+ destination);
default:
throw new CryptographicException(
SR.Format(
@@ -149,6 +146,7 @@ namespace System.Security.Cryptography
}
Debug.Assert(digestAlgorithmName.Name != null);
+ Debug.Assert(cipher != null);
using (cipher)
{
@@ -239,6 +237,14 @@ namespace System.Security.Cryptography
{
Debug.Assert(pbeParameters != null);
+ if (!Helpers.HasSymmetricEncryption)
+ {
+ throw new CryptographicException(
+ SR.Format(
+ SR.Cryptography_UnknownAlgorithmIdentifier,
+ pbeParameters.EncryptionAlgorithm));
+ }
+
isPkcs12 = false;
switch (pbeParameters.EncryptionAlgorithm)
@@ -258,7 +264,7 @@ namespace System.Security.Cryptography
cipher.KeySize = 256;
encryptionAlgorithmOid = Oids.Aes256Cbc;
break;
- case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12 when Helpers.HasNonAesSymmetricEncryption:
+ case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12:
cipher = TripleDES.Create();
cipher.KeySize = 192;
encryptionAlgorithmOid = Oids.Pkcs12PbeWithShaAnd3Key3Des;
@@ -566,6 +572,12 @@ namespace System.Security.Cryptography
{
string? algId = encryptionScheme.Algorithm;
+ if (!Helpers.HasSymmetricEncryption)
+ {
+ throw new CryptographicException(
+ SR.Format(SR.Cryptography_AlgorithmNotSupported, algId));
+ }
+
if (algId == Oids.Aes128Cbc ||
algId == Oids.Aes192Cbc ||
algId == Oids.Aes256Cbc)
@@ -604,12 +616,6 @@ namespace System.Security.Cryptography
return aes;
}
- if (!Helpers.HasNonAesSymmetricEncryption)
- {
- throw new CryptographicException(
- SR.Format(SR.Cryptography_AlgorithmNotSupported, algId));
- }
-
if (algId == Oids.TripleDesCbc)
{
// https://tools.ietf.org/html/rfc8018#appendix-B.2.2
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs
index ec1a58e1ada..c489db51973 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherOneShotTests.cs
@@ -9,6 +9,7 @@ using Xunit;
namespace System.Security.Cryptography.Encryption.Aes.Tests
{
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public class AesCipherOneShotTests : SymmetricOneShotBase
{
protected override byte[] Key =>
@@ -414,251 +415,519 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
CipherMode.CBC,
};
- if (PlatformDetection.IsNotBrowser)
+ // ECB test cases
+ // plaintext requires no padding
+ yield return new object[]
{
- // ECB test cases
- // plaintext requires no padding
- yield return new object[]
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
- 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
- 0x6D, 0xE5, 0xF6, 0x07, 0xAB, 0x7E, 0xB8, 0x20,
- 0x2F, 0x39, 0x57, 0x70, 0x3B, 0x04, 0xE8, 0xB5,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
+ 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
+ 0x6D, 0xE5, 0xF6, 0x07, 0xAB, 0x7E, 0xB8, 0x20,
+ 0x2F, 0x39, 0x57, 0x70, 0x3B, 0x04, 0xE8, 0xB5,
+ },
- PaddingMode.PKCS7,
- CipherMode.ECB,
- };
+ PaddingMode.PKCS7,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
- 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
+ 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
+ },
- PaddingMode.None,
- CipherMode.ECB,
- };
+ PaddingMode.None,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
- 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
+ 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
+ },
- PaddingMode.Zeros,
- CipherMode.ECB,
- };
+ PaddingMode.Zeros,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
- 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
- 0xC1, 0xCA, 0x44, 0xE8, 0x05, 0xFF, 0xCB, 0x6F,
- 0x4D, 0x7F, 0xE9, 0x17, 0x12, 0xFE, 0xBB, 0xAC,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
+ 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
+ 0xC1, 0xCA, 0x44, 0xE8, 0x05, 0xFF, 0xCB, 0x6F,
+ 0x4D, 0x7F, 0xE9, 0x17, 0x12, 0xFE, 0xBB, 0xAC,
+ },
- PaddingMode.ANSIX923,
- CipherMode.ECB,
- };
+ PaddingMode.ANSIX923,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
- 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
- 0xD3, 0xAA, 0x33, 0x5B, 0x93, 0xC2, 0x3D, 0x96,
- 0xFD, 0x89, 0xB1, 0x8C, 0x47, 0x75, 0x65, 0xA8,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D,
+ 0x06, 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9,
+ 0xD3, 0xAA, 0x33, 0x5B, 0x93, 0xC2, 0x3D, 0x96,
+ 0xFD, 0x89, 0xB1, 0x8C, 0x47, 0x75, 0x65, 0xA8,
+ },
- PaddingMode.ISO10126,
- CipherMode.ECB,
- };
+ PaddingMode.ISO10126,
+ CipherMode.ECB,
+ };
- // plaintext requires padding
- yield return new object[]
+ // plaintext requires padding
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
- 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
- 0x82, 0x8D, 0x60, 0xDC, 0x44, 0x26, 0xCF, 0xDE,
- 0xC9, 0x54, 0x33, 0x47, 0xE2, 0x9E, 0xF0, 0x8C,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
+ 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
+ 0x82, 0x8D, 0x60, 0xDC, 0x44, 0x26, 0xCF, 0xDE,
+ 0xC9, 0x54, 0x33, 0x47, 0xE2, 0x9E, 0xF0, 0x8C,
+ },
- PaddingMode.PKCS7,
- CipherMode.ECB,
- };
+ PaddingMode.PKCS7,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
- 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
- 0x49, 0x39, 0x1B, 0x69, 0xA1, 0xF3, 0x66, 0xE4,
- 0x3E, 0x40, 0x51, 0xB8, 0x05, 0x60, 0xDC, 0xFD,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
+ 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
+ 0x49, 0x39, 0x1B, 0x69, 0xA1, 0xF3, 0x66, 0xE4,
+ 0x3E, 0x40, 0x51, 0xB8, 0x05, 0x60, 0xDC, 0xFD,
+ },
- PaddingMode.Zeros,
- CipherMode.ECB,
- };
+ PaddingMode.Zeros,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
- 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
- 0xCD, 0x0D, 0xCD, 0xEA, 0xA2, 0x1F, 0xC1, 0xC3,
- 0x81, 0xEE, 0x8A, 0x63, 0x94, 0x5F, 0x85, 0x43,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
+ 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
+ 0xCD, 0x0D, 0xCD, 0xEA, 0xA2, 0x1F, 0xC1, 0xC3,
+ 0x81, 0xEE, 0x8A, 0x63, 0x94, 0x5F, 0x85, 0x43,
+ },
- PaddingMode.ANSIX923,
- CipherMode.ECB,
- };
+ PaddingMode.ANSIX923,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
{
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
- // ciphertext
- new byte[]
- {
- 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
- 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
- 0x9C, 0xE4, 0x0D, 0x2F, 0xCD, 0x82, 0x25, 0x0E,
- 0x13, 0xAB, 0x4B, 0x6B, 0xC0, 0x9A, 0x21, 0x2E,
- },
+ // ciphertext
+ new byte[]
+ {
+ 0xC3, 0x03, 0x87, 0xCD, 0x79, 0x19, 0xB1, 0xC3,
+ 0x50, 0x2C, 0x9D, 0x7B, 0x1F, 0x8A, 0xBE, 0x0F,
+ 0x9C, 0xE4, 0x0D, 0x2F, 0xCD, 0x82, 0x25, 0x0E,
+ 0x13, 0xAB, 0x4B, 0x6B, 0xC0, 0x9A, 0x21, 0x2E,
+ },
- PaddingMode.ISO10126,
- CipherMode.ECB,
- };
+ PaddingMode.ISO10126,
+ CipherMode.ECB,
+ };
- yield return new object[]
+ yield return new object[]
+ {
+ // plaintext
+ Array.Empty<byte>(),
+
+ // ciphertext
+ Array.Empty<byte>(),
+
+ PaddingMode.Zeros,
+ CipherMode.ECB,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ Array.Empty<byte>(),
+
+ // ciphertext
+ Array.Empty<byte>(),
+
+ PaddingMode.None,
+ CipherMode.ECB,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ Array.Empty<byte>(),
+
+ // ciphertext
+ new byte[]
{
- // plaintext
- Array.Empty<byte>(),
+ 0x6D, 0xE5, 0xF6, 0x07, 0xAB, 0x7E, 0xB8, 0x20,
+ 0x2F, 0x39, 0x57, 0x70, 0x3B, 0x04, 0xE8, 0xB5,
+ },
- // ciphertext
- Array.Empty<byte>(),
+ PaddingMode.PKCS7,
+ CipherMode.ECB,
+ };
- PaddingMode.Zeros,
- CipherMode.ECB,
- };
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
- yield return new object[]
+ // ciphertext
+ new byte[]
{
- // plaintext
- Array.Empty<byte>(),
+ 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
+ 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
+ 0xD2,
+ },
- // ciphertext
- Array.Empty<byte>(),
+ PaddingMode.PKCS7,
+ CipherMode.CFB,
+ 8,
+ };
- PaddingMode.None,
- CipherMode.ECB,
- };
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
- yield return new object[]
+ // ciphertext
+ new byte[]
{
- // plaintext
- Array.Empty<byte>(),
+ 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
+ 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
+ },
- // ciphertext
- new byte[]
- {
- 0x6D, 0xE5, 0xF6, 0x07, 0xAB, 0x7E, 0xB8, 0x20,
- 0x2F, 0x39, 0x57, 0x70, 0x3B, 0x04, 0xE8, 0xB5,
- },
+ PaddingMode.None,
+ CipherMode.CFB,
+ 8,
+ };
- PaddingMode.PKCS7,
- CipherMode.ECB,
- };
+ yield return new object[]
+ {
+
+ // plaintext
+ new byte[]
+ {
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
+ 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
+ },
+
+ PaddingMode.Zeros,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
+ 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
+ 0xD2,
+ },
+
+ PaddingMode.ANSIX923,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
+ 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
+ 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
+ 0xD2,
+ },
+
+ PaddingMode.ISO10126,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
+ 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
+ 0xF9, 0x97,
+ },
+
+ PaddingMode.PKCS7,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
+ 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
+ 0xF9,
+ },
+
+ PaddingMode.None,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
+ 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
+ 0xF9,
+ },
+ PaddingMode.Zeros,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
+ 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
+ 0xF9, 0x97,
+ },
+
+ PaddingMode.ANSIX923,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ new byte[]
+ {
+ 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
+ 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
+ 0x59,
+ },
+
+ // ciphertext
+ new byte[]
+ {
+ 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
+ 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
+ 0xF9, 0x97,
+ },
+
+ PaddingMode.ISO10126,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ Array.Empty<byte>(),
+
+ // ciphertext
+ Array.Empty<byte>(),
+
+ PaddingMode.Zeros,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ Array.Empty<byte>(),
+
+ // ciphertext
+ Array.Empty<byte>(),
+
+ PaddingMode.None,
+ CipherMode.CFB,
+ 8,
+ };
+
+ yield return new object[]
+ {
+ // plaintext
+ Array.Empty<byte>(),
+
+ // ciphertext
+ new byte[]
+ {
+ 0x02,
+ },
+
+ PaddingMode.PKCS7,
+ CipherMode.CFB,
+ 8,
+ };
+
+ // CFB128 is not supported on Windows 7.
+ if (PlatformDetection.IsNotWindows7)
+ {
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -669,18 +938,20 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
- 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
- 0xD2,
+ 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
+ 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
+ 0x2B, 0x63, 0xD4, 0x34, 0x86, 0x05, 0x9B, 0x52,
+ 0x20, 0x46, 0x65, 0xD5, 0xBC, 0xA1, 0xED, 0x11,
},
PaddingMode.PKCS7,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -691,13 +962,13 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
- 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
+ 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
+ 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
},
PaddingMode.None,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
@@ -713,17 +984,18 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
- 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
+ 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
+ 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
},
PaddingMode.Zeros,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -734,18 +1006,20 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
- 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
- 0xD2,
+ 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
+ 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
+ 0x3B, 0x73, 0xC4, 0x24, 0x96, 0x15, 0x8B, 0x42,
+ 0x30, 0x56, 0x75, 0xC5, 0xAC, 0xB1, 0xFD, 0x11,
},
PaddingMode.ANSIX923,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -756,18 +1030,20 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x53, 0x8B, 0x08, 0x3E, 0x07, 0xA4, 0x03, 0x16,
- 0x0A, 0x75, 0x1A, 0x15, 0xF6, 0x1D, 0xAB, 0xD9,
- 0xD2,
+ 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
+ 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
+ 0x3E, 0x5D, 0xED, 0x96, 0x51, 0x93, 0xF0, 0x12,
+ 0x95, 0x98, 0x51, 0x29, 0xB6, 0xF8, 0x84, 0x11,
},
PaddingMode.ISO10126,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -779,18 +1055,20 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
- 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
- 0xF9, 0x97,
+ 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
+ 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
+ 0x0C, 0xD0, 0xD4, 0xF1, 0x60, 0x93, 0xD0, 0x20,
+ 0x91, 0x11, 0xD8, 0xF6, 0x27, 0xE3, 0xAF, 0x0F,
},
PaddingMode.PKCS7,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -802,18 +1080,20 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
- 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
- 0xF9,
+ 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
+ 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
+ 0x0C, 0xDF, 0xDB, 0xFE, 0x6F, 0x9C, 0xDF, 0x2F,
+ 0x9E, 0x1E, 0xD7, 0xF9, 0x28, 0xEC, 0xA0, 0x00,
},
- PaddingMode.None,
+ PaddingMode.Zeros,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -825,18 +1105,20 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
- 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
- 0xF9,
+ 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
+ 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
+ 0x0C, 0xDF, 0xDB, 0xFE, 0x6F, 0x9C, 0xDF, 0x2F,
+ 0x9E, 0x1E, 0xD7, 0xF9, 0x28, 0xEC, 0xA0, 0x0F,
},
- PaddingMode.Zeros,
+ PaddingMode.ANSIX923,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
new byte[]
{
@@ -848,41 +1130,38 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
// ciphertext
new byte[]
{
- 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
- 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
- 0xF9, 0x97,
+ 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
+ 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
+ 0x0C, 0x0C, 0x39, 0x31, 0x1C, 0xAA, 0x41, 0x45,
+ 0x78, 0xD0, 0x9F, 0x0F, 0x44, 0xD9, 0x37, 0x0F,
},
- PaddingMode.ANSIX923,
+ PaddingMode.ISO10126,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
+ Array.Empty<byte>(),
// ciphertext
new byte[]
{
- 0x9A, 0x84, 0x44, 0xEB, 0x82, 0x11, 0xEA, 0x28,
- 0x91, 0x8E, 0xA8, 0x40, 0xE4, 0x12, 0x3F, 0x72,
- 0xF9, 0x97,
+ 0x13, 0x47, 0x4B, 0xA9, 0x1C, 0x31, 0xE1, 0xFE,
+ 0x23, 0x69, 0x61, 0xE6, 0x27, 0x01, 0xBE, 0xAA,
},
- PaddingMode.ISO10126,
+ PaddingMode.PKCS7,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
Array.Empty<byte>(),
@@ -891,11 +1170,12 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
PaddingMode.Zeros,
CipherMode.CFB,
- 8,
+ 128,
};
yield return new object[]
{
+
// plaintext
Array.Empty<byte>(),
@@ -904,290 +1184,8 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
PaddingMode.None,
CipherMode.CFB,
- 8,
+ 128,
};
-
- yield return new object[]
- {
- // plaintext
- Array.Empty<byte>(),
-
- // ciphertext
- new byte[]
- {
- 0x02,
- },
-
- PaddingMode.PKCS7,
- CipherMode.CFB,
- 8,
- };
-
- // CFB128 is not supported on Windows 7.
- if (PlatformDetection.IsNotWindows7)
- {
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
- 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
- 0x2B, 0x63, 0xD4, 0x34, 0x86, 0x05, 0x9B, 0x52,
- 0x20, 0x46, 0x65, 0xD5, 0xBC, 0xA1, 0xED, 0x11,
- },
-
- PaddingMode.PKCS7,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
- 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
- },
-
- PaddingMode.None,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
- 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
- },
-
- PaddingMode.Zeros,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
- 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
- 0x3B, 0x73, 0xC4, 0x24, 0x96, 0x15, 0x8B, 0x42,
- 0x30, 0x56, 0x75, 0xC5, 0xAC, 0xB1, 0xFD, 0x11,
- },
-
- PaddingMode.ANSIX923,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89,
- 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x53, 0x3F, 0x49, 0x1D, 0x53, 0x29, 0x39, 0x67,
- 0x8A, 0x06, 0x28, 0x76, 0x34, 0x9A, 0x2D, 0xE3,
- 0x3E, 0x5D, 0xED, 0x96, 0x51, 0x93, 0xF0, 0x12,
- 0x95, 0x98, 0x51, 0x29, 0xB6, 0xF8, 0x84, 0x11,
- },
-
- PaddingMode.ISO10126,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
- 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
- 0x0C, 0xD0, 0xD4, 0xF1, 0x60, 0x93, 0xD0, 0x20,
- 0x91, 0x11, 0xD8, 0xF6, 0x27, 0xE3, 0xAF, 0x0F,
- },
-
- PaddingMode.PKCS7,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
- 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
- 0x0C, 0xDF, 0xDB, 0xFE, 0x6F, 0x9C, 0xDF, 0x2F,
- 0x9E, 0x1E, 0xD7, 0xF9, 0x28, 0xEC, 0xA0, 0x00,
- },
-
- PaddingMode.Zeros,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
- 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
- 0x0C, 0xDF, 0xDB, 0xFE, 0x6F, 0x9C, 0xDF, 0x2F,
- 0x9E, 0x1E, 0xD7, 0xF9, 0x28, 0xEC, 0xA0, 0x0F,
- },
-
- PaddingMode.ANSIX923,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- new byte[]
- {
- 0x99, 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8,
- 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83,
- 0x59,
- },
-
- // ciphertext
- new byte[]
- {
- 0x9A, 0x07, 0x33, 0xAB, 0xA8, 0x7E, 0xF9, 0x26,
- 0xBA, 0xC0, 0x0E, 0xAF, 0xB7, 0x12, 0x25, 0x39,
- 0x0C, 0x0C, 0x39, 0x31, 0x1C, 0xAA, 0x41, 0x45,
- 0x78, 0xD0, 0x9F, 0x0F, 0x44, 0xD9, 0x37, 0x0F,
- },
-
- PaddingMode.ISO10126,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- Array.Empty<byte>(),
-
- // ciphertext
- new byte[]
- {
- 0x13, 0x47, 0x4B, 0xA9, 0x1C, 0x31, 0xE1, 0xFE,
- 0x23, 0x69, 0x61, 0xE6, 0x27, 0x01, 0xBE, 0xAA,
- },
-
- PaddingMode.PKCS7,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- Array.Empty<byte>(),
-
- // ciphertext
- Array.Empty<byte>(),
-
- PaddingMode.Zeros,
- CipherMode.CFB,
- 128,
- };
-
- yield return new object[]
- {
-
- // plaintext
- Array.Empty<byte>(),
-
- // ciphertext
- Array.Empty<byte>(),
-
- PaddingMode.None,
- CipherMode.CFB,
- 128,
- };
- }
}
}
}
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherTests.cs
index 95a8e740763..a6206fc3e63 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherTests.cs
@@ -11,6 +11,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public partial class AesCipherTests
{
[Fact]
@@ -34,7 +35,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "AES-192 is not supported on Browser")]
public static void RandomKeyRoundtrip_192()
{
using (Aes aes = AesFactory.Create())
@@ -79,7 +79,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void DecryptKnownCFB128_256()
{
byte[] encryptedBytes = new byte[]
@@ -102,7 +101,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void DecryptKnownECB192()
{
byte[] encryptedBytes = new byte[]
@@ -125,7 +123,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void DecryptKnownCFB128_192()
{
byte[] encryptedBytes = new byte[]
@@ -148,7 +145,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void DecryptKnownCFB128_128()
{
byte[] encryptedBytes = new byte[]
@@ -276,7 +272,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void VerifyKnownTransform_ECB128_NoPadding()
{
TestAesTransformDirectKey(
@@ -289,7 +284,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void VerifyKnownTransform_ECB256_NoPadding()
{
TestAesTransformDirectKey(
@@ -302,7 +296,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void VerifyKnownTransform_ECB128_NoPadding_2()
{
TestAesTransformDirectKey(
@@ -315,7 +308,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void VerifyKnownTransform_ECB128_NoPadding_3()
{
TestAesTransformDirectKey(
@@ -328,7 +320,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void VerifyKnownTransform_ECB192_NoPadding()
{
TestAesTransformDirectKey(
@@ -341,7 +332,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void VerifyKnownTransform_ECB192_NoPadding_2()
{
TestAesTransformDirectKey(
@@ -354,7 +344,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_8_NoPadding()
{
TestAesTransformDirectKey(
@@ -368,7 +357,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "PaddingMode.None is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_128_NoPadding()
{
TestAesTransformDirectKey(
@@ -406,7 +394,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_256_NoPadding()
{
TestAesTransformDirectKey(
@@ -420,7 +407,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_256_NoPadding()
{
TestAesTransformDirectKey(
@@ -446,7 +432,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_128_NoPadding_2()
{
TestAesTransformDirectKey(
@@ -472,7 +457,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_128_NoPadding_3()
{
TestAesTransformDirectKey(
@@ -486,7 +470,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "AES-192 is not supported on Browser")]
public static void VerifyKnownTransform_CBC192_NoPadding()
{
TestAesTransformDirectKey(
@@ -499,7 +482,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_192_NoPadding()
{
TestAesTransformDirectKey(
@@ -513,7 +495,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_192_NoPadding()
{
TestAesTransformDirectKey(
@@ -527,7 +508,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "AES-192 is not supported on Browser")]
public static void VerifyKnownTransform_CBC192_NoPadding_2()
{
TestAesTransformDirectKey(
@@ -540,7 +520,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_192_NoPadding_2()
{
TestAesTransformDirectKey(
@@ -554,7 +533,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void WrongKeyFailDecrypt()
{
// The test:
@@ -601,7 +579,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void WrongKeyFailDecrypt_2()
{
// The test:
@@ -652,7 +629,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_128_NoPadding_4()
{
// NIST CAVP AESMMT.ZIP CFB8MMT128.rsp, [ENCRYPT] COUNT=4
@@ -668,7 +644,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_128_NoPadding_4_Fails()
{
Assert.Throws<CryptographicException>(() =>
@@ -684,7 +659,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_128_PKCS7_4()
{
TestAesTransformDirectKey(
@@ -698,7 +672,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_128_PKCS7_4()
{
TestAesTransformDirectKey(
@@ -714,7 +687,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[Theory]
[InlineData(PaddingMode.None)]
[InlineData(PaddingMode.Zeros)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_128_NoOrZeroPadding_0_Extended(PaddingMode paddingMode)
{
// NIST CAVP AESMMT.ZIP CFB8MMT128.rsp, [ENCRYPT] COUNT=0
@@ -733,7 +705,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[Theory]
[InlineData(PaddingMode.None)]
[InlineData(PaddingMode.Zeros)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_128_NoOrZeroPadding_9_Extended(PaddingMode paddingMode)
{
// NIST CAVP AESMMT.ZIP CFB8MMT128.rsp, [ENCRYPT] COUNT=9
@@ -752,7 +723,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[Theory]
[InlineData(PaddingMode.None)]
[InlineData(PaddingMode.Zeros)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_192_NoOrZeroPadding_0_Extended(PaddingMode paddingMode)
{
// NIST CAVP AESMMT.ZIP CFB8MMT192.rsp, [ENCRYPT] COUNT=0
@@ -771,7 +741,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[Theory]
[InlineData(PaddingMode.None)]
[InlineData(PaddingMode.Zeros)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_192_NoOrZeroPadding_9_Extended(PaddingMode paddingMode)
{
// NIST CAVP AESMMT.ZIP CFB8MMT192.rsp, [ENCRYPT] COUNT=9
@@ -790,7 +759,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[Theory]
[InlineData(PaddingMode.None)]
[InlineData(PaddingMode.Zeros)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_256_NoOrZeroPadding_0_Extended(PaddingMode paddingMode)
{
// NIST CAVP AESMMT.ZIP CFB8MMT256.rsp, [ENCRYPT] COUNT=0
@@ -809,7 +777,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[Theory]
[InlineData(PaddingMode.None)]
[InlineData(PaddingMode.Zeros)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB8_256_NoOrZeroPadding_9_Extended(PaddingMode paddingMode)
{
// NIST CAVP AESMMT.ZIP CFB8MMT256.rsp, [ENCRYPT] COUNT=9
@@ -826,7 +793,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_128_NoPadding_0()
{
// NIST CAVP AESMMT.ZIP CFB128MMT128.rsp, [ENCRYPT] COUNT=0
@@ -841,7 +807,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_128_NoPadding_1_Extended()
{
// NIST CAVP AESMMT.ZIP CFB128MMT128.rsp, [ENCRYPT] COUNT=1
@@ -856,7 +821,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_192_NoPadding_0_Extended()
{
// NIST CAVP AESMMT.ZIP CFB128MMT192.rsp, [ENCRYPT] COUNT=0
@@ -871,7 +835,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_192_NoPadding_1_Extended()
{
// NIST CAVP AESMMT.ZIP CFB128MMT192.rsp, [ENCRYPT] COUNT=1
@@ -885,23 +848,11 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
feedbackSize: 128);
}
- public static IEnumerable<object[]> EncryptorReuse_LeadsToSameResultsData
- {
- get
- {
- yield return new object[] { CipherMode.CBC, 0 };
-
- if (PlatformDetection.IsNotBrowser)
- {
- yield return new object[] { CipherMode.CFB, 128 };
- yield return new object[] { CipherMode.CFB, 8 };
- yield return new object[] { CipherMode.ECB, 0 };
- }
- }
- }
-
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [MemberData(nameof(EncryptorReuse_LeadsToSameResultsData))]
+ [InlineData(CipherMode.CBC, 0)]
+ [InlineData(CipherMode.CFB, 128)]
+ [InlineData(CipherMode.CFB, 8)]
+ [InlineData(CipherMode.ECB, 0)]
public static void EncryptorReuse_LeadsToSameResults(CipherMode cipherMode, int feedbackSize)
{
// AppleCCCryptor does not allow calling Reset on CFB cipher.
@@ -928,7 +879,10 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [MemberData(nameof(EncryptorReuse_LeadsToSameResultsData))]
+ [InlineData(CipherMode.CBC, 0)]
+ [InlineData(CipherMode.CFB, 128)]
+ [InlineData(CipherMode.CFB, 8)]
+ [InlineData(CipherMode.ECB, 0)]
public static void DecryptorReuse_LeadsToSameResults(CipherMode cipherMode, int feedbackSize)
{
// AppleCCCryptor does not allow calling Reset on CFB cipher.
@@ -960,7 +914,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_256_NoPadding_0_Extended()
{
// NIST CAVP AESMMT.ZIP CFB128MMT256.rsp, [ENCRYPT] COUNT=0
@@ -975,7 +928,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void VerifyKnownTransform_CFB128_256_NoPadding_1_Extended()
{
// NIST CAVP AESMMT.ZIP CFB128MMT256.rsp, [ENCRYPT] COUNT=1
@@ -995,9 +947,9 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
yield return new object[] { CipherMode.CBC };
- if (PlatformDetection.IsNotBrowser && !PlatformDetection.IsWindows7)
+ if (!PlatformDetection.IsWindows7)
{
- // Browser and Windows 7 do not support CFB128.
+ // Windows 7 does not support CFB128.
yield return new object[] { CipherMode.CFB };
}
}
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesContractTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesContractTests.cs
index 9de09ff1203..1b4f6032248 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesContractTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesContractTests.cs
@@ -8,6 +8,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public class AesContractTests
{
[Fact]
@@ -55,10 +56,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
Assert.Equal(128, keySizeLimits.MinSize);
Assert.Equal(256, keySizeLimits.MaxSize);
-
- // Browser's SubtleCrypto doesn't support AES-192
- int expectedKeySkipSize = PlatformDetection.IsBrowser ? 128 : 64;
- Assert.Equal(expectedKeySkipSize, keySizeLimits.SkipSize);
+ Assert.Equal(64, keySizeLimits.SkipSize);
}
}
@@ -109,7 +107,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[InlineData(64, false)]
[InlineData(256, true)]
[InlineData(127, true)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void InvalidCFBFeedbackSizes(int feedbackSize, bool discoverableInSetter)
{
using (Aes aes = AesFactory.Create())
@@ -142,7 +139,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
[Theory]
[InlineData(8)]
[InlineData(128)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void ValidCFBFeedbackSizes(int feedbackSize)
{
// Windows 7 only supports CFB8.
@@ -217,7 +213,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "AES-192 is not supported on Browser")]
public static void VerifyKeyGeneration_192()
{
using (Aes aes = AesFactory.Create())
@@ -309,28 +304,25 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
Assert.Throws<CryptographicException>(() => aes.CreateDecryptor(key, null));
}
- if (PlatformDetection.IsNotBrowser)
+ using (Aes aes = AesFactory.Create())
{
- using (Aes aes = AesFactory.Create())
- {
- aes.Mode = CipherMode.ECB;
+ aes.Mode = CipherMode.ECB;
- Assert.Throws<ArgumentNullException>(() => aes.CreateEncryptor(null, iv));
- Assert.Throws<ArgumentNullException>(() => aes.CreateEncryptor(null, null));
+ Assert.Throws<ArgumentNullException>(() => aes.CreateEncryptor(null, iv));
+ Assert.Throws<ArgumentNullException>(() => aes.CreateEncryptor(null, null));
- Assert.Throws<ArgumentNullException>(() => aes.CreateDecryptor(null, iv));
- Assert.Throws<ArgumentNullException>(() => aes.CreateDecryptor(null, null));
+ Assert.Throws<ArgumentNullException>(() => aes.CreateDecryptor(null, iv));
+ Assert.Throws<ArgumentNullException>(() => aes.CreateDecryptor(null, null));
- // ECB will accept an IV (but ignore it), and doesn't require it.
- using (ICryptoTransform didNotThrow = aes.CreateEncryptor(key, null))
- {
- Assert.NotNull(didNotThrow);
- }
+ // ECB will accept an IV (but ignore it), and doesn't require it.
+ using (ICryptoTransform didNotThrow = aes.CreateEncryptor(key, null))
+ {
+ Assert.NotNull(didNotThrow);
+ }
- using (ICryptoTransform didNotThrow = aes.CreateDecryptor(key, null))
- {
- Assert.NotNull(didNotThrow);
- }
+ using (ICryptoTransform didNotThrow = aes.CreateDecryptor(key, null))
+ {
+ Assert.NotNull(didNotThrow);
}
}
}
@@ -392,7 +384,6 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void Cfb8ModeCanDepadCfb128Padding()
{
using (Aes aes = AesFactory.Create())
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCornerTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCornerTests.cs
index 94b7a9c7210..ed21b358b09 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCornerTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCornerTests.cs
@@ -12,6 +12,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public static class AesCornerTests
{
[Fact]
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesModeTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesModeTests.cs
index 154ca989715..1a496a505c6 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesModeTests.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesModeTests.cs
@@ -7,6 +7,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public class AesModeTests
{
[Fact]
@@ -16,28 +17,24 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void SupportsECB()
{
SupportsMode(CipherMode.ECB);
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void SupportsCFB8()
{
SupportsMode(CipherMode.CFB, feedbackSize: 8);
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void SupportsCFB128()
{
SupportsMode(CipherMode.CFB, feedbackSize: 128);
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void Windows7DoesNotSupportCFB128()
{
DoesNotSupportMode(CipherMode.CFB, feedbackSize: 128);
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/DecryptorReusability.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/DecryptorReusability.cs
index 5665547eab4..f0761570a47 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/DecryptorReusability.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/AES/DecryptorReusability.cs
@@ -7,6 +7,7 @@ namespace System.Security.Cryptography.Encryption.Aes.Tests
{
using Aes = System.Security.Cryptography.Aes;
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public static class DecryptorReusability
{
// See https://github.com/dotnet/runtime/issues/21354 for details
diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/Symmetric/SymmetricOneShotBase.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/Symmetric/SymmetricOneShotBase.cs
index 080f1888473..7b56a7017c4 100644
--- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/Symmetric/SymmetricOneShotBase.cs
+++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/Symmetric/SymmetricOneShotBase.cs
@@ -410,7 +410,6 @@ namespace System.Security.Cryptography.Tests
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindows7))]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public void DecryptOneShot_Cfb8_ToleratesExtraPadding()
{
using (SymmetricAlgorithm alg = CreateAlgorithm())
@@ -470,7 +469,6 @@ namespace System.Security.Cryptography.Tests
[InlineData(PaddingMode.PKCS7, 2048)]
[InlineData(PaddingMode.ANSIX923, 2048)]
[InlineData(PaddingMode.ISO10126, 2048)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public void DecryptOneShot_Ecb_InvalidPadding_DoesNotContainPlaintext(PaddingMode paddingMode, int ciphertextSize)
{
using (SymmetricAlgorithm alg = CreateAlgorithm())
@@ -497,7 +495,6 @@ namespace System.Security.Cryptography.Tests
[InlineData(PaddingMode.PKCS7, 2048)]
[InlineData(PaddingMode.ANSIX923, 2048)]
[InlineData(PaddingMode.ISO10126, 2048)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public void DecryptOneShot_Cfb_InvalidPadding_DoesNotContainPlaintext(PaddingMode paddingMode, int ciphertextSize)
{
using (SymmetricAlgorithm alg = CreateAlgorithm())
@@ -550,7 +547,6 @@ namespace System.Security.Cryptography.Tests
[InlineData(PaddingMode.PKCS7)]
[InlineData(PaddingMode.ANSIX923)]
[InlineData(PaddingMode.ISO10126)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public void DecryptOneShot_Cfb8_TooShortDoesNotContainPlaintext(PaddingMode paddingMode)
{
using (SymmetricAlgorithm alg = CreateAlgorithm())
diff --git a/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs b/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs
index 8fa22de3099..5be736fec66 100644
--- a/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs
+++ b/src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs
@@ -47,6 +47,7 @@ namespace System.Security.Cryptography
public abstract partial class Aes : System.Security.Cryptography.SymmetricAlgorithm
{
protected Aes() { }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static new System.Security.Cryptography.Aes Create() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
[System.ObsoleteAttribute("Cryptographic factory methods accepting an algorithm name are obsolete. Use the parameterless Create factory method on the algorithm type instead.", DiagnosticId="SYSLIB0045", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
@@ -98,6 +99,7 @@ namespace System.Security.Cryptography
[System.ObsoleteAttribute("Derived cryptographic types are obsolete. Use the Create method on the base type instead.", DiagnosticId="SYSLIB0021", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed partial class AesCryptoServiceProvider : System.Security.Cryptography.Aes
{
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public AesCryptoServiceProvider() { }
public override int BlockSize { get { throw null; } set { } }
public override int FeedbackSize { get { throw null; } set { } }
@@ -134,6 +136,7 @@ namespace System.Security.Cryptography
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("Derived cryptographic types are obsolete. Use the Create method on the base type instead.", DiagnosticId="SYSLIB0021", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public sealed partial class AesManaged : System.Security.Cryptography.Aes
{
public AesManaged() { }
@@ -1781,6 +1784,7 @@ namespace System.Security.Cryptography
public abstract partial class Rijndael : System.Security.Cryptography.SymmetricAlgorithm
{
protected Rijndael() { }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static new System.Security.Cryptography.Rijndael Create() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
[System.ObsoleteAttribute("Cryptographic factory methods accepting an algorithm name are obsolete. Use the parameterless Create factory method on the algorithm type instead.", DiagnosticId="SYSLIB0045", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
@@ -1788,6 +1792,7 @@ namespace System.Security.Cryptography
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("The Rijndael and RijndaelManaged types are obsolete. Use Aes instead.", DiagnosticId="SYSLIB0022", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public sealed partial class RijndaelManaged : System.Security.Cryptography.Rijndael
{
public RijndaelManaged() { }
diff --git a/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx b/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx
index 3cc428cfbee..4dc40bba0b1 100644
--- a/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx
+++ b/src/libraries/System.Security.Cryptography/src/Resources/Strings.resx
@@ -822,10 +822,4 @@
<data name="Unknown_Error" xml:space="preserve">
<value>Unknown error.</value>
</data>
- <data name="Unknown_SubtleCrypto_Error" xml:space="preserve">
- <value>SubtleCrypto returned an unknown error: '{0}'.</value>
- </data>
- <data name="PlatformNotSupported_CipherModeBrowser" xml:space="preserve">
- <value>Only CipherMode.CBC is supported on this platform.</value>
- </data>
</root>
diff --git a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
index 986ea2c977f..cf25738f6e7 100644
--- a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
+++ b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
@@ -556,13 +556,9 @@
Link="Common\Interop\Browser\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)System\Sha1ForNonSecretPurposes.cs"
Link="Common\System\Sha1ForNonSecretPurposes.cs" />
- <Compile Include="$(CommonPath)Interop\Browser\System.Security.Cryptography.Native.Browser\Interop.SubtleCrypto.cs"
- Link="Common\Interop\Browser\System.Security.Cryptography.Native.Browser\Interop.SubtleCrypto.cs" />
<Compile Include="System\Security\Cryptography\AesCcm.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\AesGcm.NotSupported.cs" />
- <Compile Include="System\Security\Cryptography\AesImplementation.Browser.cs" />
- <Compile Include="System\Security\Cryptography\AesManagedTransform.Browser.cs" />
- <Compile Include="System\Security\Cryptography\AesSubtleCryptoTransform.Browser.cs" />
+ <Compile Include="System\Security\Cryptography\AesImplementation.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\AsnFormatter.Managed.cs" />
<Compile Include="System\Security\Cryptography\CapiHelper.Browser.cs" />
<Compile Include="System\Security\Cryptography\ChaCha20Poly1305.NotSupported.cs" />
@@ -576,7 +572,6 @@
<Compile Include="System\Security\Cryptography\ECDsa.Create.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\HashProviderDispenser.Browser.cs" />
<Compile Include="System\Security\Cryptography\HMACHashProvider.Browser.Managed.cs" />
- <Compile Include="System\Security\Cryptography\HMACHashProvider.Browser.Native.cs" />
<Compile Include="System\Security\Cryptography\LiteHash.Browser.cs" />
<Compile Include="System\Security\Cryptography\OidLookup.NoFallback.cs" />
<Compile Include="System\Security\Cryptography\OpenSsl.NotSupported.cs" />
@@ -588,7 +583,6 @@
<Compile Include="System\Security\Cryptography\RSACryptoServiceProvider.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\RSA.Create.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\SHAHashProvider.Browser.Managed.cs" />
- <Compile Include="System\Security\Cryptography\SHAHashProvider.Browser.Native.cs" />
<Compile Include="System\Security\Cryptography\TripleDESCryptoServiceProvider.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\TripleDesImplementation.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\CertificatePal.NotSupported.cs" />
@@ -597,9 +591,6 @@
<Compile Include="System\Security\Cryptography\X509Certificates\StorePal.NotSupported.cs" />
<Compile Include="System\Security\Cryptography\X509Certificates\X509Pal.NotSupported.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'Browser'">
- <Compile Include="System\Security\Cryptography\AesImplementation.NonBrowser.cs" />
- </ItemGroup>
<ItemGroup Condition="'$(NeedOpenSslInitializer)' == 'true'">
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Link="Common\Interop\Unix\Interop.Libraries.cs" />
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs
index 767f97820fe..e00abeeac2d 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.Versioning;
using Internal.Cryptography;
namespace System.Security.Cryptography
@@ -11,7 +12,7 @@ namespace System.Security.Cryptography
protected Aes()
{
LegalBlockSizesValue = s_legalBlockSizes.CloneKeySizesArray();
- LegalKeySizesValue = AesImplementation.s_legalKeySizes.CloneKeySizesArray();
+ LegalKeySizesValue = s_legalKeySizes.CloneKeySizesArray();
BlockSizeValue = 128;
FeedbackSizeValue = 8;
@@ -19,6 +20,7 @@ namespace System.Security.Cryptography
ModeValue = CipherMode.CBC;
}
+ [UnsupportedOSPlatform("browser")]
public static new Aes Create()
{
return new AesImplementation();
@@ -32,5 +34,6 @@ namespace System.Security.Cryptography
}
private static readonly KeySizes[] s_legalBlockSizes = { new KeySizes(128, 128, 0) };
+ private static readonly KeySizes[] s_legalKeySizes = { new KeySizes(128, 256, 64) };
}
}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesCryptoServiceProvider.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesCryptoServiceProvider.cs
index c879a4f5460..2e081e8a064 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesCryptoServiceProvider.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesCryptoServiceProvider.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
+using System.Runtime.Versioning;
namespace System.Security.Cryptography
{
@@ -11,6 +12,7 @@ namespace System.Security.Cryptography
{
private readonly Aes _impl;
+ [UnsupportedOSPlatform("browser")]
public AesCryptoServiceProvider()
{
// This class wraps Aes
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.Browser.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.Browser.cs
deleted file mode 100644
index 3523b919f71..00000000000
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.Browser.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics;
-
-namespace System.Security.Cryptography
-{
- internal sealed partial class AesImplementation
- {
- internal const int BlockSizeBytes = 16; // 128 bits
-
- // SubtleCrypto doesn't support AES-192. http://crbug.com/533699
- internal static readonly KeySizes[] s_legalKeySizes = { new KeySizes(128, 256, 128) };
-
- private static UniversalCryptoTransform CreateTransformCore(
- CipherMode cipherMode,
- PaddingMode paddingMode,
- byte[] key,
- byte[]? iv,
- int blockSize,
- int paddingSize,
- int feedbackSize,
- bool encrypting)
- {
- ValidateCipherMode(cipherMode);
- if (iv is null)
- throw new CryptographicException(SR.Cryptography_MissingIV);
-
- Debug.Assert(blockSize == BlockSizeBytes);
- Debug.Assert(paddingSize == blockSize);
-
- BasicSymmetricCipher cipher = Interop.BrowserCrypto.CanUseSubtleCrypto ?
- new AesSubtleCryptoTransform(key, iv, encrypting) :
- new AesManagedTransform(key, iv, encrypting);
-
- return UniversalCryptoTransform.Create(paddingMode, cipher, encrypting);
- }
-
- private static ILiteSymmetricCipher CreateLiteCipher(
- CipherMode cipherMode,
- ReadOnlySpan<byte> key,
- ReadOnlySpan<byte> iv,
- int blockSize,
- int paddingSize,
- int feedbackSize,
- bool encrypting)
- {
- ValidateCipherMode(cipherMode);
-
- Debug.Assert(blockSize == BlockSizeBytes);
- Debug.Assert(paddingSize == blockSize);
-
- return Interop.BrowserCrypto.CanUseSubtleCrypto ?
- new AesSubtleCryptoTransform(key, iv, encrypting) :
- new AesManagedTransform(key, iv, encrypting);
- }
-
- private static void ValidateCipherMode(CipherMode cipherMode)
- {
- if (cipherMode != CipherMode.CBC)
- throw new PlatformNotSupportedException(SR.PlatformNotSupported_CipherModeBrowser);
- }
- }
-}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NonBrowser.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NonBrowser.cs
deleted file mode 100644
index 78b74ac82ab..00000000000
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NonBrowser.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Security.Cryptography
-{
- internal sealed partial class AesImplementation
- {
- internal static readonly KeySizes[] s_legalKeySizes = { new KeySizes(128, 256, 64) };
- }
-}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NotSupported.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NotSupported.cs
new file mode 100644
index 00000000000..86483ca1998
--- /dev/null
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.NotSupported.cs
@@ -0,0 +1,35 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using Internal.Cryptography;
+
+namespace System.Security.Cryptography
+{
+ internal sealed partial class AesImplementation : Aes
+ {
+ private static UniversalCryptoTransform CreateTransformCore(
+ CipherMode cipherMode,
+ PaddingMode paddingMode,
+ byte[] key,
+ byte[]? iv,
+ int blockSize,
+ int paddingSize,
+ int feedback,
+ bool encrypting)
+ {
+ throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_AlgorithmNotSupported, nameof(Aes)));
+ }
+
+ private static ILiteSymmetricCipher CreateLiteCipher(
+ CipherMode cipherMode,
+ ReadOnlySpan<byte> key,
+ ReadOnlySpan<byte> iv,
+ int blockSize,
+ int paddingSize,
+ int feedback,
+ bool encrypting)
+ {
+ throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_AlgorithmNotSupported, nameof(Aes)));
+ }
+ }
+}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManaged.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManaged.cs
index 3791b5a8720..dc623710517 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManaged.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManaged.cs
@@ -2,11 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
+using System.Runtime.Versioning;
namespace System.Security.Cryptography
{
[Obsolete(Obsoletions.DerivedCryptographicTypesMessage, DiagnosticId = Obsoletions.DerivedCryptographicTypesDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
+ [UnsupportedOSPlatform("browser")]
public sealed class AesManaged : Aes
{
private readonly Aes _impl;
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManagedTransform.Browser.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManagedTransform.Browser.cs
deleted file mode 100644
index 0ae66acc18e..00000000000
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesManagedTransform.Browser.cs
+++ /dev/null
@@ -1,1015 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Runtime.InteropServices;
-
-namespace System.Security.Cryptography
-{
- internal sealed class AesManagedTransform : BasicSymmetricCipher, ILiteSymmetricCipher
- {
- private const int BlockSizeBytes = AesImplementation.BlockSizeBytes;
- private const int BlockSizeInts = BlockSizeBytes / 4;
-
- private readonly bool _encrypting;
-
- private int[] _encryptKeyExpansion;
- private int[] _decryptKeyExpansion;
-
- private readonly int _Nr;
- private readonly int _Nk;
-
- private int[] _IV;
- private int[] _lastBlockBuffer;
-
- public AesManagedTransform(ReadOnlySpan<byte> key,
- ReadOnlySpan<byte> iv,
- bool encrypting)
- // AesManagedTransform doesn't use the base IV property, so just pass 'null'.
- : base(iv: null, BlockSizeBytes, BlockSizeBytes)
- {
- Debug.Assert(BitConverter.IsLittleEndian, "The logic of casting Span<int> to Span<byte> below assumes little endian");
- Debug.Assert(iv.Length == BlockSizeBytes);
-
- _encrypting = encrypting;
- _Nr = GetNumberOfRounds(key);
- _Nk = key.Length / 4;
-
- _IV = new int[BlockSizeInts];
- iv.CopyTo(MemoryMarshal.AsBytes(_IV.AsSpan()));
-
- GenerateKeyExpansion(key);
-
- _lastBlockBuffer = _IV.AsSpan().ToArray();
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- // We need to always zeroize the following fields because they contain sensitive data.
- // Note: Can't use CryptographicOperations.ZeroMemory since these are int[] and not byte[].
- if (_IV != null)
- {
- Array.Clear(_IV);
- _IV = null!;
- }
- if (_lastBlockBuffer != null)
- {
- Array.Clear(_lastBlockBuffer);
- _lastBlockBuffer = null!;
- }
- if (_encryptKeyExpansion != null)
- {
- Array.Clear(_encryptKeyExpansion);
- _encryptKeyExpansion = null!;
- }
- if (_decryptKeyExpansion != null)
- {
- Array.Clear(_decryptKeyExpansion);
- _decryptKeyExpansion = null!;
- }
- }
-
- base.Dispose(disposing);
- }
-
- public override int Transform(ReadOnlySpan<byte> input, Span<byte> output)
- {
- Debug.Assert(input.Length % BlockSizeBytes == 0);
- Debug.Assert(output.Length >= input.Length);
-
- // the below algorithm doesn't allow overlap, so rent a buffer to transform into
- if (input.Overlaps(output, out int offset) && offset != 0)
- {
- byte[] rented = CryptoPool.Rent(input.Length);
- int bytesWritten = 0;
-
- try
- {
- bytesWritten = _encrypting ?
- EncryptData(input, rented) :
- DecryptData(input, rented);
- rented.AsSpan(0, bytesWritten).CopyTo(output);
- return bytesWritten;
- }
- finally
- {
- CryptoPool.Return(rented, clearSize: bytesWritten);
- }
- }
- else
- {
- // with no overlap, we can just write directly to the output
- return _encrypting ?
- EncryptData(input, output) :
- DecryptData(input, output);
- }
- }
-
- public override int TransformFinal(ReadOnlySpan<byte> input, Span<byte> output)
- {
- int bytesWritten = Transform(input, output);
- Reset();
- return bytesWritten;
- }
-
- //
- // resets the state of the transform
- //
-
- void ILiteSymmetricCipher.Reset(ReadOnlySpan<byte> iv) => throw new NotImplementedException(); // never invoked
-
- private void Reset()
- {
- _IV.AsSpan().CopyTo(_lastBlockBuffer);
- }
-
- //
- // Encrypts input into output using the AES encryption routine.
- // This method writes the encrypted data into the output buffer.
- //
- private int EncryptData(ReadOnlySpan<byte> input, Span<byte> output)
- {
- int inputCount = input.Length;
-
- Span<int> work = stackalloc int[BlockSizeInts];
- Span<int> temp = stackalloc int[BlockSizeInts];
-
- int workBaseIndex = 0;
- int iNumBlocks = inputCount / BlockSizeBytes;
- int transformCount = 0;
- for (int blockNum = 0; blockNum < iNumBlocks; ++blockNum)
- {
- input.Slice(workBaseIndex, BlockSizeBytes).CopyTo(MemoryMarshal.AsBytes(work));
-
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- // XOR with the last encrypted block
- work[i] ^= _lastBlockBuffer[i];
- }
-
- Enc(work, temp);
-
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- output[transformCount++] = (byte)(temp[i] & 0xFF);
- output[transformCount++] = (byte)(temp[i] >> 8 & 0xFF);
- output[transformCount++] = (byte)(temp[i] >> 16 & 0xFF);
- output[transformCount++] = (byte)(temp[i] >> 24 & 0xFF);
- }
-
- Debug.Assert(_lastBlockBuffer.Length == BlockSizeInts);
- temp.CopyTo(_lastBlockBuffer);
-
- workBaseIndex += BlockSizeBytes;
- }
-
- return inputCount;
- }
-
- //
- // Decrypts intput into output using the AES encryption routine.
- // This method writes the decrypted data into the output buffer.
- //
- private int DecryptData(ReadOnlySpan<byte> input, Span<byte> output)
- {
- int inputCount = input.Length;
-
- Span<int> work = stackalloc int[BlockSizeInts];
- Span<int> temp = stackalloc int[BlockSizeInts];
-
- int iNumBlocks = inputCount / BlockSizeBytes;
- int workBaseIndex = 0, index = 0, transformCount = 0;
- for (int blockNum = 0; blockNum < iNumBlocks; ++blockNum)
- {
- index = workBaseIndex;
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- int i0 = input[index++];
- int i1 = input[index++];
- int i2 = input[index++];
- int i3 = input[index++];
- work[i] = i3 << 24 | i2 << 16 | i1 << 8 | i0;
- }
-
- Dec(work, temp);
-
- index = workBaseIndex;
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- temp[i] ^= _lastBlockBuffer[i];
- // save the input buffer
- int i0 = input[index++];
- int i1 = input[index++];
- int i2 = input[index++];
- int i3 = input[index++];
- _lastBlockBuffer[i] = i3 << 24 | i2 << 16 | i1 << 8 | i0;
- }
-
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- output[transformCount++] = (byte)(temp[i] & 0xFF);
- output[transformCount++] = (byte)(temp[i] >> 8 & 0xFF);
- output[transformCount++] = (byte)(temp[i] >> 16 & 0xFF);
- output[transformCount++] = (byte)(temp[i] >> 24 & 0xFF);
- }
-
- workBaseIndex += BlockSizeBytes;
- }
-
- return inputCount;
- }
-
- //
- // AES encryption function.
- //
- private void Enc(Span<int> work, Span<int> temp)
- {
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- work[i] ^= _encryptKeyExpansion[i];
- }
-
- ReadOnlySpan<int> T = s_T;
- ReadOnlySpan<int> encryptindex = s_encryptindex;
- int encryptindexIndex;
- int encryptKeyExpansionIndex = BlockSizeInts;
- for (int r = 1; r < _Nr; ++r)
- {
- encryptindexIndex = 0;
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- temp[i] = T[0 + (work[i] & 0xFF)] ^
- T[256 + ((work[encryptindex[encryptindexIndex]] >> 8) & 0xFF)] ^
- T[512 + ((work[encryptindex[encryptindexIndex + BlockSizeInts]] >> 16) & 0xFF)] ^
- T[768 + ((work[encryptindex[encryptindexIndex + (BlockSizeInts * 2)]] >> 24) & 0xFF)] ^
- _encryptKeyExpansion[encryptKeyExpansionIndex];
- encryptindexIndex++;
- encryptKeyExpansionIndex++;
- }
-
- temp.CopyTo(work);
- }
-
- ReadOnlySpan<int> TF = s_TF;
- encryptindexIndex = 0;
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- temp[i] = TF[0 + (work[i] & 0xFF)] ^
- TF[256 + ((work[encryptindex[encryptindexIndex]] >> 8) & 0xFF)] ^
- TF[512 + ((work[encryptindex[encryptindexIndex + BlockSizeInts]] >> 16) & 0xFF)] ^
- TF[768 + ((work[encryptindex[encryptindexIndex + (BlockSizeInts * 2)]] >> 24) & 0xFF)] ^
- _encryptKeyExpansion[encryptKeyExpansionIndex];
- encryptindexIndex++;
- encryptKeyExpansionIndex++;
- }
- }
-
- //
- // AES decryption function.
- //
-
- private void Dec(Span<int> work, Span<int> temp)
- {
- int keyIndex = BlockSizeInts * _Nr;
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- work[i] ^= _decryptKeyExpansion[keyIndex];
- keyIndex++;
- }
-
- ReadOnlySpan<int> iT = s_iT;
- ReadOnlySpan<int> decryptindex = s_decryptindex;
- int decryptindexIndex;
- int decryptKeyExpansionIndex;
- for (int r = 1; r < _Nr; ++r)
- {
- keyIndex -= 2 * BlockSizeInts;
- decryptindexIndex = 0;
- decryptKeyExpansionIndex = keyIndex;
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- temp[i] = iT[0 + ((work[i]) & 0xFF)] ^
- iT[256 + ((work[decryptindex[decryptindexIndex]] >> 8) & 0xFF)] ^
- iT[512 + ((work[decryptindex[decryptindexIndex + BlockSizeInts]] >> 16) & 0xFF)] ^
- iT[768 + ((work[decryptindex[decryptindexIndex + (BlockSizeInts * 2)]] >> 24) & 0xFF)] ^
- _decryptKeyExpansion[decryptKeyExpansionIndex];
- keyIndex++;
- decryptindexIndex++;
- decryptKeyExpansionIndex++;
- }
-
- temp.CopyTo(work);
- }
-
- ReadOnlySpan<int> iTF = s_iTF;
- keyIndex = 0;
- decryptindexIndex = 0;
- decryptKeyExpansionIndex = keyIndex;
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- temp[i] = iTF[0 + ((work[i]) & 0xFF)] ^
- iTF[256 + ((work[decryptindex[decryptindexIndex]] >> 8) & 0xFF)] ^
- iTF[512 + ((work[decryptindex[decryptindexIndex + BlockSizeInts]] >> 16) & 0xFF)] ^
- iTF[768 + ((work[decryptindex[decryptindexIndex + (BlockSizeInts * 2)]] >> 24) & 0xFF)] ^
- _decryptKeyExpansion[decryptKeyExpansionIndex];
- decryptindexIndex++;
- decryptKeyExpansionIndex++;
- }
- }
-
- private static int GetNumberOfRounds(ReadOnlySpan<byte> key)
- {
- return (BlockSizeBytes > key.Length ? BlockSizeBytes : key.Length) switch
- {
- 16 => 10, // 128 bits
- // 24 => 12, // 192 bits is not supported by SubtleCrypto, so the managed implementation doesn't support it either
- 32 => 14, // 256 bits
- _ => throw new CryptographicException(SR.Cryptography_InvalidKeySize)
- };
- }
-
- //
- // Key expansion routine.
- //
-
- [MemberNotNull(nameof(_encryptKeyExpansion))]
- [MemberNotNull(nameof(_decryptKeyExpansion))]
- private void GenerateKeyExpansion(ReadOnlySpan<byte> key)
- {
- _encryptKeyExpansion = new int[BlockSizeInts * (_Nr + 1)];
- _decryptKeyExpansion = new int[BlockSizeInts * (_Nr + 1)];
- int iTemp;
-
- int index = 0;
- for (int i = 0; i < _Nk; ++i)
- {
- int i0 = key[index++];
- int i1 = key[index++];
- int i2 = key[index++];
- int i3 = key[index++];
- _encryptKeyExpansion[i] = i3 << 24 | i2 << 16 | i1 << 8 | i0;
- }
-
- if (_Nk <= 6)
- {
- for (int i = _Nk; i < BlockSizeInts * (_Nr + 1); ++i)
- {
- iTemp = _encryptKeyExpansion[i - 1];
-
- if (i % _Nk == 0)
- {
- iTemp = SubWord(rot3(iTemp));
- iTemp ^= s_Rcon[(i / _Nk) - 1];
- }
-
- _encryptKeyExpansion[i] = _encryptKeyExpansion[i - _Nk] ^ iTemp;
- }
- }
- else
- {
- for (int i = _Nk; i < BlockSizeInts * (_Nr + 1); ++i)
- {
- iTemp = _encryptKeyExpansion[i - 1];
-
- if (i % _Nk == 0)
- {
- iTemp = SubWord(rot3(iTemp));
- iTemp ^= s_Rcon[(i / _Nk) - 1];
- }
- else if (i % _Nk == 4)
- {
- iTemp = SubWord(iTemp);
- }
-
- _encryptKeyExpansion[i] = _encryptKeyExpansion[i - _Nk] ^ iTemp;
- }
- }
-
- for (int i = 0; i < BlockSizeInts; ++i)
- {
- _decryptKeyExpansion[i] = _encryptKeyExpansion[i];
- _decryptKeyExpansion[BlockSizeInts * _Nr + i] = _encryptKeyExpansion[BlockSizeInts * _Nr + i];
- }
-
- for (int i = BlockSizeInts; i < BlockSizeInts * _Nr; ++i)
- {
- int keyVal = _encryptKeyExpansion[i];
- int mul02 = MulX(keyVal);
- int mul04 = MulX(mul02);
- int mul08 = MulX(mul04);
- int mul09 = keyVal ^ mul08;
- _decryptKeyExpansion[i] = mul02 ^ mul04 ^ mul08 ^ rot3(mul02 ^ mul09) ^ rot2(mul04 ^ mul09) ^ rot1(mul09);
- }
- }
-
- private static int rot1(int val) => int.RotateLeft(val, 8);
- private static int rot2(int val) => int.RotateLeft(val, 16);
- private static int rot3(int val) => int.RotateLeft(val, 24);
-
- private static int SubWord(int a)
- {
- ReadOnlySpan<byte> sbox = Sbox;
- return sbox[a & 0xFF] |
- sbox[a >> 8 & 0xFF] << 8 |
- sbox[a >> 16 & 0xFF] << 16 |
- sbox[a >> 24 & 0xFF] << 24;
- }
-
- private static int MulX(int x)
- {
- int u = x & unchecked((int)0x80808080);
- return ((x & unchecked((int)0x7f7f7f7f)) << 1) ^ ((u - (u >> 7 & 0x01FFFFFF)) & 0x1b1b1b1b);
- }
-
- private static ReadOnlySpan<byte> Sbox => new byte[] {
- 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118,
- 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192,
- 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21,
- 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117,
- 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132,
- 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207,
- 208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168,
- 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210,
- 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115,
- 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219,
- 224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121,
- 231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8,
- 186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138,
- 112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158,
- 225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223,
- 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22 };
-
- // Precompute the modulus operations: these are performance killers when called frequently
- private static readonly int[] s_encryptindex = new int[BlockSizeInts * 3] {
- 1, 2, 3, 0,
- 2, 3, 0, 1,
- 3, 0, 1, 2,
- };
-
- private static readonly int[] s_decryptindex = new int[BlockSizeInts * 3] {
- 3, 0, 1, 2,
- 2, 3, 0, 1,
- 1, 2, 3, 0,
- };
-
- private static readonly int[] s_Rcon = new int[] {
- 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
- 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
- 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 };
-
- private static readonly int[] s_T = new int[4 * 256]
- {
- // s_T1
- -1520213050, -2072216328, -1720223762, -1921287178, 234025727, -1117033514, -1318096930, 1422247313,
- 1345335392, 50397442, -1452841010, 2099981142, 436141799, 1658312629, -424957107, -1703512340,
- 1170918031, -1652391393, 1086966153, -2021818886, 368769775, -346465870, -918075506, 200339707,
- -324162239, 1742001331, -39673249, -357585083, -1080255453, -140204973, -1770884380, 1539358875,
- -1028147339, 486407649, -1366060227, 1780885068, 1513502316, 1094664062, 49805301, 1338821763,
- 1546925160, -190470831, 887481809, 150073849, -1821281822, 1943591083, 1395732834, 1058346282,
- 201589768, 1388824469, 1696801606, 1589887901, 672667696, -1583966665, 251987210, -1248159185,
- 151455502, 907153956, -1686077413, 1038279391, 652995533, 1764173646, -843926913, -1619692054,
- 453576978, -1635548387, 1949051992, 773462580, 756751158, -1301385508, -296068428, -73359269,
- -162377052, 1295727478, 1641469623, -827083907, 2066295122, 1055122397, 1898917726, -1752923117,
- -179088474, 1758581177, 0, 753790401, 1612718144, 536673507, -927878791, -312779850,
- -1100322092, 1187761037, -641810841, 1262041458, -565556588, -733197160, -396863312, 1255133061,
- 1808847035, 720367557, -441800113, 385612781, -985447546, -682799718, 1429418854, -1803188975,
- -817543798, 284817897, 100794884, -2122350594, -263171936, 1144798328, -1163944155, -475486133,
- -212774494, -22830243, -1069531008, -1970303227, -1382903233, -1130521311, 1211644016, 83228145,
- -541279133, -1044990345, 1977277103, 1663115586, 806359072, 452984805, 250868733, 1842533055,
- 1288555905, 336333848, 890442534, 804056259, -513843266, -1567123659, -867941240, 957814574,
- 1472513171, -223893675, -2105639172, 1195195770, -1402706744, -413311558, 723065138, -1787595802,
- -1604296512, -1736343271, -783331426, 2145180835, 1713513028, 2116692564, -1416589253, -2088204277,
- -901364084, 703524551, -742868885, 1007948840, 2044649127, -497131844, 487262998, 1994120109,
- 1004593371, 1446130276, 1312438900, 503974420, -615954030, 168166924, 1814307912, -463709000,
- 1573044895, 1859376061, -273896381, -1503501628, -1466855111, -1533700815, 937747667, -1954973198,
- 854058965, 1137232011, 1496790894, -1217565222, -1936880383, 1691735473, -766620004, -525751991,
- -1267962664, -95005012, 133494003, 636152527, -1352309302, -1904575756, -374428089, 403179536,
- -709182865, -2005370640, 1864705354, 1915629148, 605822008, -240736681, -944458637, 1371981463,
- 602466507, 2094914977, -1670089496, 555687742, -582268010, -591544991, -2037675251, -2054518257,
- -1871679264, 1111375484, -994724495, -1436129588, -666351472, 84083462, 32962295, 302911004,
- -1553899070, 1597322602, -111716434, -793134743, -1853454825, 1489093017, 656219450, -1180787161,
- 954327513, 335083755, -1281845205, 856756514, -1150719534, 1893325225, -1987146233, -1483434957,
- -1231316179, 572399164, -1836611819, 552200649, 1238290055, -11184726, 2015897680, 2061492133,
- -1886614525, -123625127, -2138470135, 386731290, -624967835, 837215959, -968736124, -1201116976,
- -1019133566, -1332111063, 1999449434, 286199582, -877612933, -61582168, -692339859, 974525996,
-
- // s_T2
- 1667483301, 2088564868, 2004348569, 2071721613, -218956019, 1802229437, 1869602481, -976907948,
- 808476752, 16843267, 1734856361, 724260477, -16849127, -673729182, -1414836762, 1987505306,
- -892694715, -2105401443, -909539008, 2105408135, -84218091, 1499050731, 1195871945, -252642549,
- -1381154324, -724257945, -1566416899, -1347467798, -1667488833, -1532734473, 1920132246, -1061119141,
- -1212713534, -33693412, -1819066962, 640044138, 909536346, 1061125697, -134744830, -859012273,
- 875849820, -1515892236, -437923532, -235800312, 1903288979, -656888973, 825320019, 353708607,
- 67373068, -943221422, 589514341, -1010590370, 404238376, -1768540255, 84216335, -1701171275,
- 117902857, 303178806, -2139087973, -488448195, -336868058, 656887401, -1296924723, 1970662047,
- 151589403, -2088559202, 741103732, 437924910, 454768173, 1852759218, 1515893998, -1600103429,
- 1381147894, 993752653, -690571423, -1280082482, 690573947, -471605954, 791633521, -2071719017,
- 1397991157, -774784664, 0, -303185620, 538984544, -50535649, -1313769016, 1532737261,
- 1785386174, -875852474, -1094817831, 960066123, 1246401758, 1280088276, 1482207464, -808483510,
- -791626901, -269499094, -1431679003, -67375850, 1128498885, 1296931543, 859006549, -2054876780,
- 1162185423, -101062384, 33686534, 2139094657, 1347461360, 1010595908, -1616960070, -1465365533,
- 1364304627, -1549574658, 1077969088, -1886452342, -1835909203, -1650646596, 943222856, -168431356,
- -1128504353, -1229555775, -623202443, 555827811, 269492272, -6886, -202113778, -757940371,
- -842170036, 202119188, 320022069, -320027857, 1600110305, -1751698014, 1145342156, 387395129,
- -993750185, -1482205710, 2122251394, 1027439175, 1684326572, 1566423783, 421081643, 1936975509,
- 1616953504, -2122245736, 1330618065, -589520001, 572671078, 707417214, -1869595733, -2004350077,
- 1179028682, -286341335, -1195873325, 336865340, -555833479, 1583267042, 185275933, -606360202,
- -522134725, 842163286, 976909390, 168432670, 1229558491, 101059594, 606357612, 1549580516,
- -1027432611, -741098130, -1397996561, 1650640038, -1852753496, -1785384540, -454765769, 2038035083,
- -404237006, -926381245, 926379609, 1835915959, -1920138868, -707415708, 1313774802, -1448523296,
- 1819072692, 1448520954, -185273593, -353710299, 1701169839, 2054878350, -1364310039, 134746136,
- -1162186795, 2021191816, 623200879, 774790258, 471611428, -1499047951, -1263242297, -960063663,
- -387396829, -572677764, 1953818780, 522141217, 1263245021, -1111662116, -1953821306, -1970663547,
- 1886445712, 1044282434, -1246400060, 1718013098, 1212715224, 50529797, -151587071, 235805714,
- 1633796771, 892693087, 1465364217, -1179031088, -2038032495, -1044276904, 488454695, -1633802311,
- -505292488, -117904621, -1734857805, 286335539, 1768542907, -640046736, -1903294583, -1802226777,
- -1684329034, 505297954, -2021190254, -370554592, -825325751, 1431677695, 673730680, -538991238,
- -1936981105, -1583261192, -1987507840, 218962455, -1077975590, -421079247, 1111655622, 1751699640,
- 1094812355, -1718015568, 757946999, 252648977, -1330611253, 1414834428, -1145344554, 370551866,
-
- // s_T3
- 1673962851, 2096661628, 2012125559, 2079755643, -218165774, 1809235307, 1876865391, -980331323,
- 811618352, 16909057, 1741597031, 727088427, -18408962, -675978537, -1420958037, 1995217526,
- -896580150, -2111857278, -913751863, 2113570685, -84994566, 1504897881, 1200539975, -251982864,
- -1388188499, -726439980, -1570767454, -1354372433, -1675378788, -1538000988, 1927583346, -1063560256,
- -1217019209, -35578627, -1824674157, 642542118, 913070646, 1065238847, -134937865, -863809588,
- 879254580, -1521355611, -439274267, -235337487, 1910674289, -659852328, 828527409, 355090197,
- 67636228, -946515257, 591815971, -1013096765, 405809176, -1774739050, 84545285, -1708149350,
- 118360327, 304363026, -2145674368, -488686110, -338876693, 659450151, -1300247118, 1978310517,
- 152181513, -2095210877, 743994412, 439627290, 456535323, 1859957358, 1521806938, -1604584544,
- 1386542674, 997608763, -692624938, -1283600717, 693271337, -472039709, 794718511, -2079090812,
- 1403450707, -776378159, 0, -306107155, 541089824, -52224004, -1317418831, 1538714971,
- 1792327274, -879933749, -1100490306, 963791673, 1251270218, 1285084236, 1487988824, -813348145,
- -793023536, -272291089, -1437604438, -68348165, 1132905795, 1301993293, 862344499, -2062445435,
- 1166724933, -102166279, 33818114, 2147385727, 1352724560, 1014514748, -1624917345, -1471421528,
- 1369633617, -1554121053, 1082179648, -1895462257, -1841320558, -1658733411, 946882616, -168753931,
- -1134305348, -1233665610, -626035238, 557998881, 270544912, -1762561, -201519373, -759206446,
- -847164211, 202904588, 321271059, -322752532, 1606345055, -1758092649, 1149815876, 388905239,
- -996976700, -1487539545, 2130477694, 1031423805, 1690872932, 1572530013, 422718233, 1944491379,
- 1623236704, -2129028991, 1335808335, -593264676, 574907938, 710180394, -1875137648, -2012511352,
- 1183631942, -288937490, -1200893000, 338181140, -559449634, 1589437022, 185998603, -609388837,
- -522503200, 845436466, 980700730, 169090570, 1234361161, 101452294, 608726052, 1555620956,
- -1029743166, -742560045, -1404833876, 1657054818, -1858492271, -1791908715, -455919644, 2045938553,
- -405458201, -930397240, 929978679, 1843050349, -1929278323, -709794603, 1318900302, -1454776151,
- 1826141292, 1454176854, -185399308, -355523094, 1707781989, 2062847610, -1371018834, 135272456,
- -1167075910, 2029029496, 625635109, 777810478, 473441308, -1504185946, -1267480652, -963161658,
- -389340184, -576619299, 1961401460, 524165407, 1268178251, -1117659971, -1962047861, -1978694262,
- 1893765232, 1048330814, -1250835275, 1724688998, 1217452104, 50726147, -151584266, 236720654,
- 1640145761, 896163637, 1471084887, -1184247623, -2045275770, -1046914879, 490350365, -1641563746,
- -505857823, -118811656, -1741966440, 287453969, 1775418217, -643206951, -1912108658, -1808554092,
- -1691502949, 507257374, -2028629369, -372694807, -829994546, 1437269845, 676362280, -542803233,
- -1945923700, -1587939167, -1995865975, 219813645, -1083843905, -422104602, 1115997762, 1758509160,
- 1099088705, -1725321063, 760903469, 253628687, -1334064208, 1420360788, -1150429509, 371997206,
-
- // s_T4
- -962239645, -125535108, -291932297, -158499973, -15863054, -692229269, -558796945, -1856715323,
- 1615867952, 33751297, -827758745, 1451043627, -417726722, -1251813417, 1306962859, -325421450,
- -1891251510, 530416258, -1992242743, -91783811, -283772166, -1293199015, -1899411641, -83103504,
- 1106029997, -1285040940, 1610457762, 1173008303, 599760028, 1408738468, -459902350, -1688485696,
- 1975695287, -518193667, 1034851219, 1282024998, 1817851446, 2118205247, -184354825, -2091922228,
- 1750873140, 1374987685, -785062427, -116854287, -493653647, -1418471208, 1649619249, 708777237,
- 135005188, -1789737017, 1181033251, -1654733885, 807933976, 933336726, 168756485, 800430746,
- 235472647, 607523346, 463175808, -549592350, -853087253, 1315514151, 2144187058, -358648459,
- 303761673, 496927619, 1484008492, 875436570, 908925723, -592286098, -1259447718, 1543217312,
- -1527360942, 1984772923, -1218324778, 2110698419, 1383803177, -583080989, 1584475951, 328696964,
- -1493871789, -1184312879, 0, -1054020115, 1080041504, -484442884, 2043195825, -1225958565,
- -725718422, -1924740149, 1742323390, 1917532473, -1797371318, -1730917300, -1326950312, -2058694705,
- -1150562096, -987041809, 1340451498, -317260805, -2033892541, -1697166003, 1716859699, 294946181,
- -1966127803, -384763399, 67502594, -25067649, -1594863536, 2017737788, 632987551, 1273211048,
- -1561112239, 1576969123, -2134884288, 92966799, 1068339858, 566009245, 1883781176, -251333131,
- 1675607228, 2009183926, -1351230758, 1113792801, 540020752, -451215361, -49351693, -1083321646,
- -2125673011, 403966988, 641012499, -1020269332, -1092526241, 899848087, -1999879100, 775493399,
- -1822964540, 1441965991, -58556802, 2051489085, -928226204, -1159242403, 841685273, -426413197,
- -1063231392, 429425025, -1630449841, -1551901476, 1147544098, 1417554474, 1001099408, 193169544,
- -1932900794, -953553170, 1809037496, 675025940, -1485185314, -1126015394, 371002123, -1384719397,
- -616832800, 1683370546, 1951283770, 337512970, -1831122615, 201983494, 1215046692, -1192993700,
- -1621245246, -1116810285, 1139780780, -995728798, 967348625, 832869781, -751311644, -225740423,
- -718084121, -1958491960, 1851340599, -625513107, 25988493, -1318791723, -1663938994, 1239460265,
- -659264404, -1392880042, -217582348, -819598614, -894474907, -191989126, 1206496942, 270010376,
- 1876277946, -259491720, 1248797989, 1550986798, 941890588, 1475454630, 1942467764, -1756248378,
- -886839064, -1585652259, -392399756, 1042358047, -1763882165, 1641856445, 226921355, 260409994,
- -527404944, 2084716094, 1908716981, -861247898, -1864873912, 100991747, -150866186, 470945294,
- -1029480095, 1784624437, -1359390889, 1775286713, 395413126, -1722236479, 975641885, 666476190,
- -650583583, -351012616, 733190296, 573772049, -759469719, -1452221991, 126455438, 866620564,
- 766942107, 1008868894, 361924487, -920589847, -2025206066, -1426107051, 1350051880, -1518673953,
- 59739276, 1509466529, 159418761, 437718285, 1708834751, -684595482, -2067381694, -793221016,
- -2101132991, 699439513, 1517759789, 504434447, 2076946608, -1459858348, 1842789307, 742004246 };
-
- private static readonly int[] s_TF = new int[4 * 256]
- {
- // s_TF1
- 99, 124, 119, 123, 242, 107, 111, 197,
- 48, 1, 103, 43, 254, 215, 171, 118,
- 202, 130, 201, 125, 250, 89, 71, 240,
- 173, 212, 162, 175, 156, 164, 114, 192,
- 183, 253, 147, 38, 54, 63, 247, 204,
- 52, 165, 229, 241, 113, 216, 49, 21,
- 4, 199, 35, 195, 24, 150, 5, 154,
- 7, 18, 128, 226, 235, 39, 178, 117,
- 9, 131, 44, 26, 27, 110, 90, 160,
- 82, 59, 214, 179, 41, 227, 47, 132,
- 83, 209, 0, 237, 32, 252, 177, 91,
- 106, 203, 190, 57, 74, 76, 88, 207,
- 208, 239, 170, 251, 67, 77, 51, 133,
- 69, 249, 2, 127, 80, 60, 159, 168,
- 81, 163, 64, 143, 146, 157, 56, 245,
- 188, 182, 218, 33, 16, 255, 243, 210,
- 205, 12, 19, 236, 95, 151, 68, 23,
- 196, 167, 126, 61, 100, 93, 25, 115,
- 96, 129, 79, 220, 34, 42, 144, 136,
- 70, 238, 184, 20, 222, 94, 11, 219,
- 224, 50, 58, 10, 73, 6, 36, 92,
- 194, 211, 172, 98, 145, 149, 228, 121,
- 231, 200, 55, 109, 141, 213, 78, 169,
- 108, 86, 244, 234, 101, 122, 174, 8,
- 186, 120, 37, 46, 28, 166, 180, 198,
- 232, 221, 116, 31, 75, 189, 139, 138,
- 112, 62, 181, 102, 72, 3, 246, 14,
- 97, 53, 87, 185, 134, 193, 29, 158,
- 225, 248, 152, 17, 105, 217, 142, 148,
- 155, 30, 135, 233, 206, 85, 40, 223,
- 140, 161, 137, 13, 191, 230, 66, 104,
- 65, 153, 45, 15, 176, 84, 187, 22,
-
- // s_TF2
- 25344, 31744, 30464, 31488, 61952, 27392, 28416, 50432,
- 12288, 256, 26368, 11008, 65024, 55040, 43776, 30208,
- 51712, 33280, 51456, 32000, 64000, 22784, 18176, 61440,
- 44288, 54272, 41472, 44800, 39936, 41984, 29184, 49152,
- 46848, 64768, 37632, 9728, 13824, 16128, 63232, 52224,
- 13312, 42240, 58624, 61696, 28928, 55296, 12544, 5376,
- 1024, 50944, 8960, 49920, 6144, 38400, 1280, 39424,
- 1792, 4608, 32768, 57856, 60160, 9984, 45568, 29952,
- 2304, 33536, 11264, 6656, 6912, 28160, 23040, 40960,
- 20992, 15104, 54784, 45824, 10496, 58112, 12032, 33792,
- 21248, 53504, 0, 60672, 8192, 64512, 45312, 23296,
- 27136, 51968, 48640, 14592, 18944, 19456, 22528, 52992,
- 53248, 61184, 43520, 64256, 17152, 19712, 13056, 34048,
- 17664, 63744, 512, 32512, 20480, 15360, 40704, 43008,
- 20736, 41728, 16384, 36608, 37376, 40192, 14336, 62720,
- 48128, 46592, 55808, 8448, 4096, 65280, 62208, 53760,
- 52480, 3072, 4864, 60416, 24320, 38656, 17408, 5888,
- 50176, 42752, 32256, 15616, 25600, 23808, 6400, 29440,
- 24576, 33024, 20224, 56320, 8704, 10752, 36864, 34816,
- 17920, 60928, 47104, 5120, 56832, 24064, 2816, 56064,
- 57344, 12800, 14848, 2560, 18688, 1536, 9216, 23552,
- 49664, 54016, 44032, 25088, 37120, 38144, 58368, 30976,
- 59136, 51200, 14080, 27904, 36096, 54528, 19968, 43264,
- 27648, 22016, 62464, 59904, 25856, 31232, 44544, 2048,
- 47616, 30720, 9472, 11776, 7168, 42496, 46080, 50688,
- 59392, 56576, 29696, 7936, 19200, 48384, 35584, 35328,
- 28672, 15872, 46336, 26112, 18432, 768, 62976, 3584,
- 24832, 13568, 22272, 47360, 34304, 49408, 7424, 40448,
- 57600, 63488, 38912, 4352, 26880, 55552, 36352, 37888,
- 39680, 7680, 34560, 59648, 52736, 21760, 10240, 57088,
- 35840, 41216, 35072, 3328, 48896, 58880, 16896, 26624,
- 16640, 39168, 11520, 3840, 45056, 21504, 47872, 5632,
-
- // s_TF3
- 6488064, 8126464, 7798784, 8060928, 15859712, 7012352, 7274496, 12910592,
- 3145728, 65536, 6750208, 2818048, 16646144, 14090240, 11206656, 7733248,
- 13238272, 8519680, 13172736, 8192000, 16384000, 5832704, 4653056, 15728640,
- 11337728, 13893632, 10616832, 11468800, 10223616, 10747904, 7471104, 12582912,
- 11993088, 16580608, 9633792, 2490368, 3538944, 4128768, 16187392, 13369344,
- 3407872, 10813440, 15007744, 15794176, 7405568, 14155776, 3211264, 1376256,
- 262144, 13041664, 2293760, 12779520, 1572864, 9830400, 327680, 10092544,
- 458752, 1179648, 8388608, 14811136, 15400960, 2555904, 11665408, 7667712,
- 589824, 8585216, 2883584, 1703936, 1769472, 7208960, 5898240, 10485760,
- 5373952, 3866624, 14024704, 11730944, 2686976, 14876672, 3080192, 8650752,
- 5439488, 13697024, 0, 15532032, 2097152, 16515072, 11599872, 5963776,
- 6946816, 13303808, 12451840, 3735552, 4849664, 4980736, 5767168, 13565952,
- 13631488, 15663104, 11141120, 16449536, 4390912, 5046272, 3342336, 8716288,
- 4521984, 16318464, 131072, 8323072, 5242880, 3932160, 10420224, 11010048,
- 5308416, 10682368, 4194304, 9371648, 9568256, 10289152, 3670016, 16056320,
- 12320768, 11927552, 14286848, 2162688, 1048576, 16711680, 15925248, 13762560,
- 13434880, 786432, 1245184, 15466496, 6225920, 9895936, 4456448, 1507328,
- 12845056, 10944512, 8257536, 3997696, 6553600, 6094848, 1638400, 7536640,
- 6291456, 8454144, 5177344, 14417920, 2228224, 2752512, 9437184, 8912896,
- 4587520, 15597568, 12058624, 1310720, 14548992, 6160384, 720896, 14352384,
- 14680064, 3276800, 3801088, 655360, 4784128, 393216, 2359296, 6029312,
- 12713984, 13828096, 11272192, 6422528, 9502720, 9764864, 14942208, 7929856,
- 15138816, 13107200, 3604480, 7143424, 9240576, 13959168, 5111808, 11075584,
- 7077888, 5636096, 15990784, 15335424, 6619136, 7995392, 11403264, 524288,
- 12189696, 7864320, 2424832, 3014656, 1835008, 10878976, 11796480, 12976128,
- 15204352, 14483456, 7602176, 2031616, 4915200, 12386304, 9109504, 9043968,
- 7340032, 4063232, 11862016, 6684672, 4718592, 196608, 16121856, 917504,
- 6356992, 3473408, 5701632, 12124160, 8781824, 12648448, 1900544, 10354688,
- 14745600, 16252928, 9961472, 1114112, 6881280, 14221312, 9306112, 9699328,
- 10158080, 1966080, 8847360, 15269888, 13500416, 5570560, 2621440, 14614528,
- 9175040, 10551296, 8978432, 851968, 12517376, 15073280, 4325376, 6815744,
- 4259840, 10027008, 2949120, 983040, 11534336, 5505024, 12255232, 1441792,
-
- // s_TF4
- 1660944384, 2080374784, 1996488704, 2063597568, -234881024, 1795162112, 1862270976, -989855744,
- 805306368, 16777216, 1728053248, 721420288, -33554432, -687865856, -1426063360, 1979711488,
- -905969664, -2113929216, -922746880, 2097152000, -100663296, 1493172224, 1191182336, -268435456,
- -1392508928, -738197504, -1577058304, -1358954496, -1677721600, -1543503872, 1912602624, -1073741824,
- -1224736768, -50331648, -1828716544, 637534208, 905969664, 1056964608, -150994944, -872415232,
- 872415232, -1526726656, -452984832, -251658240, 1895825408, -671088640, 822083584, 352321536,
- 67108864, -956301312, 587202560, -1023410176, 402653184, -1778384896, 83886080, -1711276032,
- 117440512, 301989888, -2147483648, -503316480, -352321536, 654311424, -1308622848, 1962934272,
- 150994944, -2097152000, 738197504, 436207616, 452984832, 1845493760, 1509949440, -1610612736,
- 1375731712, 989855744, -704643072, -1291845632, 687865856, -486539264, 788529152, -2080374784,
- 1392508928, -788529152, 0, -318767104, 536870912, -67108864, -1325400064, 1526726656,
- 1778384896, -889192448, -1107296256, 956301312, 1241513984, 1275068416, 1476395008, -822083584,
- -805306368, -285212672, -1442840576, -83886080, 1124073472, 1291845632, 855638016, -2063597568,
- 1157627904, -117440512, 33554432, 2130706432, 1342177280, 1006632960, -1627389952, -1476395008,
- 1358954496, -1560281088, 1073741824, -1895825408, -1845493760, -1660944384, 939524096, -184549376,
- -1140850688, -1241513984, -637534208, 553648128, 268435456, -16777216, -218103808, -771751936,
- -855638016, 201326592, 318767104, -335544320, 1593835520, -1761607680, 1140850688, 385875968,
- -1006632960, -1493172224, 2113929216, 1023410176, 1677721600, 1560281088, 419430400, 1929379840,
- 1610612736, -2130706432, 1325400064, -603979776, 570425344, 704643072, -1879048192, -2013265920,
- 1174405120, -301989888, -1207959552, 335544320, -570425344, 1577058304, 184549376, -620756992,
- -536870912, 838860800, 973078528, 167772160, 1224736768, 100663296, 603979776, 1543503872,
- -1040187392, -754974720, -1409286144, 1644167168, -1862270976, -1795162112, -469762048, 2030043136,
- -419430400, -939524096, 922746880, 1828716544, -1929379840, -721420288, 1308622848, -1459617792,
- 1811939328, 1442840576, -201326592, -369098752, 1694498816, 2046820352, -1375731712, 134217728,
- -1174405120, 2013265920, 620756992, 771751936, 469762048, -1509949440, -1275068416, -973078528,
- -402653184, -587202560, 1946157056, 520093696, 1258291200, -1124073472, -1962934272, -1979711488,
- 1879048192, 1040187392, -1258291200, 1711276032, 1207959552, 50331648, -167772160, 234881024,
- 1627389952, 889192448, 1459617792, -1191182336, -2046820352, -1056964608, 486539264, -1644167168,
- -520093696, -134217728, -1744830464, 285212672, 1761607680, -654311424, -1912602624, -1811939328,
- -1694498816, 503316480, -2030043136, -385875968, -838860800, 1426063360, 671088640, -553648128,
- -1946157056, -1593835520, -1996488704, 218103808, -1090519040, -436207616, 1107296256, 1744830464,
- 1090519040, -1728053248, 754974720, 251658240, -1342177280, 1409286144, -1157627904, 369098752 };
-
- private static readonly int[] s_iT = new int[4 * 256]
- {
- // s_iT1
- 1353184337, 1399144830, -1012656358, -1772214470, -882136261, -247096033, -1420232020, -1828461749,
- 1442459680, -160598355, -1854485368, 625738485, -52959921, -674551099, -2143013594, -1885117771,
- 1230680542, 1729870373, -1743852987, -507445667, 41234371, 317738113, -1550367091, -956705941,
- -413167869, -1784901099, -344298049, -631680363, 763608788, -752782248, 694804553, 1154009486,
- 1787413109, 2021232372, 1799248025, -579749593, -1236278850, 397248752, 1722556617, -1271214467,
- 407560035, -2110711067, 1613975959, 1165972322, -529046351, -2068943941, 480281086, -1809118983,
- 1483229296, 436028815, -2022908268, -1208452270, 601060267, -503166094, 1468997603, 715871590,
- 120122290, 63092015, -1703164538, -1526188077, -226023376, -1297760477, -1167457534, 1552029421,
- 723308426, -1833666137, -252573709, -1578997426, -839591323, -708967162, 526529745, -1963022652,
- -1655493068, -1604979806, 853641733, 1978398372, 971801355, -1427152832, 111112542, 1360031421,
- -108388034, 1023860118, -1375387939, 1186850381, -1249028975, 90031217, 1876166148, -15380384,
- 620468249, -1746289194, -868007799, 2006899047, -1119688528, -2004121337, 945494503, -605108103,
- 1191869601, -384875908, -920746760, 0, -2088337399, 1223502642, -1401941730, 1316117100,
- -67170563, 1446544655, 517320253, 658058550, 1691946762, 564550760, -783000677, 976107044,
- -1318647284, 266819475, -761860428, -1634624741, 1338359936, -1574904735, 1766553434, 370807324,
- 179999714, -450191168, 1138762300, 488053522, 185403662, -1379431438, -1180125651, -928440812,
- -2061897385, 1275557295, -1143105042, -44007517, -1624899081, -1124765092, -985962940, 880737115,
- 1982415755, -590994485, 1761406390, 1676797112, -891538985, 277177154, 1076008723, 538035844,
- 2099530373, -130171950, 288553390, 1839278535, 1261411869, -214912292, -330136051, -790380169,
- 1813426987, -1715900247, -95906799, 577038663, -997393240, 440397984, -668172970, -275762398,
- -951170681, -1043253031, -22885748, 906744984, -813566554, 685669029, 646887386, -1530942145,
- -459458004, 227702864, -1681105046, 1648787028, -1038905866, -390539120, 1593260334, -173030526,
- -1098883681, 2090061929, -1456614033, -1290656305, 999926984, -1484974064, 1852021992, 2075868123,
- 158869197, -199730834, 28809964, -1466282109, 1701746150, 2129067946, 147831841, -420997649,
- -644094022, -835293366, -737566742, -696471511, -1347247055, 824393514, 815048134, -1067015627,
- 935087732, -1496677636, -1328508704, 366520115, 1251476721, -136647615, 240176511, 804688151,
- -1915335306, 1303441219, 1414376140, -553347356, -474623586, 461924940, -1205916479, 2136040774,
- 82468509, 1563790337, 1937016826, 776014843, 1511876531, 1389550482, 861278441, 323475053,
- -1939744870, 2047648055, -1911228327, -1992551445, -299390514, 902390199, -303751967, 1018251130,
- 1507840668, 1064563285, 2043548696, -1086863501, -355600557, 1537932639, 342834655, -2032450440,
- -2114736182, 1053059257, 741614648, 1598071746, 1925389590, 203809468, -1958134744, 1100287487,
- 1895934009, -558691320, -1662733096, -1866377628, 1636092795, 1890988757, 1952214088, 1113045200,
-
- // s_iT2
- -1477160624, 1698790995, -1541989693, 1579629206, 1806384075, 1167925233, 1492823211, 65227667,
- -97509291, 1836494326, 1993115793, 1275262245, -672837636, -886389289, 1144333952, -1553812081,
- 1521606217, 465184103, 250234264, -1057071647, 1966064386, -263421678, -1756983901, -103584826,
- 1603208167, -1668147819, 2054012907, 1498584538, -2084645843, 561273043, 1776306473, -926314940,
- -1983744662, 2039411832, 1045993835, 1907959773, 1340194486, -1383534569, -1407137434, 986611124,
- 1256153880, 823846274, 860985184, 2136171077, 2003087840, -1368671356, -1602093540, 722008468,
- 1749577816, -45773031, 1826526343, -126135625, -747394269, 38499042, -1893735593, -1420466646,
- 686535175, -1028313341, 2076542618, 137876389, -2027409166, -1514200142, 1778582202, -2112426660,
- 483363371, -1267095662, -234359824, -496415071, -187013683, -1106966827, 1647628575, -22625142,
- 1395537053, 1442030240, -511048398, -336157579, -326956231, -278904662, -1619960314, 275692881,
- -1977532679, 115185213, 88006062, -1108980410, -1923837515, 1573155077, -737803153, 357589247,
- -73918172, -373434729, 1128303052, -1629919369, 1122545853, -1953953912, 1528424248, -288851493,
- 175939911, 256015593, 512030921, 0, -2038429309, -315936184, 1880170156, 1918528590,
- -15794693, 948244310, -710001378, 959264295, -653325724, -1503893471, 1415289809, 775300154,
- 1728711857, -413691121, -1762741038, -1852105826, -977239985, 551313826, 1266113129, 437394454,
- -1164713462, 715178213, -534627261, 387650077, 218697227, -947129683, -1464455751, -1457646392,
- 435246981, 125153100, -577114437, 1618977789, 637663135, -177054532, 996558021, 2130402100,
- 692292470, -970732580, -51530136, -236668829, -600713270, -2057092592, 580326208, 298222624,
- 608863613, 1035719416, 855223825, -1591097491, 798891339, 817028339, 1384517100, -473860144,
- 380840812, -1183798887, 1217663482, 1693009698, -1929598780, 1072734234, 746411736, -1875696913,
- 1313441735, -784803391, -1563783938, 198481974, -2114607409, -562387672, -1900553690, -1079165020,
- -1657131804, -1837608947, -866162021, 1182684258, 328070850, -1193766680, -147247522, -1346141451,
- -2141347906, -1815058052, 768962473, 304467891, -1716729797, 2098729127, 1671227502, -1153705093,
- 2015808777, 408514292, -1214583807, -1706064984, 1855317605, -419452290, -809754360, -401215514,
- -1679312167, 913263310, 161475284, 2091919830, -1297862225, 591342129, -1801075152, 1721906624,
- -1135709129, -897385306, -795811664, -660131051, -1744506550, -622050825, 1355644686, -158263505,
- -699566451, -1326496947, 1303039060, 76997855, -1244553501, -2006299621, 523026872, 1365591679,
- -362898172, 898367837, 1955068531, 1091304238, 493335386, -757362094, 1443948851, 1205234963,
- 1641519756, 211892090, 351820174, 1007938441, 665439982, -916342987, -451091987, -1320715716,
- -539845543, 1945261375, -837543815, 935818175, -839429142, -1426235557, 1866325780, -616269690,
- -206583167, -999769794, 874788908, 1084473951, -1021503886, 635616268, 1228679307, -1794244799,
- 27801969, -1291056930, -457910116, -1051302768, -2067039391, -1238182544, 1550600308, 1471729730,
-
- // s_iT3
- -195997529, 1098797925, 387629988, 658151006, -1422144661, -1658851003, -89347240, -481586429,
- 807425530, 1991112301, -863465098, 49620300, -447742761, 717608907, 891715652, 1656065955,
- -1310832294, -1171953893, -364537842, -27401792, 801309301, 1283527408, 1183687575, -747911431,
- -1895569569, -1844079204, 1841294202, 1385552473, -1093390973, 1951978273, -532076183, -913423160,
- -1032492407, -1896580999, 1486449470, -1188569743, -507595185, -1997531219, 550069932, -830622662,
- -547153846, 451248689, 1368875059, 1398949247, 1689378935, 1807451310, -2114052960, 150574123,
- 1215322216, 1167006205, -560691348, 2069018616, 1940595667, 1265820162, 534992783, 1432758955,
- -340654296, -1255210046, -981034373, 936617224, 674296455, -1088179547, 50510442, 384654466,
- -813028580, 2041025204, 133427442, 1766760930, -630862348, 84334014, 886120290, -1497068802,
- 775200083, -207445931, -1979370783, -156994069, -2096416276, 1614850799, 1901987487, 1857900816,
- 557775242, -577356538, 1054715397, -431143235, 1418835341, -999226019, 100954068, 1348534037,
- -1743182597, -1110009879, 1082772547, -647530594, -391070398, -1995994997, 434583643, -931537938,
- 2090944266, 1115482383, -2064070370, 0, -2146860154, 724715757, 287222896, 1517047410,
- 251526143, -2062592456, -1371726123, 758523705, 252339417, 1550328230, 1536938324, 908343854,
- 168604007, 1469255655, -290139498, -1692688751, -1065332795, -597581280, 2002413899, 303830554,
- -1813902662, -1597971158, 574374880, 454171927, 151915277, -1947030073, -1238517336, 504678569,
- -245922535, 1974422535, -1712407587, 2141453664, 33005350, 1918680309, 1715782971, -77908866,
- 1133213225, 600562886, -306812676, -457677839, 836225756, 1665273989, -1760346078, -964419567,
- 1250262308, -1143801795, -106032846, 700935585, -1642247377, -1294142672, -2045907886, -1049112349,
- -1288999914, 1890163129, -1810761144, -381214108, -56048500, -257942977, 2102843436, 857927568,
- 1233635150, 953795025, -896729438, -728222197, -173617279, 2057644254, -1210440050, -1388337985,
- 976020637, 2018512274, 1600822220, 2119459398, -1913208301, -661591880, 959340279, -1014827601,
- 1570750080, -798393197, -714102483, 634368786, -1396163687, 403744637, -1662488989, 1004239803,
- 650971512, 1500443672, -1695809097, 1334028442, -1780062866, -5603610, -1138685745, 368043752,
- -407184997, 1867173430, -1612000247, -1339435396, -1540247630, 1059729699, -1513738092, -1573535642,
- 1316239292, -2097371446, -1864322864, -1489824296, 82922136, -331221030, -847311280, -1860751370,
- 1299615190, -280801872, -1429449651, -1763385596, -778116171, 1783372680, 750893087, 1699118929,
- 1587348714, -1946067659, -2013629580, 201010753, 1739807261, -611167534, 283718486, -697494713,
- -677737375, -1590199796, -128348652, 334203196, -1446056409, 1639396809, 484568549, 1199193265,
- -761505313, -229294221, 337148366, -948715721, -145495347, -44082262, 1038029935, 1148749531,
- -1345682957, 1756970692, 607661108, -1547542720, 488010435, -490992603, 1009290057, 234832277,
- -1472630527, 201907891, -1260872476, 1449431233, -881106556, 852848822, 1816687708, -1194311081,
-
- // s_iT4
- 1364240372, 2119394625, 449029143, 982933031, 1003187115, 535905693, -1398056710, 1267925987,
- 542505520, -1376359050, -2003732788, -182105086, 1341970405, -975713494, 645940277, -1248877726,
- -565617999, 627514298, 1167593194, 1575076094, -1023249105, -2129465268, -1918658746, 1808202195,
- 65494927, 362126482, -1075086739, -1780852398, -735214658, 1490231668, 1227450848, -1908094775,
- 1969916354, -193431154, -1721024936, 668823993, -1095348255, -266883704, -916018144, 2108963534,
- 1662536415, -444452582, -1755303087, 1648721747, -1310689436, -1148932501, -31678335, -107730168,
- 1884842056, -1894122171, -1803064098, 1387788411, -1423715469, 1927414347, -480800993, 1714072405,
- -1308153621, 788775605, -2036696123, -744159177, 821200680, 598910399, 45771267, -312704490,
- -1976886065, -1483557767, -202313209, 1319232105, 1707996378, 114671109, -786472396, -997523802,
- 882725678, -1566550541, 87220618, -1535775754, 188345475, 1084944224, 1577492337, -1118760850,
- 1056541217, -1774385443, -575797954, 1296481766, -1850372780, 1896177092, 74437638, 1627329872,
- 421854104, -694687299, -1983102144, 1735892697, -1329773848, 126389129, -415737063, 2044456648,
- -1589179780, 2095648578, -121037180, 0, 159614592, 843640107, 514617361, 1817080410,
- -33816818, 257308805, 1025430958, 908540205, 174381327, 1747035740, -1680780197, 607792694,
- 212952842, -1827674281, -1261267218, 463376795, -2142255680, 1638015196, 1516850039, 471210514,
- -502613357, -1058723168, 1011081250, 303896347, 235605257, -223492213, 767142070, 348694814,
- 1468340721, -1353971851, -289677927, -1543675777, -140564991, 1555887474, 1153776486, 1530167035,
- -1955190461, -874723805, -1234633491, -1201409564, -674571215, 1108378979, 322970263, -2078273082,
- -2055396278, -755483205, -1374604551, -949116631, 491466654, -588042062, 233591430, 2010178497,
- 728503987, -1449543312, 301615252, 1193436393, -1463513860, -1608892432, 1457007741, 586125363,
- -2016981431, -641609416, -1929469238, -1741288492, -1496350219, -1524048262, -635007305, 1067761581,
- 753179962, 1343066744, 1788595295, 1415726718, -155053171, -1863796520, 777975609, -2097827901,
- -1614905251, 1769771984, 1873358293, -810347995, -935618132, 279411992, -395418724, -612648133,
- -855017434, 1861490777, -335431782, -2086102449, -429560171, -1434523905, 554225596, -270079979,
- -1160143897, 1255028335, -355202657, 701922480, 833598116, 707863359, -969894747, 901801634,
- 1949809742, -56178046, -525283184, 857069735, -246769660, 1106762476, 2131644621, 389019281,
- 1989006925, 1129165039, -866890326, -455146346, -1629243951, 1276872810, -1044898004, 1182749029,
- -1660622242, 22885772, -93096825, -80854773, -1285939865, -1840065829, -382511600, 1829980118,
- -1702075945, 930745505, 1502483704, -343327725, -823253079, -1221211807, -504503012, 2050797895,
- -1671831598, 1430221810, 410635796, 1941911495, 1407897079, 1599843069, -552308931, 2022103876,
- -897453137, -1187068824, 942421028, -1033944925, 376619805, -1140054558, 680216892, -12479219,
- 963707304, 148812556, -660806476, 1687208278, 2069988555, -714033614, 1215585388, -800958536 };
-
- private static readonly int[] s_iTF = new int[4 * 256]
- {
- // s_iTF1
- 82, 9, 106, 213, 48, 54, 165, 56,
- 191, 64, 163, 158, 129, 243, 215, 251,
- 124, 227, 57, 130, 155, 47, 255, 135,
- 52, 142, 67, 68, 196, 222, 233, 203,
- 84, 123, 148, 50, 166, 194, 35, 61,
- 238, 76, 149, 11, 66, 250, 195, 78,
- 8, 46, 161, 102, 40, 217, 36, 178,
- 118, 91, 162, 73, 109, 139, 209, 37,
- 114, 248, 246, 100, 134, 104, 152, 22,
- 212, 164, 92, 204, 93, 101, 182, 146,
- 108, 112, 72, 80, 253, 237, 185, 218,
- 94, 21, 70, 87, 167, 141, 157, 132,
- 144, 216, 171, 0, 140, 188, 211, 10,
- 247, 228, 88, 5, 184, 179, 69, 6,
- 208, 44, 30, 143, 202, 63, 15, 2,
- 193, 175, 189, 3, 1, 19, 138, 107,
- 58, 145, 17, 65, 79, 103, 220, 234,
- 151, 242, 207, 206, 240, 180, 230, 115,
- 150, 172, 116, 34, 231, 173, 53, 133,
- 226, 249, 55, 232, 28, 117, 223, 110,
- 71, 241, 26, 113, 29, 41, 197, 137,
- 111, 183, 98, 14, 170, 24, 190, 27,
- 252, 86, 62, 75, 198, 210, 121, 32,
- 154, 219, 192, 254, 120, 205, 90, 244,
- 31, 221, 168, 51, 136, 7, 199, 49,
- 177, 18, 16, 89, 39, 128, 236, 95,
- 96, 81, 127, 169, 25, 181, 74, 13,
- 45, 229, 122, 159, 147, 201, 156, 239,
- 160, 224, 59, 77, 174, 42, 245, 176,
- 200, 235, 187, 60, 131, 83, 153, 97,
- 23, 43, 4, 126, 186, 119, 214, 38,
- 225, 105, 20, 99, 85, 33, 12, 125,
-
- // s_iTF2
- 20992, 2304, 27136, 54528, 12288, 13824, 42240, 14336,
- 48896, 16384, 41728, 40448, 33024, 62208, 55040, 64256,
- 31744, 58112, 14592, 33280, 39680, 12032, 65280, 34560,
- 13312, 36352, 17152, 17408, 50176, 56832, 59648, 51968,
- 21504, 31488, 37888, 12800, 42496, 49664, 8960, 15616,
- 60928, 19456, 38144, 2816, 16896, 64000, 49920, 19968,
- 2048, 11776, 41216, 26112, 10240, 55552, 9216, 45568,
- 30208, 23296, 41472, 18688, 27904, 35584, 53504, 9472,
- 29184, 63488, 62976, 25600, 34304, 26624, 38912, 5632,
- 54272, 41984, 23552, 52224, 23808, 25856, 46592, 37376,
- 27648, 28672, 18432, 20480, 64768, 60672, 47360, 55808,
- 24064, 5376, 17920, 22272, 42752, 36096, 40192, 33792,
- 36864, 55296, 43776, 0, 35840, 48128, 54016, 2560,
- 63232, 58368, 22528, 1280, 47104, 45824, 17664, 1536,
- 53248, 11264, 7680, 36608, 51712, 16128, 3840, 512,
- 49408, 44800, 48384, 768, 256, 4864, 35328, 27392,
- 14848, 37120, 4352, 16640, 20224, 26368, 56320, 59904,
- 38656, 61952, 52992, 52736, 61440, 46080, 58880, 29440,
- 38400, 44032, 29696, 8704, 59136, 44288, 13568, 34048,
- 57856, 63744, 14080, 59392, 7168, 29952, 57088, 28160,
- 18176, 61696, 6656, 28928, 7424, 10496, 50432, 35072,
- 28416, 46848, 25088, 3584, 43520, 6144, 48640, 6912,
- 64512, 22016, 15872, 19200, 50688, 53760, 30976, 8192,
- 39424, 56064, 49152, 65024, 30720, 52480, 23040, 62464,
- 7936, 56576, 43008, 13056, 34816, 1792, 50944, 12544,
- 45312, 4608, 4096, 22784, 9984, 32768, 60416, 24320,
- 24576, 20736, 32512, 43264, 6400, 46336, 18944, 3328,
- 11520, 58624, 31232, 40704, 37632, 51456, 39936, 61184,
- 40960, 57344, 15104, 19712, 44544, 10752, 62720, 45056,
- 51200, 60160, 47872, 15360, 33536, 21248, 39168, 24832,
- 5888, 11008, 1024, 32256, 47616, 30464, 54784, 9728,
- 57600, 26880, 5120, 25344, 21760, 8448, 3072, 32000,
-
- // s_iTF3
- 5373952, 589824, 6946816, 13959168, 3145728, 3538944, 10813440, 3670016,
- 12517376, 4194304, 10682368, 10354688, 8454144, 15925248, 14090240, 16449536,
- 8126464, 14876672, 3735552, 8519680, 10158080, 3080192, 16711680, 8847360,
- 3407872, 9306112, 4390912, 4456448, 12845056, 14548992, 15269888, 13303808,
- 5505024, 8060928, 9699328, 3276800, 10878976, 12713984, 2293760, 3997696,
- 15597568, 4980736, 9764864, 720896, 4325376, 16384000, 12779520, 5111808,
- 524288, 3014656, 10551296, 6684672, 2621440, 14221312, 2359296, 11665408,
- 7733248, 5963776, 10616832, 4784128, 7143424, 9109504, 13697024, 2424832,
- 7471104, 16252928, 16121856, 6553600, 8781824, 6815744, 9961472, 1441792,
- 13893632, 10747904, 6029312, 13369344, 6094848, 6619136, 11927552, 9568256,
- 7077888, 7340032, 4718592, 5242880, 16580608, 15532032, 12124160, 14286848,
- 6160384, 1376256, 4587520, 5701632, 10944512, 9240576, 10289152, 8650752,
- 9437184, 14155776, 11206656, 0, 9175040, 12320768, 13828096, 655360,
- 16187392, 14942208, 5767168, 327680, 12058624, 11730944, 4521984, 393216,
- 13631488, 2883584, 1966080, 9371648, 13238272, 4128768, 983040, 131072,
- 12648448, 11468800, 12386304, 196608, 65536, 1245184, 9043968, 7012352,
- 3801088, 9502720, 1114112, 4259840, 5177344, 6750208, 14417920, 15335424,
- 9895936, 15859712, 13565952, 13500416, 15728640, 11796480, 15073280, 7536640,
- 9830400, 11272192, 7602176, 2228224, 15138816, 11337728, 3473408, 8716288,
- 14811136, 16318464, 3604480, 15204352, 1835008, 7667712, 14614528, 7208960,
- 4653056, 15794176, 1703936, 7405568, 1900544, 2686976, 12910592, 8978432,
- 7274496, 11993088, 6422528, 917504, 11141120, 1572864, 12451840, 1769472,
- 16515072, 5636096, 4063232, 4915200, 12976128, 13762560, 7929856, 2097152,
- 10092544, 14352384, 12582912, 16646144, 7864320, 13434880, 5898240, 15990784,
- 2031616, 14483456, 11010048, 3342336, 8912896, 458752, 13041664, 3211264,
- 11599872, 1179648, 1048576, 5832704, 2555904, 8388608, 15466496, 6225920,
- 6291456, 5308416, 8323072, 11075584, 1638400, 11862016, 4849664, 851968,
- 2949120, 15007744, 7995392, 10420224, 9633792, 13172736, 10223616, 15663104,
- 10485760, 14680064, 3866624, 5046272, 11403264, 2752512, 16056320, 11534336,
- 13107200, 15400960, 12255232, 3932160, 8585216, 5439488, 10027008, 6356992,
- 1507328, 2818048, 262144, 8257536, 12189696, 7798784, 14024704, 2490368,
- 14745600, 6881280, 1310720, 6488064, 5570560, 2162688, 786432, 8192000,
-
- // s_iTF4
- 1375731712, 150994944, 1778384896, -721420288, 805306368, 905969664, -1526726656, 939524096,
- -1090519040, 1073741824, -1560281088, -1644167168, -2130706432, -218103808, -687865856, -83886080,
- 2080374784, -486539264, 956301312, -2113929216, -1694498816, 788529152, -16777216, -2030043136,
- 872415232, -1912602624, 1124073472, 1140850688, -1006632960, -570425344, -385875968, -889192448,
- 1409286144, 2063597568, -1811939328, 838860800, -1509949440, -1040187392, 587202560, 1023410176,
- -301989888, 1275068416, -1795162112, 184549376, 1107296256, -100663296, -1023410176, 1308622848,
- 134217728, 771751936, -1593835520, 1711276032, 671088640, -654311424, 603979776, -1308622848,
- 1979711488, 1526726656, -1577058304, 1224736768, 1828716544, -1962934272, -788529152, 620756992,
- 1912602624, -134217728, -167772160, 1677721600, -2046820352, 1744830464, -1744830464, 369098752,
- -738197504, -1543503872, 1543503872, -872415232, 1560281088, 1694498816, -1241513984, -1845493760,
- 1811939328, 1879048192, 1207959552, 1342177280, -50331648, -318767104, -1191182336, -637534208,
- 1577058304, 352321536, 1174405120, 1459617792, -1493172224, -1929379840, -1660944384, -2080374784,
- -1879048192, -671088640, -1426063360, 0, -1946157056, -1140850688, -754974720, 167772160,
- -150994944, -469762048, 1476395008, 83886080, -1207959552, -1291845632, 1157627904, 100663296,
- -805306368, 738197504, 503316480, -1895825408, -905969664, 1056964608, 251658240, 33554432,
- -1056964608, -1358954496, -1124073472, 50331648, 16777216, 318767104, -1979711488, 1795162112,
- 973078528, -1862270976, 285212672, 1090519040, 1325400064, 1728053248, -603979776, -369098752,
- -1761607680, -234881024, -822083584, -838860800, -268435456, -1275068416, -436207616, 1929379840,
- -1778384896, -1409286144, 1946157056, 570425344, -419430400, -1392508928, 889192448, -2063597568,
- -503316480, -117440512, 922746880, -402653184, 469762048, 1962934272, -553648128, 1845493760,
- 1191182336, -251658240, 436207616, 1895825408, 486539264, 687865856, -989855744, -1996488704,
- 1862270976, -1224736768, 1644167168, 234881024, -1442840576, 402653184, -1107296256, 452984832,
- -67108864, 1442840576, 1040187392, 1258291200, -973078528, -771751936, 2030043136, 536870912,
- -1711276032, -620756992, -1073741824, -33554432, 2013265920, -855638016, 1509949440, -201326592,
- 520093696, -587202560, -1476395008, 855638016, -2013265920, 117440512, -956301312, 822083584,
- -1325400064, 301989888, 268435456, 1493172224, 654311424, -2147483648, -335544320, 1593835520,
- 1610612736, 1358954496, 2130706432, -1459617792, 419430400, -1258291200, 1241513984, 218103808,
- 754974720, -452984832, 2046820352, -1627389952, -1828716544, -922746880, -1677721600, -285212672,
- -1610612736, -536870912, 989855744, 1291845632, -1375731712, 704643072, -184549376, -1342177280,
- -939524096, -352321536, -1157627904, 1006632960, -2097152000, 1392508928, -1728053248, 1627389952,
- 385875968, 721420288, 67108864, 2113929216, -1174405120, 1996488704, -704643072, 637534208,
- -520093696, 1761607680, 335544320, 1660944384, 1426063360, 553648128, 201326592, 2097152000 };
- }
-}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesSubtleCryptoTransform.Browser.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesSubtleCryptoTransform.Browser.cs
deleted file mode 100644
index 08f46f5dad1..00000000000
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AesSubtleCryptoTransform.Browser.cs
+++ /dev/null
@@ -1,171 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics;
-using Internal.Cryptography;
-
-namespace System.Security.Cryptography
-{
- internal sealed class AesSubtleCryptoTransform : BasicSymmetricCipher, ILiteSymmetricCipher
- {
- private const int BlockSizeBytes = AesImplementation.BlockSizeBytes;
-
- private readonly bool _encrypting;
-
- private readonly byte[] _key;
- private byte[]? _lastBlockBuffer;
-
- public AesSubtleCryptoTransform(byte[] key,
- byte[] iv,
- bool encrypting)
- : base(iv, BlockSizeBytes, BlockSizeBytes)
- {
- _encrypting = encrypting;
-
- // iv is guaranteed to be cloned before this method, but not key
- _key = key.CloneByteArray();
- }
-
- public AesSubtleCryptoTransform(ReadOnlySpan<byte> key,
- ReadOnlySpan<byte> iv,
- bool encrypting)
- : base(iv.ToArray(), BlockSizeBytes, BlockSizeBytes)
- {
- _encrypting = encrypting;
-
- _key = key.ToArray();
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- // We need to always zeroize the following fields because they contain sensitive data
- CryptographicOperations.ZeroMemory(_key);
- CryptographicOperations.ZeroMemory(_lastBlockBuffer);
- }
-
- base.Dispose(disposing);
- }
-
- public override int Transform(ReadOnlySpan<byte> input, Span<byte> output) =>
- Transform(input, output, isFinal: false);
-
- public override int TransformFinal(ReadOnlySpan<byte> input, Span<byte> output)
- {
- int bytesWritten = Transform(input, output, isFinal: true);
- Reset();
- return bytesWritten;
- }
-
- private int Transform(ReadOnlySpan<byte> input, Span<byte> output, bool isFinal)
- {
- Debug.Assert(output.Length >= input.Length);
- Debug.Assert(input.Length % BlockSizeInBytes == 0);
-
- if (input.IsEmpty)
- {
- return 0;
- }
-
- // Note: SubtleCrypto always uses PKCS7 padding.
-
- // In order to implement streaming on top of SubtleCrypto's "one shot" API, we have to do the following:
- // 1. Remember the last block of cipher text to pass as the "IV" of the next block.
- // 2. When encrypting a complete block, PKCS7 padding will always add one block of '0x10' padding bytes. We
- // need to strip this padding block off in between Transform calls. This is done by Interop.BrowserCrypto.EncryptDecrypt.
- // 3. When decrypting, we need to do the inverse: append an encrypted block of '0x10' padding bytes, so
- // SubtleCrypto will decrypt input as a complete message. This is done by Interop.BrowserCrypto.EncryptDecrypt.
-
- return _encrypting ?
- EncryptBlock(input, output, isFinal) :
- DecryptBlock(input, output, isFinal);
- }
-
- private int EncryptBlock(ReadOnlySpan<byte> input, Span<byte> output, bool isFinal)
- {
- int bytesWritten = EncryptDecrypt(input, output);
-
- if (!isFinal)
- {
- SaveLastBlock(output.Slice(0, bytesWritten));
- }
-
- return bytesWritten;
- }
-
- private int DecryptBlock(ReadOnlySpan<byte> input, Span<byte> output, bool isFinal)
- {
- Span<byte> lastInputBlockCopy = stackalloc byte[BlockSizeBytes];
- if (!isFinal)
- {
- // Save the lastInputBlock in a temp buffer first, in case input and output are overlapped
- // and decrypting to the output overwrites the input.
- ReadOnlySpan<byte> lastInputBlock = input.Slice(input.Length - BlockSizeBytes);
- lastInputBlock.CopyTo(lastInputBlockCopy);
- }
-
- int numBytesWritten = EncryptDecrypt(input, output);
-
- if (!isFinal)
- {
- SaveLastBlock(lastInputBlockCopy);
- }
-
- return numBytesWritten;
- }
-
- private void SaveLastBlock(ReadOnlySpan<byte> buffer)
- {
- Debug.Assert(buffer.Length > 0 && buffer.Length % BlockSizeBytes == 0);
-
- ReadOnlySpan<byte> lastBlock = buffer.Slice(buffer.Length - BlockSizeBytes);
- if (_lastBlockBuffer is null)
- {
- _lastBlockBuffer = lastBlock.ToArray();
- }
- else
- {
- Debug.Assert(_lastBlockBuffer.Length == BlockSizeBytes);
- lastBlock.CopyTo(_lastBlockBuffer);
- }
- }
-
- private unsafe int EncryptDecrypt(ReadOnlySpan<byte> input, Span<byte> output)
- {
- byte[] iv = _lastBlockBuffer ?? IV!;
-
- fixed (byte* pKey = _key)
- fixed (byte* pIV = iv)
- fixed (byte* pInput = input)
- fixed (byte* pOutput = output)
- {
- int bytesWritten = Interop.BrowserCrypto.EncryptDecrypt(
- _encrypting ? 1 : 0,
- pKey, _key.Length,
- pIV, iv.Length,
- pInput, input.Length,
- pOutput, output.Length);
-
- if (bytesWritten < 0)
- {
- throw new CryptographicException(SR.Format(SR.Unknown_SubtleCrypto_Error, bytesWritten));
- }
-
- return bytesWritten;
- }
- }
-
- //
- // resets the state of the transform
- //
-
- void ILiteSymmetricCipher.Reset(ReadOnlySpan<byte> iv) => throw new NotImplementedException(); // never invoked
-
- private void Reset()
- {
- CryptographicOperations.ZeroMemory(_lastBlockBuffer);
- _lastBlockBuffer = null;
- }
- }
-}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoConfig.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoConfig.cs
index 6b52faa7a6d..d7397d28223 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoConfig.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CryptoConfig.cs
@@ -373,20 +373,6 @@ namespace System.Security.Cryptography
case "HMACSHA512":
case "System.Security.Cryptography.HMACSHA512":
return new HMACSHA512();
-
-#pragma warning disable SYSLIB0021 // Obsolete: derived cryptographic types
- case "AES":
- case "System.Security.Cryptography.AesCryptoServiceProvider":
- return new AesCryptoServiceProvider();
- case "AesManaged":
- case "System.Security.Cryptography.AesManaged":
- return new AesManaged();
- case "Rijndael":
- case "System.Security.Cryptography.Rijndael":
-#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
- return new RijndaelManaged();
-#pragma warning restore SYSLIB0022
-#pragma warning restore SYSLIB0021
}
return null;
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HMACHashProvider.Browser.Native.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HMACHashProvider.Browser.Native.cs
deleted file mode 100644
index 0ca7ccfc212..00000000000
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HMACHashProvider.Browser.Native.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.IO;
-using System.Diagnostics;
-using System.Security.Cryptography;
-
-using SimpleDigest = Interop.BrowserCrypto.SimpleDigest;
-
-namespace System.Security.Cryptography
-{
- internal sealed class HMACNativeHashProvider : HashProvider
- {
- private readonly int _hashSizeInBytes;
- private readonly SimpleDigest _hashAlgorithm;
- private readonly byte[] _key;
- private MemoryStream? _buffer;
-
- public HMACNativeHashProvider(string hashAlgorithmId, ReadOnlySpan<byte> key)
- {
- Debug.Assert(Interop.BrowserCrypto.CanUseSubtleCrypto);
-
- (_hashAlgorithm, _hashSizeInBytes) = SHANativeHashProvider.HashAlgorithmToPal(hashAlgorithmId);
- _key = key.ToArray();
- }
-
- public override void AppendHashData(ReadOnlySpan<byte> data)
- {
- _buffer ??= new MemoryStream(1000);
- _buffer.Write(data);
- }
-
- public override int FinalizeHashAndReset(Span<byte> destination)
- {
- int written = GetCurrentHash(destination);
- _buffer = null;
-
- return written;
- }
-
- public override int GetCurrentHash(Span<byte> destination)
- {
- Debug.Assert(destination.Length >= _hashSizeInBytes);
-
- ReadOnlySpan<byte> source = _buffer != null ?
- new ReadOnlySpan<byte>(_buffer.GetBuffer(), 0, (int)_buffer.Length) :
- default;
-
- Sign(_hashAlgorithm, _key, source, destination);
-
- return _hashSizeInBytes;
- }
-
- public static int MacDataOneShot(string hashAlgorithmId, ReadOnlySpan<byte> key, ReadOnlySpan<byte> data, Span<byte> destination)
- {
- (SimpleDigest hashName, int hashSizeInBytes) = SHANativeHashProvider.HashAlgorithmToPal(hashAlgorithmId);
- Debug.Assert(destination.Length >= hashSizeInBytes);
-
- Sign(hashName, key, data, destination);
-
- return hashSizeInBytes;
- }
-
- private static unsafe void Sign(SimpleDigest hashName, ReadOnlySpan<byte> key, ReadOnlySpan<byte> data, Span<byte> destination)
- {
- fixed (byte* k = key)
- fixed (byte* src = data)
- fixed (byte* dest = destination)
- {
- int res = Interop.BrowserCrypto.Sign(hashName, k, key.Length, src, data.Length, dest, destination.Length);
- if (res != 0)
- {
- throw new CryptographicException(SR.Format(SR.Unknown_SubtleCrypto_Error, res));
- }
- }
- }
-
- public override int HashSizeInBytes => _hashSizeInBytes;
-
- public override void Dispose(bool disposing)
- {
- if (disposing)
- {
- CryptographicOperations.ZeroMemory(_key);
- }
- }
-
- public override void Reset()
- {
- _buffer = null;
- }
- }
-}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderDispenser.Browser.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderDispenser.Browser.cs
index 8c604bb32b1..af0169bebd9 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderDispenser.Browser.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderDispenser.Browser.cs
@@ -13,9 +13,7 @@ namespace System.Security.Cryptography
case HashAlgorithmNames.SHA256:
case HashAlgorithmNames.SHA384:
case HashAlgorithmNames.SHA512:
- return Interop.BrowserCrypto.CanUseSubtleCrypto
- ? new SHANativeHashProvider(hashAlgorithmId)
- : new SHAManagedHashProvider(hashAlgorithmId);
+ return new SHAManagedHashProvider(hashAlgorithmId);
}
throw new CryptographicException(SR.Format(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithmId));
}
@@ -28,30 +26,16 @@ namespace System.Security.Cryptography
ReadOnlySpan<byte> source,
Span<byte> destination)
{
- if (Interop.BrowserCrypto.CanUseSubtleCrypto)
- {
- return HMACNativeHashProvider.MacDataOneShot(hashAlgorithmId, key, source, destination);
- }
- else
- {
- using HashProvider provider = CreateMacProvider(hashAlgorithmId, key);
- provider.AppendHashData(source);
- return provider.FinalizeHashAndReset(destination);
- }
+ using HashProvider provider = CreateMacProvider(hashAlgorithmId, key);
+ provider.AppendHashData(source);
+ return provider.FinalizeHashAndReset(destination);
}
public static int HashData(string hashAlgorithmId, ReadOnlySpan<byte> source, Span<byte> destination)
{
- if (Interop.BrowserCrypto.CanUseSubtleCrypto)
- {
- return SHANativeHashProvider.HashOneShot(hashAlgorithmId, source, destination);
- }
- else
- {
- HashProvider provider = CreateHashProvider(hashAlgorithmId);
- provider.AppendHashData(source);
- return provider.FinalizeHashAndReset(destination);
- }
+ HashProvider provider = CreateHashProvider(hashAlgorithmId);
+ provider.AppendHashData(source);
+ return provider.FinalizeHashAndReset(destination);
}
}
@@ -63,9 +47,7 @@ namespace System.Security.Cryptography
case HashAlgorithmNames.SHA256:
case HashAlgorithmNames.SHA384:
case HashAlgorithmNames.SHA512:
- return Interop.BrowserCrypto.CanUseSubtleCrypto
- ? new HMACNativeHashProvider(hashAlgorithmId, key)
- : new HMACManagedHashProvider(hashAlgorithmId, key);
+ return new HMACManagedHashProvider(hashAlgorithmId, key);
}
throw new CryptographicException(SR.Format(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithmId));
}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Pbkdf2Implementation.Browser.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Pbkdf2Implementation.Browser.cs
index dc087adb847..b5a59ab8d81 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Pbkdf2Implementation.Browser.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Pbkdf2Implementation.Browser.cs
@@ -4,8 +4,6 @@
using System.Diagnostics;
using Internal.Cryptography;
-using SimpleDigest = Interop.BrowserCrypto.SimpleDigest;
-
namespace System.Security.Cryptography
{
internal static partial class Pbkdf2Implementation
@@ -20,41 +18,7 @@ namespace System.Security.Cryptography
Debug.Assert(!destination.IsEmpty);
Debug.Assert(hashAlgorithmName.Name is not null);
- if (Interop.BrowserCrypto.CanUseSubtleCrypto)
- {
- FillSubtleCrypto(password, salt, iterations, hashAlgorithmName, destination);
- }
- else
- {
- FillManaged(password, salt, iterations, hashAlgorithmName, destination);
- }
- }
-
- private static unsafe void FillSubtleCrypto(
- ReadOnlySpan<byte> password,
- ReadOnlySpan<byte> salt,
- int iterations,
- HashAlgorithmName hashAlgorithmName,
- Span<byte> destination)
- {
- (SimpleDigest hashName, _) = SHANativeHashProvider.HashAlgorithmToPal(hashAlgorithmName.Name!);
-
- fixed (byte* pPassword = password)
- fixed (byte* pSalt = salt)
- fixed (byte* pDestination = destination)
- {
- int result = Interop.BrowserCrypto.DeriveBits(
- pPassword, password.Length,
- pSalt, salt.Length,
- iterations,
- hashName,
- pDestination, destination.Length);
-
- if (result != 0)
- {
- throw new CryptographicException(SR.Format(SR.Unknown_SubtleCrypto_Error, result));
- }
- }
+ FillManaged(password, salt, iterations, hashAlgorithmName, destination);
}
private static void FillManaged(
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Rijndael.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Rijndael.cs
index 1e21e1f00e1..4c9de50ee6e 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Rijndael.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Rijndael.cs
@@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
+using System.Runtime.Versioning;
using Internal.Cryptography;
namespace System.Security.Cryptography
@@ -11,6 +12,7 @@ namespace System.Security.Cryptography
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class Rijndael : SymmetricAlgorithm
{
+ [UnsupportedOSPlatform("browser")]
public static new Rijndael Create()
{
return new RijndaelImplementation();
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelImplementation.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelImplementation.cs
index ed33c655450..698926032df 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelImplementation.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelImplementation.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
+using System.Runtime.Versioning;
namespace System.Security.Cryptography
{
@@ -16,6 +17,7 @@ namespace System.Security.Cryptography
{
private readonly Aes _impl;
+ [UnsupportedOSPlatform("browser")]
internal RijndaelImplementation()
{
LegalBlockSizesValue = new KeySizes[] { new KeySizes(minSize: 128, maxSize: 128, skipSize: 0) };
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelManaged.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelManaged.cs
index 6727bdc71bc..2c866a2459f 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelManaged.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/RijndaelManaged.cs
@@ -3,11 +3,13 @@
using System.ComponentModel;
using System.Diagnostics;
+using System.Runtime.Versioning;
namespace System.Security.Cryptography
{
[Obsolete(Obsoletions.RijndaelMessage, DiagnosticId = Obsoletions.RijndaelDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
+ [UnsupportedOSPlatform("browser")]
public sealed class RijndaelManaged : Rijndael
{
private readonly Aes _impl;
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SHAHashProvider.Browser.Native.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SHAHashProvider.Browser.Native.cs
deleted file mode 100644
index d5d53c05e1a..00000000000
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SHAHashProvider.Browser.Native.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.IO;
-using System.Diagnostics;
-using System.Security.Cryptography;
-
-using SimpleDigest = Interop.BrowserCrypto.SimpleDigest;
-
-namespace System.Security.Cryptography
-{
- internal sealed class SHANativeHashProvider : HashProvider
- {
- private readonly int _hashSizeInBytes;
- private readonly SimpleDigest _impl;
- private MemoryStream? _buffer;
-
- public SHANativeHashProvider(string hashAlgorithmId)
- {
- Debug.Assert(Interop.BrowserCrypto.CanUseSubtleCrypto);
- (_impl, _hashSizeInBytes) = HashAlgorithmToPal(hashAlgorithmId);
- }
-
- public override void AppendHashData(ReadOnlySpan<byte> data)
- {
- _buffer ??= new MemoryStream(1000);
- _buffer.Write(data);
- }
-
- public override int FinalizeHashAndReset(Span<byte> destination)
- {
- GetCurrentHash(destination);
- _buffer = null;
-
- return _hashSizeInBytes;
- }
-
- public override int GetCurrentHash(Span<byte> destination)
- {
- Debug.Assert(destination.Length >= _hashSizeInBytes);
-
- ReadOnlySpan<byte> source = _buffer != null ?
- new ReadOnlySpan<byte>(_buffer.GetBuffer(), 0, (int)_buffer.Length) :
- default;
-
- SimpleDigestHash(_impl, source, destination);
-
- return _hashSizeInBytes;
- }
-
- public static int HashOneShot(string hashAlgorithmId, ReadOnlySpan<byte> data, Span<byte> destination)
- {
- (SimpleDigest impl, int hashSizeInBytes) = HashAlgorithmToPal(hashAlgorithmId);
- Debug.Assert(destination.Length >= hashSizeInBytes);
-
- SimpleDigestHash(impl, data, destination);
-
- return hashSizeInBytes;
- }
-
- private static unsafe void SimpleDigestHash(SimpleDigest hashName, ReadOnlySpan<byte> data, Span<byte> destination)
- {
- fixed (byte* src = data)
- fixed (byte* dest = destination)
- {
- int res = Interop.BrowserCrypto.SimpleDigestHash(hashName, src, data.Length, dest, destination.Length);
- if (res != 0)
- {
- throw new CryptographicException(SR.Format(SR.Unknown_SubtleCrypto_Error, res));
- }
- }
- }
-
- public override int HashSizeInBytes => _hashSizeInBytes;
-
- public override void Dispose(bool disposing)
- {
- }
-
- public override void Reset()
- {
- _buffer = null;
- }
-
- internal static (SimpleDigest HashName, int HashSizeInBytes) HashAlgorithmToPal(string hashAlgorithmId)
- {
- return hashAlgorithmId switch
- {
- HashAlgorithmNames.SHA256 => (SimpleDigest.Sha256, SHA256.HashSizeInBytes),
- HashAlgorithmNames.SHA1 => (SimpleDigest.Sha1, SHA1.HashSizeInBytes),
- HashAlgorithmNames.SHA384 => (SimpleDigest.Sha384, SHA384.HashSizeInBytes),
- HashAlgorithmNames.SHA512 => (SimpleDigest.Sha512, SHA512.HashSizeInBytes),
- _ => throw new CryptographicException(SR.Format(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithmId)),
- };
- }
- }
-}
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs
index 5adab7b88ab..c293c12374f 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs
@@ -33,7 +33,7 @@ namespace System.Security.Cryptography
}
}
- public static int PadBlock(ReadOnlySpan<byte> block, Span<byte> destination, int paddingSizeInBytes, PaddingMode paddingMode)
+ public static int PadBlock(ReadOnlySpan<byte> block, Span<byte> destination, int paddingSizeInBytes, PaddingMode paddingMode)
{
int count = block.Length;
int paddingRemainder = count % paddingSizeInBytes;
diff --git a/src/libraries/System.Security.Cryptography/tests/AesManagedTests.cs b/src/libraries/System.Security.Cryptography/tests/AesManagedTests.cs
index e38c92d6554..2db62616df8 100644
--- a/src/libraries/System.Security.Cryptography/tests/AesManagedTests.cs
+++ b/src/libraries/System.Security.Cryptography/tests/AesManagedTests.cs
@@ -11,6 +11,7 @@ namespace System.Security.Cryptography.Tests
/// <summary>
/// Since AesManaged wraps Aes, we only test minimally here.
/// </summary>
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public class AesManagedTests
{
[Fact]
@@ -26,7 +27,6 @@ namespace System.Security.Cryptography.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void EncryptDecryptKnownECB192()
{
byte[] plainTextBytes =
diff --git a/src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs b/src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs
deleted file mode 100644
index 6e2d7322f53..00000000000
--- a/src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Reflection;
-using Xunit;
-
-namespace System.Security.Cryptography.Tests
-{
- public partial class AesTests
- {
- private static byte[] s_plainText = new byte[] { 0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89, 0xB9, 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59 };
- private static byte[] s_iv = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- private static byte[] s_destination = new byte[s_plainText.Length];
-
- [Fact]
- public static void AesThrows_PlatformNotSupported_CipherMode_Browser()
- {
- using (Aes aes = Aes.Create())
- {
- Assert.Throws<PlatformNotSupportedException>(() => aes.EncryptEcb(s_plainText, PaddingMode.PKCS7));
- Assert.Throws<PlatformNotSupportedException>(() => aes.EncryptEcb(s_plainText.AsSpan(), PaddingMode.PKCS7));
- Assert.Throws<PlatformNotSupportedException>(() => aes.EncryptEcb(s_plainText.AsSpan(), s_destination, PaddingMode.PKCS7));
- Assert.Throws<PlatformNotSupportedException>(() => aes.DecryptEcb(s_plainText, PaddingMode.PKCS7));
- Assert.Throws<PlatformNotSupportedException>(() => aes.DecryptEcb(s_plainText.AsSpan(), PaddingMode.PKCS7));
- Assert.Throws<PlatformNotSupportedException>(() => aes.DecryptEcb(s_plainText.AsSpan(), s_destination, PaddingMode.PKCS7));
-
- Assert.Throws<PlatformNotSupportedException>(() => aes.EncryptCfb(s_plainText, s_iv));
- Assert.Throws<PlatformNotSupportedException>(() => aes.EncryptCfb(s_plainText.AsSpan(), s_iv.AsSpan()));
- Assert.Throws<PlatformNotSupportedException>(() => aes.EncryptCfb(s_plainText.AsSpan(), s_iv, s_destination));
- Assert.Throws<PlatformNotSupportedException>(() => aes.DecryptCfb(s_plainText, s_iv));
- Assert.Throws<PlatformNotSupportedException>(() => aes.DecryptCfb(s_plainText.AsSpan(), s_iv.AsSpan()));
- Assert.Throws<PlatformNotSupportedException>(() => aes.DecryptCfb(s_plainText.AsSpan(), s_iv, s_destination));
-
- aes.Mode = CipherMode.ECB;
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateEncryptor());
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateEncryptor(s_iv, s_iv));
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateDecryptor());
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateDecryptor(s_iv, s_iv));
-
- aes.Mode = CipherMode.CFB;
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateEncryptor());
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateEncryptor(s_iv, s_iv));
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateDecryptor());
- Assert.Throws<PlatformNotSupportedException>(() => aes.CreateDecryptor(s_iv, s_iv));
- }
- }
-
- // Browser's SubtleCrypto doesn't support AES-192
- [Fact]
- public static void Aes_InvalidKeySize_192_Browser()
- {
- byte[] key192 = new byte[192 / 8];
- using (Aes aes = Aes.Create())
- {
- Assert.False(aes.ValidKeySize(192));
- Assert.Throws<CryptographicException>(() => aes.Key = key192);
- Assert.Throws<CryptographicException>(() => aes.KeySize = 192);
- Assert.Throws<ArgumentException>(() => aes.CreateEncryptor(key192, s_iv));
- Assert.Throws<ArgumentException>(() => aes.CreateDecryptor(key192, s_iv));
- }
- }
-
- [Fact]
- public static void EnsureSubtleCryptoIsUsed()
- {
- bool canUseSubtleCrypto = (bool)Type.GetType("Interop+BrowserCrypto, System.Security.Cryptography")
- .GetField("CanUseSubtleCrypto", BindingFlags.NonPublic | BindingFlags.Static)
- .GetValue(null);
-
- bool expectedCanUseSubtleCrypto = Environment.GetEnvironmentVariable("TEST_EXPECT_SUBTLE_CRYPTO") == "true";
-
- Assert.Equal(expectedCanUseSubtleCrypto, canUseSubtleCrypto);
- }
- }
-}
diff --git a/src/libraries/System.Security.Cryptography/tests/AesTests.cs b/src/libraries/System.Security.Cryptography/tests/AesTests.cs
index e9ee4b43581..815014cc908 100644
--- a/src/libraries/System.Security.Cryptography/tests/AesTests.cs
+++ b/src/libraries/System.Security.Cryptography/tests/AesTests.cs
@@ -5,6 +5,7 @@ using Xunit;
namespace System.Security.Cryptography.Tests
{
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public partial class AesTests
{
[Fact]
diff --git a/src/libraries/System.Security.Cryptography/tests/CryptoConfigTests.cs b/src/libraries/System.Security.Cryptography/tests/CryptoConfigTests.cs
index babea22f6cd..964b4668a61 100644
--- a/src/libraries/System.Security.Cryptography/tests/CryptoConfigTests.cs
+++ b/src/libraries/System.Security.Cryptography/tests/CryptoConfigTests.cs
@@ -106,36 +106,23 @@ namespace System.Security.Cryptography.Tests
}
}
- public static IEnumerable<object[]> NamedSymmetricAlgorithmCreateData
- {
- get
- {
- yield return new object[] { "AES", typeof(Aes) };
-#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
- yield return new object[] { "Rijndael", typeof(Rijndael) };
- yield return new object[] { "System.Security.Cryptography.Rijndael", typeof(Rijndael) };
-#pragma warning restore SYSLIB0022
-
- if (PlatformDetection.IsNotBrowser)
- {
+ [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBuiltWithAggressiveTrimming))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
+ [InlineData("AES", typeof(Aes))]
#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
- yield return new object[] { "http://www.w3.org/2001/04/xmlenc#aes128-cbc", typeof(Rijndael) };
- yield return new object[] { "http://www.w3.org/2001/04/xmlenc#aes192-cbc", typeof(Rijndael) };
- yield return new object[] { "http://www.w3.org/2001/04/xmlenc#aes256-cbc", typeof(Rijndael) };
+ [InlineData("Rijndael", typeof(Rijndael))]
+ [InlineData("System.Security.Cryptography.Rijndael", typeof(Rijndael))]
+ [InlineData("http://www.w3.org/2001/04/xmlenc#aes128-cbc", typeof(Rijndael))]
+ [InlineData("http://www.w3.org/2001/04/xmlenc#aes192-cbc", typeof(Rijndael))]
+ [InlineData("http://www.w3.org/2001/04/xmlenc#aes256-cbc", typeof(Rijndael))]
#pragma warning restore SYSLIB0022
- yield return new object[] { "3DES", typeof(TripleDES) };
- yield return new object[] { "TripleDES", typeof(TripleDES) };
- yield return new object[] { "System.Security.Cryptography.TripleDES", typeof(TripleDES) };
- yield return new object[] { "http://www.w3.org/2001/04/xmlenc#tripledes-cbc", typeof(TripleDES) };
- yield return new object[] { "DES", typeof(DES) };
- yield return new object[] { "System.Security.Cryptography.DES", typeof(DES) };
- yield return new object[] { "http://www.w3.org/2001/04/xmlenc#des-cbc", typeof(DES) };
- }
- }
- }
-
- [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBuiltWithAggressiveTrimming))]
- [MemberData(nameof(NamedSymmetricAlgorithmCreateData))]
+ [InlineData("3DES", typeof(TripleDES))]
+ [InlineData("TripleDES", typeof(TripleDES))]
+ [InlineData("System.Security.Cryptography.TripleDES", typeof(TripleDES))]
+ [InlineData("http://www.w3.org/2001/04/xmlenc#tripledes-cbc", typeof(TripleDES))]
+ [InlineData("DES", typeof(DES))]
+ [InlineData("System.Security.Cryptography.DES", typeof(DES))]
+ [InlineData("http://www.w3.org/2001/04/xmlenc#des-cbc", typeof(DES))]
public static void NamedSymmetricAlgorithmCreate(string identifier, Type baseType)
{
using (SymmetricAlgorithm created = SymmetricAlgorithm.Create(identifier))
@@ -371,15 +358,6 @@ namespace System.Security.Cryptography.Tests
yield return new object[] { "HMACSHA512", "System.Security.Cryptography.HMACSHA512", true };
yield return new object[] { "System.Security.Cryptography.HMACSHA512", null, true };
- yield return new object[] { "AES", "System.Security.Cryptography.AesCryptoServiceProvider", true };
- yield return new object[] { "System.Security.Cryptography.AesCryptoServiceProvider", "System.Security.Cryptography.AesCryptoServiceProvider", true };
- yield return new object[] { "AesManaged", typeof(AesManaged).FullName, true };
- yield return new object[] { "System.Security.Cryptography.AesManaged", typeof(AesManaged).FullName, true };
-#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
- yield return new object[] { "Rijndael", typeof(RijndaelManaged).FullName, true };
- yield return new object[] { "System.Security.Cryptography.Rijndael", typeof(RijndaelManaged).FullName, true };
-#pragma warning restore SYSLIB0022 // Rijndael types are obsolete
-
if (PlatformDetection.IsBrowser)
{
// Hash functions
@@ -444,9 +422,15 @@ namespace System.Security.Cryptography.Tests
yield return new object[] { "RC2", "System.Security.Cryptography.RC2CryptoServiceProvider", true };
yield return new object[] { "System.Security.Cryptography.RC2", "System.Security.Cryptography.RC2CryptoServiceProvider", true };
#pragma warning disable SYSLIB0022 // Rijndael types are obsolete
+ yield return new object[] { "Rijndael", typeof(RijndaelManaged).FullName, true };
+ yield return new object[] { "System.Security.Cryptography.Rijndael", typeof(RijndaelManaged).FullName, true };
yield return new object[] { "System.Security.Cryptography.SymmetricAlgorithm", typeof(RijndaelManaged).FullName, true };
#pragma warning restore SYSLIB0022 // Rijndael types are obsolete
+ yield return new object[] { "AES", "System.Security.Cryptography.AesCryptoServiceProvider", true };
yield return new object[] { "AesCryptoServiceProvider", "System.Security.Cryptography.AesCryptoServiceProvider", true };
+ yield return new object[] { "System.Security.Cryptography.AesCryptoServiceProvider", "System.Security.Cryptography.AesCryptoServiceProvider", true };
+ yield return new object[] { "AesManaged", typeof(AesManaged).FullName, true };
+ yield return new object[] { "System.Security.Cryptography.AesManaged", typeof(AesManaged).FullName, true };
// Xml Dsig/ Enc Hash algorithms
yield return new object[] { "http://www.w3.org/2000/09/xmldsig#sha1", "System.Security.Cryptography.SHA1CryptoServiceProvider", true };
diff --git a/src/libraries/System.Security.Cryptography/tests/PaddingModeTests.cs b/src/libraries/System.Security.Cryptography/tests/PaddingModeTests.cs
index 21541682781..dbde519a416 100644
--- a/src/libraries/System.Security.Cryptography/tests/PaddingModeTests.cs
+++ b/src/libraries/System.Security.Cryptography/tests/PaddingModeTests.cs
@@ -10,6 +10,7 @@ using Xunit;
namespace System.Security.Cryptography.Tests
{
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public static class PaddingModeTests
{
[Theory]
diff --git a/src/libraries/System.Security.Cryptography/tests/RijndaelTests.cs b/src/libraries/System.Security.Cryptography/tests/RijndaelTests.cs
index b35973aa377..d8e9f975cae 100644
--- a/src/libraries/System.Security.Cryptography/tests/RijndaelTests.cs
+++ b/src/libraries/System.Security.Cryptography/tests/RijndaelTests.cs
@@ -13,6 +13,7 @@ namespace System.Security.Cryptography.Tests
/// Since RijndaelImplementation (from Rijndael.Create()) and RijndaelManaged classes wrap Aes,
/// we only test minimally here.
/// </summary>
+ [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public class RijndaelTests
{
[Fact]
@@ -89,7 +90,6 @@ namespace System.Security.Cryptography.Tests
}
[Fact]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.ECB is not supported on Browser")]
public static void EncryptDecryptKnownECB192()
{
static void test(Rijndael alg)
@@ -300,7 +300,6 @@ namespace System.Security.Cryptography.Tests
[InlineData(128)]
[InlineData(8)]
[InlineData(null)]
- [SkipOnPlatform(TestPlatforms.Browser, "CipherMode.CFB is not supported on Browser")]
public static void CfbFeedbackSizeIsRespected(int? feedbackSize)
{
// Windows 7 CFB only supports CFB8.
diff --git a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj
index 9b95e193b87..50e110c0445 100644
--- a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj
+++ b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj
@@ -13,10 +13,6 @@
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
</PropertyGroup>
- <PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
- <WasmXHarnessMonoArgs Condition="'$(ContinuousIntegrationBuild)' != 'true' and '$(UseSubtleCryptoForTests)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=TEST_EXPECT_SUBTLE_CRYPTO=true</WasmXHarnessMonoArgs>
- <WasmXHarnessArgs Condition="'$(ContinuousIntegrationBuild)' != 'true' and '$(UseSubtleCryptoForTests)' == 'true'">$(WasmXHarnessArgs) --web-server-use-cop</WasmXHarnessArgs>
- </PropertyGroup>
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'Android'">
<UseAndroidCrypto>true</UseAndroidCrypto>
<XUnitSingleThreadedMode>true</XUnitSingleThreadedMode>
@@ -313,9 +309,6 @@
<Compile Include="DefaultECDsaProvider.Android.cs" />
<Compile Include="DefaultECDiffieHellmanProvider.Android.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Browser'">
- <Compile Include="AesTests.Browser.cs" />
- </ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Cryptography.Pkcs\src\System.Security.Cryptography.Pkcs.csproj" />
diff --git a/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt b/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt
index 93dd3423e9b..1361a3c323a 100644
--- a/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt
+++ b/src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt
@@ -28,7 +28,6 @@ CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatfo
CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Security.Cryptography.RC2.Create()' changed from '[UnsupportedOSPlatformAttribute("android")]' in the contract to '[UnsupportedOSPlatformAttribute("android")]' in the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Rfc2898DeriveBytes' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Rijndael' in the contract but not the implementation.
-CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RijndaelManaged' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSA' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSAEncryptionPadding' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSAOAEPKeyExchangeDeformatter' in the contract but not the implementation.
@@ -61,7 +60,6 @@ CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAtt
CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAttribute' exists on 'System.Numerics.Vector<T>.TryCopyTo(System.Span<T>)' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.RequiresPreviewFeaturesAttribute' exists on 'System.String System.Runtime.CompilerServices.RuntimeFeature.VirtualStaticsInInterfaces' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Aes' in the contract but not the implementation.
-CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AesManaged' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AsymmetricKeyExchangeDeformatter' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AsymmetricKeyExchangeFormatter' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AsymmetricSignatureDeformatter' in the contract but not the implementation.
@@ -93,7 +91,6 @@ CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatfo
CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Security.Cryptography.RC2.Create()' changed from '[UnsupportedOSPlatformAttribute("android")]' in the contract to '[UnsupportedOSPlatformAttribute("android")]' in the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Rfc2898DeriveBytes' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Rijndael' in the contract but not the implementation.
-CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RijndaelManaged' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSA' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSAEncryptionPadding' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSAOAEPKeyExchangeDeformatter' in the contract but not the implementation.
@@ -112,7 +109,6 @@ Compat issues with assembly System.Core:
CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute' exists on 'System.Linq.EnumerableQuery<T>..ctor(System.Collections.Generic.IEnumerable<T>)' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute' exists on 'System.Linq.EnumerableQuery<T>..ctor(System.Linq.Expressions.Expression)' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Aes' in the contract but not the implementation.
-CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AesManaged' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.ECCurve' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.ECDiffieHellman' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.ECDsa' in the contract but not the implementation.
@@ -156,7 +152,6 @@ MembersMustExist : Member 'public System.Runtime.Intrinsics.Vector256<U> System.
MembersMustExist : Member 'public System.Runtime.Intrinsics.Vector64<U> System.Runtime.Intrinsics.Vector64.As<T, U>(System.Runtime.Intrinsics.Vector64<T>)' does not exist in the implementation but it does exist in the contract.
Compat issues with assembly System.Security.Cryptography.Algorithms:
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Aes' in the contract but not the implementation.
-CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AesManaged' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AsymmetricKeyExchangeDeformatter' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AsymmetricKeyExchangeFormatter' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.AsymmetricSignatureDeformatter' in the contract but not the implementation.
@@ -189,7 +184,6 @@ CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatfo
CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Security.Cryptography.RC2.Create()' changed from '[UnsupportedOSPlatformAttribute("android")]' in the contract to '[UnsupportedOSPlatformAttribute("android")]' in the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Rfc2898DeriveBytes' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.Rijndael' in the contract but not the implementation.
-CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RijndaelManaged' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSA' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSAEncryptionPadding' in the contract but not the implementation.
CannotRemoveAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' exists on 'System.Security.Cryptography.RSAOAEPKeyExchangeDeformatter' in the contract but not the implementation.
@@ -203,4 +197,4 @@ Compat issues with assembly System.Security.Cryptography.X509Certificates:
CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Security.Cryptography.X509Certificates.PublicKey.GetDSAPublicKey()' changed from '[UnsupportedOSPlatformAttribute("ios")]' in the contract to '[UnsupportedOSPlatformAttribute("browser")]' in the implementation.
Compat issues with assembly System.Text.Json:
CannotMakeTypeAbstract : Type 'System.Text.Json.Serialization.Metadata.JsonTypeInfo' is abstract in the implementation but is not abstract in the contract.
-Total Issues: 190
+Total Issues: 184
diff --git a/src/mono/wasi/mono-wasi-driver/driver.c b/src/mono/wasi/mono-wasi-driver/driver.c
index 78b1bfa94e9..80a0339a0df 100644
--- a/src/mono/wasi/mono-wasi-driver/driver.c
+++ b/src/mono/wasi/mono-wasi-driver/driver.c
@@ -324,15 +324,6 @@ static PinvokeImport SystemGlobalizationNativeImports [] = {
{NULL, NULL}
};
-int SystemCryptoNativeBrowser_CanUseSubtleCryptoImpl() {
- return 0;
-}
-
-static PinvokeImport SystemSecurityCryptographyNativeBrowserImports [] = {
- {"SystemCryptoNativeBrowser_CanUseSubtleCryptoImpl", SystemCryptoNativeBrowser_CanUseSubtleCryptoImpl },
- {NULL, NULL}
-};
-
static void*
wasm_dl_load (const char *name, int flags, char **err, void *user_data)
{
@@ -340,8 +331,6 @@ wasm_dl_load (const char *name, int flags, char **err, void *user_data)
return SystemNativeImports;
if (!strcmp (name, "libSystem.Globalization.Native"))
return SystemGlobalizationNativeImports;
- if (!strcmp (name, "libSystem.Security.Cryptography.Native.Browser"))
- return SystemSecurityCryptographyNativeBrowserImports;
//printf("In wasm_dl_load for name %s but treating as NOT FOUND\n", name);
return 0;
diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets
index f45230c3346..14070469f0d 100644
--- a/src/mono/wasm/build/WasmApp.Native.targets
+++ b/src/mono/wasm/build/WasmApp.Native.targets
@@ -272,7 +272,6 @@
<_WasmPInvokeModules Include="libSystem.Native" />
<_WasmPInvokeModules Include="libSystem.IO.Compression.Native" />
<_WasmPInvokeModules Include="libSystem.Globalization.Native" />
- <_WasmPInvokeModules Include="libSystem.Security.Cryptography.Native.Browser" />
</ItemGroup>
<PropertyGroup>
diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets
index 602896b55da..2df2cf3dde0 100644
--- a/src/mono/wasm/build/WasmApp.targets
+++ b/src/mono/wasm/build/WasmApp.targets
@@ -286,7 +286,6 @@
<_HasDotnetWasm Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.wasm'">true</_HasDotnetWasm>
<_HasDotnetJsWorker Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.worker.js'">true</_HasDotnetJsWorker>
- <_HasDotnetJsCryptoWorker Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet-crypto-worker.js'">true</_HasDotnetJsCryptoWorker>
<_HasDotnetJsSymbols Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.js.symbols'">true</_HasDotnetJsSymbols>
<_HasDotnetJs Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.js'">true</_HasDotnetJs>
</PropertyGroup>
@@ -296,7 +295,6 @@
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.wasm" Condition="'$(_HasDotnetWasm)' != 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.js" Condition="'$(_HasDotnetJs)' != 'true'" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.worker.js" Condition="'$(_HasDotnetJsWorker)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.worker.js')" />
- <WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet-crypto-worker.js" Condition="'$(_HasDotnetJsCryptoWorker)' != 'true' and Exists('$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet-crypto-worker.js')" />
<WasmNativeAsset Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)dotnet.js.symbols"
Condition="'$(WasmEmitSymbolMap)' == 'true' and
'$(_HasDotnetJsSymbols)' != 'true' and
diff --git a/src/mono/wasm/runtime/CMakeLists.txt b/src/mono/wasm/runtime/CMakeLists.txt
index 2eeb255fb41..76a17f73e0c 100644
--- a/src/mono/wasm/runtime/CMakeLists.txt
+++ b/src/mono/wasm/runtime/CMakeLists.txt
@@ -27,8 +27,7 @@ target_link_libraries(dotnet
${MONO_ARTIFACTS_DIR}/libmono-wasm-eh-js.a
${MONO_ARTIFACTS_DIR}/libmono-profiler-aot.a
${NATIVE_BIN_DIR}/libSystem.Native.a
- ${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a
- ${NATIVE_BIN_DIR}/libSystem.Security.Cryptography.Native.Browser.a)
+ ${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a)
set_target_properties(dotnet PROPERTIES
LINK_DEPENDS "${NATIVE_BIN_DIR}/src/emcc-default.rsp;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js;${NATIVE_BIN_DIR}/src/es6/runtime.es6.iffe.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js;${NATIVE_BIN_DIR}/src/pal_random.lib.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.post.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js;"
diff --git a/src/mono/wasm/runtime/assets.ts b/src/mono/wasm/runtime/assets.ts
index 8d44101617b..80d63429102 100644
--- a/src/mono/wasm/runtime/assets.ts
+++ b/src/mono/wasm/runtime/assets.ts
@@ -28,7 +28,6 @@ let throttlingPromise: PromiseAndController<void> | undefined;
const skipDownloadsByAssetTypes: {
[k: string]: boolean
} = {
- "js-module-crypto": true,
"js-module-threads": true,
};
@@ -43,7 +42,6 @@ const skipBufferByAssetTypes: {
const skipInstantiateByAssetTypes: {
[k: string]: boolean
} = {
- "js-module-crypto": true,
"js-module-threads": true,
"dotnetwasm": true,
};
@@ -356,7 +354,6 @@ function _instantiate_asset(asset: AssetEntry, url: string, bytes: Uint8Array) {
switch (asset.behavior) {
case "dotnetwasm":
- case "js-module-crypto":
case "js-module-threads":
// do nothing
break;
diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts
index 704b8ab94e2..83accc3b01b 100644
--- a/src/mono/wasm/runtime/dotnet.d.ts
+++ b/src/mono/wasm/runtime/dotnet.d.ts
@@ -166,7 +166,7 @@ interface AssetEntry extends ResourceRequest {
*/
pendingDownload?: LoadingResource;
}
-declare type AssetBehaviours = "resource" | "assembly" | "pdb" | "heap" | "icu" | "vfs" | "dotnetwasm" | "js-module-crypto" | "js-module-threads";
+declare type AssetBehaviours = "resource" | "assembly" | "pdb" | "heap" | "icu" | "vfs" | "dotnetwasm" | "js-module-threads";
declare type GlobalizationMode = "icu" | // load ICU globalization data from any runtime assets with behavior "icu".
"invariant" | // operate in invariant globalization mode.
"auto";
diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js
index 74aed3030e8..bde650aea36 100644
--- a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js
+++ b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js
@@ -95,13 +95,6 @@ const linked_functions = [
"mono_wasm_load_icu_data",
"mono_wasm_get_icudt_name",
- // pal_crypto_webworker.c
- "dotnet_browser_can_use_subtle_crypto_impl",
- "dotnet_browser_simple_digest_hash",
- "dotnet_browser_sign",
- "dotnet_browser_encrypt_decrypt",
- "dotnet_browser_derive_bits",
-
#if USE_PTHREADS
/// mono-threads-wasm.c
"mono_wasm_pthread_on_pthread_attached",
diff --git a/src/mono/wasm/runtime/exports-linker.ts b/src/mono/wasm/runtime/exports-linker.ts
index 89dfc822b99..22f8a66cdee 100644
--- a/src/mono/wasm/runtime/exports-linker.ts
+++ b/src/mono/wasm/runtime/exports-linker.ts
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
import MonoWasmThreads from "consts:monoWasmThreads";
-import { dotnet_browser_can_use_subtle_crypto_impl, dotnet_browser_simple_digest_hash, dotnet_browser_sign, dotnet_browser_encrypt_decrypt, dotnet_browser_derive_bits } from "./subtle-crypto";
import { mono_wasm_fire_debugger_agent_message, mono_wasm_debugger_log, mono_wasm_add_dbg_command_received, mono_wasm_set_entrypoint_breakpoint } from "./debug";
import { mono_wasm_release_cs_owned_object } from "./gc-handles";
import { mono_wasm_load_icu_data, mono_wasm_get_icudt_name } from "./icu";
@@ -78,14 +77,7 @@ export function export_linker(): any {
mono_wasm_load_icu_data,
mono_wasm_get_icudt_name,
- // pal_crypto_webworker.c
- dotnet_browser_can_use_subtle_crypto_impl,
- dotnet_browser_simple_digest_hash,
- dotnet_browser_sign,
- dotnet_browser_encrypt_decrypt,
- dotnet_browser_derive_bits,
-
// threading exports, if threading is enabled
...mono_wasm_threads_exports,
};
-} \ No newline at end of file
+}
diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts
index 68996b266d2..c576927f177 100644
--- a/src/mono/wasm/runtime/startup.ts
+++ b/src/mono/wasm/runtime/startup.ts
@@ -13,7 +13,6 @@ import { mono_wasm_init_aot_profiler, mono_wasm_init_coverage_profiler } from ".
import { mono_on_abort, mono_exit } from "./run";
import { initialize_marshalers_to_cs } from "./marshal-to-cs";
import { initialize_marshalers_to_js } from "./marshal-to-js";
-import { init_crypto } from "./subtle-crypto";
import { init_polyfills_async } from "./polyfills";
import * as pthreads_worker from "./pthreads/worker";
import { createPromiseController } from "./promise-controller";
@@ -255,7 +254,6 @@ async function mono_wasm_pre_init_essential_async(): Promise<void> {
await init_polyfills_async();
await mono_wasm_load_config(Module.configSrc);
- init_crypto();
if (MonoWasmThreads) {
preAllocatePThreadWorkerPool(MONO_PTHREAD_POOL_SIZE, config);
diff --git a/src/mono/wasm/runtime/subtle-crypto.ts b/src/mono/wasm/runtime/subtle-crypto.ts
deleted file mode 100644
index 8a60cc5ef93..00000000000
--- a/src/mono/wasm/runtime/subtle-crypto.ts
+++ /dev/null
@@ -1,412 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-import { resolve_asset_path } from "./assets";
-import { Module, runtimeHelpers } from "./imports";
-import { mono_assert } from "./types";
-
-class OperationFailedError extends Error { }
-
-const ERR_ARGS = -1;
-const ERR_WORKER_FAILED = -2;
-const ERR_OP_FAILED = -3;
-const ERR_UNKNOWN = -100;
-
-let mono_wasm_crypto: {
- channel: LibraryChannel
- worker: Worker
-} | null = null;
-
-export function dotnet_browser_can_use_subtle_crypto_impl(): number {
- return mono_wasm_crypto === null ? 0 : 1;
-}
-
-export function dotnet_browser_simple_digest_hash(ver: number, input_buffer: number, input_len: number, output_buffer: number, output_len: number): number {
- const msg = {
- func: "digest",
- type: ver,
- data: Array.from(Module.HEAPU8.subarray(input_buffer, input_buffer + input_len))
- };
-
- return _send_simple_msg(msg, "DIGEST HASH", output_buffer, output_len);
-}
-
-export function dotnet_browser_sign(hashAlgorithm: number, key_buffer: number, key_len: number, input_buffer: number, input_len: number, output_buffer: number, output_len: number): number {
- const msg = {
- func: "sign",
- type: hashAlgorithm,
- key: Array.from(Module.HEAPU8.subarray(key_buffer, key_buffer + key_len)),
- data: Array.from(Module.HEAPU8.subarray(input_buffer, input_buffer + input_len))
- };
-
- return _send_simple_msg(msg, "SIGN HASH", output_buffer, output_len);
-}
-
-const AesBlockSizeBytes = 16; // 128 bits
-
-export function dotnet_browser_encrypt_decrypt(isEncrypting: boolean, key_buffer: number, key_len: number, iv_buffer: number, iv_len: number, input_buffer: number, input_len: number, output_buffer: number, output_len: number): number {
- if (input_len <= 0 || input_len % AesBlockSizeBytes !== 0) {
- throw "ENCRYPT DECRYPT: data was not a full block: " + input_len;
- }
-
- const msg = {
- func: "encrypt_decrypt",
- isEncrypting: isEncrypting,
- key: Array.from(Module.HEAPU8.subarray(key_buffer, key_buffer + key_len)),
- iv: Array.from(Module.HEAPU8.subarray(iv_buffer, iv_buffer + iv_len)),
- data: Array.from(Module.HEAPU8.subarray(input_buffer, input_buffer + input_len))
- };
-
- const result = _send_msg_worker(msg);
- if (typeof result === "number") {
- return result;
- }
-
- if (result.length > output_len) {
- console.error(`MONO_WASM_ENCRYPT_DECRYPT: Encrypt/Decrypt length exceeds output length: ${result.length} > ${output_len}`);
- return ERR_ARGS;
- }
-
- Module.HEAPU8.set(result, output_buffer);
- return result.length;
-}
-
-export function dotnet_browser_derive_bits(password_buffer: number, password_len: number, salt_buffer: number, salt_len: number, iterations: number, hashAlgorithm: number, output_buffer: number, output_len: number): number {
- const msg = {
- func: "derive_bits",
- password: Array.from(Module.HEAPU8.subarray(password_buffer, password_buffer + password_len)),
- salt: Array.from(Module.HEAPU8.subarray(salt_buffer, salt_buffer + salt_len)),
- iterations: iterations,
- hashAlgorithm: hashAlgorithm,
- lengthInBytes: output_len
- };
-
- return _send_simple_msg(msg, "DERIVE BITS", output_buffer, output_len);
-}
-
-function _send_simple_msg(msg: any, prefix: string, output_buffer: number, output_len: number): number {
- const result = _send_msg_worker(msg);
-
- if (typeof result === "number") {
- return result;
- }
-
- if (result.length > output_len) {
- console.error(`MONO_WASM_ENCRYPT_DECRYPT: ${prefix}: Result length exceeds output length: ${result.length} > ${output_len}`);
- return ERR_ARGS;
- }
-
- Module.HEAPU8.set(result, output_buffer);
- return 0;
-}
-
-export function init_crypto(): void {
- if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.subtle !== "undefined"
- && typeof SharedArrayBuffer !== "undefined"
- && typeof Worker !== "undefined"
- ) {
- console.debug("MONO_WASM: Initializing Crypto WebWorker");
-
- const chan = LibraryChannel.create(1024); // 1024 is the buffer size in char units.
- const asset = resolve_asset_path("js-module-crypto");
- mono_assert(asset && asset.resolvedUrl, "Can't find js-module-crypto");
- const worker = new Worker(asset.resolvedUrl);
- mono_wasm_crypto = {
- channel: chan,
- worker: worker,
- };
- const messageData: InitCryptoMessageData = {
- config: JSON.stringify(runtimeHelpers.config),// there could be things in config which could not be cloned to worker
- comm_buf: chan.get_comm_buffer(),
- msg_buf: chan.get_msg_buffer(),
- msg_char_len: chan.get_msg_len()
- };
- worker.onerror = event => {
- console.warn(`MONO_WASM: Error in Crypto WebWorker. Cryptography digest calls will fallback to managed implementation. Error: ${event.message}`);
- mono_wasm_crypto = null;
- };
- worker.postMessage(messageData);
- }
-}
-
-function _send_msg_worker(msg: any): number | any {
- mono_assert(!!mono_wasm_crypto, "subtle crypto not initialized");
-
- try {
- const response = mono_wasm_crypto.channel.send_msg(JSON.stringify(msg));
- const responseJson = JSON.parse(response);
-
- if (responseJson.error !== undefined) {
- console.error(`MONO_WASM_ENCRYPT_DECRYPT: Worker failed with: ${responseJson.error}`);
- if (responseJson.error_type == "ArgumentsError")
- return ERR_ARGS;
- if (responseJson.error_type == "WorkerFailedError")
- return ERR_WORKER_FAILED;
-
- return ERR_UNKNOWN;
- }
-
- return responseJson.result;
- } catch (err) {
- if (err instanceof Error && err.stack !== undefined)
- console.error(`MONO_WASM_ENCRYPT_DECRYPT: ${err.stack}`);
- else
- console.error(`MONO_WASM_ENCRYPT_DECRYPT: _send_msg_worker failed: ${err}`);
- return ERR_OP_FAILED;
- }
-}
-
-class LibraryChannel {
- private msg_char_len: number;
- private comm_buf: SharedArrayBuffer;
- private msg_buf: SharedArrayBuffer;
- private comm: Int32Array;
- private msg: Uint16Array;
-
- // LOCK states
- private get LOCK_UNLOCKED(): number { return 0; } // 0 means the lock is unlocked
- private get LOCK_OWNED(): number { return 1; } // 1 means the LibraryChannel owns the lock
-
- // Index constants for the communication buffer.
- private get STATE_IDX(): number { return 0; }
- private get MSG_SIZE_IDX(): number { return 1; }
- private get LOCK_IDX(): number { return 2; }
- private get COMM_LAST_IDX(): number { return this.LOCK_IDX; }
-
- // Communication states.
- private get STATE_SHUTDOWN(): number { return -1; } // Shutdown
- private get STATE_IDLE(): number { return 0; }
- private get STATE_REQ(): number { return 1; }
- private get STATE_RESP(): number { return 2; }
- private get STATE_REQ_P(): number { return 3; } // Request has multiple parts
- private get STATE_RESP_P(): number { return 4; } // Response has multiple parts
- private get STATE_AWAIT(): number { return 5; } // Awaiting the next part
- private get STATE_REQ_FAILED(): number { return 6; } // The Request failed
- private get STATE_RESET(): number { return 7; } // Reset to a known state
-
- private constructor(msg_char_len: number) {
- this.msg_char_len = msg_char_len;
-
- const int_bytes = 4;
- const comm_byte_len = int_bytes * (this.COMM_LAST_IDX + 1);
- this.comm_buf = new SharedArrayBuffer(comm_byte_len);
-
- // JavaScript character encoding is UTF-16.
- const char_bytes = 2;
- const msg_byte_len = char_bytes * this.msg_char_len;
- this.msg_buf = new SharedArrayBuffer(msg_byte_len);
-
- // Create the local arrays to use.
- this.comm = new Int32Array(this.comm_buf);
- this.msg = new Uint16Array(this.msg_buf);
- }
-
- public get_msg_len(): number { return this.msg_char_len; }
- public get_msg_buffer(): SharedArrayBuffer { return this.msg_buf; }
- public get_comm_buffer(): SharedArrayBuffer { return this.comm_buf; }
-
- public send_msg(msg: string): string {
- try {
- this.wait_for_state_change_to(pstate => pstate == this.STATE_IDLE, "waiting");
- this.send_request(msg);
- return this.read_response();
- } catch (err) {
- this.reset(LibraryChannel.stringify_err(err));
- throw err;
- }
- }
-
- public shutdown(): void {
- console.debug("MONO_WASM_ENCRYPT_DECRYPT: Shutting down crypto");
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state !== this.STATE_IDLE)
- throw new Error(`OWNER: Invalid sync communication channel state: ${state}`);
-
- this.using_lock(() => {
- Atomics.store(this.comm, this.MSG_SIZE_IDX, 0);
- this.change_state_locked(this.STATE_SHUTDOWN);
- });
- // Notify webworker
- Atomics.notify(this.comm, this.STATE_IDX);
- }
-
- private reset(reason: string): void {
- console.debug(`MONO_WASM_ENCRYPT_DECRYPT: reset: ${reason}`);
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state === this.STATE_SHUTDOWN)
- return;
-
- if (state === this.STATE_RESET || state === this.STATE_IDLE) {
- console.debug(`MONO_WASM_ENCRYPT_DECRYPT: state is already RESET or idle: ${state}`);
- return;
- }
-
- this.using_lock(() => {
- Atomics.store(this.comm, this.MSG_SIZE_IDX, 0);
- this.change_state_locked(this.STATE_RESET);
- });
- // Notify webworker
- Atomics.notify(this.comm, this.STATE_IDX);
- }
-
- private send_request(msg: string): void {
- let state;
- const msg_len = msg.length;
- let msg_written = 0;
-
- for (; ;) {
- this.using_lock(() => {
- // Write the message and return how much was written.
- const wrote = this.write_to_msg(msg, msg_written, msg_len);
- msg_written += wrote;
-
- // Indicate how much was written to the this.msg buffer.
- Atomics.store(this.comm, this.MSG_SIZE_IDX, wrote);
-
- // Indicate if this was the whole message or part of it.
- state = msg_written === msg_len ? this.STATE_REQ : this.STATE_REQ_P;
-
- this.change_state_locked(state);
- });
- // Notify webworker
- Atomics.notify(this.comm, this.STATE_IDX);
-
- // The send message is complete.
- if (state === this.STATE_REQ) {
- break;
- }
- else if (state !== this.STATE_REQ_P) {
- throw new Error(`Unexpected state ${state}`);
- }
-
- this.wait_for_state_change_to(state => state == this.STATE_AWAIT, "send_request");
- }
- }
-
- private write_to_msg(input: string, start: number, input_len: number): number {
- let mi = 0;
- let ii = start;
- while (mi < this.msg_char_len && ii < input_len) {
- this.msg[mi] = input.charCodeAt(ii);
- ii++; // Next character
- mi++; // Next buffer index
- }
- return ii - start;
- }
-
- private read_response(): string {
- let response = "";
- for (; ;) {
- this.wait_for_state_change_to(state => state == this.STATE_RESP || state == this.STATE_RESP_P, "read_response");
- const done = this.using_lock(() => {
- const size_to_read = Atomics.load(this.comm, this.MSG_SIZE_IDX);
-
- // Append the latest part of the message.
- response += this.read_from_msg(0, size_to_read);
-
- // The response is complete.
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state === this.STATE_RESP) {
- Atomics.store(this.comm, this.MSG_SIZE_IDX, 0);
- return true;
- } else if (state !== this.STATE_RESP_P) {
- throw new Error(`Unexpected state ${state}`);
- }
-
- // Reset the size and transition to await state.
- Atomics.store(this.comm, this.MSG_SIZE_IDX, 0);
- this.change_state_locked(this.STATE_AWAIT);
- return false;
- });
-
- // Notify webworker
- Atomics.notify(this.comm, this.STATE_IDX);
-
- if (done) {
- break;
- }
- }
-
- // Reset the communication channel's state and let the
- // webworker know we are done.
- this.using_lock(() => {
- this.change_state_locked(this.STATE_IDLE);
- });
- Atomics.notify(this.comm, this.STATE_IDX);
-
- return response;
- }
-
- private change_state_locked(newState: number): void {
- Atomics.store(this.comm, this.STATE_IDX, newState);
- }
-
- private wait_for_state_change_to(is_ready: (state: number) => boolean, msg: string): void {
- // Wait for webworker
- // - Atomics.wait() is not permissible on the main thread.
- for (; ;) {
- const done = this.using_lock(() => {
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state == this.STATE_REQ_FAILED)
- throw new OperationFailedError(`Worker failed during ${msg} with state=${state}`);
-
- if (is_ready(state))
- return true;
- });
- if (done) return;
- }
- }
-
- private read_from_msg(begin: number, end: number): string {
- const slicedMessage: number[] = [];
- this.msg.slice(begin, end).forEach((value, index) => slicedMessage[index] = value);
- return String.fromCharCode.apply(null, slicedMessage);
- }
-
- private using_lock(callback: Function) {
- try {
- this.acquire_lock();
- return callback();
- } finally {
- this.release_lock();
- }
- }
-
- private acquire_lock() {
- for (; ;) {
- const lock_state = Atomics.compareExchange(this.comm, this.LOCK_IDX, this.LOCK_UNLOCKED, this.LOCK_OWNED);
-
- if (lock_state === this.LOCK_UNLOCKED) {
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state === this.STATE_REQ_FAILED)
- throw new OperationFailedError("Worker failed");
- return;
- }
- }
- }
-
- private release_lock() {
- const result = Atomics.compareExchange(this.comm, this.LOCK_IDX, this.LOCK_OWNED, this.LOCK_UNLOCKED);
- if (result !== this.LOCK_OWNED) {
- throw new Error("CRYPTO: LibraryChannel tried to release a lock that wasn't acquired: " + result);
- }
- }
-
- private static stringify_err(err: any) {
- return (err instanceof Error && err.stack !== undefined) ? err.stack : err;
- }
-
- public static create(msg_char_len: number): LibraryChannel {
- if (msg_char_len === undefined) {
- msg_char_len = 1024; // Default size is arbitrary but is in 'char' units (i.e. UTF-16 code points).
- }
- return new LibraryChannel(msg_char_len);
- }
-}
-
-export type InitCryptoMessageData = {
- config: string,// serialized to avoid passing non-clonable objects
- comm_buf: SharedArrayBuffer,
- msg_buf: SharedArrayBuffer,
- msg_char_len: number
-}
diff --git a/src/mono/wasm/runtime/types.ts b/src/mono/wasm/runtime/types.ts
index ac6256b5679..ea01f16a9e5 100644
--- a/src/mono/wasm/runtime/types.ts
+++ b/src/mono/wasm/runtime/types.ts
@@ -195,7 +195,6 @@ export type AssetBehaviours =
| "icu" // load asset as an ICU data archive
| "vfs" // load asset into the virtual filesystem (for fopen, File.Open, etc)
| "dotnetwasm" // the binary of the dotnet runtime
- | "js-module-crypto" // the javascript module for subtle crypto
| "js-module-threads" // the javascript module for threads
export type RuntimeHelpers = {
diff --git a/src/mono/wasm/runtime/workers/dotnet-crypto-worker.ts b/src/mono/wasm/runtime/workers/dotnet-crypto-worker.ts
deleted file mode 100644
index 47aeba44882..00000000000
--- a/src/mono/wasm/runtime/workers/dotnet-crypto-worker.ts
+++ /dev/null
@@ -1,404 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-import { setup_proxy_console } from "../logging";
-import type { InitCryptoMessageData } from "../subtle-crypto";
-import type { MonoConfig } from "../types";
-
-class FailedOrStoppedLoopError extends Error { }
-class ArgumentsError extends Error { }
-class WorkerFailedError extends Error { }
-
-class ChannelWorker {
- // LOCK states
- get LOCK_UNLOCKED() { return 0; } // 0 means the lock is unlocked
- get LOCK_OWNED() { return 2; } // 2 means the ChannelWorker owns the lock
-
- // BEGIN ChannelOwner contract - shared constants.
- get STATE_IDX() { return 0; }
- get MSG_SIZE_IDX() { return 1; }
- get LOCK_IDX() { return 2; }
-
- // Communication states.
- get STATE_SHUTDOWN() { return -1; } // Shutdown
- get STATE_IDLE() { return 0; }
- get STATE_REQ() { return 1; }
- get STATE_RESP() { return 2; }
- get STATE_REQ_P() { return 3; } // Request has multiple parts
- get STATE_RESP_P() { return 4; } // Response has multiple parts
- get STATE_AWAIT() { return 5; } // Awaiting the next part
- get STATE_REQ_FAILED() { return 6; } // The Request failed
- get STATE_RESET() { return 7; } // Reset to a known state
- // END ChannelOwner contract - shared constants.
-
- private comm: Int32Array;
- private msg: Uint16Array;
- private msg_char_len: number;
-
- constructor(comm_buf: SharedArrayBuffer, msg_buf: SharedArrayBuffer, msg_char_len: number) {
- this.comm = new Int32Array(comm_buf);
- this.msg = new Uint16Array(msg_buf);
- this.msg_char_len = msg_char_len;
- }
-
- async run_message_loop(async_op: (jsonRequest: string) => Promise<number[]>) {
- for (; ;) {
- try {
- // Wait for signal to perform operation
- let state;
- do {
- this.wait_for_state_to_change_from(this.STATE_IDLE);
- state = Atomics.load(this.comm, this.STATE_IDX);
- } while (state !== this.STATE_REQ && state !== this.STATE_REQ_P && state !== this.STATE_SHUTDOWN && state !== this.STATE_REQ_FAILED && state !== this.STATE_RESET);
-
- this.throw_if_reset_or_shutdown();
-
- // Read in request
- const request_json = this.read_request();
- const response: any = {};
- try {
- // Perform async action based on request
- response.result = await async_op(request_json);
- }
- catch (err) {
- response.error_type = typeof err;
- response.error = _stringify_err(err);
- console.error(`MONO_WASM: Request error: ${response.error}. req was: ${request_json}`);
- }
-
- // Send response
- this.send_response(JSON.stringify(response));
- } catch (err) {
- if (err instanceof FailedOrStoppedLoopError) {
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state === this.STATE_SHUTDOWN)
- break;
- if (state === this.STATE_RESET)
- console.debug("MONO_WASM: caller failed, resetting worker");
- } else {
- console.error(`MONO_WASM: Worker failed to handle the request: ${_stringify_err(err)}`);
- this.using_lock(() => {
- this.change_state_locked(this.STATE_REQ_FAILED);
- });
-
- console.debug("MONO_WASM: set state to failed, now waiting to get RESET");
- Atomics.wait(this.comm, this.STATE_IDX, this.STATE_REQ_FAILED);
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state !== this.STATE_RESET) {
- throw new WorkerFailedError(`expected to RESET, but got ${state}`);
- }
- }
-
- this.using_lock(() => {
- Atomics.store(this.comm, this.MSG_SIZE_IDX, 0);
- Atomics.store(this.comm, this.LOCK_IDX, this.LOCK_UNLOCKED);
- this.change_state_locked(this.STATE_IDLE);
- });
- }
-
- const state = Atomics.load(this.comm, this.STATE_IDX);
- const lock_state = Atomics.load(this.comm, this.LOCK_IDX);
-
- if (state !== this.STATE_IDLE && state !== this.STATE_REQ && state !== this.STATE_REQ_P)
- console.error(`MONO_WASM: -- state is not idle at the top of the loop: ${state}, and lock_state: ${lock_state}`);
- if (lock_state !== this.LOCK_UNLOCKED && state !== this.STATE_REQ && state !== this.STATE_REQ_P && state !== this.STATE_IDLE)
- console.error(`MONO_WASM: -- lock is not unlocked at the top of the loop: ${lock_state}, and state: ${state}`);
- }
-
- this.using_lock(() => {
- Atomics.store(this.comm, this.MSG_SIZE_IDX, 0);
- this.change_state_locked(this.STATE_SHUTDOWN);
- });
- console.debug("MONO_WASM: ******* run_message_loop ending");
- }
-
- private read_request(): string {
- let request = "";
- for (; ;) {
- const done = this.using_lock(() => {
- this.throw_if_reset_or_shutdown();
-
- // Get the current state and message size
- const state = Atomics.load(this.comm, this.STATE_IDX);
- const size_to_read = Atomics.load(this.comm, this.MSG_SIZE_IDX);
-
- const view = this.msg.subarray(0, size_to_read);
- const part = String.fromCharCode(...view);
- // Append the latest part of the message.
- request += part;
-
- // The request is complete.
- if (state === this.STATE_REQ) {
- return true;
- } else if (state !== this.STATE_REQ_P) {
- throw new Error(`Unexpected state ${state}`);
- }
-
- // Shutdown the worker.
- this.throw_if_reset_or_shutdown();
-
- // Reset the size and transition to await state.
- Atomics.store(this.comm, this.MSG_SIZE_IDX, 0);
- this.change_state_locked(this.STATE_AWAIT);
- });
- if (done) {
- break;
- }
-
- this.wait_for_state_to_change_from(this.STATE_AWAIT);
- }
-
- return request;
- }
-
- private send_response(msg: string) {
- if (Atomics.load(this.comm, this.STATE_IDX) !== this.STATE_REQ)
- throw new WorkerFailedError("WORKER: Invalid sync communication channel state.");
-
- const msg_len = msg.length;
- let msg_written = 0;
-
- for (; ;) {
- const state = this.using_lock(() => {
- // Write the message and return how much was written.
- const wrote = this.write_to_msg(msg, msg_written, msg_len);
- msg_written += wrote;
-
- // Indicate how much was written to the this.msg buffer.
- Atomics.store(this.comm, this.MSG_SIZE_IDX, wrote);
-
- // Indicate if this was the whole message or part of it.
- const state = msg_written === msg_len ? this.STATE_RESP : this.STATE_RESP_P;
-
- // Update the state
- this.change_state_locked(state);
-
- return state;
- });
-
- // Wait for the transition to know the main thread has
- // received the response by moving onto a new state.
- this.wait_for_state_to_change_from(state);
-
- // Done sending response.
- if (state === this.STATE_RESP) {
- break;
- } else if (state !== this.STATE_RESP_P) {
- throw new Error(`Unexpected state ${state}`);
- }
- }
- }
-
- private write_to_msg(input: string, start: number, input_len: number) {
- let mi = 0;
- let ii = start;
- while (mi < this.msg_char_len && ii < input_len) {
- this.msg[mi] = input.charCodeAt(ii);
- ii++; // Next character
- mi++; // Next buffer index
- }
- return ii - start;
- }
-
- private change_state_locked(newState: number) {
- Atomics.store(this.comm, this.STATE_IDX, newState);
- }
-
- private using_lock(callback: Function) {
- try {
- this.acquire_lock();
- return callback();
- } finally {
- this.release_lock();
- }
- }
-
- private acquire_lock() {
- for (; ;) {
- const lockState = Atomics.compareExchange(this.comm, this.LOCK_IDX, this.LOCK_UNLOCKED, this.LOCK_OWNED);
- this.throw_if_reset_or_shutdown();
-
- if (lockState === this.LOCK_UNLOCKED)
- return;
- }
- }
-
- private release_lock() {
- const result = Atomics.compareExchange(this.comm, this.LOCK_IDX, this.LOCK_OWNED, this.LOCK_UNLOCKED);
- if (result !== this.LOCK_OWNED) {
- throw new WorkerFailedError("CRYPTO: ChannelWorker tried to release a lock that wasn't acquired: " + result);
- }
- }
-
- private wait_for_state_to_change_from(expected_state: number) {
- Atomics.wait(this.comm, this.STATE_IDX, expected_state);
- this.throw_if_reset_or_shutdown();
- }
-
- private throw_if_reset_or_shutdown() {
- const state = Atomics.load(this.comm, this.STATE_IDX);
- if (state === this.STATE_RESET || state === this.STATE_SHUTDOWN)
- throw new FailedOrStoppedLoopError();
- }
-}
-
-async function call_digest(type: number, data: Uint8Array) {
- const digest_type = get_hash_name(type);
-
- // The 'crypto' API is not available in non-browser
- // environments (for example, v8 server).
- const digest = await crypto.subtle.digest(digest_type, data);
- return Array.from(new Uint8Array(digest));
-}
-
-async function sign(type: number, key: Uint8Array, data: Uint8Array) {
- const hash_name = get_hash_name(type);
-
- if (key.length === 0) {
- // crypto.subtle.importKey will raise an error for an empty key.
- // To prevent an error, reset it to a key with just a `0x00` byte. This is equivalent
- // since HMAC keys get zero-extended up to the block size of the algorithm.
- key = new Uint8Array([0]);
- }
-
- const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "HMAC", hash: hash_name }, false /* extractable */, ["sign"]);
- const signResult = await crypto.subtle.sign("HMAC", cryptoKey, data);
- return Array.from(new Uint8Array(signResult));
-}
-
-async function derive_bits(password: Uint8Array, salt: Uint8Array, iterations: number, hashAlgorithm: number, lengthInBytes: number) {
- const hash_name = get_hash_name(hashAlgorithm);
-
- const passwordKey = await importKey(password, "PBKDF2", ["deriveBits"]);
- const result = await crypto.subtle.deriveBits(
- {
- name: "PBKDF2",
- salt: salt,
- iterations: iterations,
- hash: hash_name
- },
- passwordKey,
- lengthInBytes * 8 // deriveBits takes number of bits
- );
-
- return Array.from(new Uint8Array(result));
-}
-
-function get_hash_name(type: number) {
- switch (type) {
- case 0: return "SHA-1";
- case 1: return "SHA-256";
- case 2: return "SHA-384";
- case 3: return "SHA-512";
- default:
- throw new ArgumentsError("CRYPTO: Unknown digest: " + type);
- }
-}
-
-const AesBlockSizeBytes = 16; // 128 bits
-
-async function encrypt_decrypt(isEncrypting: boolean, key: number[], iv: number[], data: number[]) {
- const algorithmName = "AES-CBC";
- const keyUsage: KeyUsage[] = isEncrypting ? ["encrypt"] : ["encrypt", "decrypt"];
- const cryptoKey = await importKey(new Uint8Array(key), algorithmName, keyUsage);
- const algorithm = {
- name: algorithmName,
- iv: new Uint8Array(iv)
- };
-
- const result = await (isEncrypting ?
- crypto.subtle.encrypt(
- algorithm,
- cryptoKey,
- new Uint8Array(data)) :
- decrypt(
- algorithm,
- cryptoKey,
- data));
-
- let resultByteArray = new Uint8Array(result);
- if (isEncrypting) {
- // trim off the last block, which is always a padding block.
- resultByteArray = resultByteArray.slice(0, resultByteArray.length - AesBlockSizeBytes);
- }
- return Array.from(resultByteArray);
-}
-
-async function decrypt(algorithm: Algorithm, cryptoKey: CryptoKey, data: number[]) {
- // crypto.subtle AES-CBC will only allow a PaddingMode of PKCS7, but we need to use
- // PaddingMode None. To simulate this, we only decrypt full blocks of data, with an extra full
- // padding block of 0x10 (16) bytes appended to data. crypto.subtle will see that padding block and return
- // the fully decrypted message. To create the encrypted padding block, we encrypt an empty array using the
- // last block of the cipher text as the IV. This will create a full block of padding bytes.
-
- const paddingBlockIV = new Uint8Array(data).slice(data.length - AesBlockSizeBytes);
- const empty = new Uint8Array();
- const encryptedPaddingBlockResult = await crypto.subtle.encrypt(
- {
- name: algorithm.name,
- iv: paddingBlockIV
- },
- cryptoKey,
- empty
- );
-
- const encryptedPaddingBlock = new Uint8Array(encryptedPaddingBlockResult);
- for (let i = 0; i < encryptedPaddingBlock.length; i++) {
- data.push(encryptedPaddingBlock[i]);
- }
-
- return await crypto.subtle.decrypt(
- algorithm,
- cryptoKey,
- new Uint8Array(data));
-}
-
-function importKey(key: ArrayBuffer, algorithmName: string, keyUsage: KeyUsage[]) {
- return crypto.subtle.importKey(
- "raw",
- key,
- {
- name: algorithmName
- },
- false /* extractable */,
- keyUsage);
-}
-
-// Operation to perform.
-async function handle_req_async(jsonRequest: string): Promise<number[]> {
- const req = JSON.parse(jsonRequest);
-
- if (req.func === "digest") {
- return await call_digest(req.type, new Uint8Array(req.data));
- }
- else if (req.func === "sign") {
- return await sign(req.type, new Uint8Array(req.key), new Uint8Array(req.data));
- }
- else if (req.func === "encrypt_decrypt") {
- return await encrypt_decrypt(req.isEncrypting, req.key, req.iv, req.data);
- }
- else if (req.func === "derive_bits") {
- return await derive_bits(new Uint8Array(req.password), new Uint8Array(req.salt), req.iterations, req.hashAlgorithm, req.lengthInBytes);
- }
- else {
- throw new ArgumentsError("CRYPTO: Unknown request: " + req.func);
- }
-}
-
-function _stringify_err(err: any) {
- return (err instanceof Error && err.stack !== undefined) ? err.stack : err;
-}
-
-let s_channel;
-let config: MonoConfig = <any>null;
-
-// Initialize WebWorker
-self.addEventListener("message", (event: MessageEvent) => {
- const data = event.data as InitCryptoMessageData;
- config = data && data.config ? JSON.parse(data.config) : {};
- if (config.diagnosticTracing) {
- setup_proxy_console("crypto-worker", console, self.location.origin);
- }
- s_channel = new ChannelWorker(data.comm_buf, data.msg_buf, data.msg_char_len);
- s_channel.run_message_loop(handle_req_async);
-});
diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj
index 8ba45094fb9..cac849c5818 100644
--- a/src/mono/wasm/wasm.proj
+++ b/src/mono/wasm/wasm.proj
@@ -26,7 +26,6 @@
<_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp</_EmccCompileRspPath>
<_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp</_EmccLinkRspPath>
<WasmNativeStrip Condition="'$(ContinuousIntegrationBuild)' == 'true'">false</WasmNativeStrip>
- <SystemCryptoNativeDir>$(RepoRoot)\src\native\libs\System.Security.Cryptography.Native.Browser</SystemCryptoNativeDir>
</PropertyGroup>
<Target Name="CheckEnv">
@@ -62,7 +61,6 @@
<WasmPInvokeModule Include="libSystem.Native" />
<WasmPInvokeModule Include="libSystem.IO.Compression.Native" />
<WasmPInvokeModule Include="libSystem.Globalization.Native" />
- <WasmPInvokeModule Include="libSystem.Security.Cryptography.Native.Browser" />
<WasmPInvokeAssembly Include="@(LibrariesRuntimeFiles)" Condition="'%(Extension)' == '.dll' and '%(IsNative)' != 'true'" />
</ItemGroup>
@@ -295,7 +293,6 @@
$(NativeBinDir)dotnet-legacy.d.ts;
$(NativeBinDir)package.json;
$(NativeBinDir)dotnet.wasm;
- $(NativeBinDir)\src\dotnet-crypto-worker.js;
$(NativeBinDir)dotnet.timezones.blat"
DestinationFolder="$(MicrosoftNetCoreAppRuntimePackNativeDir)"
SkipUnchangedFiles="true" />
diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt
index cbb208d0a7f..11d3799129b 100644
--- a/src/native/libs/CMakeLists.txt
+++ b/src/native/libs/CMakeLists.txt
@@ -156,7 +156,7 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER)
add_subdirectory(System.Native)
if (CLR_CMAKE_TARGET_BROWSER)
- add_subdirectory(System.Security.Cryptography.Native.Browser)
+ # skip for now
elseif (CLR_CMAKE_TARGET_MACCATALYST)
add_subdirectory(System.Net.Security.Native)
# System.Security.Cryptography.Native is intentionally disabled on iOS
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt
deleted file mode 100644
index c411aa9ee9c..00000000000
--- a/src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-project(System.Security.Cryptography.Native.Browser C)
-
-set (NATIVE_SOURCES
- pal_crypto_webworker.c
-)
-
-add_library (System.Security.Cryptography.Native.Browser-Static
- STATIC
- ${NATIVE_SOURCES}
-)
-
-set_target_properties(System.Security.Cryptography.Native.Browser-Static PROPERTIES OUTPUT_NAME System.Security.Cryptography.Native.Browser CLEAN_DIRECT_OUTPUT 1)
-
-install (TARGETS System.Security.Cryptography.Native.Browser-Static DESTINATION ${STATIC_LIB_DESTINATION})
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h
deleted file mode 100644
index 775fe634536..00000000000
--- a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-#pragma once
-
-#include <emscripten.h>
-
-#ifndef __EMSCRIPTEN__
-#error Cryptography Native Browser is designed to be compiled with Emscripten.
-#endif // __EMSCRIPTEN__
-
-#ifndef PALEXPORT
-#ifdef TARGET_UNIX
-#define PALEXPORT __attribute__ ((__visibility__ ("default")))
-#else
-#define PALEXPORT __declspec(dllexport)
-#endif
-#endif // PALEXPORT
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c
deleted file mode 100644
index 6514ddafb3a..00000000000
--- a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c
+++ /dev/null
@@ -1,99 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-#include "pal_browser.h"
-#include "pal_crypto_webworker.h"
-
-// Forward declarations
-extern int32_t dotnet_browser_simple_digest_hash(
- enum simple_digest ver,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len);
-
-extern int32_t dotnet_browser_sign(
- enum simple_digest hashAlgorithm,
- uint8_t* key_buffer,
- int32_t key_len,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len);
-
-extern int32_t dotnet_browser_encrypt_decrypt(
- int32_t encrypting,
- uint8_t* key_buffer,
- int32_t key_len,
- uint8_t* iv_buffer,
- int32_t iv_len,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len);
-
-extern int32_t dotnet_browser_derive_bits(
- uint8_t* password_buffer,
- int32_t password_len,
- uint8_t* salt_buffer,
- int32_t salt_len,
- int32_t iterations,
- enum simple_digest hashAlgorithm,
- uint8_t* output_buffer,
- int32_t output_len);
-
-extern int32_t dotnet_browser_can_use_subtle_crypto_impl(void);
-
-int32_t SystemCryptoNativeBrowser_SimpleDigestHash(
- enum simple_digest ver,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len)
-{
- return dotnet_browser_simple_digest_hash(ver, input_buffer, input_len, output_buffer, output_len);
-}
-
-int32_t SystemCryptoNativeBrowser_Sign(
- enum simple_digest hashAlgorithm,
- uint8_t* key_buffer,
- int32_t key_len,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len)
-{
- return dotnet_browser_sign(hashAlgorithm, key_buffer, key_len, input_buffer, input_len, output_buffer, output_len);
-}
-
-int32_t SystemCryptoNativeBrowser_EncryptDecrypt(
- int32_t encrypting,
- uint8_t* key_buffer,
- int32_t key_len,
- uint8_t* iv_buffer,
- int32_t iv_len,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len)
-{
- return dotnet_browser_encrypt_decrypt(encrypting, key_buffer, key_len, iv_buffer, iv_len, input_buffer, input_len, output_buffer, output_len);
-}
-
-int32_t SystemCryptoNativeBrowser_DeriveBits(
- uint8_t* password_buffer,
- int32_t password_len,
- uint8_t* salt_buffer,
- int32_t salt_len,
- int32_t iterations,
- enum simple_digest hashAlgorithm,
- uint8_t* output_buffer,
- int32_t output_len)
-{
- return dotnet_browser_derive_bits(password_buffer, password_len, salt_buffer, salt_len, iterations, hashAlgorithm, output_buffer, output_len);
-}
-
-int32_t SystemCryptoNativeBrowser_CanUseSubtleCryptoImpl(void)
-{
- return dotnet_browser_can_use_subtle_crypto_impl();
-}
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h
deleted file mode 100644
index 6129a6a286c..00000000000
--- a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-#pragma once
-
-#include <stdint.h>
-
-// These values are also defined in the System.Security.Cryptography library's
-// browser-crypto implementation, and utilized in the dotnet-crypto-worker in the wasm runtime.
-enum simple_digest
-{
- sd_sha_1,
- sd_sha_256,
- sd_sha_384,
- sd_sha_512,
-};
-
-PALEXPORT int32_t SystemCryptoNativeBrowser_SimpleDigestHash(
- enum simple_digest ver,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len);
-
-PALEXPORT int32_t SystemCryptoNativeBrowser_Sign(
- enum simple_digest ver,
- uint8_t* key_buffer,
- int32_t key_len,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len);
-
-PALEXPORT int32_t SystemCryptoNativeBrowser_EncryptDecrypt(
- int32_t encrypting,
- uint8_t* key_buffer,
- int32_t key_len,
- uint8_t* iv_buffer,
- int32_t iv_len,
- uint8_t* input_buffer,
- int32_t input_len,
- uint8_t* output_buffer,
- int32_t output_len);
-
-PALEXPORT int32_t SystemCryptoNativeBrowser_DeriveBits(
- uint8_t* password_buffer,
- int32_t password_len,
- uint8_t* salt_buffer,
- int32_t salt_len,
- int32_t iterations,
- enum simple_digest hashAlgorithm,
- uint8_t* output_buffer,
- int32_t output_len);
-
-PALEXPORT int32_t SystemCryptoNativeBrowser_CanUseSubtleCryptoImpl(void);
diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs
index de43aee1d97..c45a413ef53 100644
--- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs
+++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs
@@ -109,11 +109,6 @@ public class WasmAppBuilder : Task
public WasmEntry(string name) : base(name, "dotnetwasm") { }
}
- private sealed class CryptoWorkerEntry : AssetEntry
- {
- public CryptoWorkerEntry(string name) : base(name, "js-module-crypto") { }
- }
-
private sealed class ThreadsWorkerEntry : AssetEntry
{
public ThreadsWorkerEntry(string name) : base(name, "js-module-threads") { }
@@ -320,7 +315,6 @@ public class WasmAppBuilder : Task
config.Assets.Add(new VfsEntry ("dotnet.timezones.blat") { VirtualPath = "/usr/share/zoneinfo/"});
config.Assets.Add(new WasmEntry ("dotnet.wasm") );
- config.Assets.Add(new CryptoWorkerEntry ("dotnet-crypto-worker.js") );
if (IncludeThreadsWorker)
config.Assets.Add(new ThreadsWorkerEntry ("dotnet.worker.js") );
diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
index a2fd1c3c247..9e3b2e5b0b7 100644
--- a/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
+++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs
@@ -552,8 +552,7 @@ namespace Wasm.Build.Tests
"dotnet.timezones.blat",
"dotnet.wasm",
"mono-config.json",
- "dotnet.js",
- "dotnet-crypto-worker.js"
+ "dotnet.js"
});
AssertFilesExist(bundleDir, new[] { "run-v8.sh" }, expectToExist: hasV8Script);
diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/NativeLibraryTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/NativeLibraryTests.cs
index d5f0d0f5975..278f5872125 100644
--- a/src/tests/BuildWasmApps/Wasm.Build.Tests/NativeLibraryTests.cs
+++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/NativeLibraryTests.cs
@@ -140,7 +140,7 @@ public class Test
output);
string cryptoInitMsg = "MONO_WASM: Initializing Crypto WebWorker";
- Assert.Contains(cryptoInitMsg, output);
+ Assert.DoesNotContain(cryptoInitMsg, output);
}
}
}