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