os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/md4impl.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-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 * software md4 implementation
    16 * software md4 implementation
    17 *
    18 */
    19 
    20 
    21 /**
    22  @file
    23 */
    24 
    25 #include "md4impl.h"
    26 #include <cryptospi/hashplugin.h>
    27 #include "pluginconfig.h"
    28 
    29 
    30 using namespace SoftwareCrypto;
    31 
    32 	
    33 CMD4Impl* CMD4Impl::NewL()
    34 	{
    35 	CMD4Impl* self=new (ELeave) CMD4Impl();
    36 	self->Reset();
    37 	return self;						
    38 	}
    39 														
    40 CMD4Impl* CMD4Impl::NewLC()
    41 	{
    42 	CMD4Impl* self=NewL();
    43 	CleanupStack::PushL(self);
    44 	return self;						
    45 	}
    46 														
    47 CMD4Impl::CMD4Impl() : iHash(KMD4HashSize)
    48 	{		
    49 	}
    50 	
    51 CMD4Impl::CMD4Impl(const CMD4Impl& aCMD4Impl)
    52 : iHash(aCMD4Impl.iHash),iA(aCMD4Impl.iA),iB(aCMD4Impl.iB),iC(aCMD4Impl.iC),iD(aCMD4Impl.iD),
    53   iNl(aCMD4Impl.iNl),iNh(aCMD4Impl.iNh)
    54 	{
    55 	(void)Mem::Copy(iData, aCMD4Impl.iData, sizeof(iData));
    56 	}
    57 	
    58 CMD4Impl::~CMD4Impl()
    59 	{	
    60 	}
    61 	
    62 void CMD4Impl::Reset()
    63 	{
    64 	iA=0x67452301;
    65 	iB=0xefcdab89;
    66 	iC=0x98badcfe;
    67 	iD=0x10325476;
    68 	iNh=0;
    69 	iNl=0;
    70 	}
    71 	
    72 void CMD4Impl::Close()
    73 	{
    74 	delete this;	
    75 	}
    76 	
    77 void CMD4Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
    78 	{
    79 	aPluginCharacteristics=NULL;
    80 	TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
    81 	for (TInt i=0;i<hashNum;i++)
    82 		{
    83 		if (KHashCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
    84 			{
    85 			aPluginCharacteristics = KHashCharacteristics[i];
    86 			break;
    87 			}
    88 		}	
    89 	}
    90 	
    91 CExtendedCharacteristics* CMD4Impl::CreateExtendedCharacteristicsL()
    92 	{
    93 	// All Symbian software plug-ins have unlimited concurrency, cannot be reserved
    94 	// for exclusive use and are not CERTIFIED to be standards compliant.
    95 	return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
    96 	}
    97 const CExtendedCharacteristics* CMD4Impl::GetExtendedCharacteristicsL()
    98 	{
    99 	return CMD4Impl::CreateExtendedCharacteristicsL();
   100 	}
   101 
   102 TPtrC8 CMD4Impl::Hash(const TDesC8& aMessage)
   103 	{
   104 	DoUpdate(aMessage.Ptr(),aMessage.Size());
   105 	StoreState();
   106 	DoFinal();
   107 	RestoreState();
   108 	return iHash;
   109 	}		
   110 	
   111 void CMD4Impl::Update(const TDesC8& aMessage)
   112 	{
   113 	DoUpdate(aMessage.Ptr(),aMessage.Size());	
   114 	}
   115 	
   116 TPtrC8 CMD4Impl::Final(const TDesC8& aMessage)
   117 	{
   118 	if (aMessage!=KNullDesC8())
   119 		{
   120 		DoUpdate(aMessage.Ptr(),aMessage.Size());			
   121 		}
   122 	DoFinal();
   123 	Reset();
   124 	return iHash;
   125 	}
   126 	
   127 MHash* CMD4Impl::ReplicateL()
   128 	{	 
   129 	return CMD4Impl::NewL();
   130 	}
   131 	
   132 MHash* CMD4Impl::CopyL()
   133 	{
   134 	return new(ELeave) CMD4Impl(*this);	
   135 	}
   136 
   137 TUid CMD4Impl::ImplementationUid()
   138 	{
   139 	return KCryptoPluginMd4Uid;
   140 	}
   141 
   142 void CMD4Impl::DoUpdate(const TUint8* aData,TUint aLength)
   143 	{
   144 	const TUint8* pend=aData+aLength;	
   145 	for (const TUint8* paData=aData;paData<pend;paData++) 
   146 		{
   147 		const TUint8 byte=*paData;
   148 		switch (iNl&3) 
   149 			{
   150 			case 0:
   151 				iData[iNl>>2]=byte;
   152 				break;
   153 			case 1:
   154 				iData[iNl>>2]|=byte<<8;
   155 				break;
   156 			case 2:
   157 				iData[iNl>>2]|=byte<<16;
   158 				break;
   159 			case 3:
   160 				iData[iNl>>2]|=byte<<24;
   161 				break;
   162 			default:
   163 				break;
   164 			};
   165 		if(++iNl==64) 
   166 			{
   167 			Block();
   168 			iNh+=64;
   169 			iNl=0;
   170 			}
   171 		}
   172 	}
   173 	
   174 static inline TUint CMD4_F(TUint x,TUint y,TUint z)
   175 	{
   176 	return (x&y) | (~x&z);
   177 	}
   178 static inline TUint CMD4_G(TUint x,TUint y,TUint z)
   179 	{
   180 	return (x&y) | (x&z) | (y&z);
   181 	}
   182 static inline TUint CMD4_H(TUint x,TUint y,TUint z)
   183 	{
   184 	return x^y^z;
   185 	}
   186 
   187 	
   188 #ifdef NOREFS
   189 static inline TUint CMD4_FF(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
   190 	{
   191 	a+=CMD4_F(b,c,d) + x; 
   192 	a=CMD_R(a,s);
   193 	return a;
   194 	}
   195 static inline TUint CMD4_GG(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
   196 	{
   197 	a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999; 
   198 	a=CMD_R(a,s);
   199 	return a;
   200 	}
   201 static inline TUint CMD4_HH(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
   202 	{
   203 	a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1; 
   204 	a=CMD_R(a,s);
   205 	return a;
   206 	}
   207 
   208 void CMD4Impl::Block()
   209 	{
   210 	register TUint tempA=iA;
   211 	register TUint tempB=iB;
   212 	register TUint tempC=iC;
   213 	register TUint tempD=iD;
   214 
   215 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3);
   216 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7);
   217 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11);
   218 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19);
   219 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3);
   220 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7);
   221 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11);
   222 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19);
   223 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3);
   224 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7);
   225 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11);
   226 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19);
   227 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3);
   228 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7);
   229 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11);
   230 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19);
   231 
   232 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3);
   233 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5);
   234 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9);
   235 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13);
   236 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3);
   237 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5);
   238 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9);
   239 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13);
   240 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3);
   241 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5);
   242 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9);
   243 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13);
   244 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3);
   245 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5);
   246 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9);
   247 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13);
   248 
   249 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3);
   250 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9);
   251 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11);
   252 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15);
   253 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3);
   254 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9);
   255 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11);
   256 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15);
   257 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3);
   258 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9);
   259 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11);
   260 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15);
   261 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3);
   262 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9);
   263 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11);
   264 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15);
   265 
   266 	iA+=tempA;
   267 	iB+=tempB;
   268 	iC+=tempC;
   269 	iD+=tempD;
   270 	}
   271 #else
   272 #ifdef MACRO
   273 #define CMD4_FF(a, b, c, d, x, s) (CMD_R(a += CMD4_F(b,c,d) + x, s))
   274 #define CMD4_GG(a, b, c, d, x, s) (CMD_R(a += CMD4_G(b,c,d) + x + (TUint32)0x5a827999, s))
   275 #define CMD4_HH(a, b, c, d, x, s) (CMD_R(a += CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1, s))
   276 void CMD4Impl::Block()
   277 	{
   278 	register TUint tempA=iA;
   279 	register TUint tempB=iB;
   280 	register TUint tempC=iC;
   281 	register TUint tempD=iD;
   282 	
   283 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3);
   284 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7);
   285 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11);
   286 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19);
   287 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3);
   288 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7);
   289 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11);
   290 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19);
   291 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3);
   292 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7);
   293 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11);
   294 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19);
   295 	tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3);
   296 	tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7);
   297 	tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11);
   298 	tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19);
   299 
   300 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3);
   301 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5);
   302 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9);
   303 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13);
   304 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3);
   305 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5);
   306 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9);
   307 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13);
   308 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3);
   309 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5);
   310 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9);
   311 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13);
   312 	tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3);
   313 	tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5);
   314 	tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9);
   315 	tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13);
   316 
   317 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3);
   318 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9);
   319 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11);
   320 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15);
   321 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3);
   322 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9);
   323 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11);
   324 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15);
   325 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3);
   326 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9);
   327 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11);
   328 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15);
   329 	tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3);
   330 	tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9);
   331 	tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11);
   332 	tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15);
   333 
   334 	iA+=tempA;
   335 	iB+=tempB;
   336 	iC+=tempC;
   337 	iD+=tempD;
   338 	}
   339 #else
   340 static inline void CMD4_FF(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
   341 	{
   342 	a+=CMD4_F(b,c,d) + x; 
   343 	a=CMD_R(a,s);
   344 	}
   345 static inline void CMD4_GG(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
   346 	{
   347 	a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999; 
   348 	a=CMD_R(a,s);
   349 	}
   350 static inline void CMD4_HH(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
   351 	{
   352 	a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1; 
   353 	a=CMD_R(a,s);
   354 	}
   355 
   356 void CMD4Impl::Block()
   357 	{
   358 	register TUint tempA=iA;
   359 	register TUint tempB=iB;
   360 	register TUint tempC=iC;
   361 	register TUint tempD=iD;
   362 
   363 	CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3);
   364 	CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7);
   365 	CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11);
   366 	CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19);
   367 	CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3);
   368 	CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7);
   369 	CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11);
   370 	CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19);
   371 	CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3);
   372 	CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7);
   373 	CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11);
   374 	CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19);
   375 	CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3);
   376 	CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7);
   377 	CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11);
   378 	CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19);
   379 
   380 	CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3);
   381 	CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5);
   382 	CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9);
   383 	CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13);
   384 	CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3);
   385 	CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5);
   386 	CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9);
   387 	CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13);
   388 	CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3);
   389 	CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5);
   390 	CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9);
   391 	CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13);
   392 	CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3);
   393 	CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5);
   394 	CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9);
   395 	CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13);
   396 
   397 	CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3);
   398 	CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9);
   399 	CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11);
   400 	CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15);
   401 	CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3);
   402 	CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9);
   403 	CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11);
   404 	CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15);
   405 	CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3);
   406 	CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9);
   407 	CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11);
   408 	CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15);
   409 	CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3);
   410 	CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9);
   411 	CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11);
   412 	CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15);
   413 		
   414 	iA+=tempA;
   415 	iB+=tempB;
   416 	iC+=tempC;
   417 	iD+=tempD;
   418 	}
   419 #endif
   420 #endif
   421 
   422 void CMD4Impl::DoFinal(void)
   423 	{
   424 	iNh += iNl;
   425 	const TUint ul128=128;
   426 	switch (iNl&3) 
   427 		{
   428 		case 0:
   429 			iData[iNl>>2] = ul128;
   430 			break;
   431 		case 1:
   432 			iData[iNl>>2] += ul128<<8;
   433 			break;
   434 		case 2:
   435 			iData[iNl>>2] += ul128<<16;
   436 			break;
   437 		case 3:
   438 			iData[iNl>>2] += ul128<<24;
   439 			break;
   440 		default:
   441 			break;
   442 		};
   443 	if (iNl>=56) 
   444 		{
   445 		if (iNl<60)
   446 			iData[15]=0;		
   447 		Block();
   448 		Mem::FillZ(iData,14*sizeof(TUint));
   449 		} 
   450 	else
   451 		{
   452 		const TUint offset=(iNl+4)>>2;
   453 		Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint));
   454 		}
   455    
   456     iData[14]=iNh<<3;//number in bits
   457 	// this will fail if the total input length is longer than 2^32 in bits
   458 	//(2^31 in bytes) which is roughly half a gig.
   459 	iData[15]=0;
   460 
   461 	Block();
   462 	//
   463 	// Generate hash value into iHash
   464 	//
   465 	TUint tmp=iA;
   466 	iHash[0]=(TUint8)(tmp & 255);
   467 	iHash[1]=(TUint8)((tmp >>= 8) & 255);
   468 	iHash[2]=(TUint8)((tmp >>= 8) & 255);
   469 	iHash[3]=(TUint8)((tmp >>= 8) & 255);
   470 
   471 	tmp=iB;
   472 	iHash[4]=(TUint8)(tmp & 255);
   473 	iHash[5]=(TUint8)((tmp >>= 8) & 255);
   474 	iHash[6]=(TUint8)((tmp >>= 8) & 255);
   475 	iHash[7]=(TUint8)((tmp >>= 8) & 255);
   476 
   477 	tmp=iC;
   478 	iHash[8] =(TUint8)(tmp & 255);
   479 	iHash[9] =(TUint8)((tmp >>= 8) & 255);
   480 	iHash[10]=(TUint8)((tmp >>= 8) & 255);
   481 	iHash[11]=(TUint8)((tmp >>= 8) & 255);
   482 
   483 	tmp=iD;
   484 	iHash[12]=(TUint8)(tmp & 255);
   485 	iHash[13]=(TUint8)((tmp >>= 8) & 255);
   486 	iHash[14]=(TUint8)((tmp >>= 8) & 255);
   487 	iHash[15]=(TUint8)((tmp >>= 8) & 255);
   488 	}
   489 
   490 void CMD4Impl::RestoreState()
   491 	{
   492 	iA = iACopy;
   493 	iB = iBCopy;
   494 	iC = iCCopy;
   495 	iD = iDCopy;
   496 	iNl = iNlCopy;
   497 	iNh = iNhCopy;	
   498 	Mem::Copy(&iData[0], &iDataCopy[0], KMD4BlockSize*sizeof(TUint)); 
   499 	}
   500 
   501 void CMD4Impl::StoreState()
   502 	{
   503 	iACopy = iA;
   504 	iBCopy = iB;
   505 	iCCopy = iC;
   506 	iDCopy = iD;
   507 	iNlCopy = iNl;
   508 	iNhCopy = iNh;	
   509 	Mem::Copy(&iDataCopy[0], &iData[0], KMD4BlockSize*sizeof(TUint));
   510 	}
   511 
   512 
   513 // Implemented in hmacimpl.cpp or softwarehashbase.cpp
   514 // but required as derived from MHash. No coverage here.
   515 #ifdef _BullseyeCoverage
   516 #pragma suppress_warnings on
   517 #pragma BullseyeCoverage off
   518 #pragma suppress_warnings off
   519 #endif
   520 
   521 TAny* CMD4Impl::GetExtension(TUid /*aExtensionId*/)
   522 	{
   523 	return NULL;	
   524 	}
   525 
   526 void CMD4Impl::SetOperationModeL(TUid /*aOperationMode*/)
   527 	{
   528 	User::Leave(KErrNotSupported);
   529 	}
   530 
   531 void CMD4Impl::SetKeyL(const CKey& /*aKey*/)
   532 	{
   533 	User::Leave(KErrNotSupported);
   534 	}
   535 
   536 
   537 
   538