Skip to content

Commit

Permalink
[Android] Rename System.Security.Cryptography.Native.OpenSsl on Andro…
Browse files Browse the repository at this point in the history
…id (#52406)

* Rename System.Security.Cryptography.Native.OpenSsl to System.Security.Cryptography.Native.Android on Android and split remaining shared Interop files.
  • Loading branch information
tqiu8 authored May 14, 2021
1 parent be19e1c commit 6ddabaf
Show file tree
Hide file tree
Showing 31 changed files with 531 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
<PlatformManifestFileEntry Include="libSystem.Net.Security.Native.so" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Apple.a" IsNative="true" />
<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.OpenSsl.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.so" IsNative="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ internal static partial class Interop
{
internal static partial class JObjectLifetime
{
[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_NewGlobalReference")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_NewGlobalReference")]
internal static extern IntPtr NewGlobalReference(IntPtr obj);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DeleteGlobalReference")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DeleteGlobalReference")]
internal static extern void DeleteGlobalReference(IntPtr obj);

internal class SafeJObjectHandle : SafeHandle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ internal static partial class Interop
internal static partial class Libraries
{
internal const string Liblog = "liblog";
internal const string AndroidCryptoNative = "libSystem.Security.Cryptography.Native.Android";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ internal static partial class Interop
// TODO: [AndroidCrypto] Rename class to AndroidCrypto once all consumers are split in Android vs. Unix
internal static partial class Crypto
{
[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_BigNumToBinary")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_BigNumToBinary")]
private static extern unsafe int BigNumToBinary(SafeBignumHandle a, byte* to);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_GetBigNumBytes")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_GetBigNumBytes")]
private static extern int GetBigNumBytes(SafeBignumHandle a);

internal static unsafe byte[]? ExtractBignum(SafeBignumHandle? bignum, int targetSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static partial class Interop
{
internal static partial class Crypto
{
[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherCreate")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherCreate")]
internal static extern SafeEvpCipherCtxHandle EvpCipherCreate(
IntPtr cipher,
ref byte key,
Expand All @@ -19,11 +19,11 @@ internal static extern SafeEvpCipherCtxHandle EvpCipherCreate(
ref byte iv,
int enc);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherCreatePartial")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherCreatePartial")]
internal static extern SafeEvpCipherCtxHandle EvpCipherCreatePartial(
IntPtr cipher);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetKeyAndIV")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetKeyAndIV")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EvpCipherSetKeyAndIV(
SafeEvpCipherCtxHandle ctx,
Expand All @@ -47,7 +47,7 @@ ref MemoryMarshal.GetReference(iv),
}
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetNonceLength")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetNonceLength")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AndroidCryptoNative_CipherSetNonceLength(
SafeEvpCipherCtxHandle ctx, int nonceLength);
Expand All @@ -60,18 +60,18 @@ internal static void CipherSetNonceLength(SafeEvpCipherCtxHandle ctx, int nonceL
}
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherDestroy")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherDestroy")]
internal static extern void EvpCipherDestroy(IntPtr ctx);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherReset")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherReset")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool EvpCipherReset(SafeEvpCipherCtxHandle ctx);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherCtxSetPadding")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherCtxSetPadding")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool EvpCipherCtxSetPadding(SafeEvpCipherCtxHandle x, int padding);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdate")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdate")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EvpCipherUpdate(
SafeEvpCipherCtxHandle ctx,
Expand All @@ -94,7 +94,7 @@ ref MemoryMarshal.GetReference(input),
input.Length);
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdateAAD")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdateAAD")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CipherUpdateAAD(
SafeEvpCipherCtxHandle ctx,
Expand All @@ -114,7 +114,7 @@ ref MemoryMarshal.GetReference(input),
}
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherFinalEx")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherFinalEx")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EvpCipherFinalEx(
SafeEvpCipherCtxHandle ctx,
Expand All @@ -129,91 +129,91 @@ internal static bool EvpCipherFinalEx(
return EvpCipherFinalEx(ctx, ref MemoryMarshal.GetReference(output), out bytesWritten);
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetTagLength")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetTagLength")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CipherSetTagLength(
SafeEvpCipherCtxHandle ctx,
int tagLength);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Ecb")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Ecb")]
internal static extern IntPtr EvpAes128Ecb();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Cbc")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Cbc")]
internal static extern IntPtr EvpAes128Cbc();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Gcm")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Gcm")]
internal static extern IntPtr EvpAes128Gcm();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Cfb8")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Cfb8")]
internal static extern IntPtr EvpAes128Cfb8();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Cfb128")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Cfb128")]
internal static extern IntPtr EvpAes128Cfb128();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Ccm")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes128Ccm")]
internal static extern IntPtr EvpAes128Ccm();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Ecb")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Ecb")]
internal static extern IntPtr EvpAes192Ecb();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Cbc")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Cbc")]
internal static extern IntPtr EvpAes192Cbc();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Gcm")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Gcm")]
internal static extern IntPtr EvpAes192Gcm();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Cfb8")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Cfb8")]
internal static extern IntPtr EvpAes192Cfb8();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Cfb128")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Cfb128")]
internal static extern IntPtr EvpAes192Cfb128();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Ccm")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes192Ccm")]
internal static extern IntPtr EvpAes192Ccm();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Ecb")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Ecb")]
internal static extern IntPtr EvpAes256Ecb();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Cbc")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Cbc")]
internal static extern IntPtr EvpAes256Cbc();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Gcm")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Gcm")]
internal static extern IntPtr EvpAes256Gcm();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Cfb128")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Cfb128")]
internal static extern IntPtr EvpAes256Cfb128();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Cfb8")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Cfb8")]
internal static extern IntPtr EvpAes256Cfb8();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Ccm")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Aes256Ccm")]
internal static extern IntPtr EvpAes256Ccm();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DesCbc")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DesCbc")]
internal static extern IntPtr EvpDesCbc();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DesEcb")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DesEcb")]
internal static extern IntPtr EvpDesEcb();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DesCfb8")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DesCfb8")]
internal static extern IntPtr EvpDesCfb8();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Des3Cbc")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Des3Cbc")]
internal static extern IntPtr EvpDes3Cbc();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Des3Ecb")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Des3Ecb")]
internal static extern IntPtr EvpDes3Ecb();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Des3Cfb8")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Des3Cfb8")]
internal static extern IntPtr EvpDes3Cfb8();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_Des3Cfb64")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_Des3Cfb64")]
internal static extern IntPtr EvpDes3Cfb64();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_RC2Cbc")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_RC2Cbc")]
internal static extern IntPtr EvpRC2Cbc();

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_RC2Ecb")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_RC2Ecb")]
internal static extern IntPtr EvpRC2Ecb();

internal enum EvpCipherDirection : int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ internal static partial class Interop
{
internal static partial class AndroidCrypto
{
[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DsaGenerateKey")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DsaGenerateKey")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DsaGenerateKey(out SafeDsaHandle dsa, int bits);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DsaSizeSignature")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DsaSizeSignature")]
private static extern int DsaSizeSignature(SafeDsaHandle dsa);

/// <summary>
Expand All @@ -27,7 +27,7 @@ internal static int DsaEncodedSignatureSize(SafeDsaHandle dsa)
return size;
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DsaSignatureFieldSize")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DsaSignatureFieldSize")]
private static extern int AndroidCryptoNative_DsaSignatureFieldSize(SafeDsaHandle dsa);

/// <summary>
Expand All @@ -41,7 +41,7 @@ internal static int DsaSignatureFieldSize(SafeDsaHandle dsa)
return size;
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DsaSizeP")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DsaSizeP")]
private static extern int DsaSizeP(SafeDsaHandle dsa);

/// <summary>
Expand All @@ -59,7 +59,7 @@ internal static int DsaKeySize(SafeDsaHandle dsa)
internal static bool DsaSign(SafeDsaHandle dsa, ReadOnlySpan<byte> hash, Span<byte> refSignature, out int outSignatureLength) =>
DsaSign(dsa, ref MemoryMarshal.GetReference(hash), hash.Length, ref MemoryMarshal.GetReference(refSignature), out outSignatureLength);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DsaSign")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DsaSign")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool DsaSign(SafeDsaHandle dsa, ref byte hash, int hashLength, ref byte refSignature, out int outSignatureLength);

Expand All @@ -80,7 +80,7 @@ ref MemoryMarshal.GetReference(signature),
return ret == 1;
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DsaVerify")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DsaVerify")]
private static extern int DsaVerify(SafeDsaHandle dsa, ref byte hash, int hashLength, ref byte signature, int signatureLength);

internal static DSAParameters ExportDsaParameters(SafeDsaHandle key, bool includePrivateParameters)
Expand Down Expand Up @@ -141,7 +141,7 @@ internal static DSAParameters ExportDsaParameters(SafeDsaHandle key, bool includ
}
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_GetDsaParameters")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_GetDsaParameters")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetDsaParameters(
SafeDsaHandle key,
Expand All @@ -151,7 +151,7 @@ private static extern bool GetDsaParameters(
out SafeBignumHandle y, out int y_cb,
out SafeBignumHandle x, out int x_cb);

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_DsaKeyCreateByExplicitParameters")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_DsaKeyCreateByExplicitParameters")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DsaKeyCreateByExplicitParameters(
out SafeDsaHandle dsa,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static partial class Interop
{
internal static partial class AndroidCrypto
{
[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_EcKeyCreateByKeyParameters", CharSet = CharSet.Ansi)]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_EcKeyCreateByKeyParameters", CharSet = CharSet.Ansi)]
private static extern int EcKeyCreateByKeyParameters(
out SafeEcKeyHandle key,
string oid,
Expand All @@ -35,7 +35,7 @@ internal static SafeEcKeyHandle EcKeyCreateByKeyParameters(
return key;
}

[DllImport(Libraries.CryptoNative, EntryPoint = "AndroidCryptoNative_EcKeyCreateByExplicitParameters")]
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_EcKeyCreateByExplicitParameters")]
internal static extern SafeEcKeyHandle EcKeyCreateByExplicitParameters(
ECCurve.ECCurveType curveType,
byte[]? qx, int qxLength,
Expand Down Expand Up @@ -91,7 +91,7 @@ internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve)
}


[DllImport(Libraries.CryptoNative)]
[DllImport(Libraries.AndroidCryptoNative)]
private static extern int AndroidCryptoNative_GetECKeyParameters(
SafeEcKeyHandle key,
bool includePrivate,
Expand Down Expand Up @@ -149,7 +149,7 @@ internal static ECParameters GetECKeyParameters(
return parameters;
}

[DllImport(Libraries.CryptoNative)]
[DllImport(Libraries.AndroidCryptoNative)]
private static extern int AndroidCryptoNative_GetECCurveParameters(
SafeEcKeyHandle key,
bool includePrivate,
Expand Down
Loading

0 comments on commit 6ddabaf

Please sign in to comment.