2 * Copyright (c) 2003,2011-2012,2014 Apple 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
7 * obtain a copy of the License at http://www.apple.com/publicsource and
8 * read it before using this file.
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.
19 * AppleCSPKeys.cpp - Key support
22 #include "AppleCSPKeys.h"
23 #include "AppleCSPUtils.h"
25 * CSPKeyInfoProvider for symmetric keys.
27 CSPKeyInfoProvider
*SymmetricKeyInfoProvider::provider(
28 const CssmKey
&cssmKey
,
29 AppleCSPSession
&session
)
31 if(cssmKey
.blobType() != CSSM_KEYBLOB_RAW
) {
32 errorLog0("KeyInfoProvider deals only with RAW keys!\n");
33 CssmError::throwMe(CSSMERR_CSP_INTERNAL_ERROR
);
35 if(cssmKey
.keyClass() != CSSM_KEYCLASS_SESSION_KEY
) {
36 /* that's all we need to know */
39 return new SymmetricKeyInfoProvider(cssmKey
, session
);
42 SymmetricKeyInfoProvider::SymmetricKeyInfoProvider(
43 const CssmKey
&cssmKey
,
44 AppleCSPSession
&session
) :
45 CSPKeyInfoProvider(cssmKey
, session
)
49 /* cook up a Binary key */
50 void SymmetricKeyInfoProvider::CssmKeyToBinary(
51 CssmKey
*paramKey
, // ignored
52 CSSM_KEYATTR_FLAGS
&attrFlags
, // IN/OUT
55 CASSERT(mKey
.keyClass() == CSSM_KEYCLASS_SESSION_KEY
);
56 SymmetricBinaryKey
*symBinKey
= new SymmetricBinaryKey(
57 mKey
.KeyHeader
.LogicalKeySizeInBits
);
60 symBinKey
->mAllocator
);
64 /* obtain key size in bits */
65 void SymmetricKeyInfoProvider::QueryKeySizeInBits(
66 CSSM_KEY_SIZE
&keySize
)
68 /* FIXME - do we ever need to calculate RC2 effective size here? */
69 keySize
.LogicalKeySizeInBits
= keySize
.EffectiveKeySizeInBits
=
70 (uint32
)(mKey
.length() * 8);
74 * Obtain blob suitable for hashing in CSSM_APPLECSP_KEYDIGEST
77 bool SymmetricKeyInfoProvider::getHashableBlob(
79 CssmData
&blob
) // blob to hash goes here
82 * This is trivial: the raw key is already in the "proper" format.
84 assert(mKey
.blobType() == CSSM_KEYBLOB_RAW
);
85 const CssmData
&keyBlob
= CssmData::overlay(mKey
.KeyData
);
86 copyCssmData(keyBlob
, blob
, allocator
);