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 #ifndef _H_CDSA_CLIENT_WRAPKEY
23 #define _H_CDSA_CLIENT_WRAPKEY 1
25 #include <security_cdsa_client/cspclient.h>
26 #include <security_cdsa_client/cryptoclient.h>
27 #include <security_cdsa_client/keyclient.h>
31 namespace CssmClient
{
37 class WrapKey
: public Crypt
{
39 WrapKey(const CSP
&csp
, CSSM_ALGORITHMS alg
) :
40 Crypt(csp
, alg
), mWrappedKeyFormat(CSSM_KEYBLOB_WRAPPED_FORMAT_NONE
) {}
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
); }
48 Key
operator () (Key
&keyToBeWrapped
, const CssmData
*descriptiveData
= NULL
);
49 void operator () (const CssmKey
&keyToBeWrapped
, CssmKey
&wrappedKey
,
50 const CssmData
*descriptiveData
= NULL
);
56 CSSM_KEYBLOB_FORMAT mWrappedKeyFormat
;
61 // Unwrap a key. This creates a new key object
63 class UnwrapKey
: public Crypt
, public RccBearer
{
65 UnwrapKey(const CSP
&csp
, CSSM_ALGORITHMS alg
) : Crypt(csp
, alg
) {}
69 Key
operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
);
70 void operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
71 CssmKey
&unwrappedKey
);
73 Key
operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
74 Key
&optionalPublicKey
);
75 void operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
76 CssmKey
&unwrappedKey
, const CssmKey
*optionalPublicKey
);
78 Key
operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
79 CssmData
*descriptiveData
);
80 void operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
81 CssmKey
&unwrappedKey
, CssmData
*descriptiveData
);
83 Key
operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
84 const Key
&optionalPublicKey
, CssmData
*descriptiveData
);
85 void operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
86 CssmKey
&unwrappedKey
, CssmData
*descriptiveData
,
87 const CssmKey
*optionalPublicKey
);
92 // Derive a key in various and wonderous ways. Creates a new key object.
94 class DeriveKey
: public Crypt
, public RccBearer
{
96 DeriveKey(const CSP
&csp
, CSSM_ALGORITHMS alg
, CSSM_ALGORITHMS target
, uint32 size
= 0)
97 : Crypt(csp
, alg
), mKeySize(size
), mTargetType(target
), mIterationCount(0),
98 mSeed(NULL
), mSalt(NULL
) { }
101 CSSM_ALGORITHMS
targetType() const { return mTargetType
; }
102 void targetType(CSSM_ALGORITHMS alg
) { mTargetType
= alg
; }
103 uint32
iterationCount() const { return mIterationCount
; }
104 void iterationCount(uint32 c
) { mIterationCount
= c
; }
105 const CssmCryptoData
seed() const { return *mSeed
; }
106 void seed(const CssmCryptoData
&data
) { mSeed
= &data
; }
107 const CssmData
salt() const { return *mSalt
; }
108 void salt(const CssmData
&data
) { mSalt
= &data
; }
110 Key
operator () (CssmData
*param
, const KeySpec
&spec
);
111 void operator () (CssmData
*param
, const KeySpec
&spec
,
112 CssmKey
&derivedKey
);
118 CSSM_ALGORITHMS mTargetType
;
119 uint32 mIterationCount
;
120 const CssmCryptoData
*mSeed
;
121 const CssmData
*mSalt
;
124 } // end namespace CssmClient
125 } // end namespace Security
127 #endif // _H_CDSA_CLIENT_WRAPKEY