2 * Copyright (c) 2006-2008,2010-2012 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * sslCrypto.h - interface between SSL and crypto libraries
28 #ifndef _SSL_CRYPTO_H_
29 #define _SSL_CRYPTO_H_ 1
32 #include "sslContext.h"
33 #include <Security/SecKeyPriv.h>
40 extern void stPrintCdsaError(const char *op
, OSStatus crtn
);
42 #define stPrintCdsaError(o, cr)
46 * Free a pubKey object.
48 extern OSStatus
sslFreePubKey(SSLPubKey
**pubKey
);
51 * Free a privKey object.
53 extern OSStatus
sslFreePrivKey(SSLPrivKey
**privKey
);
55 extern CFIndex
sslPubKeyGetAlgorithmID(SSLPubKey
*pubKey
);
56 extern CFIndex
sslPrivKeyGetAlgorithmID(SSLPrivKey
*privKey
);
59 * Create a new SecTrust object and return it.
66 SecTrustRef
*trust
); /* RETURNED */
70 * Verify a cert chain.
72 extern OSStatus
sslVerifyCertChain(
74 #ifdef USE_SSLCERTIFICATE
75 const SSLCertificate
*certChain
,
76 #else /* !USE_SSLCERTIFICATE */
78 #endif /* !USE_SSLCERTIFICATE */
82 * Get the peer's public key from the certificate chain.
84 extern OSStatus
sslCopyPeerPubKey(
90 * Raw RSA/DSA sign/verify.
95 const uint8_t *plainText
,
97 uint8_t *sig
, // mallocd by caller; RETURNED
98 size_t sigLen
, // available
99 size_t *actualBytes
); // RETURNED
101 OSStatus
sslRawVerify(
104 const uint8_t *plainText
,
107 size_t sigLen
); // available
109 /* TLS 1.2 style RSA sign */
113 const SecAsn1AlgId
*algId
,
114 const uint8_t *plainText
,
116 uint8_t *sig
, // mallocd by caller; RETURNED
117 size_t sigLen
, // available
118 size_t *actualBytes
); // RETURNED
120 /* TLS 1.2 style RSA verify */
121 OSStatus
sslRsaVerify(
124 const SecAsn1AlgId
*algId
,
125 const uint8_t *plainText
,
128 size_t sigLen
); // available
133 OSStatus
sslRsaEncrypt(
136 #ifdef USE_CDSA_CRYPTO
137 CSSM_CSP_HANDLE cspHand
,
139 const uint32_t padding
,
140 const uint8_t *plainText
,
142 uint8_t *cipherText
, // mallocd by caller; RETURNED
143 size_t cipherTextLen
, // available
144 size_t *actualBytes
); // RETURNED
145 OSStatus
sslRsaDecrypt(
148 const uint32_t padding
,
149 const uint8_t *cipherText
,
150 size_t cipherTextLen
,
151 uint8_t *plainText
, // mallocd by caller; RETURNED
152 size_t plainTextLen
, // available
153 size_t *actualBytes
); // RETURNED
156 * Obtain size of key in bytes.
158 extern size_t sslPrivKeyLengthInBytes(
161 extern size_t sslPubKeyLengthInBytes(
164 /* Obtain max signature size in bytes. */
165 extern OSStatus
sslGetMaxSigSize(
171 * Get raw key bits from an RSA public key.
173 OSStatus
sslGetPubKeyBits(
176 SSLBuffer
*modulus
, // data mallocd and RETURNED
177 SSLBuffer
*exponent
); // data mallocd and RETURNED
181 * Given raw RSA key bits, cook up a SSLPubKey. Used in
182 * Server-initiated key exchange.
184 OSStatus
sslGetPubKeyFromBits(
186 const SSLBuffer
*modulus
,
187 const SSLBuffer
*exponent
,
188 SSLPubKey
**pubKey
); // mallocd and RETURNED
190 OSStatus
sslVerifySelectedCipher(
192 const SSLCipherSpec
*selectedCipherSpec
);
195 int sslDhGenerateParams(SSLContext
*ctx
, uint32_t g
, size_t prime_size
,
196 SSLBuffer
*params
, SSLBuffer
*generator
, SSLBuffer
*prime
);
198 OSStatus
sslDhCreateKey(SSLContext
*ctx
);
199 OSStatus
sslDhGenerateKeyPair(SSLContext
*ctx
);
200 OSStatus
sslDhKeyExchange(SSLContext
*ctx
);
202 OSStatus
sslDecodeDhParams(
203 const SSLBuffer
*blob
, /* Input - PKCS-3 encoded */
204 SSLBuffer
*prime
, /* Output - wire format */
205 SSLBuffer
*generator
); /* Output - wire format */
207 OSStatus
sslEncodeDhParams(
208 SSLBuffer
*blob
, /* data mallocd and RETURNED - PKCS-3 encoded */
209 const SSLBuffer
*prime
, /* Input - wire format */
210 const SSLBuffer
*generator
); /* Input - wire format */
212 #endif /* APPLE_DH */
215 * Given an ECDSA public key in CSSM format, extract the SSL_ECDSA_NamedCurve
216 * from its algorithm parameters.
218 OSStatus
sslEcdsaPeerCurve(
220 SSL_ECDSA_NamedCurve
*namedCurve
);
221 OSStatus
sslEcdhGenerateKeyPair(
223 SSL_ECDSA_NamedCurve namedCurve
);
224 OSStatus
sslEcdhKeyExchange(
226 SSLBuffer
*exchanged
);
233 #endif /* _SSL_CRYPTO_H_ */