1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/md4impl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,538 @@
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 +* software md4 implementation
1.19 +* software md4 implementation
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +
1.28 +#include "md4impl.h"
1.29 +#include <cryptospi/hashplugin.h>
1.30 +#include "pluginconfig.h"
1.31 +
1.32 +
1.33 +using namespace SoftwareCrypto;
1.34 +
1.35 +
1.36 +CMD4Impl* CMD4Impl::NewL()
1.37 + {
1.38 + CMD4Impl* self=new (ELeave) CMD4Impl();
1.39 + self->Reset();
1.40 + return self;
1.41 + }
1.42 +
1.43 +CMD4Impl* CMD4Impl::NewLC()
1.44 + {
1.45 + CMD4Impl* self=NewL();
1.46 + CleanupStack::PushL(self);
1.47 + return self;
1.48 + }
1.49 +
1.50 +CMD4Impl::CMD4Impl() : iHash(KMD4HashSize)
1.51 + {
1.52 + }
1.53 +
1.54 +CMD4Impl::CMD4Impl(const CMD4Impl& aCMD4Impl)
1.55 +: iHash(aCMD4Impl.iHash),iA(aCMD4Impl.iA),iB(aCMD4Impl.iB),iC(aCMD4Impl.iC),iD(aCMD4Impl.iD),
1.56 + iNl(aCMD4Impl.iNl),iNh(aCMD4Impl.iNh)
1.57 + {
1.58 + (void)Mem::Copy(iData, aCMD4Impl.iData, sizeof(iData));
1.59 + }
1.60 +
1.61 +CMD4Impl::~CMD4Impl()
1.62 + {
1.63 + }
1.64 +
1.65 +void CMD4Impl::Reset()
1.66 + {
1.67 + iA=0x67452301;
1.68 + iB=0xefcdab89;
1.69 + iC=0x98badcfe;
1.70 + iD=0x10325476;
1.71 + iNh=0;
1.72 + iNl=0;
1.73 + }
1.74 +
1.75 +void CMD4Impl::Close()
1.76 + {
1.77 + delete this;
1.78 + }
1.79 +
1.80 +void CMD4Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
1.81 + {
1.82 + aPluginCharacteristics=NULL;
1.83 + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
1.84 + for (TInt i=0;i<hashNum;i++)
1.85 + {
1.86 + if (KHashCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
1.87 + {
1.88 + aPluginCharacteristics = KHashCharacteristics[i];
1.89 + break;
1.90 + }
1.91 + }
1.92 + }
1.93 +
1.94 +CExtendedCharacteristics* CMD4Impl::CreateExtendedCharacteristicsL()
1.95 + {
1.96 + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
1.97 + // for exclusive use and are not CERTIFIED to be standards compliant.
1.98 + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
1.99 + }
1.100 +const CExtendedCharacteristics* CMD4Impl::GetExtendedCharacteristicsL()
1.101 + {
1.102 + return CMD4Impl::CreateExtendedCharacteristicsL();
1.103 + }
1.104 +
1.105 +TPtrC8 CMD4Impl::Hash(const TDesC8& aMessage)
1.106 + {
1.107 + DoUpdate(aMessage.Ptr(),aMessage.Size());
1.108 + StoreState();
1.109 + DoFinal();
1.110 + RestoreState();
1.111 + return iHash;
1.112 + }
1.113 +
1.114 +void CMD4Impl::Update(const TDesC8& aMessage)
1.115 + {
1.116 + DoUpdate(aMessage.Ptr(),aMessage.Size());
1.117 + }
1.118 +
1.119 +TPtrC8 CMD4Impl::Final(const TDesC8& aMessage)
1.120 + {
1.121 + if (aMessage!=KNullDesC8())
1.122 + {
1.123 + DoUpdate(aMessage.Ptr(),aMessage.Size());
1.124 + }
1.125 + DoFinal();
1.126 + Reset();
1.127 + return iHash;
1.128 + }
1.129 +
1.130 +MHash* CMD4Impl::ReplicateL()
1.131 + {
1.132 + return CMD4Impl::NewL();
1.133 + }
1.134 +
1.135 +MHash* CMD4Impl::CopyL()
1.136 + {
1.137 + return new(ELeave) CMD4Impl(*this);
1.138 + }
1.139 +
1.140 +TUid CMD4Impl::ImplementationUid()
1.141 + {
1.142 + return KCryptoPluginMd4Uid;
1.143 + }
1.144 +
1.145 +void CMD4Impl::DoUpdate(const TUint8* aData,TUint aLength)
1.146 + {
1.147 + const TUint8* pend=aData+aLength;
1.148 + for (const TUint8* paData=aData;paData<pend;paData++)
1.149 + {
1.150 + const TUint8 byte=*paData;
1.151 + switch (iNl&3)
1.152 + {
1.153 + case 0:
1.154 + iData[iNl>>2]=byte;
1.155 + break;
1.156 + case 1:
1.157 + iData[iNl>>2]|=byte<<8;
1.158 + break;
1.159 + case 2:
1.160 + iData[iNl>>2]|=byte<<16;
1.161 + break;
1.162 + case 3:
1.163 + iData[iNl>>2]|=byte<<24;
1.164 + break;
1.165 + default:
1.166 + break;
1.167 + };
1.168 + if(++iNl==64)
1.169 + {
1.170 + Block();
1.171 + iNh+=64;
1.172 + iNl=0;
1.173 + }
1.174 + }
1.175 + }
1.176 +
1.177 +static inline TUint CMD4_F(TUint x,TUint y,TUint z)
1.178 + {
1.179 + return (x&y) | (~x&z);
1.180 + }
1.181 +static inline TUint CMD4_G(TUint x,TUint y,TUint z)
1.182 + {
1.183 + return (x&y) | (x&z) | (y&z);
1.184 + }
1.185 +static inline TUint CMD4_H(TUint x,TUint y,TUint z)
1.186 + {
1.187 + return x^y^z;
1.188 + }
1.189 +
1.190 +
1.191 +#ifdef NOREFS
1.192 +static inline TUint CMD4_FF(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
1.193 + {
1.194 + a+=CMD4_F(b,c,d) + x;
1.195 + a=CMD_R(a,s);
1.196 + return a;
1.197 + }
1.198 +static inline TUint CMD4_GG(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
1.199 + {
1.200 + a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999;
1.201 + a=CMD_R(a,s);
1.202 + return a;
1.203 + }
1.204 +static inline TUint CMD4_HH(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
1.205 + {
1.206 + a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1;
1.207 + a=CMD_R(a,s);
1.208 + return a;
1.209 + }
1.210 +
1.211 +void CMD4Impl::Block()
1.212 + {
1.213 + register TUint tempA=iA;
1.214 + register TUint tempB=iB;
1.215 + register TUint tempC=iC;
1.216 + register TUint tempD=iD;
1.217 +
1.218 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3);
1.219 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7);
1.220 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11);
1.221 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19);
1.222 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3);
1.223 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7);
1.224 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11);
1.225 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19);
1.226 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3);
1.227 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7);
1.228 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11);
1.229 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19);
1.230 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3);
1.231 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7);
1.232 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11);
1.233 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19);
1.234 +
1.235 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3);
1.236 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5);
1.237 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9);
1.238 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13);
1.239 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3);
1.240 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5);
1.241 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9);
1.242 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13);
1.243 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3);
1.244 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5);
1.245 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9);
1.246 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13);
1.247 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3);
1.248 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5);
1.249 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9);
1.250 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13);
1.251 +
1.252 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3);
1.253 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9);
1.254 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11);
1.255 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15);
1.256 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3);
1.257 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9);
1.258 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11);
1.259 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15);
1.260 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3);
1.261 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9);
1.262 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11);
1.263 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15);
1.264 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3);
1.265 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9);
1.266 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11);
1.267 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15);
1.268 +
1.269 + iA+=tempA;
1.270 + iB+=tempB;
1.271 + iC+=tempC;
1.272 + iD+=tempD;
1.273 + }
1.274 +#else
1.275 +#ifdef MACRO
1.276 +#define CMD4_FF(a, b, c, d, x, s) (CMD_R(a += CMD4_F(b,c,d) + x, s))
1.277 +#define CMD4_GG(a, b, c, d, x, s) (CMD_R(a += CMD4_G(b,c,d) + x + (TUint32)0x5a827999, s))
1.278 +#define CMD4_HH(a, b, c, d, x, s) (CMD_R(a += CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1, s))
1.279 +void CMD4Impl::Block()
1.280 + {
1.281 + register TUint tempA=iA;
1.282 + register TUint tempB=iB;
1.283 + register TUint tempC=iC;
1.284 + register TUint tempD=iD;
1.285 +
1.286 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3);
1.287 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7);
1.288 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11);
1.289 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19);
1.290 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3);
1.291 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7);
1.292 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11);
1.293 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19);
1.294 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3);
1.295 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7);
1.296 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11);
1.297 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19);
1.298 + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3);
1.299 + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7);
1.300 + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11);
1.301 + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19);
1.302 +
1.303 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3);
1.304 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5);
1.305 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9);
1.306 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13);
1.307 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3);
1.308 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5);
1.309 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9);
1.310 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13);
1.311 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3);
1.312 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5);
1.313 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9);
1.314 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13);
1.315 + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3);
1.316 + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5);
1.317 + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9);
1.318 + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13);
1.319 +
1.320 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3);
1.321 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9);
1.322 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11);
1.323 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15);
1.324 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3);
1.325 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9);
1.326 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11);
1.327 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15);
1.328 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3);
1.329 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9);
1.330 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11);
1.331 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15);
1.332 + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3);
1.333 + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9);
1.334 + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11);
1.335 + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15);
1.336 +
1.337 + iA+=tempA;
1.338 + iB+=tempB;
1.339 + iC+=tempC;
1.340 + iD+=tempD;
1.341 + }
1.342 +#else
1.343 +static inline void CMD4_FF(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
1.344 + {
1.345 + a+=CMD4_F(b,c,d) + x;
1.346 + a=CMD_R(a,s);
1.347 + }
1.348 +static inline void CMD4_GG(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
1.349 + {
1.350 + a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999;
1.351 + a=CMD_R(a,s);
1.352 + }
1.353 +static inline void CMD4_HH(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s)
1.354 + {
1.355 + a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1;
1.356 + a=CMD_R(a,s);
1.357 + }
1.358 +
1.359 +void CMD4Impl::Block()
1.360 + {
1.361 + register TUint tempA=iA;
1.362 + register TUint tempB=iB;
1.363 + register TUint tempC=iC;
1.364 + register TUint tempD=iD;
1.365 +
1.366 + CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3);
1.367 + CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7);
1.368 + CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11);
1.369 + CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19);
1.370 + CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3);
1.371 + CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7);
1.372 + CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11);
1.373 + CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19);
1.374 + CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3);
1.375 + CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7);
1.376 + CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11);
1.377 + CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19);
1.378 + CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3);
1.379 + CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7);
1.380 + CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11);
1.381 + CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19);
1.382 +
1.383 + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3);
1.384 + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5);
1.385 + CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9);
1.386 + CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13);
1.387 + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3);
1.388 + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5);
1.389 + CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9);
1.390 + CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13);
1.391 + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3);
1.392 + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5);
1.393 + CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9);
1.394 + CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13);
1.395 + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3);
1.396 + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5);
1.397 + CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9);
1.398 + CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13);
1.399 +
1.400 + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3);
1.401 + CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9);
1.402 + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11);
1.403 + CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15);
1.404 + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3);
1.405 + CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9);
1.406 + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11);
1.407 + CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15);
1.408 + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3);
1.409 + CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9);
1.410 + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11);
1.411 + CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15);
1.412 + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3);
1.413 + CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9);
1.414 + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11);
1.415 + CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15);
1.416 +
1.417 + iA+=tempA;
1.418 + iB+=tempB;
1.419 + iC+=tempC;
1.420 + iD+=tempD;
1.421 + }
1.422 +#endif
1.423 +#endif
1.424 +
1.425 +void CMD4Impl::DoFinal(void)
1.426 + {
1.427 + iNh += iNl;
1.428 + const TUint ul128=128;
1.429 + switch (iNl&3)
1.430 + {
1.431 + case 0:
1.432 + iData[iNl>>2] = ul128;
1.433 + break;
1.434 + case 1:
1.435 + iData[iNl>>2] += ul128<<8;
1.436 + break;
1.437 + case 2:
1.438 + iData[iNl>>2] += ul128<<16;
1.439 + break;
1.440 + case 3:
1.441 + iData[iNl>>2] += ul128<<24;
1.442 + break;
1.443 + default:
1.444 + break;
1.445 + };
1.446 + if (iNl>=56)
1.447 + {
1.448 + if (iNl<60)
1.449 + iData[15]=0;
1.450 + Block();
1.451 + Mem::FillZ(iData,14*sizeof(TUint));
1.452 + }
1.453 + else
1.454 + {
1.455 + const TUint offset=(iNl+4)>>2;
1.456 + Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint));
1.457 + }
1.458 +
1.459 + iData[14]=iNh<<3;//number in bits
1.460 + // this will fail if the total input length is longer than 2^32 in bits
1.461 + //(2^31 in bytes) which is roughly half a gig.
1.462 + iData[15]=0;
1.463 +
1.464 + Block();
1.465 + //
1.466 + // Generate hash value into iHash
1.467 + //
1.468 + TUint tmp=iA;
1.469 + iHash[0]=(TUint8)(tmp & 255);
1.470 + iHash[1]=(TUint8)((tmp >>= 8) & 255);
1.471 + iHash[2]=(TUint8)((tmp >>= 8) & 255);
1.472 + iHash[3]=(TUint8)((tmp >>= 8) & 255);
1.473 +
1.474 + tmp=iB;
1.475 + iHash[4]=(TUint8)(tmp & 255);
1.476 + iHash[5]=(TUint8)((tmp >>= 8) & 255);
1.477 + iHash[6]=(TUint8)((tmp >>= 8) & 255);
1.478 + iHash[7]=(TUint8)((tmp >>= 8) & 255);
1.479 +
1.480 + tmp=iC;
1.481 + iHash[8] =(TUint8)(tmp & 255);
1.482 + iHash[9] =(TUint8)((tmp >>= 8) & 255);
1.483 + iHash[10]=(TUint8)((tmp >>= 8) & 255);
1.484 + iHash[11]=(TUint8)((tmp >>= 8) & 255);
1.485 +
1.486 + tmp=iD;
1.487 + iHash[12]=(TUint8)(tmp & 255);
1.488 + iHash[13]=(TUint8)((tmp >>= 8) & 255);
1.489 + iHash[14]=(TUint8)((tmp >>= 8) & 255);
1.490 + iHash[15]=(TUint8)((tmp >>= 8) & 255);
1.491 + }
1.492 +
1.493 +void CMD4Impl::RestoreState()
1.494 + {
1.495 + iA = iACopy;
1.496 + iB = iBCopy;
1.497 + iC = iCCopy;
1.498 + iD = iDCopy;
1.499 + iNl = iNlCopy;
1.500 + iNh = iNhCopy;
1.501 + Mem::Copy(&iData[0], &iDataCopy[0], KMD4BlockSize*sizeof(TUint));
1.502 + }
1.503 +
1.504 +void CMD4Impl::StoreState()
1.505 + {
1.506 + iACopy = iA;
1.507 + iBCopy = iB;
1.508 + iCCopy = iC;
1.509 + iDCopy = iD;
1.510 + iNlCopy = iNl;
1.511 + iNhCopy = iNh;
1.512 + Mem::Copy(&iDataCopy[0], &iData[0], KMD4BlockSize*sizeof(TUint));
1.513 + }
1.514 +
1.515 +
1.516 +// Implemented in hmacimpl.cpp or softwarehashbase.cpp
1.517 +// but required as derived from MHash. No coverage here.
1.518 +#ifdef _BullseyeCoverage
1.519 +#pragma suppress_warnings on
1.520 +#pragma BullseyeCoverage off
1.521 +#pragma suppress_warnings off
1.522 +#endif
1.523 +
1.524 +TAny* CMD4Impl::GetExtension(TUid /*aExtensionId*/)
1.525 + {
1.526 + return NULL;
1.527 + }
1.528 +
1.529 +void CMD4Impl::SetOperationModeL(TUid /*aOperationMode*/)
1.530 + {
1.531 + User::Leave(KErrNotSupported);
1.532 + }
1.533 +
1.534 +void CMD4Impl::SetKeyL(const CKey& /*aKey*/)
1.535 + {
1.536 + User::Leave(KErrNotSupported);
1.537 + }
1.538 +
1.539 +
1.540 +
1.541 +