2 * Copyright (c) 2000-2001,2011,2014 Apple 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.
24 #ifdef CRYPTKIT_CSP_ENABLE
26 #ifndef _FEE_CSP_UTILS_H_
27 #define _FEE_CSP_UTILS_H_
29 #include "AppleCSPSession.h"
30 #include <security_cryptkit/feeTypes.h>
31 #include <security_cdsa_utilities/context.h>
34 * Default FEE keyblob format, indicating DER-encoding.
35 * FEE keys can optionally be generated by requesting
36 * CSSM_KEYBLOB_RAW_FORMAT_OCTET_STRING, indicating native FEE key blobs.
38 #define FEE_KEYBLOB_DEFAULT_FORMAT CSSM_KEYBLOB_RAW_FORMAT_NONE
42 /* Given a FEE error, throw appropriate CssmError */
45 const char *op
); /* optional */
49 * -- obtain CSSM key of specified CSSM_ATTRIBUTE_TYPE
50 * -- validate keyClass
51 * -- validate keyUsage
52 * -- convert to feePubKey, allocating the feePubKey if necessary
54 feePubKey
contextToFeeKey(
55 const Context
&context
,
56 AppleCSPSession
&session
,
57 CSSM_ATTRIBUTE_TYPE attrType
, // CSSM_ATTRIBUTE_KEY, CSSM_ATTRIBUTE_PUBLIC_KEY
58 CSSM_KEYCLASS keyClass
, // CSSM_KEYCLASS_{PUBLIC,PRIVATE}_KEY
59 CSSM_KEYUSE usage
, // CSSM_KEYUSE_ENCRYPT, CSSM_KEYUSE_SIGN, etc.
60 bool &mallocdKey
); // RETURNED
63 * Convert a CssmKey to a feePubKey. May result in the creation of a new
64 * feePubKey (when cssmKey is a raw key); allocdKey is true in that case
65 * in which case the caller generally has to free the allocd key).
67 feePubKey
cssmKeyToFee(
68 const CssmKey
&cssmKey
,
69 AppleCSPSession
&session
,
70 bool &allocdKey
); // RETURNED
73 * Convert a raw CssmKey to a newly alloc'd feePubKey.
75 feePubKey
rawCssmKeyToFee(
76 const CssmKey
&cssmKey
);
79 * Glue function which allows C code to use AppleCSPSession
80 * as an RNG. A ptr to this function gets passed down to
81 * CryptKit C functions as a feeRandFcn.
83 feeReturn
feeRandCallback(
84 void *ref
, // actually an AppleCSPSession *
85 unsigned char *bytes
, // must be alloc'd by caller
88 } /* namespace CryptKit */
90 #endif /* _FEE_CSP_UTILS_H_ */
91 #endif /* CRYPTKIT_CSP_ENABLE */