3 * libsecurity_libSecOTR
5 * Created by Mitch Adler on 2/9/11.
6 * Copyright 2011 Apple Inc. All rights reserved.
10 #ifndef _SECOTRIDENTITYPRIV_H_
12 #include <CoreFoundation/CFRuntime.h>
13 #include <CoreFoundation/CFData.h>
15 #include <Security/SecKey.h>
17 #include <Security/oidsalg.h>
19 #include <CommonCrypto/CommonDigest.h> // DIGEST_LENGTH
20 #include <Security/SecOTR.h>
24 extern CFStringRef sErrorDomain
;
26 // OAEP Padding, uses lots of space. Might need this to be data
27 // Driven when we support more key types.
28 #define kPaddingOverhead (2 + 2 * CC_SHA1_DIGEST_LENGTH + 1)
31 // Identity opaque structs
34 #define kMPIDHashSize CC_SHA1_DIGEST_LENGTH
36 struct _SecOTRFullIdentity
{
39 SecKeyRef publicSigningKey
;
40 SecKeyRef privateSigningKey
;
42 uint8_t publicIDHash
[kMPIDHashSize
];
46 struct _SecOTRPublicIdentity
{
49 SecKeyRef publicSigningKey
;
53 uint8_t hash
[kMPIDHashSize
];
61 const SecAsn1AlgId
*kOTRSignatureAlgIDPtr
;
62 void EnsureOTRAlgIDInited(void);
64 // Private functions for Public and Full IDs
65 SecOTRFullIdentityRef
SecOTRFullIdentityCreateWithSize(CFAllocatorRef allocator
, int bits
);
67 bool SecOTRFIAppendSignature(SecOTRFullIdentityRef fullID
,
69 CFMutableDataRef appendTo
,
72 void SecOTRFIAppendPublicHash(SecOTRFullIdentityRef fullID
, CFMutableDataRef appendTo
);
73 bool SecOTRFIComparePublicHash(SecOTRFullIdentityRef fullID
, const uint8_t hash
[kMPIDHashSize
]);
75 size_t SecOTRFISignatureSize(SecOTRFullIdentityRef privateID
);
77 bool SecOTRPIVerifySignature(SecOTRPublicIdentityRef publicID
,
78 const uint8_t *dataToHash
, size_t amountToHash
,
79 const uint8_t *signatureStart
, size_t signatureSize
, CFErrorRef
*error
);
81 bool SecOTRPIEqualToBytes(SecOTRPublicIdentityRef id
, const uint8_t*bytes
, CFIndex size
);
82 bool SecOTRPIEqual(SecOTRPublicIdentityRef left
, SecOTRPublicIdentityRef right
);
84 size_t SecOTRPISignatureSize(SecOTRPublicIdentityRef publicID
);
86 void SecOTRPICopyHash(SecOTRPublicIdentityRef publicID
, uint8_t hash
[kMPIDHashSize
]);
87 void SecOTRPIAppendHash(SecOTRPublicIdentityRef publicID
, CFMutableDataRef appendTo
);
89 bool SecOTRPICompareHash(SecOTRPublicIdentityRef publicID
, const uint8_t hash
[kMPIDHashSize
]);
91 // Utility streaming functions
92 OSStatus
insertSize(CFIndex size
, uint8_t* here
);
93 OSStatus
appendSize(CFIndex size
, CFMutableDataRef into
);
94 OSStatus
readSize(const uint8_t** data
, size_t* limit
, uint16_t* size
);
96 OSStatus
appendPublicOctets(SecKeyRef fromKey
, CFMutableDataRef appendTo
);
97 OSStatus
appendPublicOctetsAndSize(SecKeyRef fromKey
, CFMutableDataRef appendTo
);
98 OSStatus
appendSizeAndData(CFDataRef data
, CFMutableDataRef appendTo
);
100 SecKeyRef
CreateECPrivateKeyFrom(CFAllocatorRef allocator
, const uint8_t** data
, size_t* limit
);
101 SecKeyRef
CreateECPublicKeyFrom(CFAllocatorRef allocator
, const uint8_t** data
, size_t* limit
);
103 void SecOTRCreateError(enum SecOTRError family
, CFIndex errorCode
, CFStringRef descriptionString
, CFErrorRef previousError
, CFErrorRef
*newError
);