]>
git.saurik.com Git - apple/security.git/blob - SecureTransport/privateInc/appleCdsa.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
22 Contains: interface between SSL and CDSA
24 Written by: Doug Mitchell
26 Copyright: (c) 1999 by Apple Computer, Inc., all rights reserved.
30 #ifndef _APPLE_CDSA_H_
31 #define _APPLE_CDSA_H_ 1
35 #include "sslContext.h"
36 #include <Security/cssmtype.h>
43 extern void stPrintCdsaError(const char *op
, CSSM_RETURN crtn
);
44 extern char *stCssmErrToStr(CSSM_RETURN err
);
46 #define stPrintCdsaError(o, cr)
49 extern OSStatus
sslSetUpSymmKey(
52 CSSM_KEYUSE keyUse
, // CSSM_KEYUSE_ENCRYPT, etc.
53 CSSM_BOOL copyKey
, // true: copy keyData false: set by reference
55 uint32 keyDataLen
); // in bytes
57 extern OSStatus
sslFreeKey(CSSM_CSP_HANDLE cspHand
,
59 #if ST_KC_KEYS_NEED_REF
60 SecKeychainRef
*kcItem
);
61 #else /* !ST_KC_KEYS_NEED_REF */
63 #endif /* ST_KC_KEYS_NEED_REF*/
65 extern OSStatus
attachToCsp(SSLContext
*ctx
);
66 extern OSStatus
attachToCl(SSLContext
*ctx
);
67 extern OSStatus
attachToTp(SSLContext
*ctx
);
68 extern OSStatus
attachToAll(SSLContext
*ctx
);
69 extern OSStatus
detachFromAll(SSLContext
*ctx
);
71 extern CSSM_DATA_PTR
stMallocCssmData(uint32 size
);
72 extern void stFreeCssmData(CSSM_DATA_PTR data
, CSSM_BOOL freeStruct
);
73 extern OSStatus
stSetUpCssmData(CSSM_DATA_PTR data
, uint32 length
);
77 * Given a DER-encoded cert, obtain its public key as a CSSM_KEY_PTR.
79 extern OSStatus
sslPubKeyFromCert(
81 const SSLBuffer
&derCert
,
82 CSSM_KEY_PTR
*pubKey
, // RETURNED
83 CSSM_CSP_HANDLE
*cspHand
); // RETURNED
86 * Verify a cert chain.
88 extern OSStatus
sslVerifyCertChain(
90 const SSLCertificate
&certChain
,
91 bool arePeerCerts
= true);
94 * Raw RSA/DSA sign/verify.
98 const CSSM_KEY
*privKey
,
99 CSSM_CSP_HANDLE cspHand
,
100 const UInt8
*plainText
,
102 UInt8
*sig
, // mallocd by caller; RETURNED
103 UInt32 sigLen
, // available
104 UInt32
*actualBytes
); // RETURNED
106 OSStatus
sslRawVerify(
108 const CSSM_KEY
*pubKey
,
109 CSSM_CSP_HANDLE cspHand
,
110 const UInt8
*plainText
,
113 UInt32 sigLen
); // available
118 OSStatus
sslRsaEncrypt(
120 const CSSM_KEY
*pubKey
,
121 CSSM_CSP_HANDLE cspHand
,
122 const UInt8
*plainText
,
124 UInt8
*cipherText
, // mallocd by caller; RETURNED
125 UInt32 cipherTextLen
, // available
126 UInt32
*actualBytes
); // RETURNED
127 OSStatus
sslRsaDecrypt(
129 const CSSM_KEY
*privKey
,
130 CSSM_CSP_HANDLE cspHand
,
131 const UInt8
*cipherText
,
132 UInt32 cipherTextLen
,
133 UInt8
*plainText
, // mallocd by caller; RETURNED
134 UInt32 plainTextLen
, // available
135 UInt32
*actualBytes
); // RETURNED
138 * Obtain size of key in bytes.
140 extern UInt32
sslKeyLengthInBytes(
141 const CSSM_KEY
*key
);
143 /* Obtain max signature size in bytes. */
144 extern OSStatus
sslGetMaxSigSize(
145 const CSSM_KEY
*privKey
,
149 * Get raw key bits from an RSA public key.
151 OSStatus
sslGetPubKeyBits(
153 const CSSM_KEY
*pubKey
,
154 CSSM_CSP_HANDLE cspHand
,
155 SSLBuffer
*modulus
, // data mallocd and RETURNED
156 SSLBuffer
*exponent
); // data mallocd and RETURNED
159 * Given raw RSA key bits, cook up a CSSM_KEY_PTR. Used in
160 * Server-initiated key exchange.
162 OSStatus
sslGetPubKeyFromBits(
164 const SSLBuffer
*modulus
,
165 const SSLBuffer
*exponent
,
166 CSSM_KEY_PTR
*pubKey
, // mallocd and RETURNED
167 CSSM_CSP_HANDLE
*cspHand
); // RETURNED
170 * Given a DER-encoded cert, obtain its DER-encoded subject name.
172 CSSM_DATA_PTR
sslGetCertSubjectName(
174 const CSSM_DATA_PTR cert
);
177 void verifyTrustedRoots(SSLContext
*ctx
,
182 void * stAppMalloc (uint32 size
, void *allocRef
);
183 void stAppFree (void *mem_ptr
, void *allocRef
);
184 void * stAppRealloc (void *ptr
, uint32 size
, void *allocRef
);
185 void * stAppCalloc (uint32 num
, uint32 size
, void *allocRef
);
187 OSStatus
sslDhGenKeyPairClient(
189 const SSLBuffer
&prime
,
190 const SSLBuffer
&generator
,
191 CSSM_KEY_PTR publicKey
, // RETURNED
192 CSSM_KEY_PTR privateKey
); // RETURNED
193 OSStatus
sslDhGenerateKeyPair(
195 const SSLBuffer
¶mBlob
,
196 UInt32 keySizeInBits
,
197 CSSM_KEY_PTR publicKey
, // RETURNED
198 CSSM_KEY_PTR privateKey
); // RETURNED
199 OSStatus
sslDhKeyExchange(
201 uint32 deriveSizeInBits
,
202 SSLBuffer
*exchanged
);
203 OSStatus
sslVerifyNegotiatedCipher(
207 * Convert between SSLBuffer and CSSM_DATA, which are after all identical.
208 * No mallocs, just copy the pointer and length.
210 #define SSLBUF_TO_CSSM(sb, cd) { \
211 (cd)->Length = (sb)->length; \
212 (cd)->Data = (sb)->data; \
215 #define CSSM_TO_SSLBUF(cd, sb) { \
216 (sb)->length = (cd)->Length; \
217 (sb)->data = (cd)->Data; \
225 #endif /* _APPLE_CDSA_H_ */