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.
20 // AppleCSPUtils.h - CSP-wide utility functions
23 #ifndef _H_APPLE_CSP_UTILS
24 #define _H_APPLE_CSP_UTILS
26 #include "cspdebugging.h"
27 #include <Security/cssmtype.h>
28 #include <Security/utilities.h>
29 #include <Security/cssmalloc.h>
30 #include <Security/context.h>
43 /* Key storage type returned from cspParseKeyAttr() */
50 #define KEY_ATTR_RETURN_MASK (CSSM_KEYATTR_RETURN_DATA | \
51 CSSM_KEYATTR_RETURN_REF | \
52 CSSM_KEYATTR_RETURN_NONE)
55 * Validate key attribute bits per specified key type.
57 * Used to check requested key attributes for new keys and for validating
58 * incoming existing keys. For checking key attributes for new keys,
59 * assumes that KEYATTR_RETURN_xxx bits have been checked elsewhere
60 * and stripped off before coming here.
62 void cspValidateKeyAttr(
67 * Perform sanity check of incoming key attribute bits for a given
68 * key type, and return a malKeyStorage value.
70 * Called from any routine which generates a new key. This specifically
73 cspKeyStorage
cspParseKeyAttr(
78 * Validate key usage bits for specified key type.
80 void cspValidateKeyUsageBits (
85 * Validate existing key's usage bits against intended use.
87 void cspValidateIntendedKeyUsage(
88 const CSSM_KEYHEADER
*hdr
,
89 CSSM_KEYUSE intendedUsage
);
92 * Set up a key header.
98 CSSM_KEYCLASS keyClass
,
99 CSSM_KEYATTR_FLAGS attrs
,
103 * Ensure that indicated CssmData can handle 'length' bytes
104 * of data. Malloc the Data ptr if necessary.
109 CssmAllocator
&allocator
);
114 CssmAllocator
&allocator
);
118 CssmAllocator
&allocator
);
122 CssmAllocator
&allocator
,
123 bool freeStruct
); // free the CSSM_DATA itself
126 * Copy source to destination, mallocing destination if necessary.
131 CssmAllocator
&allocator
);
134 const CSSM_DATA
&src
,
136 CssmAllocator
&allocator
);
139 * Compare two CSSM_DATAs, return CSSM_TRUE if identical.
141 CSSM_BOOL
cspCompareCssmData(
142 const CSSM_DATA
*data1
,
143 const CSSM_DATA
*data2
);
146 * This takes care of mallocing the and KeyLabel field.
149 const CssmKey::Header
&src
,
150 CssmKey::Header
&dst
,
151 CssmAllocator
&allocator
);
154 * Given a wrapped key, infer its raw format.
155 * This is a real kludge; it only works as long as each {algorithm, keyClass}
156 * maps to exactly one format.
158 CSSM_KEYBLOB_FORMAT
inferFormat(
159 const CssmKey
&wrappedKey
);
162 * Given a key and a Context, obtain the optional associated
163 * CSSM_ATTRIBUTE_{PUBLIC,PRIVATE,SYMMETRIC}_KEY_FORMAT attribute as a
164 * CSSM_KEYBLOB_FORMAT.
166 CSSM_KEYBLOB_FORMAT
requestedKeyFormat(
167 const Context
&context
,
170 /* stateless function to calculate SHA-1 hash of a blob */
172 #define SHA1_DIGEST_SIZE 20
176 void *out
); // caller mallocs, digest goes here
178 void cspVerifyKeyTimes(
179 const CSSM_KEYHEADER
&hdr
);
185 #endif // _H_APPLE_CSP_UTILS