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