1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 #pragma once
6 
7 #include "pal_digest.h"
8 #include "pal_seckey.h"
9 
10 #include <Security/Security.h>
11 
12 /*
13 Generate a new RSA keypair with the specified key size, in bits.
14 
15 Returns 1 on success, 0 on failure.  On failure, *pOSStatus should contain the OS reported error.
16 */
17 extern "C" int32_t AppleCryptoNative_RsaGenerateKey(int32_t keySizeBits,
18                                                     SecKeychainRef tempKeychain,
19                                                     SecKeyRef* pPublicKey,
20                                                     SecKeyRef* pPrivateKey,
21                                                     int32_t* pOSStatus);
22 
23 /*
24 Decrypt the contents of pbData using the provided privateKey under OAEP padding.
25 
26 Follows pal_seckey return conventions.
27 */
28 extern "C" int32_t AppleCryptoNative_RsaDecryptOaep(SecKeyRef privateKey,
29                                                     uint8_t* pbData,
30                                                     int32_t cbData,
31                                                     PAL_HashAlgorithm mfgAlgorithm,
32                                                     CFDataRef* pDecryptedOut,
33                                                     CFErrorRef* pErrorOut);
34 
35 /*
36 Decrypt the contents of pbData using the provided privateKey under PKCS#1 padding.
37 
38 Follows pal_seckey return conventions.
39 */
40 extern "C" int32_t AppleCryptoNative_RsaDecryptPkcs(
41     SecKeyRef privateKey, uint8_t* pbData, int32_t cbData, CFDataRef* pDecryptedOut, CFErrorRef* pErrorOut);
42 
43 /*
44 Encrypt pbData for the provided publicKey using OAEP padding.
45 
46 Follows pal_seckey return conventions.
47 */
48 extern "C" int32_t AppleCryptoNative_RsaEncryptOaep(SecKeyRef publicKey,
49                                                     uint8_t* pbData,
50                                                     int32_t cbData,
51                                                     PAL_HashAlgorithm mgfAlgorithm,
52                                                     CFDataRef* pEncryptedOut,
53                                                     CFErrorRef* pErrorOut);
54 
55 /*
56 Encrypt pbData for the provided publicKey using PKCS#1 padding.
57 
58 Follows pal_seckey return conventions.
59 */
60 extern "C" int32_t AppleCryptoNative_RsaEncryptPkcs(
61     SecKeyRef publicKey, uint8_t* pbData, int32_t cbData, CFDataRef* pEncryptedOut, CFErrorRef* pErrorOut);
62