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/cspclient.h>
26 #include <Security/cryptoclient.h>
27 #include <Security/keyclient.h>
36 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
;
59 class UnwrapKey
: public Crypt
62 UnwrapKey(const CSP
&csp
, CSSM_ALGORITHMS alg
) : Crypt(csp
, alg
) {}
66 Key
operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
);
67 void operator () (const CssmKey
&keyToBeUnwrapped
, const KeySpec
&spec
,
68 CssmKey
&unwrappedKey
);
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
);
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
);
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
);
87 class DeriveKey
: public Crypt
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
) { }
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
; }
104 Key
operator () (CssmData
*param
, const KeySpec
&spec
);
105 void operator () (CssmData
*param
, const KeySpec
&spec
,
106 CssmKey
&derivedKey
);
112 CSSM_ALGORITHMS mTargetType
;
113 uint32 mIterationCount
;
114 const CssmCryptoData
*mSeed
;
115 const CssmData
*mSalt
;
118 } // end namespace CssmClient
120 } // end namespace Security
122 #endif // _H_CDSA_CLIENT_WRAPKEY