os/security/crypto/weakcryptospi/test/tplugins/src/tplugin01/softwarehashbase.cpp
Update contrib.
2 * Copyright (c) 2007-2010 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 hash base class implementation
16 * software hash base class implementation
25 #include "softwarehashbase.h"
27 #include <cryptospi/hashplugin.h>
28 #include "pluginconfig.h"
29 #include <cryptospi/keys.h>
35 using namespace SoftwareCrypto;
37 CSoftwareHash* CSoftwareHash::NewL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey)
39 CSoftwareHash* self=NewLC(aAlgorithm, aOperationMode, aKey);
44 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
45 CSoftwareHash* CSoftwareHash::NewL(TUid aAlgorithm)
47 CSoftwareHash* self=NewLC(aAlgorithm, KHashModeUid, NULL);
53 CSoftwareHash* CSoftwareHash::NewLC(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey)
55 CSoftwareHash* self=new (ELeave) CSoftwareHash();
56 CleanupStack::PushL(self);
57 self->ConstructL(aAlgorithm, aOperationMode, aKey);
61 CSoftwareHash::CSoftwareHash()
65 CSoftwareHash::~CSoftwareHash()
79 void CSoftwareHash::ConstructL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey)
82 // Only Hash and Hmac mode are supported.
84 if (aOperationMode!=KHmacModeUid && aOperationMode!=KHashModeUid)
86 User::Leave(KErrNotSupported);
89 //Set the key if there is one
95 switch (aAlgorithm.iUid)
97 case KTestPlugin01Md2_1:
98 case KTestPlugin01Md2_2:
100 iHashImpl=CMD2Impl::NewL(aAlgorithm);
104 // case KCryptoPluginMd5:
106 // iHashImpl=CMD5Impl::NewL();
110 // case KCryptoPluginSha1:
112 // iHashImpl=CSHA1Impl::NewL();
117 User::Leave(KErrNotSupported);
120 SetOperationModeL(aOperationMode);
123 void CSoftwareHash::SetOperationModeL(TUid aOperationMode)
125 switch (aOperationMode.iUid)
130 //Only create hmac implementation if there isn't one
136 iHmacImpl=CHMacImpl::NewL(*iKey, iHashImpl);
140 iHmacImpl=CHMacImpl::NewL(iHashImpl);
153 User::Leave(KErrNotSupported);
157 // Set the operation mode.
159 iOperationMode=aOperationMode;
162 MSoftwareHash* CSoftwareHash::Impl()
164 MSoftwareHash* impl=NULL;
165 if (iOperationMode==KHashModeUid)
169 else if (iOperationMode==KHmacModeUid && iKey)
176 void CSoftwareHash::SetKeyL(const CKey& aKey)
180 iKey=CKey::NewL(aKey);
183 iHmacImpl->SetKeyL(aKey);
187 void CSoftwareHash::Reset()
200 void CSoftwareHash::Close()
205 void CSoftwareHash::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
207 MSoftwareHash* impl=Impl();
210 impl->GetCharacteristicsL(aPluginCharacteristics);
214 User::Leave(KErrNotReady);
218 const CExtendedCharacteristics* CSoftwareHash::GetExtendedCharacteristicsL()
220 MSoftwareHash* impl=Impl();
223 User::Leave(KErrNotReady);
225 return impl->GetExtendedCharacteristicsL();
228 TAny* CSoftwareHash::GetExtension(TUid aExtensionId)
230 MSoftwareHash* impl=Impl();
233 return impl->GetExtension(aExtensionId);
241 TPtrC8 CSoftwareHash::Hash(const TDesC8& aMessage)
243 MSoftwareHash* impl=Impl();
246 return impl->Hash(aMessage);
254 void CSoftwareHash::Update(const TDesC8& aMessage)
256 MSoftwareHash* impl=Impl();
259 return impl->Update(aMessage);
263 TPtrC8 CSoftwareHash::Final(const TDesC8& aMessage)
265 MSoftwareHash* impl=Impl();
268 return impl->Final(aMessage);
276 MHash* CSoftwareHash::ReplicateL()
278 CSoftwareHash* that=new(ELeave)CSoftwareHash();
279 CleanupStack::PushL(that);
282 that->iKey=CKey::NewL(*this->iKey);
284 that->iOperationMode=this->iOperationMode;
285 that->iHashImpl=static_cast<MSoftwareHash*>(this->iHashImpl->ReplicateL());
288 that->iHmacImpl=static_cast<MSoftwareHash*>(this->iHmacImpl->ReplicateL());
294 MHash* CSoftwareHash::CopyL()
296 CSoftwareHash* that=new(ELeave)CSoftwareHash();
297 CleanupStack::PushL(that);
300 that->iKey=CKey::NewL(*this->iKey);
302 that->iOperationMode=this->iOperationMode;
303 that->iHashImpl=static_cast<MSoftwareHash*>(this->iHashImpl->CopyL());
306 that->iHmacImpl=static_cast<MSoftwareHash*>(this->iHmacImpl->CopyL());