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 // wrapkey - client interface for wrapping and unwrapping keys
22 #include <security_cdsa_client/wrapkey.h>
25 namespace CssmClient
{
29 WrapKey::operator () (Key
&keyToBeWrapped
, const CssmData
*descriptiveData
)
33 check(CSSM_WrapKey(handle(), neededCred(), keyToBeWrapped
, descriptiveData
,
34 wrappedKey
.makeNewKey(attachment())));
35 wrappedKey
->activate();
41 WrapKey::operator () (const CssmKey
&keyToBeWrapped
, CssmKey
&wrappedKey
,
42 const CssmData
*descriptiveData
)
44 check(CSSM_WrapKey(handle(), neededCred(), &keyToBeWrapped
,
45 descriptiveData
, &wrappedKey
));
54 if (mWrappedKeyFormat
!= CSSM_KEYBLOB_WRAPPED_FORMAT_NONE
)
55 set(CSSM_ATTRIBUTE_WRAPPED_KEY_FORMAT
, mWrappedKeyFormat
);
60 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
)
62 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
64 check(CSSM_UnwrapKey(handle(), NULL
,
65 &keyToBeUnwrapped
, spec
.usage
, spec
.attributes
,
66 spec
.label
, &compositeRcc(),
67 unwrappedKey
.makeNewKey(attachment()), &data
));
68 unwrappedKey
->activate();
74 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
75 CssmKey
&unwrappedKey
)
77 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
78 check(CSSM_UnwrapKey(handle(), NULL
, &keyToBeUnwrapped
, spec
.usage
,
79 spec
.attributes
, spec
.label
, &compositeRcc(),
80 &unwrappedKey
, &data
));
84 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
85 Key
&optionalPublicKey
)
87 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
89 check(CSSM_UnwrapKey(handle(), optionalPublicKey
,
90 &keyToBeUnwrapped
, spec
.usage
, spec
.attributes
,
91 spec
.label
, &compositeRcc(),
92 unwrappedKey
.makeNewKey(attachment()), &data
));
94 unwrappedKey
->activate();
100 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
101 CssmKey
&unwrappedKey
,
102 const CssmKey
*optionalPublicKey
)
104 CssmData
data(reinterpret_cast<uint8
*>(1), 0);
105 check(CSSM_UnwrapKey(handle(), optionalPublicKey
, &keyToBeUnwrapped
,
106 spec
.usage
, spec
.attributes
, spec
.label
,
107 &compositeRcc(), &unwrappedKey
, &data
));
112 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
113 CssmData
*descriptiveData
)
116 check(CSSM_UnwrapKey(handle(), NULL
, &keyToBeUnwrapped
, spec
.usage
,
117 spec
.attributes
, spec
.label
, &compositeRcc(),
118 unwrappedKey
.makeNewKey(attachment()),
120 unwrappedKey
->activate();
126 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
127 CssmKey
&unwrappedKey
, CssmData
*descriptiveData
)
129 check(CSSM_UnwrapKey(handle(), NULL
, &keyToBeUnwrapped
, spec
.usage
,
130 spec
.attributes
, spec
.label
, &compositeRcc(),
131 &unwrappedKey
, descriptiveData
));
135 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
136 const Key
&optionalPublicKey
, CssmData
*descriptiveData
)
139 check(CSSM_UnwrapKey(handle(), optionalPublicKey
, &keyToBeUnwrapped
,
140 spec
.usage
, spec
.attributes
, spec
.label
,
142 unwrappedKey
.makeNewKey(attachment()),
144 unwrappedKey
->activate();
150 UnwrapKey::operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
151 CssmKey
&unwrappedKey
, CssmData
*descriptiveData
,
152 const CssmKey
*optionalPublicKey
)
154 check(CSSM_UnwrapKey(handle(), optionalPublicKey
, &keyToBeUnwrapped
,
155 spec
.usage
, spec
.attributes
, spec
.label
,
156 &compositeRcc(), &unwrappedKey
,
161 void DeriveKey::activate()
165 check(CSSM_CSP_CreateDeriveKeyContext(attachment()->handle(), mAlgorithm
,
166 mTargetType
, mKeySize
, mCred
, mKey
, mIterationCount
, mSalt
, mSeed
, &mHandle
));
173 DeriveKey::operator () (CssmData
*param
, const KeySpec
&spec
)
176 check(CSSM_DeriveKey(handle(), param
, spec
.usage
, spec
.attributes
,
177 spec
.label
, &compositeRcc(),
178 derivedKey
.makeNewKey(attachment())));
179 derivedKey
->activate();
185 DeriveKey::operator () (CssmData
*param
, const KeySpec
&spec
,
188 check(CSSM_DeriveKey(handle(), param
, spec
.usage
, spec
.attributes
,
189 spec
.label
, &compositeRcc(), &derivedKey
));
192 } // end namespace CssmClient
193 } // end namespace Security