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