]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_apple_csp/lib/AppleCSPKeys.h
Security-57337.40.85.tar.gz
[apple/security.git] / OSX / libsecurity_apple_csp / lib / AppleCSPKeys.h
1 /*
2 * Copyright (c) 2003,2011,2014 Apple 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
7 * obtain a copy of the License at http://www.apple.com/publicsource and
8 * read it before 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
12 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
13 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
15 * Please see the License for the specific language governing rights and
16 * limitations under the License.
17 */
18 /*
19 * AppleCSPKeys.h - Key support
20 */
21
22 #ifndef _APPLE_CSP_KEYS_H_
23 #define _APPLE_CSP_KEYS_H_
24
25 #include "AppleCSPSession.h"
26
27 /*
28 * Class to provide key-specific info. Each module dealing with keys
29 * implements one of these. It's sort of like a CSP-specific CSPContext
30 * without the Context object. AppleCSPSession finds one of these by
31 * querying module-specific subclasses, looking for one in which
32 * the constructor succeeds (which occurs when the specified key
33 * meets a subclass's specification).
34 */
35 class CSPKeyInfoProvider
36 {
37 protected:
38 CSPKeyInfoProvider(
39 const CssmKey &cssmKey,
40 AppleCSPSession &session) :
41 mKey(cssmKey),
42 mSession(session) { }
43 public:
44 /*
45 * This is the public way to construct - returns NULL if key is
46 * not handled. Static declaration per subclass.
47 *
48 * static CSPKeyInfoProvider *provider(
49 * const CssmKey &cssmKey,
50 *  AppleCSPSession &session);
51 */
52 virtual ~CSPKeyInfoProvider() { }
53
54 /*
55 * Cook up a Binary key.
56 *
57 * Incoming paramKey optionally contains a key from which
58 * additional algorithm parameters may be obtained to create
59 * a fully specified key in case the key provided to our
60 * constructor was a partial key.
61 *
62 * The attrFlags argument is a means for the info provider to
63 * inform the caller that the incoming key has additional
64 * attributes, currently CSSM_KEYATTR_PARTIAL. The provider
65 * ORs in bits as appropriate.
66 */
67 virtual void CssmKeyToBinary(
68 CssmKey *paramKey, // optional
69 CSSM_KEYATTR_FLAGS &attrFlags, // IN/OUT
70 BinaryKey **binKey) = 0; // RETURNED
71
72 /* obtain key size in bits */
73 virtual void QueryKeySizeInBits(
74 CSSM_KEY_SIZE &keySize) = 0; // RETURNED
75
76 /*
77 * Get blob appropriate for calculating key digest, if possible
78 * to do without generating a BinaryKey. Returns true if
79 * successful, falseif BinaryKey generation is required.
80 */
81 virtual bool getHashableBlob(
82 Allocator &allocator,
83 CssmData &hashBlob) = 0; // blob to hash goes here
84
85 protected:
86 const CssmKey &mKey;
87 AppleCSPSession &mSession;
88 };
89
90 /*
91 * CSPKeyInfoProvider for symmetric keys (handled directly by
92 * the session).
93 */
94 class SymmetricKeyInfoProvider : public CSPKeyInfoProvider
95 {
96 private:
97 SymmetricKeyInfoProvider(
98 const CssmKey &cssmKey,
99 AppleCSPSession &session);
100 public:
101 static CSPKeyInfoProvider *provider(
102 const CssmKey &cssmKey,
103 AppleCSPSession &session);
104
105 ~SymmetricKeyInfoProvider() { }
106 void CssmKeyToBinary(
107 CssmKey *paramKey, // ignored
108 CSSM_KEYATTR_FLAGS &attrFlags, // IN/OUT
109 BinaryKey **binKey); // RETURNED
110 void QueryKeySizeInBits(
111 CSSM_KEY_SIZE &keySize); // RETURNED
112 bool getHashableBlob(
113 Allocator &allocator,
114 CssmData &hashBlob);
115 };
116
117 #endif /* _APPLE_CSP_KEYS_H_ */
118