crypto/weakcrypto/source/hash/md5.cpp
changeset 0 2c201484c85f
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * (c) 2003 Symbian Ltd.  All rights reserved.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file
       
    24 */
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <hash.h>
       
    28 #include "hashinc.h"
       
    29 #define EXPANDLOOP
       
    30 
       
    31 //
       
    32 // 32bit endianness independent MD5 implementation
       
    33 //
       
    34 CMD5::CMD5(void)
       
    35 : CMessageDigest(),iHash(MD5_HASH)
       
    36 	{
       
    37 	}
       
    38 CMD5::CMD5(const CMD5& aMD)
       
    39 : CMessageDigest(aMD),
       
    40   iHash(aMD.iHash),iA(aMD.iA),iB(aMD.iB),iC(aMD.iC),iD(aMD.iD),
       
    41   iNl(aMD.iNl),iNh(aMD.iNh)
       
    42 	{
       
    43 	(void)Mem::Copy(iData,aMD.iData,sizeof(iData));
       
    44 	}
       
    45 EXPORT_C CMD5* CMD5::NewL(void)
       
    46 	{
       
    47 	CMD5* self = new (ELeave) CMD5();
       
    48 	self->Reset();
       
    49 	return (self);
       
    50 	}
       
    51 EXPORT_C CMessageDigest* CMD5::ReplicateL(void)
       
    52 	{
       
    53 	CMD5* newMD5 = CMD5::NewL();
       
    54 	return (newMD5);
       
    55 	}
       
    56 EXPORT_C CMD5::~CMD5(void)
       
    57 	{
       
    58 	}
       
    59 
       
    60 EXPORT_C TPtrC8 CMD5::Hash(const TDesC8& aMessage)
       
    61 	{
       
    62 	TPtrC8 ptr(KNullDesC8());
       
    63 	DoUpdate(aMessage.Ptr(),aMessage.Size());
       
    64 	StoreState();
       
    65 	DoFinal();
       
    66 	ptr.Set(iHash);
       
    67 	RestoreState();
       
    68 	return ptr;
       
    69 	}
       
    70 
       
    71 EXPORT_C CMessageDigest* CMD5::CopyL(void)
       
    72 	{
       
    73 	return new(ELeave) CMD5(*this);
       
    74 	}
       
    75 EXPORT_C TInt CMD5::BlockSize(void)
       
    76 	{
       
    77 	return sizeof(iData);
       
    78 	}
       
    79 EXPORT_C TInt CMD5::HashSize(void)
       
    80 	{
       
    81 	return MD5_HASH;
       
    82 	}
       
    83 EXPORT_C void CMD5::Reset(void)
       
    84 	{
       
    85 	iA=0x67452301;
       
    86 	iB=0xefcdab89;
       
    87 	iC=0x98badcfe;
       
    88 	iD=0x10325476;
       
    89 	iNh=0;
       
    90 	iNl=0;
       
    91 	}
       
    92 
       
    93 EXPORT_C void CMD5::Update(const TDesC8& aMessage)
       
    94 	{
       
    95 	DoUpdate(aMessage.Ptr(),aMessage.Size());
       
    96 	}
       
    97 EXPORT_C TPtrC8 CMD5::Final(const TDesC8& aMessage)
       
    98 	{
       
    99 	TPtrC8 ptr(KNullDesC8());
       
   100 	DoUpdate(aMessage.Ptr(),aMessage.Size());
       
   101 	DoFinal();
       
   102 	ptr.Set(iHash);
       
   103 	Reset();
       
   104 	return ptr;
       
   105 	}
       
   106 
       
   107 EXPORT_C TPtrC8 CMD5::Final()
       
   108 	{
       
   109 	TPtrC8 ptr(KNullDesC8());
       
   110 	DoFinal();
       
   111 	ptr.Set(iHash);
       
   112 	Reset();
       
   113 	return ptr;
       
   114 	}
       
   115 
       
   116 void CMD5::DoUpdate(const TUint8* aData,TUint aLength)
       
   117 	{
       
   118 	const TUint8* pend=aData+aLength;	
       
   119 	for (const TUint8* paData=aData;paData<pend;paData++) 
       
   120 		{
       
   121 		const TUint8 byte=*paData;
       
   122 		switch (iNl&3) 
       
   123 			{
       
   124 			case 0:
       
   125 				iData[iNl>>2]=byte;
       
   126 				break;
       
   127 			case 1:
       
   128 				iData[iNl>>2]|=byte<<8;
       
   129 				break;
       
   130 			case 2:
       
   131 				iData[iNl>>2]|=byte<<16;
       
   132 				break;
       
   133 			case 3:
       
   134 				iData[iNl>>2]|=byte<<24;
       
   135 				break;
       
   136 			default:
       
   137 				break;
       
   138 			};
       
   139 		if(++iNl==64) 
       
   140 			{
       
   141 			Block();
       
   142 			iNh+=64;
       
   143 			iNl=0;
       
   144 			}
       
   145 		}
       
   146 	}
       
   147 
       
   148 static inline TUint CMD5_F(TUint x,TUint y,TUint z)
       
   149 	{
       
   150 	return (x&y) | (~x&z);
       
   151 	}
       
   152 static inline TUint CMD5_G(TUint x,TUint y,TUint z)
       
   153 	{
       
   154 	return (x&z) | (y&~z);
       
   155 	}
       
   156 static inline TUint CMD5_H(TUint x,TUint y,TUint z)
       
   157 	{
       
   158 	return x^y^z;
       
   159 	}
       
   160 static inline TUint CMD5_I(TUint x,TUint y,TUint z)
       
   161 	{
       
   162 	return y^(x|~z);
       
   163 	}
       
   164 
       
   165 	
       
   166 #ifdef NOREFS
       
   167 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)
       
   168 	{
       
   169 	a+=CMD5_F(b,c,d) + m + t; 
       
   170 	a=b + CMD_R(a,s);
       
   171 	return a;
       
   172 	}
       
   173 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)
       
   174 	{
       
   175 	a+=CMD5_G(b,c,d) + m + t; 
       
   176 	a=b + CMD_R(a,s);
       
   177 	return a;
       
   178 	}
       
   179 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)
       
   180 	{
       
   181 	a+=CMD5_H(b,c,d) + m + t; 
       
   182 	a=b + CMD_R(a,s);
       
   183 	return a;
       
   184 	}
       
   185 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)
       
   186 	{
       
   187 	a+=CMD5_I(b,c,d) + m + t; 
       
   188 	a=b + CMD_R(a,s);
       
   189 	return a;
       
   190 	}
       
   191 void CMD5::Block()
       
   192 	{
       
   193 	register TUint tempA=iA;
       
   194 	register TUint tempB=iB;
       
   195 	register TUint tempC=iC;
       
   196 	register TUint tempD=iD;
       
   197 
       
   198 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478);
       
   199 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756);
       
   200 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db);
       
   201 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee);
       
   202 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf);
       
   203 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a);
       
   204 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613);
       
   205 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501);
       
   206 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8);
       
   207 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af);
       
   208 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1);
       
   209 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be);
       
   210 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122);
       
   211 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193);
       
   212 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e);
       
   213 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821);
       
   214 
       
   215 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562);
       
   216 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340);
       
   217 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51);
       
   218 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa);
       
   219 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d);
       
   220 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453);
       
   221 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681);
       
   222 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8);
       
   223 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6);
       
   224 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6);
       
   225 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87);
       
   226 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed);
       
   227 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905);
       
   228 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8);
       
   229 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9);
       
   230 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a);
       
   231 
       
   232 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942);
       
   233 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681);
       
   234 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122);
       
   235 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c);
       
   236 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44);
       
   237 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9);
       
   238 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60);
       
   239 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70);
       
   240 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6);
       
   241 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa);
       
   242 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085);
       
   243 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05);
       
   244 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039);
       
   245 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5);
       
   246 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8);
       
   247 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665);
       
   248 
       
   249 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244);
       
   250 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97);
       
   251 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7);
       
   252 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039);
       
   253 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3);
       
   254 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92);
       
   255 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d);
       
   256 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1);
       
   257 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f);
       
   258 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0);
       
   259 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314);
       
   260 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1);
       
   261 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82);
       
   262 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235);
       
   263 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb);
       
   264 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391);
       
   265 
       
   266 	iA+=tempA;
       
   267 	iB+=tempB;
       
   268 	iC+=tempC;
       
   269 	iD+=tempD;
       
   270 	}
       
   271 #else
       
   272 #ifdef MACRO
       
   273 #define CMD5_FF(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_F(b,c,d) + m + t, s))
       
   274 #define CMD5_GG(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_G(b,c,d) + m + t, s))
       
   275 #define CMD5_HH(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_H(b,c,d) + m + t, s))
       
   276 #define CMD5_II(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_I(b,c,d) + m + t, s))
       
   277 void CMD5::Block()
       
   278 	{
       
   279 	register TUint tempA=iA;
       
   280 	register TUint tempB=iB;
       
   281 	register TUint tempC=iC;
       
   282 	register TUint tempD=iD;
       
   283 
       
   284 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478);
       
   285 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756);
       
   286 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db);
       
   287 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee);
       
   288 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf);
       
   289 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a);
       
   290 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613);
       
   291 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501);
       
   292 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8);
       
   293 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af);
       
   294 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1);
       
   295 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be);
       
   296 	tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122);
       
   297 	tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193);
       
   298 	tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e);
       
   299 	tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821);
       
   300 
       
   301 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562);
       
   302 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340);
       
   303 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51);
       
   304 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa);
       
   305 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d);
       
   306 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453);
       
   307 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681);
       
   308 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8);
       
   309 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6);
       
   310 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6);
       
   311 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87);
       
   312 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed);
       
   313 	tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905);
       
   314 	tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8);
       
   315 	tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9);
       
   316 	tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a);
       
   317 
       
   318 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942);
       
   319 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681);
       
   320 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122);
       
   321 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c);
       
   322 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44);
       
   323 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9);
       
   324 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60);
       
   325 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70);
       
   326 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6);
       
   327 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa);
       
   328 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085);
       
   329 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05);
       
   330 	tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039);
       
   331 	tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5);
       
   332 	tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8);
       
   333 	tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665);
       
   334 
       
   335 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244);
       
   336 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97);
       
   337 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7);
       
   338 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039);
       
   339 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3);
       
   340 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92);
       
   341 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d);
       
   342 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1);
       
   343 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f);
       
   344 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0);
       
   345 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314);
       
   346 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1);
       
   347 	tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82);
       
   348 	tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235);
       
   349 	tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb);
       
   350 	tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391);
       
   351 
       
   352 	iA+=tempA;
       
   353 	iB+=tempB;
       
   354 	iC+=tempC;
       
   355 	iD+=tempD;
       
   356 	}
       
   357 #else
       
   358 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)
       
   359 	{
       
   360 	a+=CMD5_F(b,c,d) + m + t; 
       
   361 	a=b + CMD_R(a,s);
       
   362 	}
       
   363 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)
       
   364 	{
       
   365 	a+=CMD5_G(b,c,d) + m + t; 
       
   366 	a=b + CMD_R(a,s);
       
   367 	}
       
   368 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)
       
   369 	{
       
   370 	a+=CMD5_H(b,c,d) + m + t; 
       
   371 	a=b + CMD_R(a,s);
       
   372 	}
       
   373 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)
       
   374 	{
       
   375 	a+=CMD5_I(b,c,d) + m + t; 
       
   376 	a=b + CMD_R(a,s);
       
   377 	}
       
   378 void CMD5::Block()
       
   379 	{
       
   380 	register TUint tempA=iA;
       
   381 	register TUint tempB=iB;
       
   382 	register TUint tempC=iC;
       
   383 	register TUint tempD=iD;
       
   384 
       
   385 	CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478);
       
   386 	CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756);
       
   387 	CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db);
       
   388 	CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee);
       
   389 	CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf);
       
   390 	CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a);
       
   391 	CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613);
       
   392 	CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501);
       
   393 	CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8);
       
   394 	CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af);
       
   395 	CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1);
       
   396 	CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be);
       
   397 	CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122);
       
   398 	CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193);
       
   399 	CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e);
       
   400 	CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821);
       
   401 
       
   402 	CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562);
       
   403 	CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340);
       
   404 	CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51);
       
   405 	CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa);
       
   406 	CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d);
       
   407 	CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453);
       
   408 	CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681);
       
   409 	CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8);
       
   410 	CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6);
       
   411 	CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6);
       
   412 	CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87);
       
   413 	CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed);
       
   414 	CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905);
       
   415 	CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8);
       
   416 	CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9);
       
   417 	CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a);
       
   418 
       
   419 	CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942);
       
   420 	CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681);
       
   421 	CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122);
       
   422 	CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c);
       
   423 	CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44);
       
   424 	CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9);
       
   425 	CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60);
       
   426 	CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70);
       
   427 	CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6);
       
   428 	CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa);
       
   429 	CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085);
       
   430 	CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05);
       
   431 	CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039);
       
   432 	CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5);
       
   433 	CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8);
       
   434 	CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665);
       
   435 
       
   436 	CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244);
       
   437 	CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97);
       
   438 	CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7);
       
   439 	CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039);
       
   440 	CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3);
       
   441 	CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92);
       
   442 	CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d);
       
   443 	CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1);
       
   444 	CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f);
       
   445 	CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0);
       
   446 	CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314);
       
   447 	CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1);
       
   448 	CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82);
       
   449 	CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235);
       
   450 	CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb);
       
   451 	CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391);
       
   452 
       
   453 	iA+=tempA;
       
   454 	iB+=tempB;
       
   455 	iC+=tempC;
       
   456 	iD+=tempD;
       
   457 	}
       
   458 #endif
       
   459 #endif
       
   460 
       
   461 void CMD5::DoFinal(void)
       
   462 	{
       
   463 	iNh += iNl;
       
   464 	const TUint ul128=128;
       
   465 	switch (iNl&3) 
       
   466 		{
       
   467 		case 0:
       
   468 			iData[iNl>>2] = ul128;
       
   469 			break;
       
   470 		case 1:
       
   471 			iData[iNl>>2] += ul128<<8;
       
   472 			break;
       
   473 		case 2:
       
   474 			iData[iNl>>2] += ul128<<16;
       
   475 			break;
       
   476 		case 3:
       
   477 			iData[iNl>>2] += ul128<<24;
       
   478 			break;
       
   479 		default:
       
   480 			break;
       
   481 		};
       
   482 	if (iNl>=56) 
       
   483 		{
       
   484 		if (iNl<60)
       
   485 			iData[15]=0;		
       
   486 		Block();
       
   487 		Mem::FillZ(iData,14*sizeof(TUint));
       
   488 		} 
       
   489 	else
       
   490 		{
       
   491 		const TUint offset=(iNl+4)>>2;
       
   492 		Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint));
       
   493 		}
       
   494 
       
   495 	iData[14]=iNh<<3;//number in bits
       
   496 	// this will fail if the total input length is longer than 2^32 in bits
       
   497 	//(2^31 in bytes) which is roughly half a gig.
       
   498 	iData[15]=0;
       
   499 	Block();
       
   500 	//
       
   501 	// Generate hash value into iHash
       
   502 	//
       
   503 	TUint tmp=iA;
       
   504 	iHash[0]=(TUint8)(tmp & 255);
       
   505 	iHash[1]=(TUint8)((tmp >>= 8) & 255);
       
   506 	iHash[2]=(TUint8)((tmp >>= 8) & 255);
       
   507 	iHash[3]=(TUint8)((tmp >>= 8) & 255);
       
   508 
       
   509 	tmp=iB;
       
   510 	iHash[4]=(TUint8)(tmp & 255);
       
   511 	iHash[5]=(TUint8)((tmp >>= 8) & 255);
       
   512 	iHash[6]=(TUint8)((tmp >>= 8) & 255);
       
   513 	iHash[7]=(TUint8)((tmp >>= 8) & 255);
       
   514 
       
   515 	tmp=iC;
       
   516 	iHash[8]=(TUint8)(tmp & 255);
       
   517 	iHash[9]=(TUint8)((tmp >>= 8) & 255);
       
   518 	iHash[10]=(TUint8)((tmp >>= 8) & 255);
       
   519 	iHash[11]=(TUint8)((tmp >>= 8) & 255);
       
   520 
       
   521 	tmp=iD;
       
   522 	iHash[12]=(TUint8)(tmp & 255);
       
   523 	iHash[13]=(TUint8)((tmp >>= 8) & 255);
       
   524 	iHash[14]=(TUint8)((tmp >>= 8) & 255);
       
   525 	iHash[15]=(TUint8)((tmp >>= 8) & 255);
       
   526 	}
       
   527 
       
   528 void CMD5::RestoreState()
       
   529 {
       
   530 	iA = iACopy;
       
   531 	iB = iBCopy;
       
   532 	iC = iCCopy;
       
   533 	iD = iDCopy;
       
   534 	iNl = iNlCopy;
       
   535 	iNh = iNhCopy;	
       
   536 	Mem::Copy(&iData[0], &iDataCopy[0], MD5_LBLOCK*sizeof(TUint)); 
       
   537 }
       
   538 
       
   539 void CMD5::StoreState()
       
   540 {
       
   541 	iACopy = iA;
       
   542 	iBCopy = iB;
       
   543 	iCCopy = iC;
       
   544 	iDCopy = iD;
       
   545 	iNlCopy = iNl;
       
   546 	iNhCopy = iNh;	
       
   547 	Mem::Copy(&iDataCopy[0], &iData[0], MD5_LBLOCK*sizeof(TUint));
       
   548 }