]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/wrapkey.h
Security-28.tar.gz
[apple/security.git] / cdsa / cdsa_client / wrapkey.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 // wrapkey - client interface for wrapping and unwrapping keys
21 //
22 #ifndef _H_CDSA_CLIENT_WRAPKEY
23 #define _H_CDSA_CLIENT_WRAPKEY 1
24
25 #include <Security/cspclient.h>
26 #include <Security/cryptoclient.h>
27 #include <Security/keyclient.h>
28
29
30 namespace Security
31 {
32
33 namespace CssmClient
34 {
35
36 class WrapKey : public Crypt
37 {
38 public:
39 WrapKey(const CSP &csp, CSSM_ALGORITHMS alg) :
40 Crypt(csp, alg), mWrappedKeyFormat(CSSM_KEYBLOB_WRAPPED_FORMAT_NONE) {}
41
42 public:
43 CSSM_KEYBLOB_FORMAT wrappedKeyFormat() const { return mWrappedKeyFormat; }
44 void wrappedKeyFormat(CSSM_KEYBLOB_FORMAT wrappedKeyFormat)
45 { mWrappedKeyFormat = wrappedKeyFormat; set(CSSM_ATTRIBUTE_WRAPPED_KEY_FORMAT, wrappedKeyFormat); }
46
47 // wrap the key
48 Key operator () (Key &keyToBeWrapped, const CssmData *descriptiveData = NULL);
49 void operator () (const CssmKey &keyToBeWrapped, CssmKey &wrappedKey,
50 const CssmData *descriptiveData = NULL);
51
52 protected:
53 void activate();
54
55 private:
56 CSSM_KEYBLOB_FORMAT mWrappedKeyFormat;
57 };
58
59 class UnwrapKey : public Crypt
60 {
61 public:
62 UnwrapKey(const CSP &csp, CSSM_ALGORITHMS alg) : Crypt(csp, alg) {}
63
64 public:
65 // wrap the key
66 Key operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec);
67 void operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec,
68 CssmKey &unwrappedKey);
69
70 Key operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec,
71 Key &optionalPublicKey);
72 void operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec,
73 CssmKey &unwrappedKey, const CssmKey *optionalPublicKey);
74
75 Key operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec,
76 CssmData *descriptiveData);
77 void operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec,
78 CssmKey &unwrappedKey, CssmData *descriptiveData);
79
80 Key operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec,
81 Key &optionalPublicKey, CssmData *descriptiveData);
82 void operator () (const CssmKey &keyToBeUnwrapped, const KeySpec &spec,
83 CssmKey &unwrappedKey, CssmData *descriptiveData,
84 const CssmKey *optionalPublicKey);
85 };
86
87 class DeriveKey : public Crypt
88 {
89 public:
90 DeriveKey(const CSP &csp, CSSM_ALGORITHMS alg, CSSM_ALGORITHMS target, uint32 size = 0)
91 : Crypt(csp, alg), mKeySize(size), mTargetType(target), mIterationCount(0),
92 mSeed(NULL), mSalt(NULL) { }
93
94 public:
95 CSSM_ALGORITHMS targetType() const { return mTargetType; }
96 void targetType(CSSM_ALGORITHMS alg) { mTargetType = alg; }
97 uint32 iterationCount() const { return mIterationCount; }
98 void iterationCount(uint32 c) { mIterationCount = c; }
99 const CssmCryptoData seed() const { return *mSeed; }
100 void seed(const CssmCryptoData &data) { mSeed = &data; }
101 const CssmData salt() const { return *mSalt; }
102 void salt(const CssmData &data) { mSalt = &data; }
103
104 Key operator () (CssmData *param, const KeySpec &spec);
105 void operator () (CssmData *param, const KeySpec &spec,
106 CssmKey &derivedKey);
107
108 void activate();
109
110 private:
111 uint32 mKeySize;
112 CSSM_ALGORITHMS mTargetType;
113 uint32 mIterationCount;
114 const CssmCryptoData *mSeed;
115 const CssmData *mSalt;
116 };
117
118 } // end namespace CssmClient
119
120 } // end namespace Security
121
122 #endif // _H_CDSA_CLIENT_WRAPKEY