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 * FEECSPUtils.h - Misc. utility function for FEE/CryptKit CSP.
22 * Created 2/20/2001 by dmitch.
25 #ifdef CRYPTKIT_CSP_ENABLE
27 #ifndef _FEE_CSP_UTILS_H_
28 #define _FEE_CSP_UTILS_H_
30 #include "AppleCSPSession.h"
31 #include <security_cryptkit/feeTypes.h>
32 #include <security_cdsa_utilities/context.h>
35 * Default FEE keyblob format, indicating DER-encoding.
36 * FEE keys can optionally be generated by requesting
37 * CSSM_KEYBLOB_RAW_FORMAT_OCTET_STRING, indicating native FEE key blobs.
39 #define FEE_KEYBLOB_DEFAULT_FORMAT CSSM_KEYBLOB_RAW_FORMAT_NONE
43 /* Given a FEE error, throw appropriate CssmError */
46 const char *op
); /* optional */
50 * -- obtain CSSM key of specified CSSM_ATTRIBUTE_TYPE
51 * -- validate keyClass
52 * -- validate keyUsage
53 * -- convert to feePubKey, allocating the feePubKey if necessary
55 feePubKey
contextToFeeKey(
56 const Context
&context
,
57 AppleCSPSession
&session
,
58 CSSM_ATTRIBUTE_TYPE attrType
, // CSSM_ATTRIBUTE_KEY, CSSM_ATTRIBUTE_PUBLIC_KEY
59 CSSM_KEYCLASS keyClass
, // CSSM_KEYCLASS_{PUBLIC,PRIVATE}_KEY
60 CSSM_KEYUSE usage
, // CSSM_KEYUSE_ENCRYPT, CSSM_KEYUSE_SIGN, etc.
61 bool &mallocdKey
); // RETURNED
64 * Convert a CssmKey to a feePubKey. May result in the creation of a new
65 * feePubKey (when cssmKey is a raw key); allocdKey is true in that case
66 * in which case the caller generally has to free the allocd key).
68 feePubKey
cssmKeyToFee(
69 const CssmKey
&cssmKey
,
70 AppleCSPSession
&session
,
71 bool &allocdKey
); // RETURNED
74 * Convert a raw CssmKey to a newly alloc'd feePubKey.
76 feePubKey
rawCssmKeyToFee(
77 const CssmKey
&cssmKey
);
80 * Glue function which allows C code to use AppleCSPSession
81 * as an RNG. A ptr to this function gets passed down to
82 * CryptKit C functions as a feeRandFcn.
84 feeReturn
feeRandCallback(
85 void *ref
, // actually an AppleCSPSession *
86 unsigned char *bytes
, // must be alloc'd by caller
89 } /* namespace CryptKit */
91 #endif /* _FEE_CSP_UTILS_H_ */
92 #endif /* CRYPTKIT_CSP_ENABLE */