os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/md5impl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/md5impl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,604 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* software md5 implementation
    1.19 +* software md5 implementation
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +/**
    1.25 + @file
    1.26 +*/
    1.27 +
    1.28 +#include "md5impl.h"
    1.29 +#include <cryptospi/hashplugin.h>
    1.30 +#include "pluginconfig.h"
    1.31 +
    1.32 +using namespace SoftwareCrypto;
    1.33 +
    1.34 +	
    1.35 +CMD5Impl* CMD5Impl::NewL()
    1.36 +	{
    1.37 +	CMD5Impl* self=new (ELeave) CMD5Impl();
    1.38 +	self->Reset();
    1.39 +	return self;						
    1.40 +	}
    1.41 +														
    1.42 +CMD5Impl* CMD5Impl::NewLC()
    1.43 +	{
    1.44 +	CMD5Impl* self=NewL();
    1.45 +	CleanupStack::PushL(self);
    1.46 +	return self;						
    1.47 +	}
    1.48 +														
    1.49 +CMD5Impl::CMD5Impl() : iHash(KMD5HashSize)
    1.50 +	{		
    1.51 +	}
    1.52 +	
    1.53 +CMD5Impl::CMD5Impl(const CMD5Impl& aCMD5Impl)
    1.54 +: iHash(aCMD5Impl.iHash),iA(aCMD5Impl.iA),iB(aCMD5Impl.iB),iC(aCMD5Impl.iC),iD(aCMD5Impl.iD),
    1.55 +  iNl(aCMD5Impl.iNl),iNh(aCMD5Impl.iNh)
    1.56 +	{
    1.57 +	(void)Mem::Copy(iData, aCMD5Impl.iData, sizeof(iData));
    1.58 +	}
    1.59 +	
    1.60 +CMD5Impl::~CMD5Impl()
    1.61 +	{	
    1.62 +	}
    1.63 +	
    1.64 +void CMD5Impl::Reset()
    1.65 +	{
    1.66 +	iA=0x67452301;
    1.67 +	iB=0xefcdab89;
    1.68 +	iC=0x98badcfe;
    1.69 +	iD=0x10325476;
    1.70 +	iNh=0;
    1.71 +	iNl=0;
    1.72 +	}
    1.73 +	
    1.74 +void CMD5Impl::Close()
    1.75 +	{
    1.76 +	delete this;	
    1.77 +	}
    1.78 +	
    1.79 +void CMD5Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
    1.80 +	{
    1.81 +	aPluginCharacteristics=NULL;
    1.82 +	TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
    1.83 +	for (TInt i=0;i<hashNum;i++)
    1.84 +		{
    1.85 +		if (KHashCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
    1.86 +			{
    1.87 +			aPluginCharacteristics = KHashCharacteristics[i];
    1.88 +			break;
    1.89 +			}
    1.90 +		}	
    1.91 +	}
    1.92 +
    1.93 +CExtendedCharacteristics* CMD5Impl::CreateExtendedCharacteristicsL()
    1.94 +	{
    1.95 +	// All Symbian software plug-ins have unlimited concurrency, cannot be reserved
    1.96 +	// for exclusive use and are not CERTIFIED to be standards compliant.
    1.97 +	return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
    1.98 +	}
    1.99 +
   1.100 +const CExtendedCharacteristics* CMD5Impl::GetExtendedCharacteristicsL()
   1.101 +	{
   1.102 +	return CMD5Impl::CreateExtendedCharacteristicsL();
   1.103 +	}
   1.104 +
   1.105 +TPtrC8 CMD5Impl::Hash(const TDesC8& aMessage)
   1.106 +	{
   1.107 +	
   1.108 +	TPtrC8 ptr(KNullDesC8());
   1.109 +	DoUpdate(aMessage.Ptr(),aMessage.Size());
   1.110 +	StoreState();
   1.111 +	DoFinal();
   1.112 +	ptr.Set(iHash);
   1.113 +	RestoreState();
   1.114 +	return ptr;
   1.115 +	}		
   1.116 +	
   1.117 +void CMD5Impl::Update(const TDesC8& aMessage)
   1.118 +	{
   1.119 +	DoUpdate(aMessage.Ptr(),aMessage.Size());	
   1.120 +	}
   1.121 +	
   1.122 +TPtrC8 CMD5Impl::Final(const TDesC8& aMessage)
   1.123 +	{
   1.124 +	TPtrC8 ptr(KNullDesC8());
   1.125 +	if (aMessage!=KNullDesC8())
   1.126 +		{
   1.127 +		DoUpdate(aMessage.Ptr(),aMessage.Size());			
   1.128 +		}
   1.129 +	DoFinal();
   1.130 +	ptr.Set(iHash);
   1.131 +	Reset();
   1.132 +	return ptr;
   1.133 +	}
   1.134 +	
   1.135 +MHash* CMD5Impl::ReplicateL()
   1.136 +	{	 
   1.137 +	return CMD5Impl::NewL();
   1.138 +	}
   1.139 +	
   1.140 +MHash* CMD5Impl::CopyL()
   1.141 +	{
   1.142 +	return new(ELeave) CMD5Impl(*this);	
   1.143 +	}
   1.144 +
   1.145 +TUid CMD5Impl::ImplementationUid()
   1.146 +	{
   1.147 +	return KCryptoPluginMd5Uid;
   1.148 +	}
   1.149 +
   1.150 +void CMD5Impl::DoUpdate(const TUint8* aData,TUint aLength)
   1.151 +	{
   1.152 +	const TUint8* pend=aData+aLength;	
   1.153 +	for (const TUint8* paData=aData;paData<pend;paData++) 
   1.154 +		{
   1.155 +		const TUint8 byte=*paData;
   1.156 +		switch (iNl&3) 
   1.157 +			{
   1.158 +			case 0:
   1.159 +				iData[iNl>>2]=byte;
   1.160 +				break;
   1.161 +			case 1:
   1.162 +				iData[iNl>>2]|=byte<<8;
   1.163 +				break;
   1.164 +			case 2:
   1.165 +				iData[iNl>>2]|=byte<<16;
   1.166 +				break;
   1.167 +			case 3:
   1.168 +				iData[iNl>>2]|=byte<<24;
   1.169 +				break;
   1.170 +			default:
   1.171 +				break;
   1.172 +			};
   1.173 +		if(++iNl==64) 
   1.174 +			{
   1.175 +			Block();
   1.176 +			iNh+=64;
   1.177 +			iNl=0;
   1.178 +			}
   1.179 +		}
   1.180 +	}
   1.181 +	
   1.182 +static inline TUint CMD5_F(TUint x,TUint y,TUint z)
   1.183 +	{
   1.184 +	return (x&y) | (~x&z);
   1.185 +	}
   1.186 +static inline TUint CMD5_G(TUint x,TUint y,TUint z)
   1.187 +	{
   1.188 +	return (x&z) | (y&~z);
   1.189 +	}
   1.190 +static inline TUint CMD5_H(TUint x,TUint y,TUint z)
   1.191 +	{
   1.192 +	return x^y^z;
   1.193 +	}
   1.194 +static inline TUint CMD5_I(TUint x,TUint y,TUint z)
   1.195 +	{
   1.196 +	return y^(x|~z);
   1.197 +	}
   1.198 +
   1.199 +	
   1.200 +#ifdef NOREFS
   1.201 +static inline TUint CMD5_FF(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.202 +	{
   1.203 +	a+=CMD5_F(b,c,d) + m + t; 
   1.204 +	a=b + CMD_R(a,s);
   1.205 +	return a;
   1.206 +	}
   1.207 +static inline TUint CMD5_GG(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.208 +	{
   1.209 +	a+=CMD5_G(b,c,d) + m + t; 
   1.210 +	a=b + CMD_R(a,s);
   1.211 +	return a;
   1.212 +	}
   1.213 +static inline TUint CMD5_HH(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.214 +	{
   1.215 +	a+=CMD5_H(b,c,d) + m + t; 
   1.216 +	a=b + CMD_R(a,s);
   1.217 +	return a;
   1.218 +	}
   1.219 +static inline TUint CMD5_II(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.220 +	{
   1.221 +	a+=CMD5_I(b,c,d) + m + t; 
   1.222 +	a=b + CMD_R(a,s);
   1.223 +	return a;
   1.224 +	}
   1.225 +void CMD5Impl::Block()
   1.226 +	{
   1.227 +	register TUint tempA=iA;
   1.228 +	register TUint tempB=iB;
   1.229 +	register TUint tempC=iC;
   1.230 +	register TUint tempD=iD;
   1.231 +
   1.232 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478);
   1.233 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756);
   1.234 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db);
   1.235 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee);
   1.236 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf);
   1.237 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a);
   1.238 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613);
   1.239 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501);
   1.240 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8);
   1.241 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af);
   1.242 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1);
   1.243 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be);
   1.244 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122);
   1.245 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193);
   1.246 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e);
   1.247 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821);
   1.248 +
   1.249 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562);
   1.250 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340);
   1.251 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51);
   1.252 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa);
   1.253 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d);
   1.254 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453);
   1.255 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681);
   1.256 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8);
   1.257 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6);
   1.258 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6);
   1.259 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87);
   1.260 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed);
   1.261 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905);
   1.262 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8);
   1.263 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9);
   1.264 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a);
   1.265 +
   1.266 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942);
   1.267 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681);
   1.268 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122);
   1.269 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c);
   1.270 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44);
   1.271 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9);
   1.272 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60);
   1.273 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70);
   1.274 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6);
   1.275 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa);
   1.276 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085);
   1.277 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05);
   1.278 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039);
   1.279 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5);
   1.280 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8);
   1.281 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665);
   1.282 +
   1.283 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244);
   1.284 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97);
   1.285 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7);
   1.286 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039);
   1.287 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3);
   1.288 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92);
   1.289 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d);
   1.290 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1);
   1.291 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f);
   1.292 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0);
   1.293 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314);
   1.294 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1);
   1.295 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82);
   1.296 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235);
   1.297 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb);
   1.298 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391);
   1.299 +
   1.300 +	iA+=tempA;
   1.301 +	iB+=tempB;
   1.302 +	iC+=tempC;
   1.303 +	iD+=tempD;
   1.304 +	}
   1.305 +#else
   1.306 +#ifdef MACRO
   1.307 +#define CMD5_FF(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_F(b,c,d) + m + t, s))
   1.308 +#define CMD5_GG(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_G(b,c,d) + m + t, s))
   1.309 +#define CMD5_HH(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_H(b,c,d) + m + t, s))
   1.310 +#define CMD5_II(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_I(b,c,d) + m + t, s))
   1.311 +void CMD5Impl::Block()
   1.312 +	{
   1.313 +	register TUint tempA=iA;
   1.314 +	register TUint tempB=iB;
   1.315 +	register TUint tempC=iC;
   1.316 +	register TUint tempD=iD;
   1.317 +
   1.318 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478);
   1.319 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756);
   1.320 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db);
   1.321 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee);
   1.322 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf);
   1.323 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a);
   1.324 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613);
   1.325 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501);
   1.326 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8);
   1.327 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af);
   1.328 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1);
   1.329 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be);
   1.330 +	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122);
   1.331 +	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193);
   1.332 +	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e);
   1.333 +	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821);
   1.334 +
   1.335 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562);
   1.336 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340);
   1.337 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51);
   1.338 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa);
   1.339 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d);
   1.340 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453);
   1.341 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681);
   1.342 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8);
   1.343 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6);
   1.344 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6);
   1.345 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87);
   1.346 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed);
   1.347 +	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905);
   1.348 +	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8);
   1.349 +	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9);
   1.350 +	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a);
   1.351 +
   1.352 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942);
   1.353 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681);
   1.354 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122);
   1.355 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c);
   1.356 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44);
   1.357 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9);
   1.358 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60);
   1.359 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70);
   1.360 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6);
   1.361 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa);
   1.362 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085);
   1.363 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05);
   1.364 +	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039);
   1.365 +	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5);
   1.366 +	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8);
   1.367 +	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665);
   1.368 +
   1.369 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244);
   1.370 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97);
   1.371 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7);
   1.372 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039);
   1.373 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3);
   1.374 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92);
   1.375 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d);
   1.376 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1);
   1.377 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f);
   1.378 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0);
   1.379 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314);
   1.380 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1);
   1.381 +	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82);
   1.382 +	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235);
   1.383 +	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb);
   1.384 +	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391);
   1.385 +
   1.386 +	iA+=tempA;
   1.387 +	iB+=tempB;
   1.388 +	iC+=tempC;
   1.389 +	iD+=tempD;
   1.390 +	}
   1.391 +#else
   1.392 +static inline void CMD5_FF(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.393 +	{
   1.394 +	a+=CMD5_F(b,c,d) + m + t; 
   1.395 +	a=b + CMD_R(a,s);
   1.396 +	}
   1.397 +static inline void CMD5_GG(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.398 +	{
   1.399 +	a+=CMD5_G(b,c,d) + m + t; 
   1.400 +	a=b + CMD_R(a,s);
   1.401 +	}
   1.402 +static inline void CMD5_HH(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.403 +	{
   1.404 +	a+=CMD5_H(b,c,d) + m + t; 
   1.405 +	a=b + CMD_R(a,s);
   1.406 +	}
   1.407 +static inline void CMD5_II(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t)
   1.408 +	{
   1.409 +	a+=CMD5_I(b,c,d) + m + t; 
   1.410 +	a=b + CMD_R(a,s);
   1.411 +	}
   1.412 +void CMD5Impl::Block()
   1.413 +	{
   1.414 +	register TUint tempA=iA;
   1.415 +	register TUint tempB=iB;
   1.416 +	register TUint tempC=iC;
   1.417 +	register TUint tempD=iD;
   1.418 +
   1.419 +	CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478);
   1.420 +	CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756);
   1.421 +	CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db);
   1.422 +	CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee);
   1.423 +	CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf);
   1.424 +	CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a);
   1.425 +	CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613);
   1.426 +	CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501);
   1.427 +	CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8);
   1.428 +	CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af);
   1.429 +	CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1);
   1.430 +	CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be);
   1.431 +	CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122);
   1.432 +	CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193);
   1.433 +	CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e);
   1.434 +	CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821);
   1.435 +
   1.436 +	CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562);
   1.437 +	CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340);
   1.438 +	CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51);
   1.439 +	CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa);
   1.440 +	CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d);
   1.441 +	CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453);
   1.442 +	CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681);
   1.443 +	CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8);
   1.444 +	CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6);
   1.445 +	CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6);
   1.446 +	CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87);
   1.447 +	CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed);
   1.448 +	CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905);
   1.449 +	CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8);
   1.450 +	CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9);
   1.451 +	CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a);
   1.452 +
   1.453 +	CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942);
   1.454 +	CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681);
   1.455 +	CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122);
   1.456 +	CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c);
   1.457 +	CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44);
   1.458 +	CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9);
   1.459 +	CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60);
   1.460 +	CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70);
   1.461 +	CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6);
   1.462 +	CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa);
   1.463 +	CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085);
   1.464 +	CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05);
   1.465 +	CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039);
   1.466 +	CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5);
   1.467 +	CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8);
   1.468 +	CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665);
   1.469 +
   1.470 +	CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244);
   1.471 +	CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97);
   1.472 +	CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7);
   1.473 +	CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039);
   1.474 +	CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3);
   1.475 +	CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92);
   1.476 +	CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d);
   1.477 +	CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1);
   1.478 +	CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f);
   1.479 +	CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0);
   1.480 +	CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314);
   1.481 +	CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1);
   1.482 +	CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82);
   1.483 +	CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235);
   1.484 +	CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb);
   1.485 +	CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391);
   1.486 +
   1.487 +	iA+=tempA;
   1.488 +	iB+=tempB;
   1.489 +	iC+=tempC;
   1.490 +	iD+=tempD;
   1.491 +	}
   1.492 +#endif
   1.493 +#endif
   1.494 +
   1.495 +void CMD5Impl::DoFinal(void)
   1.496 +	{
   1.497 +	iNh += iNl;
   1.498 +	const TUint ul128=128;
   1.499 +	switch (iNl&3) 
   1.500 +		{
   1.501 +		case 0:
   1.502 +			iData[iNl>>2] = ul128;
   1.503 +			break;
   1.504 +		case 1:
   1.505 +			iData[iNl>>2] += ul128<<8;
   1.506 +			break;
   1.507 +		case 2:
   1.508 +			iData[iNl>>2] += ul128<<16;
   1.509 +			break;
   1.510 +		case 3:
   1.511 +			iData[iNl>>2] += ul128<<24;
   1.512 +			break;
   1.513 +		default:
   1.514 +			break;
   1.515 +		};
   1.516 +	if (iNl>=56) 
   1.517 +		{
   1.518 +		if (iNl<60)
   1.519 +			iData[15]=0;		
   1.520 +		Block();
   1.521 +		Mem::FillZ(iData,14*sizeof(TUint));
   1.522 +		} 
   1.523 +	else
   1.524 +		{
   1.525 +		const TUint offset=(iNl+4)>>2;
   1.526 +		Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint));
   1.527 +		}
   1.528 +
   1.529 +	iData[14]=iNh<<3;//number in bits
   1.530 +	// this will fail if the total input length is longer than 2^32 in bits
   1.531 +	//(2^31 in bytes) which is roughly half a gig.
   1.532 +	iData[15]=0;
   1.533 +	Block();
   1.534 +	//
   1.535 +	// Generate hash value into iHash
   1.536 +	//
   1.537 +	TUint tmp=iA;
   1.538 +	iHash[0]=(TUint8)(tmp & 255);
   1.539 +	iHash[1]=(TUint8)((tmp >>= 8) & 255);
   1.540 +	iHash[2]=(TUint8)((tmp >>= 8) & 255);
   1.541 +	iHash[3]=(TUint8)((tmp >>= 8) & 255);
   1.542 +
   1.543 +	tmp=iB;
   1.544 +	iHash[4]=(TUint8)(tmp & 255);
   1.545 +	iHash[5]=(TUint8)((tmp >>= 8) & 255);
   1.546 +	iHash[6]=(TUint8)((tmp >>= 8) & 255);
   1.547 +	iHash[7]=(TUint8)((tmp >>= 8) & 255);
   1.548 +
   1.549 +	tmp=iC;
   1.550 +	iHash[8]=(TUint8)(tmp & 255);
   1.551 +	iHash[9]=(TUint8)((tmp >>= 8) & 255);
   1.552 +	iHash[10]=(TUint8)((tmp >>= 8) & 255);
   1.553 +	iHash[11]=(TUint8)((tmp >>= 8) & 255);
   1.554 +
   1.555 +	tmp=iD;
   1.556 +	iHash[12]=(TUint8)(tmp & 255);
   1.557 +	iHash[13]=(TUint8)((tmp >>= 8) & 255);
   1.558 +	iHash[14]=(TUint8)((tmp >>= 8) & 255);
   1.559 +	iHash[15]=(TUint8)((tmp >>= 8) & 255);
   1.560 +	}
   1.561 +
   1.562 +void CMD5Impl::RestoreState()
   1.563 +	{
   1.564 +	iA = iACopy;
   1.565 +	iB = iBCopy;
   1.566 +	iC = iCCopy;
   1.567 +	iD = iDCopy;
   1.568 +	iNl = iNlCopy;
   1.569 +	iNh = iNhCopy;	
   1.570 +	Mem::Copy(&iData[0], &iDataCopy[0], KMD5BlockSize*sizeof(TUint)); 
   1.571 +	}
   1.572 +
   1.573 +void CMD5Impl::StoreState()
   1.574 +	{
   1.575 +	iACopy = iA;
   1.576 +	iBCopy = iB;
   1.577 +	iCCopy = iC;
   1.578 +	iDCopy = iD;
   1.579 +	iNlCopy = iNl;
   1.580 +	iNhCopy = iNh;	
   1.581 +	Mem::Copy(&iDataCopy[0], &iData[0], KMD5BlockSize*sizeof(TUint));
   1.582 +	}
   1.583 +
   1.584 +
   1.585 +// Implemented in hmacimpl.cpp or softwarehashbase.cpp
   1.586 +// but required as derived from MHash. No coverage here.
   1.587 +#ifdef _BullseyeCoverage
   1.588 +#pragma suppress_warnings on
   1.589 +#pragma BullseyeCoverage off
   1.590 +#pragma suppress_warnings off
   1.591 +#endif
   1.592 +
   1.593 +TAny* CMD5Impl::GetExtension(TUid /*aExtensionId*/)
   1.594 +	{
   1.595 +	return NULL;	
   1.596 +	}
   1.597 +
   1.598 +void CMD5Impl::SetOperationModeL(TUid /*aOperationMode*/)
   1.599 +	{
   1.600 +	User::Leave(KErrNotSupported);
   1.601 +	}
   1.602 +
   1.603 +void CMD5Impl::SetKeyL(const CKey& /*aKey*/)
   1.604 +	{
   1.605 +	User::Leave(KErrNotSupported);
   1.606 +	}
   1.607 +