enum
{
CIPHER_NONE = 0,
- CIPHER_IS_SUPPORTED = 1,
- CIPHER_HAS_TAG = 2,
- CIPHER_REQUIRES_IV = 4,
+ CIPHER_HAS_TAG = 1,
+ CIPHER_REQUIRES_IV = 2,
};
typedef uint32_t CipherFlags;
#define DEFINE_CIPHER(cipherId, width, javaName, flags) \
CipherInfo* AndroidCryptoNative_ ## cipherId() \
{ \
- static CipherInfo info = { flags | CIPHER_IS_SUPPORTED, width, javaName }; \
- return &info; \
-}
-
-#define DEFINE_UNSUPPORTED_CIPHER(cipherId) \
-CipherInfo* AndroidCryptoNative_ ## cipherId() \
-{ \
- static CipherInfo info = { CIPHER_NONE, 0, NULL }; \
+ static CipherInfo info = { flags, width, javaName }; \
return &info; \
}
DEFINE_CIPHER(Des3Cbc, 128, "DESede/CBC/NoPadding", CIPHER_REQUIRES_IV)
DEFINE_CIPHER(Des3Cfb8, 128, "DESede/CFB8/NoPadding", CIPHER_REQUIRES_IV)
DEFINE_CIPHER(Des3Cfb64, 128, "DESede/CFB/NoPadding", CIPHER_REQUIRES_IV)
-DEFINE_UNSUPPORTED_CIPHER(RC2Ecb)
-DEFINE_UNSUPPORTED_CIPHER(RC2Cbc)
-
-
-static bool IsSupported(CipherInfo* type)
-{
- return (type->flags & CIPHER_IS_SUPPORTED) == CIPHER_IS_SUPPORTED;
-}
static bool HasTag(CipherInfo* type)
{
return (type->flags & CIPHER_REQUIRES_IV) == CIPHER_REQUIRES_IV;
}
-static int32_t GetAlgorithmDefaultWidth(CipherInfo* type)
-{
- if (!IsSupported(type))
- {
- assert(false);
- return FAIL;
- }
- return type->width;
-}
-
static jobject GetAlgorithmName(JNIEnv* env, CipherInfo* type)
{
- if (!IsSupported(type))
- {
- LOG_ERROR("This cipher is not supported");
- assert(false);
- return FAIL;
- }
return JSTRING(type->name);
}
ctx->cipher = cipher;
ctx->type = type;
ctx->tagLength = TAG_MAX_LENGTH;
- ctx->keySizeInBits = GetAlgorithmDefaultWidth(type);
+ ctx->keySizeInBits = type->width;
ctx->ivLength = 0;
ctx->encMode = 0;
ctx->key = NULL;
PALEXPORT CipherInfo* AndroidCryptoNative_DesEcb(void);
PALEXPORT CipherInfo* AndroidCryptoNative_DesCfb8(void);
PALEXPORT CipherInfo* AndroidCryptoNative_DesCbc(void);
-PALEXPORT CipherInfo* AndroidCryptoNative_RC2Ecb(void);
-PALEXPORT CipherInfo* AndroidCryptoNative_RC2Cbc(void);
--- /dev/null
+// 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.Security.Cryptography;
+
+namespace Internal.Cryptography
+{
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA5350", Justification = "We are providing the implementation for RC2, not consuming it.")]
+ internal sealed partial class RC2Implementation : RC2
+ {
+ private static ICryptoTransform CreateTransformCore(
+ CipherMode cipherMode,
+ PaddingMode paddingMode,
+ byte[] key,
+ int effectiveKeyLength,
+ byte[]? iv,
+ int blockSize,
+ int feedbackSizeInBytes,
+ int paddingSize,
+ bool encrypting)
+ {
+ throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_AlgorithmNotSupported, nameof(RC2)));
+ }
+ }
+}
<data name="Cryptography_AlgKdfRequiresChars" xml:space="preserve">
<value>The KDF for algorithm '{0}' requires a char-based password input.</value>
</data>
+ <data name="Cryptography_AlgorithmNotSupported" xml:space="preserve">
+ <value>Algorithm '{0}' is not supported on this platform.</value>
+ </data>
<data name="Cryptography_ArgECDHKeySizeMismatch" xml:space="preserve">
<value>The keys from both parties must be the same size to generate a secret agreement.</value>
</data>
<Compile Include="Internal\Cryptography\OpenSslCipher.cs" />
<Compile Condition="'$(TargetsBrowser)' != 'true'" Include="Internal\Cryptography\RandomNumberGeneratorImplementation.Unix.cs" />
<Compile Condition="'$(TargetsBrowser)' != 'true'" Include="Internal\Cryptography\Pbkdf2Implementation.Unix.cs" />
- <Compile Include="Internal\Cryptography\RC2Implementation.Unix.cs" />
<Compile Include="Internal\Cryptography\TripleDesImplementation.Unix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(UseAppleCrypto)' == 'true'">
Link="Common\Microsoft\Win32\SafeHandles\SafeRsaHandle.Unix.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\RSAOpenSsl.cs"
Link="Common\System\Security\Cryptography\RSAOpenSsl.cs" />
+ <Compile Include="Internal\Cryptography\RC2Implementation.Unix.cs" />
<Compile Include="System\Security\Cryptography\ECDiffieHellman.Create.OpenSsl.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true' and '$(UseAndroidCrypto)' == 'true'">
Link="Common\System\Security\Cryptography\ECDsaAndroid.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\RSAAndroid.cs"
Link="Common\System\Security\Cryptography\RSAAndroid.cs" />
+ <Compile Include="Internal\Cryptography\RC2Implementation.Android.cs" />
<Compile Include="System\Security\Cryptography\AesCcm.Android.cs" />
<Compile Include="System\Security\Cryptography\AesGcm.Android.cs" />
<Compile Include="System\Security\Cryptography\ECDiffieHellmanAndroid.Derive.cs" />