os/security/crypto/weakcryptospi/test/tplugins/src/tplugin02/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>
33 using namespace SoftwareCrypto;
35 CSoftwareHash* CSoftwareHash::NewL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey)
37 CSoftwareHash* self=NewLC(aAlgorithm, aOperationMode, aKey);
42 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
43 CSoftwareHash* CSoftwareHash::NewL(TUid aAlgorithm)
45 CSoftwareHash* self=NewLC(aAlgorithm, KHashModeUid, NULL);
51 CSoftwareHash* CSoftwareHash::NewLC(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey)
53 CSoftwareHash* self=new (ELeave) CSoftwareHash();
54 CleanupStack::PushL(self);
55 self->ConstructL(aAlgorithm, aOperationMode, aKey);
59 CSoftwareHash::CSoftwareHash()
63 CSoftwareHash::~CSoftwareHash()
77 void CSoftwareHash::ConstructL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey)
80 // Only Hash and Hmac mode are supported.
82 if (aOperationMode!=KHmacModeUid && aOperationMode!=KHashModeUid)
84 User::Leave(KErrNotSupported);
87 //Set the key if there is one
93 switch (aAlgorithm.iUid)
95 /*case KCryptoPluginMd2:
97 iHashImpl=CMD2Impl::NewL();
101 case KTestPlugin02Md5_1:
103 iHashImpl=CMD5Impl::NewL(aAlgorithm);
107 /*case KTestPlugin02Sha1_1:
109 iHashImpl=CSHA1Impl::NewL(aAlgorithm);
114 User::Leave(KErrNotSupported);
117 SetOperationModeL(aOperationMode);
120 void CSoftwareHash::SetOperationModeL(TUid aOperationMode)
122 switch (aOperationMode.iUid)
127 //Only create hmac implementation if there isn't one
133 iHmacImpl=CHMacImpl::NewL(*iKey, iHashImpl);
137 iHmacImpl=CHMacImpl::NewL(iHashImpl);
150 User::Leave(KErrNotSupported);
154 // Set the operation mode.
156 iOperationMode=aOperationMode;
159 MSoftwareHash* CSoftwareHash::Impl()
161 MSoftwareHash* impl=NULL;
162 if (iOperationMode==KHashModeUid)
166 else if (iOperationMode==KHmacModeUid && iKey)
173 void CSoftwareHash::SetKeyL(const CKey& aKey)
177 iKey=CKey::NewL(aKey);
180 iHmacImpl->SetKeyL(aKey);
184 void CSoftwareHash::Reset()
197 void CSoftwareHash::Close()
202 void CSoftwareHash::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
204 MSoftwareHash* impl=Impl();
207 impl->GetCharacteristicsL(aPluginCharacteristics);
211 User::Leave(KErrNotReady);
215 const CExtendedCharacteristics* CSoftwareHash::GetExtendedCharacteristicsL()
217 MSoftwareHash* impl=Impl();
220 User::Leave(KErrNotReady);
222 return impl->GetExtendedCharacteristicsL();
225 TAny* CSoftwareHash::GetExtension(TUid aExtensionId)
227 MSoftwareHash* impl=Impl();
230 return impl->GetExtension(aExtensionId);
238 TPtrC8 CSoftwareHash::Hash(const TDesC8& aMessage)
240 MSoftwareHash* impl=Impl();
243 return impl->Hash(aMessage);
251 void CSoftwareHash::Update(const TDesC8& aMessage)
253 MSoftwareHash* impl=Impl();
256 return impl->Update(aMessage);
260 TPtrC8 CSoftwareHash::Final(const TDesC8& aMessage)
262 MSoftwareHash* impl=Impl();
265 return impl->Final(aMessage);
273 MHash* CSoftwareHash::ReplicateL()
275 CSoftwareHash* that=new(ELeave)CSoftwareHash();
276 CleanupStack::PushL(that);
279 that->iKey=CKey::NewL(*this->iKey);
281 that->iOperationMode=this->iOperationMode;
282 that->iHashImpl=static_cast<MSoftwareHash*>(this->iHashImpl->ReplicateL());
285 that->iHmacImpl=static_cast<MSoftwareHash*>(this->iHmacImpl->ReplicateL());
291 MHash* CSoftwareHash::CopyL()
293 CSoftwareHash* that=new(ELeave)CSoftwareHash();
294 CleanupStack::PushL(that);
297 that->iKey=CKey::NewL(*this->iKey);
299 that->iOperationMode=this->iOperationMode;
300 that->iHashImpl=static_cast<MSoftwareHash*>(this->iHashImpl->CopyL());
303 that->iHmacImpl=static_cast<MSoftwareHash*>(this->iHmacImpl->CopyL());