Skip to content

Commit

Permalink
Convert Crypto P/Invokes to GeneratedDllImport. (#61742)
Browse files Browse the repository at this point in the history
* Convert Crypto P/Invokes to GeneratedDllImport.
  • Loading branch information
AaronRobinsonMSFT authored Nov 18, 2021
1 parent 8275c37 commit f6e2377
Show file tree
Hide file tree
Showing 52 changed files with 399 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ internal static partial class Interop
{
internal static partial class JObjectLifetime
{
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_NewGlobalReference")]
internal static extern IntPtr NewGlobalReference(IntPtr obj);
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_NewGlobalReference")]
internal static partial IntPtr NewGlobalReference(IntPtr obj);

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

internal class SafeJObjectHandle : SafeHandle
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ 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.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_BigNumToBinary")]
private static extern unsafe int BigNumToBinary(SafeBignumHandle a, byte* to);
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_BigNumToBinary")]
private static unsafe partial int BigNumToBinary(SafeBignumHandle a, byte* to);

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_GetBigNumBytes")]
private static extern int GetBigNumBytes(SafeBignumHandle a);
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_GetBigNumBytes")]
private static partial 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,21 +10,21 @@ internal static partial class Interop
{
internal static partial class Crypto
{
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherCreate")]
internal static extern SafeEvpCipherCtxHandle EvpCipherCreate(
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherCreate")]
internal static partial SafeEvpCipherCtxHandle EvpCipherCreate(
IntPtr cipher,
ref byte key,
int keyLength,
ref byte iv,
int enc);

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

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetKeyAndIV")]
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetKeyAndIV")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EvpCipherSetKeyAndIV(
private static partial bool EvpCipherSetKeyAndIV(
SafeEvpCipherCtxHandle ctx,
ref byte key,
ref byte iv,
Expand All @@ -46,9 +46,9 @@ ref MemoryMarshal.GetReference(iv),
}
}

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetNonceLength")]
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherSetNonceLength")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AndroidCryptoNative_CipherSetNonceLength(
private static partial bool AndroidCryptoNative_CipherSetNonceLength(
SafeEvpCipherCtxHandle ctx, int nonceLength);

internal static void CipherSetNonceLength(SafeEvpCipherCtxHandle ctx, int nonceLength)
Expand All @@ -59,20 +59,20 @@ internal static void CipherSetNonceLength(SafeEvpCipherCtxHandle ctx, int nonceL
}
}

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

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

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

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdate")]
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdate")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EvpCipherUpdate(
private static partial bool EvpCipherUpdate(
SafeEvpCipherCtxHandle ctx,
ref byte @out,
out int outl,
Expand All @@ -93,9 +93,9 @@ ref MemoryMarshal.GetReference(input),
input.Length);
}

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdateAAD")]
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherUpdateAAD")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CipherUpdateAAD(
private static partial bool CipherUpdateAAD(
SafeEvpCipherCtxHandle ctx,
ref byte @in,
int inl);
Expand All @@ -113,9 +113,9 @@ ref MemoryMarshal.GetReference(input),
}
}

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherFinalEx")]
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherFinalEx")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EvpCipherFinalEx(
private static partial bool EvpCipherFinalEx(
SafeEvpCipherCtxHandle ctx,
ref byte outm,
out int outl);
Expand All @@ -128,99 +128,99 @@ internal static bool EvpCipherFinalEx(
return EvpCipherFinalEx(ctx, ref MemoryMarshal.GetReference(output), out bytesWritten);
}

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

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherIsSupported")]
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_CipherIsSupported")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CipherIsSupported(IntPtr cipher);
internal static partial bool CipherIsSupported(IntPtr cipher);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_ChaCha20Poly1305")]
internal static extern IntPtr EvpChaCha20Poly1305();
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_ChaCha20Poly1305")]
internal static partial IntPtr EvpChaCha20Poly1305();

internal enum EvpCipherDirection : int
{
Expand Down
Loading

0 comments on commit f6e2377

Please sign in to comment.