]>
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.
99 const UInt8
*plainText
,
101 UInt8
*sig
, // mallocd by caller; RETURNED
102 UInt32 sigLen
, // available
103 UInt32
*actualBytes
); // RETURNED
105 OSStatus
sslRawVerify(
107 const CSSM_KEY
*pubKey
,
108 CSSM_CSP_HANDLE cspHand
,
109 const UInt8
*plainText
,
112 UInt32 sigLen
); // available
117 OSStatus
sslRsaEncrypt(
119 const CSSM_KEY
*pubKey
,
120 CSSM_CSP_HANDLE cspHand
,
121 const UInt8
*plainText
,
123 UInt8
*cipherText
, // mallocd by caller; RETURNED
124 UInt32 cipherTextLen
, // available
125 UInt32
*actualBytes
); // RETURNED
126 OSStatus
sslRsaDecrypt(
128 SecKeyRef privKeyRef
,
129 const UInt8
*cipherText
,
130 UInt32 cipherTextLen
,
131 UInt8
*plainText
, // mallocd by caller; RETURNED
132 UInt32 plainTextLen
, // available
133 UInt32
*actualBytes
); // RETURNED
136 * Obtain size of key in bytes.
138 extern UInt32
sslKeyLengthInBytes(
139 const CSSM_KEY
*key
);
141 /* Obtain max signature size in bytes. */
142 extern OSStatus
sslGetMaxSigSize(
143 const CSSM_KEY
*privKey
,
147 * Get raw key bits from an RSA public key.
149 OSStatus
sslGetPubKeyBits(
151 const CSSM_KEY
*pubKey
,
152 CSSM_CSP_HANDLE cspHand
,
153 SSLBuffer
*modulus
, // data mallocd and RETURNED
154 SSLBuffer
*exponent
); // data mallocd and RETURNED
157 * Given raw RSA key bits, cook up a CSSM_KEY_PTR. Used in
158 * Server-initiated key exchange.
160 OSStatus
sslGetPubKeyFromBits(
162 const SSLBuffer
*modulus
,
163 const SSLBuffer
*exponent
,
164 CSSM_KEY_PTR
*pubKey
, // mallocd and RETURNED
165 CSSM_CSP_HANDLE
*cspHand
); // RETURNED
168 * Given a DER-encoded cert, obtain its DER-encoded subject name.
170 CSSM_DATA_PTR
sslGetCertSubjectName(
172 const CSSM_DATA_PTR cert
);
175 void verifyTrustedRoots(SSLContext
*ctx
,
180 void * stAppMalloc (uint32 size
, void *allocRef
);
181 void stAppFree (void *mem_ptr
, void *allocRef
);
182 void * stAppRealloc (void *ptr
, uint32 size
, void *allocRef
);
183 void * stAppCalloc (uint32 num
, uint32 size
, void *allocRef
);
185 OSStatus
sslDhGenKeyPairClient(
187 const SSLBuffer
&prime
,
188 const SSLBuffer
&generator
,
189 CSSM_KEY_PTR publicKey
, // RETURNED
190 CSSM_KEY_PTR privateKey
); // RETURNED
191 OSStatus
sslDhGenerateKeyPair(
193 const SSLBuffer
¶mBlob
,
194 UInt32 keySizeInBits
,
195 CSSM_KEY_PTR publicKey
, // RETURNED
196 CSSM_KEY_PTR privateKey
); // RETURNED
197 OSStatus
sslDhKeyExchange(
199 uint32 deriveSizeInBits
,
200 SSLBuffer
*exchanged
);
201 OSStatus
sslVerifyNegotiatedCipher(
205 * Convert between SSLBuffer and CSSM_DATA, which are after all identical.
206 * No mallocs, just copy the pointer and length.
208 #define SSLBUF_TO_CSSM(sb, cd) { \
209 (cd)->Length = (sb)->length; \
210 (cd)->Data = (sb)->data; \
213 #define CSSM_TO_SSLBUF(cd, sb) { \
214 (sb)->length = (cd)->Length; \
215 (sb)->data = (cd)->Data; \
223 #endif /* _APPLE_CDSA_H_ */