#ifndef _SECURITY_SECKEYPRIV_H_
#define _SECURITY_SECKEYPRIV_H_
#include <Security/SecKey.h>
#include <Security/SecAsn1Types.h>
#include <CoreFoundation/CFRuntime.h>
#include <CoreFoundation/CoreFoundation.h>
__BEGIN_DECLS
typedef struct __SecDERKey {
uint8_t *oid;
CFIndex oidLength;
uint8_t *parameters;
CFIndex parametersLength;
uint8_t *key;
CFIndex keyLength;
} SecDERKey;
typedef uint32_t SecKeyEncoding;
enum {
kSecKeyEncodingRaw = 0,
kSecKeyEncodingPkcs1 = 1,
kSecKeyEncodingApplePkcs1 = 2,
kSecKeyEncodingRSAPublicParams = 3,
kSecDERKeyEncoding = 4,
kSecGenerateKey = 5,
kSecExtractPublicFromPrivate = 6,
kSecKeyEncodingBytes = 7,
kSecKeyCoreCrypto = 8,
};
typedef uint32_t SecKeyWrapType;
enum {
kSecKeyWrapRFC3394 = 0,
kSecKeyWrapPublicKeyPGP = 1,
};
typedef OSStatus (*SecKeyInitMethod)(SecKeyRef, const uint8_t *, CFIndex,
SecKeyEncoding);
typedef void (*SecKeyDestroyMethod)(SecKeyRef);
typedef OSStatus (*SecKeyRawSignMethod)(SecKeyRef key, SecPadding padding,
const uint8_t *dataToSign, size_t dataToSignLen,
uint8_t *sig, size_t *sigLen);
typedef OSStatus (*SecKeyRawVerifyMethod)(
SecKeyRef key, SecPadding padding, const uint8_t *signedData,
size_t signedDataLen, const uint8_t *sig, size_t sigLen);
typedef OSStatus (*SecKeyEncryptMethod)(SecKeyRef key, SecPadding padding,
const uint8_t *plainText, size_t plainTextLen,
uint8_t *cipherText, size_t *cipherTextLen);
typedef OSStatus (*SecKeyDecryptMethod)(SecKeyRef key, SecPadding padding,
const uint8_t *cipherText, size_t cipherTextLen,
uint8_t *plainText, size_t *plainTextLen);
typedef OSStatus (*SecKeyComputeMethod)(SecKeyRef key,
const uint8_t *pub_key, size_t pub_key_len,
uint8_t *computed_key, size_t *computed_key_len);
typedef size_t (*SecKeyBlockSizeMethod)(SecKeyRef key);
typedef CFDictionaryRef (*SecKeyCopyDictionaryMethod)(SecKeyRef key);
typedef CFIndex (*SecKeyGetAlgorithmIDMethod)(SecKeyRef key);
typedef OSStatus (*SecKeyCopyPublicBytesMethod)(SecKeyRef key, CFDataRef *serialization);
typedef CFDataRef (*SecKeyCopyWrapKeyMethod)(SecKeyRef key, SecKeyWrapType type, CFDataRef unwrappedKey, CFDictionaryRef parameters, CFDictionaryRef *outParam, CFErrorRef *error);
typedef CFDataRef (*SecKeyCopyUnwrapKeyMethod)(SecKeyRef key, SecKeyWrapType type, CFDataRef wrappedKey, CFDictionaryRef parameters, CFDictionaryRef *outParam, CFErrorRef *error);
typedef CFStringRef (*SecKeyDescribeMethod)(SecKeyRef key);
#define kSecKeyDescriptorVersion (3)
typedef struct __SecKeyDescriptor {
uint32_t version;
const char *name;
uint32_t extraBytes;
SecKeyInitMethod init;
SecKeyDestroyMethod destroy;
SecKeyRawSignMethod rawSign;
SecKeyRawVerifyMethod rawVerify;
SecKeyEncryptMethod encrypt;
SecKeyDecryptMethod decrypt;
SecKeyComputeMethod compute;
SecKeyBlockSizeMethod blockSize;
SecKeyCopyDictionaryMethod copyDictionary;
SecKeyDescribeMethod describe;
#if kSecKeyDescriptorVersion > 0
SecKeyGetAlgorithmIDMethod getAlgorithmID;
#endif
#if kSecKeyDescriptorVersion > 1
SecKeyCopyPublicBytesMethod copyPublic;
#endif
#if kSecKeyDescriptorVersion > 2
SecKeyCopyWrapKeyMethod copyWrapKey;
SecKeyCopyUnwrapKeyMethod copyUnwrapKey;
#endif
} SecKeyDescriptor;
struct __SecKey {
CFRuntimeBase _base;
const SecKeyDescriptor *key_class;
void *key;
};
SecKeyRef SecKeyCreate(CFAllocatorRef allocator,
const SecKeyDescriptor *key_class, const uint8_t *keyData,
CFIndex keyDataLength, SecKeyEncoding encoding);
SecKeyRef SecKeyCreatePublicFromDER(CFAllocatorRef allocator,
const SecAsn1Oid *oid1, const SecAsn1Item *params,
const SecAsn1Item *keyData);
SecKeyRef SecKeyCreatePublicFromPrivate(SecKeyRef privateKey);
SecKeyRef SecKeyCopyMatchingPrivateKey(SecKeyRef publicKey, CFErrorRef *error);
CFDataRef SecKeyCreatePersistentRefToMatchingPrivateKey(SecKeyRef publicKey, CFErrorRef *error);
CFDictionaryRef SecKeyCopyAttributeDictionary(SecKeyRef key);
SecKeyRef SecKeyCreateFromAttributeDictionary(CFDictionaryRef refAttributes);
OSStatus SecKeyDigestAndVerify(
SecKeyRef key,
const SecAsn1AlgId *algId,
const uint8_t *dataToDigest,
size_t dataToDigestLen,
const uint8_t *sig,
size_t sigLen);
OSStatus SecKeyDigestAndSign(
SecKeyRef key,
const SecAsn1AlgId *algId,
const uint8_t *dataToDigest,
size_t dataToDigestLen,
uint8_t *sig,
size_t *sigLen);
OSStatus SecKeyVerifyDigest(
SecKeyRef key,
const SecAsn1AlgId *algId,
const uint8_t *digestData,
size_t digestDataLen,
const uint8_t *sig,
size_t sigLen);
OSStatus SecKeySignDigest(
SecKeyRef key,
const SecAsn1AlgId *algId,
const uint8_t *digestData,
size_t digestDataLen,
uint8_t *sig,
size_t *sigLen);
OSStatus SecKeyCopyPublicBytes(SecKeyRef key, CFDataRef* serializedPublic);
SecKeyRef SecKeyCreateFromPublicBytes(CFAllocatorRef allocator, CFIndex algorithmID, const uint8_t *keyData, CFIndex keyDataLength);
SecKeyRef SecKeyCreateFromPublicData(CFAllocatorRef allocator, CFIndex algorithmID, CFDataRef serialized);
CF_RETURNS_RETAINED
CFDictionaryRef SecKeyGeneratePrivateAttributeDictionary(SecKeyRef key,
CFTypeRef keyType,
CFDataRef privateBlob);
CF_RETURNS_RETAINED
CFDictionaryRef SecKeyGeneratePublicAttributeDictionary(SecKeyRef key, CFTypeRef keyType);
enum {
kSecNullAlgorithmID = 0,
kSecRSAAlgorithmID = 1,
kSecDSAAlgorithmID = 2,
kSecECDSAAlgorithmID = 3,
};
CFIndex SecKeyGetAlgorithmID(SecKeyRef key);
typedef enum {
kSecKeyKeySizeInBits = 0,
kSecKeySignatureSize = 1,
kSecKeyEncryptedDataSize = 2,
} SecKeySize;
size_t SecKeyGetSize(SecKeyRef key, SecKeySize whichSize)
__OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_5_0);
OSStatus SecKeyFindWithPersistentRef(CFDataRef persistentRef, SecKeyRef* lookedUpData)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
OSStatus SecKeyCopyPersistentRef(SecKeyRef key, CFDataRef* persistentRef)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
extern CFTypeRef _kSecKeyWrapPGPSymAlg;
extern CFTypeRef _kSecKeyWrapPGPFingerprint;
extern CFTypeRef _kSecKeyWrapPGPWrapAlg;
extern CFTypeRef _kSecKeyWrapRFC6637Flags;
extern CFTypeRef _kSecKeyWrapRFC6637WrapDigestSHA256KekAES128;
extern CFTypeRef _kSecKeyWrapRFC6637WrapDigestSHA512KekAES256;
enum { kSecKeyWrapPGPFingerprintMinSize = 20 };
CFDataRef
_SecKeyCopyWrapKey(SecKeyRef key, SecKeyWrapType type, CFDataRef unwrappedKey, CFDictionaryRef parameters, CFDictionaryRef *outParam, CFErrorRef *error)
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
CFDataRef
_SecKeyCopyUnwrapKey(SecKeyRef key, SecKeyWrapType type, CFDataRef wrappedKey, CFDictionaryRef parameters, CFDictionaryRef *outParam, CFErrorRef *error)
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
__END_DECLS
#endif