Update contrib.
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * software Mac implementation
16 * Software Mac Implementation
28 #include "pluginconfig.h"
30 // headers from cryptospi framework
31 #include <cryptospi/cryptospidef.h>
33 // HMAC plugin headers
38 using namespace SoftwareCrypto;
41 CMacImpl* CMacImpl::NewL(const CKey& aKey, const TUid aImplementationId, const CCryptoParams* aAlgorithmParams)
43 CMacImpl* self = new (ELeave) CMacImpl();
44 CleanupStack::PushL(self);
45 self->ConstructL(aKey, aImplementationId, aAlgorithmParams);
54 void CMacImpl::ConstructL(const CKey& aKey, const TUid aImplementationId, const CCryptoParams* /*aAlgorithmParams*/)
56 iImplementationUid = aImplementationId;
57 iKey = CryptoSpi::CKey::NewL(aKey);
59 MSoftwareHash* hashImpl = NULL;
61 switch (aImplementationId.iUid)
63 case KTestPlugin01MacMd2_1:
64 case KTestPlugin01MacMd2_2:
66 hashImpl = CMD2Impl::NewL(KTestPlugin01Md2_1Uid);
67 CleanupClosePushL(*hashImpl);
68 iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl);
72 case KTestPlugin01XcbcMac96:
74 CSymmetricCipher* symmetricCipher = NULL;
75 CryptoSpi::CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipher,
76 CryptoSpi::KAesUid, *iKey,
77 CryptoSpi::KCryptoModeEncryptUid,
78 CryptoSpi::KOperationModeCBCUid,
79 CryptoSpi::KPaddingModeNoneUid,
82 iCmacImpl= CCMacImpl::NewL(*iKey, symmetricCipher, CryptoSpi::KAlgorithmCipherAesXcbcMac96);
88 User::Leave(KErrNotSupported);
92 if(iBase == EHashBased)
94 CleanupStack::PopAndDestroy(hashImpl);
108 void CMacImpl::Reset()
110 if (iBase == EHashBased)
114 else if (iBase == ECipherBased)
120 void CMacImpl::Close()
125 void CMacImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
127 aPluginCharacteristics=NULL;
128 TInt macNum=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*);
129 for (TInt i=0;i<macNum;++i)
131 if (KMacCharacteristics[i]->iMacChar.iImplementationUID==ImplementationUid().iUid)
133 aPluginCharacteristics = KMacCharacteristics[i];
139 const CExtendedCharacteristics* CMacImpl::GetExtendedCharacteristicsL()
141 return (iBase == EHashBased) ? iHmacImpl->GetExtendedCharacteristicsL(): iCmacImpl->GetExtendedCharacteristicsL();
144 TAny* CMacImpl::GetExtension(TUid aExtensionId)
146 return (iBase == EHashBased) ? iHmacImpl->GetExtension(aExtensionId): NULL;
149 TUid CMacImpl::ImplementationUid() const
151 return iImplementationUid;
154 TPtrC8 CMacImpl::MacL(const TDesC8& aMessage)
156 return (iBase == EHashBased) ? iHmacImpl->Hash(aMessage):iCmacImpl->MacL(aMessage);
159 void CMacImpl::UpdateL(const TDesC8& aMessage)
161 (iBase == EHashBased) ? iHmacImpl->Update(aMessage):iCmacImpl->UpdateL(aMessage);
164 TPtrC8 CMacImpl::FinalL(const TDesC8& aMessage)
166 return (iBase == EHashBased) ? iHmacImpl->Final(aMessage):iCmacImpl->FinalL(aMessage);
169 void CMacImpl::ReInitialiseAndSetKeyL(const CKey& aKey)
173 iKey = CryptoSpi::CKey::NewL(aKey);
175 if (iBase == EHashBased)
177 iHmacImpl->SetKeyL(aKey);
180 else if (iBase == ECipherBased)
182 iCmacImpl->ReInitialiseAndSetKeyL(aKey);
186 MMac* CMacImpl::ReplicateL()
188 CMacImpl* that= new(ELeave) CMacImpl();
189 CleanupStack::PushL(that);
190 that->iImplementationUid = iImplementationUid;
192 that->iKey=CKey::NewL(*iKey);
194 if(iBase == EHashBased)
196 that->iHmacImpl=static_cast<CHMacImpl*>(iHmacImpl->ReplicateL());
198 else if (iBase == ECipherBased)
200 that->iCmacImpl= iCmacImpl->ReplicateL();
202 CleanupStack::Pop(that);
206 MMac* CMacImpl::CopyL()
208 CMacImpl* that= new(ELeave) CMacImpl();
209 CleanupStack::PushL(that);
210 that->iImplementationUid = iImplementationUid;
212 that->iKey=CKey::NewL(*iKey);
214 if(iBase == EHashBased)
216 that->iHmacImpl=static_cast<CHMacImpl*>(iHmacImpl->CopyL());
218 else if (iBase == ECipherBased)
220 that->iCmacImpl= iCmacImpl->CopyL();
222 CleanupStack::Pop(that);