]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
1 | /* |
2 | * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. | |
3 | * | |
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 | |
8 | * using this file. | |
9 | * | |
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. | |
16 | */ | |
17 | ||
18 | ||
19 | /* | |
20 | * FEECSPUtils.h - Misc. utility function for FEE/CryptKit CSP. | |
21 | * | |
22 | * Created 2/20/2001 by dmitch. | |
23 | */ | |
24 | ||
25 | #ifdef CRYPTKIT_CSP_ENABLE | |
26 | ||
27 | #ifndef _FEE_CSP_UTILS_H_ | |
28 | #define _FEE_CSP_UTILS_H_ | |
29 | ||
30 | #include "AppleCSPSession.h" | |
31 | #include <security_cryptkit/feeTypes.h> | |
32 | #include <security_cdsa_utilities/context.h> | |
33 | ||
34 | /* | |
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. | |
38 | */ | |
39 | #define FEE_KEYBLOB_DEFAULT_FORMAT CSSM_KEYBLOB_RAW_FORMAT_NONE | |
40 | ||
41 | namespace CryptKit { | |
42 | ||
43 | /* Given a FEE error, throw appropriate CssmError */ | |
44 | void throwCryptKit( | |
45 | feeReturn frtn, | |
46 | const char *op); /* optional */ | |
47 | ||
48 | /* | |
49 | * Given a Context: | |
50 | * -- obtain CSSM key of specified CSSM_ATTRIBUTE_TYPE | |
51 | * -- validate keyClass | |
52 | * -- validate keyUsage | |
53 | * -- convert to feePubKey, allocating the feePubKey if necessary | |
54 | */ | |
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 | |
62 | ||
63 | /* | |
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). | |
67 | */ | |
68 | feePubKey cssmKeyToFee( | |
69 | const CssmKey &cssmKey, | |
70 | AppleCSPSession &session, | |
71 | bool &allocdKey); // RETURNED | |
72 | ||
73 | /* | |
74 | * Convert a raw CssmKey to a newly alloc'd feePubKey. | |
75 | */ | |
76 | feePubKey rawCssmKeyToFee( | |
77 | const CssmKey &cssmKey); | |
78 | ||
79 | /* | |
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. | |
83 | */ | |
84 | feeReturn feeRandCallback( | |
85 | void *ref, // actually an AppleCSPSession * | |
86 | unsigned char *bytes, // must be alloc'd by caller | |
87 | unsigned numBytes); | |
88 | ||
89 | } /* namespace CryptKit */ | |
90 | ||
91 | #endif /* _FEE_CSP_UTILS_H_ */ | |
92 | #endif /* CRYPTKIT_CSP_ENABLE */ |