Skip to content

Commit af6a9f3

Browse files
Change the CryptoKit interop entrypoints to use the Swift calling convention (#99970)
Co-authored-by: Aleksey Kliger (λgeek) <[email protected]>
1 parent 1a36949 commit af6a9f3

File tree

5 files changed

+18
-62
lines changed

5 files changed

+18
-62
lines changed

src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Aead.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
78
using System.Security.Cryptography;
89
using System.Security.Cryptography.Apple;
910

11+
#pragma warning disable CS3016 // Arrays as attribute arguments are not CLS Compliant
12+
1013
internal static partial class Interop
1114
{
1215
internal static partial class AppleCrypto
@@ -164,6 +167,7 @@ internal static unsafe void AesGcmDecrypt(
164167
}
165168

166169
[LibraryImport(Libraries.AppleCryptoNative)]
170+
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
167171
private static unsafe partial int AppleCryptoNative_ChaCha20Poly1305Encrypt(
168172
byte* keyPtr,
169173
int keyLength,
@@ -179,6 +183,7 @@ private static unsafe partial int AppleCryptoNative_ChaCha20Poly1305Encrypt(
179183
int aadLength);
180184

181185
[LibraryImport(Libraries.AppleCryptoNative)]
186+
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
182187
private static unsafe partial int AppleCryptoNative_ChaCha20Poly1305Decrypt(
183188
byte* keyPtr,
184189
int keyLength,
@@ -194,6 +199,7 @@ private static unsafe partial int AppleCryptoNative_ChaCha20Poly1305Decrypt(
194199
int aadLength);
195200

196201
[LibraryImport(Libraries.AppleCryptoNative)]
202+
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
197203
private static unsafe partial int AppleCryptoNative_AesGcmEncrypt(
198204
byte* keyPtr,
199205
int keyLength,
@@ -209,6 +215,7 @@ private static unsafe partial int AppleCryptoNative_AesGcmEncrypt(
209215
int aadLength);
210216

211217
[LibraryImport(Libraries.AppleCryptoNative)]
218+
[UnmanagedCallConv(CallConvs = [ typeof(CallConvSwift) ])]
212219
private static unsafe partial int AppleCryptoNative_AesGcmDecrypt(
213220
byte* keyPtr,
214221
int keyLength,

src/mono/mono/metadata/native-library-qcall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
static Entry mono_qcalls[] =
55
{
6-
DllImportEntry(NULL) // This NULL entry can be removed when a QCall is added to Mono (and added to this array)
6+
{"NULL", NULL}, // This NULL entry can be removed when a QCall is added to Mono (and added to this array)
77
};
88

99
gpointer

src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.h

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,7 @@
66
#include "pal_types.h"
77
#include "pal_compiler.h"
88

9-
PALEXPORT int32_t AppleCryptoNative_ChaCha20Poly1305Encrypt(
10-
uint8_t* keyPtr,
11-
int32_t keyLength,
12-
uint8_t* noncePtr,
13-
int32_t nonceLength,
14-
uint8_t* plaintextPtr,
15-
int32_t plaintextLength,
16-
uint8_t* ciphertextBuffer,
17-
int32_t ciphertextBufferLength,
18-
uint8_t* tagBuffer,
19-
int32_t tagBufferLength,
20-
uint8_t* aadPtr,
21-
int32_t aadLength);
22-
23-
PALEXPORT int32_t AppleCryptoNative_ChaCha20Poly1305Decrypt(
24-
uint8_t* keyPtr,
25-
int32_t keyLength,
26-
uint8_t* noncePtr,
27-
int32_t nonceLength,
28-
uint8_t* ciphertextPtr,
29-
int32_t ciphertextLength,
30-
uint8_t* tagPtr,
31-
int32_t tagLength,
32-
uint8_t* plaintextBuffer,
33-
int32_t plaintextBufferLength,
34-
uint8_t* aadPtr,
35-
int32_t aadLength);
36-
37-
PALEXPORT int32_t AppleCryptoNative_AesGcmEncrypt(
38-
uint8_t* keyPtr,
39-
int32_t keyLength,
40-
uint8_t* noncePtr,
41-
int32_t nonceLength,
42-
uint8_t* plaintextPtr,
43-
int32_t plaintextLength,
44-
uint8_t* ciphertextBuffer,
45-
int32_t ciphertextBufferLength,
46-
uint8_t* tagBuffer,
47-
int32_t tagBufferLength,
48-
uint8_t* aadPtr,
49-
int32_t aadLength);
50-
51-
PALEXPORT int32_t AppleCryptoNative_AesGcmDecrypt(
52-
uint8_t* keyPtr,
53-
int32_t keyLength,
54-
uint8_t* noncePtr,
55-
int32_t nonceLength,
56-
uint8_t* ciphertextPtr,
57-
int32_t ciphertextLength,
58-
uint8_t* tagPtr,
59-
int32_t tagLength,
60-
uint8_t* plaintextBuffer,
61-
int32_t plaintextBufferLength,
62-
uint8_t* aadPtr,
63-
int32_t aadLength);
9+
EXTERN_C void* AppleCryptoNative_ChaCha20Poly1305Encrypt;
10+
EXTERN_C void* AppleCryptoNative_ChaCha20Poly1305Decrypt;
11+
EXTERN_C void* AppleCryptoNative_AesGcmEncrypt;
12+
EXTERN_C void* AppleCryptoNative_AesGcmDecrypt;

src/native/libs/System.Security.Cryptography.Native.Apple/pal_swiftbindings.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import CryptoKit
55
import Foundation
66

7-
@_cdecl("AppleCryptoNative_ChaCha20Poly1305Encrypt")
7+
@_silgen_name("AppleCryptoNative_ChaCha20Poly1305Encrypt")
88
public func AppleCryptoNative_ChaCha20Poly1305Encrypt(
99
keyPtr: UnsafeMutableRawPointer,
1010
keyLength: Int32,
@@ -41,7 +41,7 @@ public func AppleCryptoNative_ChaCha20Poly1305Encrypt(
4141
return 1
4242
}
4343

44-
@_cdecl("AppleCryptoNative_ChaCha20Poly1305Decrypt")
44+
@_silgen_name("AppleCryptoNative_ChaCha20Poly1305Decrypt")
4545
public func AppleCryptoNative_ChaCha20Poly1305Decrypt(
4646
keyPtr: UnsafeMutableRawPointer,
4747
keyLength: Int32,
@@ -86,7 +86,7 @@ public func AppleCryptoNative_ChaCha20Poly1305Decrypt(
8686
}
8787
}
8888

89-
@_cdecl("AppleCryptoNative_AesGcmEncrypt")
89+
@_silgen_name("AppleCryptoNative_AesGcmEncrypt")
9090
public func AppleCryptoNative_AesGcmEncrypt(
9191
keyPtr: UnsafeMutableRawPointer,
9292
keyLength: Int32,
@@ -123,7 +123,7 @@ public func AppleCryptoNative_AesGcmEncrypt(
123123
return 1
124124
}
125125

126-
@_cdecl("AppleCryptoNative_AesGcmDecrypt")
126+
@_silgen_name("AppleCryptoNative_AesGcmDecrypt")
127127
public func AppleCryptoNative_AesGcmDecrypt(
128128
keyPtr: UnsafeMutableRawPointer,
129129
keyLength: Int32,

src/native/minipal/entrypoints.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ typedef struct
1414
const void* method;
1515
} Entry;
1616

17-
// expands to: {"impl", (void*)impl},
17+
// expands to: {"impl", (void*)&impl},
1818
#define DllImportEntry(impl) \
19-
{#impl, (void*)impl},
19+
{#impl, (void*)&impl},
2020

2121
static const void* minipal_resolve_dllimport(const Entry* resolutionTable, size_t tableLength, const char* name)
2222
{

0 commit comments

Comments
 (0)