4 Description: common CDSA access utilities
8 Copyright: © Copyright 2001 Apple Computer, Inc. All rights reserved.
10 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
11 Computer, Inc. ("Apple") in consideration of your agreement to
12 the following terms, and your use, installation, modification
13 or redistribution of this Apple software constitutes acceptance
14 of these terms. If you do not agree with these terms, please
15 do not use, install, modify or redistribute this Apple software.
17 In consideration of your agreement to abide by the following
18 terms, and subject to these terms, Apple grants you a personal,
19 non-exclusive license, under Apple's copyrights in this
20 original Apple software (the "Apple Software"), to use,
21 reproduce, modify and redistribute the Apple Software, with
22 or without modifications, in source and/or binary forms;
23 provided that if you redistribute the Apple Software in
24 its entirety and without modifications, you must retain
25 this notice and the following text and disclaimers in all
26 such redistributions of the Apple Software. Neither the
27 name, trademarks, service marks or logos of Apple Computer,
28 Inc. may be used to endorse or promote products derived from the
29 Apple Software without specific prior written permission from
30 Apple. Except as expressly stated in this notice, no other
31 rights or licenses, express or implied, are granted by Apple
32 herein, including but not limited to any patent rights that
33 may be infringed by your derivative works or by other works
34 in which the Apple Software may be incorporated.
36 The Apple Software is provided by Apple on an "AS IS" basis.
37 APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
38 WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
39 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
40 REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE
41 OR IN COMBINATION WITH YOUR PRODUCTS.
43 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT,
44 INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION
48 AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
49 AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING
50 NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE
51 HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #ifndef _COMMON_CDSA_UTILS_H_
55 #define _COMMON_CDSA_UTILS_H_
57 #include <Security/cssm.h>
58 #include <Security/SecKeychain.h>
64 /* common memory allocators shared by app and CSSM */
65 extern void * cuAppMalloc (uint32 size
, void *allocRef
);
66 extern void cuAppFree (void *mem_ptr
, void *allocRef
);
67 extern void * cuAppRealloc (void *ptr
, uint32 size
, void *allocRef
);
68 extern void * cuAppCalloc (uint32 num
, uint32 size
, void *allocRef
);
70 #define APP_MALLOC(s) cuAppMalloc(s, NULL)
71 #define APP_FREE(p) cuAppFree(p, NULL)
72 #define APP_REALLOC(p, s) cuAppRealloc(p, s, NULL)
73 #define APP_CALLOC(n, s) cuAppRealloc(n, s, NULL)
75 extern CSSM_BOOL
cuCompareCssmData(
78 void cuPrintError(char *op
, CSSM_RETURN err
);
80 /* Init CSSM; returns CSSM_FALSE on error. Reusable. */
81 extern CSSM_BOOL
cuCssmStartup();
83 /* Attach to CSP. Returns zero on error. */
84 extern CSSM_CSP_HANDLE
cuCspStartup(
85 CSSM_BOOL bareCsp
); // true ==> CSP, false ==> CSP/DL
87 /* Attach to DL side of CSPDL. */
88 extern CSSM_DL_HANDLE
cuDlStartup();
90 /* Attach to CL, TP */
91 extern CSSM_CL_HANDLE
cuClStartup();
92 extern CSSM_TP_HANDLE
cuTpStartup();
94 /* Open a DB, ensure it's empty. */
95 CSSM_DB_HANDLE
cuDbStartup(
96 CSSM_DL_HANDLE dlHand
, // from dlStartup()
99 /* Attach to existing DB or create an empty new one. */
100 CSSM_DB_HANDLE
cuDbStartupByName(CSSM_DL_HANDLE dlHand
,
106 * Derive symmetric key using PBE.
108 extern CSSM_RETURN
cuCspDeriveKey(CSSM_CSP_HANDLE cspHand
,
109 uint32 keyAlg
, // CSSM_ALGID_RC5, etc.
110 const char *keyLabel
,
111 unsigned keyLabelLen
,
112 uint32 keyUsage
, // CSSM_KEYUSE_ENCRYPT, etc.
113 uint32 keySizeInBits
,
114 CSSM_DATA_PTR password
, // in PKCS-5 lingo
115 CSSM_DATA_PTR salt
, // ditto
116 uint32 iterationCnt
, // ditto
120 * Generate key pair of arbitrary algorithm.
122 extern CSSM_RETURN
cuCspGenKeyPair(CSSM_CSP_HANDLE cspHand
,
123 CSSM_DL_DB_HANDLE
*dlDbHand
, // optional
125 const char *keyLabel
,
126 unsigned keyLabelLen
,
127 uint32 keySize
, // in bits
128 CSSM_KEY_PTR pubKey
, // mallocd by caller
129 CSSM_KEYUSE pubKeyUsage
, // CSSM_KEYUSE_ENCRYPT, etc.
130 CSSM_KEYATTR_FLAGS pubAttrs
, // CSSM_KEYATTR_EXTRACTABLE, etc.
131 CSSM_KEY_PTR privKey
, // mallocd by caller
132 CSSM_KEYUSE privKeyUsage
, // CSSM_KEYUSE_DECRYPT, etc.
133 CSSM_KEYATTR_FLAGS privAttrs
); // CSSM_KEYATTR_EXTRACTABLE, etc.
135 /* Convert a reference key to a raw key. */
136 CSSM_RETURN
cuRefKeyToRaw(CSSM_CSP_HANDLE cspHand
,
137 const CSSM_KEY
*refKey
,
138 CSSM_KEY_PTR rawKey
); // RETURNED
141 * Add a certificate to an open DLDB.
143 CSSM_RETURN
cuAddCertToDb(
144 CSSM_DL_DB_HANDLE dlDbHand
,
145 const CSSM_DATA
*cert
,
146 CSSM_CERT_TYPE certType
,
147 CSSM_CERT_ENCODING certEncoding
,
148 const char *printName
, // C string
149 const CSSM_DATA
*publicKeyHash
); // ??
152 * Add a certificate to a keychain.
154 CSSM_RETURN
cuAddCertToKC(
155 SecKeychainRef keychain
,
156 const CSSM_DATA
*cert
,
157 CSSM_CERT_TYPE certType
,
158 CSSM_CERT_ENCODING certEncoding
,
159 const char *printName
, // C string
160 const CSSM_DATA
*keyLabel
); // ??
166 #endif /* _COMMON_CDSA_UTILS_H_ */