os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha384and512impl.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/sha384and512impl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,539 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-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 +* Common implementation of SHA384 and SHA512
    1.19 +* RFC 4634 (US Secure Hash Algorithms (SHA and HMAC-SHA))
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +/**
    1.25 + @file
    1.26 +*/
    1.27 +
    1.28 +#include <cryptospi/hashplugin.h>
    1.29 +#include "sha384and512impl.h"
    1.30 +#include "pluginconfig.h"
    1.31 +
    1.32 +/**
    1.33 + * SHA512 Constants
    1.34 + * 
    1.35 + * SHA-512 uses a sequence of eighty constant 64-bit words. 
    1.36 + * These words represent the first sixty-four bits of the fractional 
    1.37 + * parts of the cube roots of the first eighty prime numbers.
    1.38 + * 
    1.39 + * FIPS 180-2 Section 4.2.3
    1.40 + */
    1.41 +const TUint64 K[80] = 
    1.42 +	{
    1.43 +	UI64LIT(0x428a2f98d728ae22), UI64LIT(0x7137449123ef65cd), UI64LIT(0xb5c0fbcfec4d3b2f), UI64LIT(0xe9b5dba58189dbbc),
    1.44 +	UI64LIT(0x3956c25bf348b538), UI64LIT(0x59f111f1b605d019), UI64LIT(0x923f82a4af194f9b), UI64LIT(0xab1c5ed5da6d8118),
    1.45 +	UI64LIT(0xd807aa98a3030242), UI64LIT(0x12835b0145706fbe), UI64LIT(0x243185be4ee4b28c), UI64LIT(0x550c7dc3d5ffb4e2),
    1.46 +	UI64LIT(0x72be5d74f27b896f), UI64LIT(0x80deb1fe3b1696b1), UI64LIT(0x9bdc06a725c71235), UI64LIT(0xc19bf174cf692694),
    1.47 +	UI64LIT(0xe49b69c19ef14ad2), UI64LIT(0xefbe4786384f25e3), UI64LIT(0x0fc19dc68b8cd5b5), UI64LIT(0x240ca1cc77ac9c65),
    1.48 +	UI64LIT(0x2de92c6f592b0275), UI64LIT(0x4a7484aa6ea6e483), UI64LIT(0x5cb0a9dcbd41fbd4), UI64LIT(0x76f988da831153b5),
    1.49 +	UI64LIT(0x983e5152ee66dfab), UI64LIT(0xa831c66d2db43210), UI64LIT(0xb00327c898fb213f), UI64LIT(0xbf597fc7beef0ee4),
    1.50 +	UI64LIT(0xc6e00bf33da88fc2), UI64LIT(0xd5a79147930aa725), UI64LIT(0x06ca6351e003826f), UI64LIT(0x142929670a0e6e70),
    1.51 +	UI64LIT(0x27b70a8546d22ffc), UI64LIT(0x2e1b21385c26c926), UI64LIT(0x4d2c6dfc5ac42aed), UI64LIT(0x53380d139d95b3df),
    1.52 +	UI64LIT(0x650a73548baf63de), UI64LIT(0x766a0abb3c77b2a8), UI64LIT(0x81c2c92e47edaee6), UI64LIT(0x92722c851482353b),
    1.53 +	UI64LIT(0xa2bfe8a14cf10364), UI64LIT(0xa81a664bbc423001), UI64LIT(0xc24b8b70d0f89791), UI64LIT(0xc76c51a30654be30),
    1.54 +	UI64LIT(0xd192e819d6ef5218), UI64LIT(0xd69906245565a910), UI64LIT(0xf40e35855771202a), UI64LIT(0x106aa07032bbd1b8),
    1.55 +	UI64LIT(0x19a4c116b8d2d0c8), UI64LIT(0x1e376c085141ab53), UI64LIT(0x2748774cdf8eeb99), UI64LIT(0x34b0bcb5e19b48a8),
    1.56 +	UI64LIT(0x391c0cb3c5c95a63), UI64LIT(0x4ed8aa4ae3418acb), UI64LIT(0x5b9cca4f7763e373), UI64LIT(0x682e6ff3d6b2b8a3),
    1.57 +	UI64LIT(0x748f82ee5defb2fc), UI64LIT(0x78a5636f43172f60), UI64LIT(0x84c87814a1f0ab72), UI64LIT(0x8cc702081a6439ec),
    1.58 +	UI64LIT(0x90befffa23631e28), UI64LIT(0xa4506cebde82bde9), UI64LIT(0xbef9a3f7b2c67915), UI64LIT(0xc67178f2e372532b),
    1.59 +	UI64LIT(0xca273eceea26619c), UI64LIT(0xd186b8c721c0c207), UI64LIT(0xeada7dd6cde0eb1e), UI64LIT(0xf57d4f7fee6ed178),
    1.60 +	UI64LIT(0x06f067aa72176fba), UI64LIT(0x0a637dc5a2c898a6), UI64LIT(0x113f9804bef90dae), UI64LIT(0x1b710b35131c471b),
    1.61 +	UI64LIT(0x28db77f523047d84), UI64LIT(0x32caab7b40c72493), UI64LIT(0x3c9ebe0a15c9bebc), UI64LIT(0x431d67c49c100d4c),
    1.62 +	UI64LIT(0x4cc5d4becb3e42b6), UI64LIT(0x597f299cfc657e2a), UI64LIT(0x5fcb6fab3ad6faec), UI64LIT(0x6c44198c4a475817)
    1.63 +	};
    1.64 +
    1.65 +/**
    1.66 + * Define the SHA SIGMA and sigma macros 
    1.67 + * 
    1.68 + * FIPS 180-2 section 4.1.3
    1.69 + */
    1.70 +// Equation 4.10
    1.71 +inline TUint64 SHA512_SIGMA0(TUint64 aWord)
    1.72 +	{
    1.73 +	return (SHA_ROTR<TUint64>(28,aWord) ^ SHA_ROTR<TUint64>(34,aWord) ^ SHA_ROTR<TUint64>(39,aWord));
    1.74 +	}
    1.75 +// Equation 4.11
    1.76 +inline TUint64 SHA512_SIGMA1(TUint64 aWord)
    1.77 +	{
    1.78 +	return (SHA_ROTR<TUint64>(14,aWord) ^ SHA_ROTR<TUint64>(18,aWord) ^ SHA_ROTR<TUint64>(41,aWord));
    1.79 +	}
    1.80 +// Equation 4.12
    1.81 +inline TUint64 SHA512_sigma0(TUint64 aWord)
    1.82 +	{
    1.83 +	return (SHA_ROTR<TUint64>(1, aWord) ^ SHA_ROTR<TUint64>(8, aWord) ^ SHA_SHR<TUint64>(7, aWord));
    1.84 +	}
    1.85 +// Equation 4.13
    1.86 +inline TUint64 SHA512_sigma1(TUint64 aWord)
    1.87 +	{
    1.88 +	return (SHA_ROTR<TUint64>(19,aWord) ^ SHA_ROTR<TUint64>(61,aWord) ^ SHA_SHR<TUint64>(6,aWord));
    1.89 +	}
    1.90 +
    1.91 +// Macros
    1.92 +inline TUint64 Make64BitWord(const TUint8* aData)
    1.93 +	{
    1.94 +	TUint64 result = (TUint64)aData[0] << 56 | (TUint64)aData[1] << 48 | (TUint64)aData[2] << 40 | 
    1.95 +					 (TUint64)aData[3] << 32 | (TUint64)aData[4] << 24 | (TUint64)aData[5] << 16 |
    1.96 +					 (TUint64)aData[6] << 8 | (TUint64)aData[7];
    1.97 +	return result;
    1.98 +	}
    1.99 +
   1.100 +
   1.101 +using namespace SoftwareCrypto;
   1.102 +	
   1.103 +CSHA384And512Impl* CSHA384And512Impl::NewL(TInt aHashSize)
   1.104 +	{
   1.105 +	CSHA384And512Impl* self=new (ELeave) CSHA384And512Impl(aHashSize);
   1.106 +	return self;						
   1.107 +	}
   1.108 +														
   1.109 +CSHA384And512Impl::CSHA384And512Impl(TInt aHashSize) : iHash(aHashSize)
   1.110 +	{		
   1.111 +	}
   1.112 +	
   1.113 +CSHA384And512Impl::CSHA384And512Impl(const CSHA384And512Impl& aSHA512Impl)
   1.114 +				: 	iHash(aSHA512Impl.iHash),
   1.115 +					iA(aSHA512Impl.iA),
   1.116 +					iB(aSHA512Impl.iB),
   1.117 +					iC(aSHA512Impl.iC),
   1.118 +					iD(aSHA512Impl.iD),
   1.119 +					iE(aSHA512Impl.iE),
   1.120 +					iF(aSHA512Impl.iF),
   1.121 +					iG(aSHA512Impl.iG),
   1.122 +					iH(aSHA512Impl.iH),
   1.123 +					iNl(aSHA512Impl.iNl),
   1.124 +					iNh(aSHA512Impl.iNh),
   1.125 +					iBlockIndex(aSHA512Impl.iBlockIndex)
   1.126 +	{
   1.127 +	Mem::Copy(iData, aSHA512Impl.iData, KSHA512BlockSize*sizeof(TUint64));
   1.128 +	}
   1.129 +	
   1.130 +void CSHA384And512Impl::Reset(const TAny* aValueArr)
   1.131 +	{
   1.132 +	const TUint64* values = static_cast<const TUint64*>(aValueArr);
   1.133 +	/**
   1.134 +	 * Initial Hash Value
   1.135 +	 * 
   1.136 +	 * These words were obtained by taking the first thirty-two bits 
   1.137 +	 * of the fractional parts of the square roots of the first eight
   1.138 +	 * prime numbers.
   1.139 +	 * 
   1.140 +	 * FIPS 180-2 Section 5.3.2
   1.141 +	 */
   1.142 +	iA = values[0];
   1.143 +	iB = values[1];
   1.144 +	iC = values[2];
   1.145 +	iD = values[3];
   1.146 +	iE = values[4];
   1.147 +	iF = values[5];
   1.148 +	iG = values[6];
   1.149 +	iH = values[7];
   1.150 +	iNh = 0;
   1.151 +	iNl = 0;
   1.152 +	iBlockIndex = 0;
   1.153 +	}
   1.154 +
   1.155 +//This function will panic if the total input length is longer than 2^128 in bits
   1.156 +_LIT(KPanicString, "Message length exceeds supported length");
   1.157 +inline void CSHA384And512Impl::AddLength(const TUint64 aLength)
   1.158 +	{
   1.159 +	TUint64 temp = iNl;
   1.160 +	iNl += aLength << 3;
   1.161 +	__ASSERT_ALWAYS(((iNh != KMaxTUint64) || (temp <= iNl)), User::Panic(KPanicString, KErrOverflow));
   1.162 +	iNh += (temp > iNl);
   1.163 +	}
   1.164 +
   1.165 +// This assumes a big-endian architecture
   1.166 +void CSHA384And512Impl::Update(const TUint8* aData,TUint aLength)
   1.167 +	{
   1.168 +	while((aLength / 8) > 0 && (iBlockIndex % 8 == 0))
   1.169 +		{
   1.170 +		iData[iBlockIndex>>3] = Make64BitWord(aData);
   1.171 +		iBlockIndex+=8;
   1.172 +		aData+=8;
   1.173 +		aLength-=8;
   1.174 +		if(iBlockIndex==KSHA512BlockSize) 
   1.175 +			{
   1.176 +			Block();
   1.177 +			AddLength(KSHA512BlockSize);
   1.178 +			}
   1.179 +		}
   1.180 +
   1.181 +	while(aLength--)
   1.182 +		{
   1.183 +		if(!(iBlockIndex&0x07))
   1.184 +			{
   1.185 +			iData[iBlockIndex >> 3] = 0;
   1.186 +			}
   1.187 +		iData[iBlockIndex >> 3] |= static_cast<TUint64>(*aData) << ((7 - iBlockIndex&0x07) << 3) ;
   1.188 +		++aData;
   1.189 +		++iBlockIndex;
   1.190 +		if(iBlockIndex==KSHA512BlockSize) 
   1.191 +			{
   1.192 +			Block();
   1.193 +			AddLength(KSHA512BlockSize);
   1.194 +			}
   1.195 +		}
   1.196 +	}
   1.197 +
   1.198 +static inline void CSHA512_16(	const TUint64 aA, 
   1.199 +								const TUint64 aB, 
   1.200 +								const TUint64 aC,
   1.201 +								TUint64& aD, 
   1.202 +								const TUint64 aE, 
   1.203 +								const TUint64 aF,
   1.204 +								const TUint64 aG, 
   1.205 +								TUint64& aH,
   1.206 +								TUint64 aTemp1,
   1.207 +								TUint64 aTemp2,
   1.208 +								const TUint64 aK,
   1.209 +								const TUint64 aWord)
   1.210 +	{
   1.211 +	aTemp1 = aH + SHA512_SIGMA1(aE) + SHA_Ch(aE,aF,aG) + aK + aWord;
   1.212 +	aTemp2 = SHA512_SIGMA0(aA) + SHA_Maj(aA,aB,aC);
   1.213 +	aD = aD + aTemp1;
   1.214 +	aH = aTemp1 + aTemp2;
   1.215 +	}
   1.216 +
   1.217 +static inline void CSHA512_64(	const TUint64 aA, 
   1.218 +								const TUint64 aB, 
   1.219 +								const TUint64 aC,
   1.220 +								TUint64& aD, 
   1.221 +								const TUint64 aE, 
   1.222 +								const TUint64 aF,
   1.223 +								const TUint64 aG, 
   1.224 +								TUint64& aH,
   1.225 +								TUint64 aTemp1,
   1.226 +								TUint64 aTemp2,
   1.227 +								const TUint64 aK,
   1.228 +								TUint64& aWord0,
   1.229 +								const TUint64 aWord2,
   1.230 +								const TUint64 aWord7,
   1.231 +								const TUint64 aWord15,
   1.232 +								const TUint64 aWord16)
   1.233 +	{
   1.234 +	aWord0 = SHA512_sigma1(aWord2) + aWord7 + SHA512_sigma0(aWord15) + aWord16;
   1.235 +	CSHA512_16(aA, aB, aC, aD, aE, aF, aG, aH, aTemp1, aTemp2, aK, aWord0);
   1.236 +	}
   1.237 +
   1.238 +/**
   1.239 + * This function actually calculates the hash.
   1.240 + * Function is defined in FIPS 180-2 section 6.3.2
   1.241 + * 
   1.242 + * This function is the expanded version of the following loop.
   1.243 + *	for(TUint i = 0; i < 80; ++i)
   1.244 + *		{
   1.245 + *		if(i >= 16)
   1.246 + *			{
   1.247 + *			iData[i] = SHA512_sigma1(iData[i-2]) + iData[i-7] + SHA512_sigma0(iData[i-15]) + iData[i-16];
   1.248 + *			}
   1.249 + *
   1.250 + *		temp1 = tempH + SHA512_SIGMA1(tempE) + SHA_Ch(tempE,tempF,tempG) + K[i] + iData[i];
   1.251 + *	    temp2 = SHA512_SIGMA0(tempA) + SHA_Maj(tempA,tempB,tempC);
   1.252 + *	    tempH = tempG;
   1.253 + *	    tempG = tempF;
   1.254 + *	    tempF = tempE;
   1.255 + *	    tempE = tempD + temp1;
   1.256 + *	    tempD = tempC;
   1.257 + *	    tempC = tempB;
   1.258 + *	    tempB = tempA;
   1.259 + *	    tempA = temp1 + temp2;		
   1.260 + *		}
   1.261 + */
   1.262 +void CSHA384And512Impl::Block()
   1.263 +	{
   1.264 +	TUint64 tempA=iA;
   1.265 +	TUint64 tempB=iB;
   1.266 +	TUint64 tempC=iC;
   1.267 +	TUint64 tempD=iD;
   1.268 +	TUint64 tempE=iE;
   1.269 +	TUint64 tempF=iF;
   1.270 +	TUint64 tempG=iG;
   1.271 +	TUint64 tempH=iH;
   1.272 +	TUint64 temp1=0;
   1.273 +	TUint64 temp2=0;
   1.274 +	
   1.275 +	CSHA512_16(tempA,tempB,tempC,tempD,tempE,tempF,tempG,tempH,temp1,temp2,K[0],iData[0]);
   1.276 +	CSHA512_16(tempH,tempA,tempB,tempC,tempD,tempE,tempF,tempG,temp1,temp2,K[1],iData[1]);
   1.277 +	CSHA512_16(tempG,tempH,tempA,tempB,tempC,tempD,tempE,tempF,temp1,temp2,K[2],iData[2]);
   1.278 +	CSHA512_16(tempF,tempG,tempH,tempA,tempB,tempC,tempD,tempE,temp1,temp2,K[3],iData[3]);
   1.279 +	CSHA512_16(tempE,tempF,tempG,tempH,tempA,tempB,tempC,tempD,temp1,temp2,K[4],iData[4]);
   1.280 +	CSHA512_16(tempD,tempE,tempF,tempG,tempH,tempA,tempB,tempC,temp1,temp2,K[5],iData[5]);
   1.281 +	CSHA512_16(tempC,tempD,tempE,tempF,tempG,tempH,tempA,tempB,temp1,temp2,K[6],iData[6]);
   1.282 +	CSHA512_16(tempB,tempC,tempD,tempE,tempF,tempG,tempH,tempA,temp1,temp2,K[7],iData[7]);
   1.283 +
   1.284 +	CSHA512_16(tempA,tempB,tempC,tempD,tempE,tempF,tempG,tempH,temp1,temp2,K[8],iData[8]);
   1.285 +	CSHA512_16(tempH,tempA,tempB,tempC,tempD,tempE,tempF,tempG,temp1,temp2,K[9],iData[9]);
   1.286 +	CSHA512_16(tempG,tempH,tempA,tempB,tempC,tempD,tempE,tempF,temp1,temp2,K[10],iData[10]);
   1.287 +	CSHA512_16(tempF,tempG,tempH,tempA,tempB,tempC,tempD,tempE,temp1,temp2,K[11],iData[11]);
   1.288 +	CSHA512_16(tempE,tempF,tempG,tempH,tempA,tempB,tempC,tempD,temp1,temp2,K[12],iData[12]);
   1.289 +	CSHA512_16(tempD,tempE,tempF,tempG,tempH,tempA,tempB,tempC,temp1,temp2,K[13],iData[13]);
   1.290 +	CSHA512_16(tempC,tempD,tempE,tempF,tempG,tempH,tempA,tempB,temp1,temp2,K[14],iData[14]);
   1.291 +	CSHA512_16(tempB,tempC,tempD,tempE,tempF,tempG,tempH,tempA,temp1,temp2,K[15],iData[15]);
   1.292 +
   1.293 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.294 +				K[16], iData[16], iData[14], iData[9], iData[1], iData[0]);
   1.295 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.296 +				K[17], iData[17], iData[15], iData[10], iData[2], iData[1]);
   1.297 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.298 +				K[18], iData[18], iData[16], iData[11], iData[3], iData[2]);
   1.299 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.300 +				K[19], iData[19], iData[17], iData[12], iData[4], iData[3]);
   1.301 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.302 +				K[20], iData[20], iData[18], iData[13], iData[5], iData[4]);
   1.303 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.304 +				K[21], iData[21], iData[19], iData[14], iData[6], iData[5]);
   1.305 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.306 +				K[22], iData[22], iData[20], iData[15], iData[7], iData[6]);
   1.307 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.308 +				K[23], iData[23], iData[21], iData[16], iData[8], iData[7]);
   1.309 +
   1.310 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.311 +				K[24], iData[24], iData[22], iData[17], iData[9], iData[8]);
   1.312 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.313 +				K[25], iData[25], iData[23], iData[18], iData[10], iData[9]);
   1.314 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.315 +				K[26], iData[26], iData[24], iData[19], iData[11], iData[10]);
   1.316 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.317 +				K[27], iData[27], iData[25], iData[20], iData[12], iData[11]);
   1.318 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.319 +				K[28], iData[28], iData[26], iData[21], iData[13], iData[12]);
   1.320 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.321 +				K[29], iData[29], iData[27], iData[22], iData[14], iData[13]);
   1.322 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.323 +				K[30], iData[30], iData[28], iData[23], iData[15], iData[14]);
   1.324 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.325 +				K[31], iData[31], iData[29], iData[24], iData[16], iData[15]);
   1.326 +
   1.327 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.328 +				K[32], iData[32], iData[30], iData[25], iData[17], iData[16]);
   1.329 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.330 +				K[33], iData[33], iData[31], iData[26], iData[18], iData[17]);
   1.331 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.332 +				K[34], iData[34], iData[32], iData[27], iData[19], iData[18]);
   1.333 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.334 +				K[35], iData[35], iData[33], iData[28], iData[20], iData[19]);
   1.335 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.336 +				K[36], iData[36], iData[34], iData[29], iData[21], iData[20]);
   1.337 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.338 +				K[37], iData[37], iData[35], iData[30], iData[22], iData[21]);
   1.339 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.340 +				K[38], iData[38], iData[36], iData[31], iData[23], iData[22]);
   1.341 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.342 +				K[39], iData[39], iData[37], iData[32], iData[24], iData[23]);
   1.343 +
   1.344 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.345 +				K[40], iData[40], iData[38], iData[33], iData[25], iData[24]);
   1.346 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.347 +				K[41], iData[41], iData[39], iData[34], iData[26], iData[25]);
   1.348 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.349 +				K[42], iData[42], iData[40], iData[35], iData[27], iData[26]);
   1.350 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.351 +				K[43], iData[43], iData[41], iData[36], iData[28], iData[27]);
   1.352 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.353 +				K[44], iData[44], iData[42], iData[37], iData[29], iData[28]);
   1.354 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.355 +				K[45], iData[45], iData[43], iData[38], iData[30], iData[29]);
   1.356 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.357 +				K[46], iData[46], iData[44], iData[39], iData[31], iData[30]);
   1.358 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.359 +				K[47], iData[47], iData[45], iData[40], iData[32], iData[31]);
   1.360 +
   1.361 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.362 +				K[48], iData[48], iData[46], iData[41], iData[33], iData[32]);
   1.363 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.364 +				K[49], iData[49], iData[47], iData[42], iData[34], iData[33]);
   1.365 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.366 +				K[50], iData[50], iData[48], iData[43], iData[35], iData[34]);
   1.367 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.368 +				K[51], iData[51], iData[49], iData[44], iData[36], iData[35]);
   1.369 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.370 +				K[52], iData[52], iData[50], iData[45], iData[37], iData[36]);
   1.371 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.372 +				K[53], iData[53], iData[51], iData[46], iData[38], iData[37]);
   1.373 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.374 +				K[54], iData[54], iData[52], iData[47], iData[39], iData[38]);
   1.375 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.376 +				K[55], iData[55], iData[53], iData[48], iData[40], iData[39]);
   1.377 +
   1.378 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.379 +				K[56], iData[56], iData[54], iData[49], iData[41], iData[40]);
   1.380 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.381 +				K[57], iData[57], iData[55], iData[50], iData[42], iData[41]);
   1.382 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.383 +				K[58], iData[58], iData[56], iData[51], iData[43], iData[42]);
   1.384 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.385 +				K[59], iData[59], iData[57], iData[52], iData[44], iData[43]);
   1.386 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.387 +				K[60], iData[60], iData[58], iData[53], iData[45], iData[44]);
   1.388 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.389 +				K[61], iData[61], iData[59], iData[54], iData[46], iData[45]);
   1.390 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.391 +				K[62], iData[62], iData[60], iData[55], iData[47], iData[46]);
   1.392 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.393 +				K[63], iData[63], iData[61], iData[56], iData[48], iData[47]);
   1.394 +
   1.395 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.396 +				K[64], iData[64], iData[62], iData[57], iData[49], iData[48]);
   1.397 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.398 +				K[65], iData[65], iData[63], iData[58], iData[50], iData[49]);
   1.399 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.400 +				K[66], iData[66], iData[64], iData[59], iData[51], iData[50]);
   1.401 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.402 +				K[67], iData[67], iData[65], iData[60], iData[52], iData[51]);
   1.403 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.404 +				K[68], iData[68], iData[66], iData[61], iData[53], iData[52]);
   1.405 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.406 +				K[69], iData[69], iData[67], iData[62], iData[54], iData[53]);
   1.407 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.408 +				K[70], iData[70], iData[68], iData[63], iData[55], iData[54]);
   1.409 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.410 +				K[71], iData[71], iData[69], iData[64], iData[56], iData[55]);
   1.411 +
   1.412 +	CSHA512_64(	tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2,
   1.413 +				K[72], iData[72], iData[70], iData[65], iData[57], iData[56]);
   1.414 +	CSHA512_64(	tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2,
   1.415 +				K[73], iData[73], iData[71], iData[66], iData[58], iData[57]);
   1.416 +	CSHA512_64(	tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2,
   1.417 +				K[74], iData[74], iData[72], iData[67], iData[59], iData[58]);
   1.418 +	CSHA512_64(	tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2,
   1.419 +				K[75], iData[75], iData[73], iData[68], iData[60], iData[59]);
   1.420 +	CSHA512_64(	tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2,
   1.421 +				K[76], iData[76], iData[74], iData[69], iData[61], iData[60]);
   1.422 +	CSHA512_64(	tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2,
   1.423 +				K[77], iData[77], iData[75], iData[70], iData[62], iData[61]);
   1.424 +	CSHA512_64(	tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2,
   1.425 +				K[78], iData[78], iData[76], iData[71], iData[63], iData[62]);
   1.426 +	CSHA512_64(	tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2,
   1.427 +				K[79], iData[79], iData[77], iData[72], iData[64], iData[63]);
   1.428 +
   1.429 +	iA+=tempA;
   1.430 +	iB+=tempB;
   1.431 +	iC+=tempC;
   1.432 +	iD+=tempD;
   1.433 +	iE+=tempE;
   1.434 +	iF+=tempF;
   1.435 +	iG+=tempG;
   1.436 +	iH+=tempH;
   1.437 +
   1.438 +	iBlockIndex=0;
   1.439 +	}
   1.440 +
   1.441 +/**
   1.442 + * According to the standard, the message must be padded to an
   1.443 + * even 512 bits. The first padding bit must be a '1'. The last
   1.444 + * 64 bits represent the length of the original message. All bits 
   1.445 + * in between should be 0. This helper function will pad the 
   1.446 + * message according to those rules by filling the iData array 
   1.447 + * accordingly. 
   1.448 + */ 
   1.449 +void CSHA384And512Impl::PadMessage()
   1.450 +	{
   1.451 +	const TUint64 padByte = 0x80;
   1.452 +	
   1.453 +	if(!(iBlockIndex&0x07))
   1.454 +		{
   1.455 +		iData[iBlockIndex >> 3] = 0;
   1.456 +		}
   1.457 +	iData[iBlockIndex >> 3] |= padByte << ((7 - iBlockIndex&0x07) << 3) ;
   1.458 +	
   1.459 +	if (iBlockIndex >= (KSHA512BlockSize - 2*sizeof(TUint64))) 
   1.460 +		{
   1.461 +		if (iBlockIndex < (KSHA512BlockSize - sizeof(TUint64)))
   1.462 +			iData[(KSHA512BlockSize>>3)-1]=0;		
   1.463 +		Block();
   1.464 +		Mem::FillZ(iData,KSHA512BlockSize);
   1.465 +		} 
   1.466 +	else
   1.467 +		{
   1.468 +		const TUint offset=(iBlockIndex+8)>>3; //+8 to account for the word added in the
   1.469 +		//switch statement above
   1.470 +		Mem::FillZ(iData+offset, (KSHA512BlockSize - offset*sizeof(TUint64)));
   1.471 +		}
   1.472 +
   1.473 +	iData[(KSHA512BlockSize >> 3) - 2] = iNh;
   1.474 +	iData[(KSHA512BlockSize >> 3) - 1] = iNl;	
   1.475 +	}
   1.476 +
   1.477 +inline void CSHA384And512Impl::CopyWordToHash(TUint64 aVal, TUint aIndex)
   1.478 +	{
   1.479 +	TUint64 value = Make64BitWord(reinterpret_cast<TUint8*>(&aVal));
   1.480 +	Mem::Copy(const_cast<TUint8*>(iHash.Ptr())+ (8*aIndex), &value, sizeof(aVal));
   1.481 +	}
   1.482 +
   1.483 +const TDesC8& CSHA384And512Impl::Final()
   1.484 +	{
   1.485 +	AddLength(iBlockIndex);
   1.486 +	PadMessage();
   1.487 +	Block();
   1.488 +	//
   1.489 +	// Generate hash value into iHash
   1.490 +	//
   1.491 +	CopyWordToHash(iA, 0);
   1.492 +	CopyWordToHash(iB, 1);
   1.493 +	CopyWordToHash(iC, 2);
   1.494 +	CopyWordToHash(iD, 3);
   1.495 +	CopyWordToHash(iE, 4);
   1.496 +	CopyWordToHash(iF, 5);
   1.497 +	CopyWordToHash(iG, 6);
   1.498 +	CopyWordToHash(iH, 7);
   1.499 +	
   1.500 +	return iHash;
   1.501 +	}
   1.502 +
   1.503 +void CSHA384And512Impl::RestoreState()
   1.504 +	{
   1.505 +	iA = iACopy;
   1.506 +	iB = iBCopy;
   1.507 +	iC = iCCopy;
   1.508 +	iD = iDCopy;
   1.509 +	iE = iECopy;
   1.510 +	iF = iFCopy;
   1.511 +	iG = iGCopy;
   1.512 +	iH = iHCopy;
   1.513 +	iNl = iNlCopy;
   1.514 +	iNh = iNhCopy;	
   1.515 +	iBlockIndex = iBlockIndexCopy;
   1.516 +	Mem::Copy((TAny*)iData, (TAny*)iDataCopy, KSHA512BlockSize*sizeof(TUint64)); 
   1.517 +	}
   1.518 +
   1.519 +void CSHA384And512Impl::StoreState()
   1.520 +	{
   1.521 +	iACopy = iA;
   1.522 +	iBCopy = iB;
   1.523 +	iCCopy = iC;
   1.524 +	iDCopy = iD;
   1.525 +	iECopy = iE;
   1.526 +	iFCopy = iF;
   1.527 +	iGCopy = iG;
   1.528 +	iHCopy = iH;
   1.529 +	iNlCopy = iNl;
   1.530 +	iNhCopy = iNh;	
   1.531 +	iBlockIndexCopy = iBlockIndex;
   1.532 +	Mem::Copy((TAny*)iDataCopy, (TAny*)iData, KSHA512BlockSize*sizeof(TUint64));
   1.533 +	}
   1.534 +
   1.535 +// Implemented in hmacimpl.cpp or softwarehashbase.cpp
   1.536 +// but required as derived from MHash. No coverage here.
   1.537 +#ifdef _BullseyeCoverage
   1.538 +#pragma suppress_warnings on
   1.539 +#pragma BullseyeCoverage off
   1.540 +#pragma suppress_warnings off
   1.541 +#endif
   1.542 +