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 // BinaryKey.h - CSP-wide BinaryKey base class
23 #ifndef _H_BINARY_KEY_
24 #define _H_BINARY_KEY_
26 #include <Security/utilities.h>
27 #include <Security/cssmtype.h>
29 // opaque key reference type
30 typedef uint32 KeyRef
;
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().
38 BinaryKey() : mKeyRef(0) { }
39 virtual ~BinaryKey() { mKeyRef
= 0; }
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.
50 virtual void generateKeyBlob(
51 CssmAllocator
&allocator
,
53 CSSM_KEYBLOB_FORMAT
&format
) // in/out, CSSM_KEYBLOB_RAW_FORMAT_PKCS1, etc.
55 CssmError::throwMe(CSSMERR_CSP_FUNCTION_NOT_IMPLEMENTED
);
58 CssmKey::Header mKeyHeader
;
62 // Binary key representing a symmetric key.
63 class SymmetricBinaryKey
: public BinaryKey
67 unsigned keySizeInBits
);
68 ~SymmetricBinaryKey();
70 CssmAllocator
&allocator
,
72 CSSM_KEYBLOB_FORMAT
&format
); // CSSM_KEYBLOB_RAW_FORMAT_PKCS1, etc.
75 CssmAllocator
&mAllocator
;
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.
84 bool symmetricCssmKeyToBinary(
85 const CssmKey
&cssmKey
,
86 BinaryKey
**binKey
); // RETURNED
88 #endif // _H_BINARY_KEY_