diff -r da2ae96f639b -r cd501b96611d cryptoplugins/cryptospiplugins/source/softwarecrypto/md2impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/md2impl.cpp Fri Nov 06 13:21:00 2009 +0200 @@ -0,0 +1,315 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software md2 implementation +* software md2 implementation +* +*/ + + +/** + @file +*/ + +#include "md2impl.h" + +#include +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + +CMD2Impl* CMD2Impl::NewL() + { + CMD2Impl* self=new (ELeave) CMD2Impl(); + return self; + } + +CMD2Impl* CMD2Impl::NewLC() + { + CMD2Impl* self=NewL(); + CleanupStack::PushL(self); + return self; + } + +CMD2Impl::CMD2Impl() : iHash(KMD2HashSize) + { + } + +CMD2Impl::CMD2Impl(const CMD2Impl& aCMD2Impl) +: iHash(aCMD2Impl.iHash),iNum(aCMD2Impl.iNum) + { + (void)Mem::Copy(iData, aCMD2Impl.iData, sizeof(iData)); + (void)Mem::Copy(iChecksum, aCMD2Impl.iChecksum, sizeof(iChecksum)); + (void)Mem::Copy(iState, aCMD2Impl.iState, sizeof(iState)); + } + +CMD2Impl::~CMD2Impl() + { + } + +void CMD2Impl::Reset() + { + Mem::FillZ(iData,sizeof(iData)); + Mem::FillZ(iChecksum,sizeof(iChecksum)); + Mem::FillZ(iState,sizeof(iState)); + iNum=0; + } + +void CMD2Impl::Close() + { + delete this; + } + +void CMD2Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + for (TInt i=0;icmn.iImplementationUID==ImplementationUid().iUid) + { + aPluginCharacteristics = KHashCharacteristics[i]; + break; + } + } + } + +CExtendedCharacteristics* CMD2Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CMD2Impl::GetExtendedCharacteristicsL() + { + return CMD2Impl::CreateExtendedCharacteristicsL(); + } + +TPtrC8 CMD2Impl::Hash(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + DoUpdate(aMessage.Ptr(),aMessage.Size()); + StoreState(); + DoFinal(); + ptr.Set(iHash); + RestoreState(); + return ptr; + } + +void CMD2Impl::Update(const TDesC8& aMessage) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + +TPtrC8 CMD2Impl::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if (aMessage!=KNullDesC8()) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + DoFinal(); + ptr.Set(iHash); + Reset(); + return ptr; + } + +MHash* CMD2Impl::ReplicateL() + { + return NewL(); + } + +MHash* CMD2Impl::CopyL() + { + return new(ELeave) CMD2Impl(*this); + } + +void CMD2Impl::RestoreState() + { + Mem::Copy(&iData[0], &iDataTemp[0], KMD2BlockSize); + Mem::Copy(&iChecksum[0], &iChecksumTemp[0], KMD2BlockSize*sizeof(TUint)); + Mem::Copy(&iState[0], &iStateTemp[0], KMD2BlockSize*sizeof(TUint)); + } + +void CMD2Impl::StoreState() + { + Mem::Copy(&iDataTemp[0], &iData[0], KMD2BlockSize); + Mem::Copy(&iChecksumTemp[0], &iChecksum[0], KMD2BlockSize*sizeof(TUint)); + Mem::Copy(&iStateTemp[0], &iState[0], KMD2BlockSize*sizeof(TUint)); + } + + +TUid CMD2Impl::ImplementationUid() + { + return KCryptoPluginMd2Uid; + } + +static inline TUint CMD2_S(TUint& elt,TUint8 val) + { + return elt^=val; + } + +void CMD2Impl::DoUpdate(const TUint8* aData,TUint aLength) + { + TBool carryOn=ETrue; + if (iNum) + { + if (iNum+aLength>=(TUint)KMD2BlockSize) + { + const TUint temp=KMD2BlockSize-iNum; + (void)Mem::Copy(iData+iNum,aData,temp); + Block(iData); + aData+=temp; + aLength-=temp; + iNum=0; + } + else + { + (void)Mem::Copy(iData+iNum,aData,aLength); + iNum+=aLength; + carryOn=EFalse; + } + } + // processing by block of KMD2BlockSize + if (carryOn) + { + while (aLength>=(TUint)KMD2BlockSize) + { + Block(aData); + aData+=KMD2BlockSize; + aLength-=KMD2BlockSize; + } + (void)Mem::Copy(iData,aData,aLength); + iNum=aLength; + } + } + +void CMD2Impl::DoFinal() + { + const TUint pad=KMD2BlockSize-iNum; + if (pad>0) + Mem::Fill(iData+iNum,(TUint8)pad,pad); + Block(iData); + + TUint8* pData=iData; + const TUint8* pEnd=iData+KMD2BlockSize; + const TUint* pChecksum=iChecksum; + while (pData