]> git.saurik.com Git - apple/security.git/blob - AppleCSP/AppleCSP/BinaryKey.h
ef42392d67691e653a847c4f025629aa33151eb1
[apple/security.git] / AppleCSP / AppleCSP / BinaryKey.h
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 // BinaryKey.h - CSP-wide BinaryKey base class
21 //
22
23 #ifndef _H_BINARY_KEY_
24 #define _H_BINARY_KEY_
25
26 #include <Security/utilities.h>
27 #include <Security/cssmtype.h>
28
29 // opaque key reference type
30 typedef uint32 KeyRef;
31
32 // frame for Binary key; all modules (BSAFE, CryptKit) must subclass
33 // this and add a member whose type is the native raw key object.
34 // Subclasses must implement constructor, destructor, and generateKeyBlob().
35 class BinaryKey
36 {
37 public:
38 BinaryKey() : mKeyRef(0) { }
39 virtual ~BinaryKey() { mKeyRef = 0; }
40
41 /*
42 * Generate raw key blob.
43 * The format argument is an in/out parameter and is optionally used
44 * to request a specific keyblob format for providers which can generate
45 * multipleÊformats. This value comes from an optional
46 * CSSM_ATTRIBUTE_{PUBLIC,PRIVATE,SYMMETRIC}_KEY_FORMAT attribute in the current
47 * context. If so such attribute is present, the default value
48 * CSSM_KEYBLOB_RAW_FORMAT_NONE is specified as the default input param.
49 */
50 virtual void generateKeyBlob(
51 CssmAllocator &allocator,
52 CssmData &blob,
53 CSSM_KEYBLOB_FORMAT &format) // in/out, CSSM_KEYBLOB_RAW_FORMAT_PKCS1, etc.
54 {
55 CssmError::throwMe(CSSMERR_CSP_FUNCTION_NOT_IMPLEMENTED);
56 }
57
58 CssmKey::Header mKeyHeader;
59 KeyRef mKeyRef;
60 };
61
62 // Binary key representing a symmetric key.
63 class SymmetricBinaryKey : public BinaryKey
64 {
65 public:
66 SymmetricBinaryKey(
67 unsigned keySizeInBits);
68 ~SymmetricBinaryKey();
69 void generateKeyBlob(
70 CssmAllocator &allocator,
71 CssmData &blob,
72 CSSM_KEYBLOB_FORMAT &format); // CSSM_KEYBLOB_RAW_FORMAT_PKCS1, etc.
73
74 CssmData mKeyData;
75 CssmAllocator &mAllocator;
76 };
77
78 /*
79 * Stateless function to cook up a BinaryKey given a
80 * symmetric CssmKey in RAW format. Returns true on
81 * success, false if we can't deal with this type of key,
82 * throws exception on other runtime errors.
83 */
84 bool symmetricCssmKeyToBinary(
85 const CssmKey &cssmKey,
86 BinaryKey **binKey); // RETURNED
87
88 #endif // _H_BINARY_KEY_
89