|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 */ |
|
24 |
|
25 #include <e32std.h> |
|
26 #include <hash.h> |
|
27 #include "hashinc.h" |
|
28 #define EXPANDLOOP |
|
29 |
|
30 |
|
31 CMD4::CMD4(void) |
|
32 : CMessageDigest(),iHash(MD4_HASH) |
|
33 { |
|
34 } |
|
35 |
|
36 CMD4::CMD4(const CMD4& aMD) |
|
37 : CMessageDigest(aMD), |
|
38 iHash(aMD.iHash),iA(aMD.iA),iB(aMD.iB),iC(aMD.iC),iD(aMD.iD), |
|
39 iNl(aMD.iNl),iNh(aMD.iNh) |
|
40 { |
|
41 (void)Mem::Copy(iData,aMD.iData,sizeof(iData)); |
|
42 } |
|
43 |
|
44 EXPORT_C CMD4* CMD4::NewL(void) |
|
45 { |
|
46 CMD4* self = new (ELeave) CMD4(); |
|
47 self->Reset(); |
|
48 return (self); |
|
49 } |
|
50 |
|
51 EXPORT_C CMessageDigest* CMD4::ReplicateL(void) |
|
52 { |
|
53 return CMD4::NewL(); |
|
54 } |
|
55 |
|
56 EXPORT_C CMD4::~CMD4(void) |
|
57 { |
|
58 } |
|
59 |
|
60 EXPORT_C TPtrC8 CMD4::Hash(const TDesC8& aMessage) |
|
61 { |
|
62 //Adds the aMessage to the internal representation of data to be hashed i.e iData |
|
63 DoUpdate(aMessage.Ptr(),aMessage.Size()); |
|
64 StoreState(); |
|
65 //Does the padding and does the block operation on the final 512 bit block. |
|
66 DoFinal(); |
|
67 RestoreState(); |
|
68 return iHash; |
|
69 } |
|
70 |
|
71 EXPORT_C CMessageDigest* CMD4::CopyL(void) |
|
72 { |
|
73 return new(ELeave) CMD4(*this); |
|
74 } |
|
75 |
|
76 EXPORT_C TInt CMD4::BlockSize(void) |
|
77 { |
|
78 return sizeof(iData); |
|
79 } |
|
80 |
|
81 EXPORT_C TInt CMD4::HashSize(void) |
|
82 { |
|
83 return MD4_HASH; |
|
84 } |
|
85 |
|
86 EXPORT_C void CMD4::Reset(void) |
|
87 { |
|
88 iA=0x67452301; |
|
89 iB=0xefcdab89; |
|
90 iC=0x98badcfe; |
|
91 iD=0x10325476; |
|
92 iNh=0; |
|
93 iNl=0; |
|
94 } |
|
95 |
|
96 EXPORT_C void CMD4::Update(const TDesC8& aMessage) |
|
97 { |
|
98 DoUpdate(aMessage.Ptr(),aMessage.Size()); |
|
99 } |
|
100 |
|
101 EXPORT_C TPtrC8 CMD4::Final(const TDesC8& aMessage) |
|
102 { |
|
103 //Adds the aMessage to the internal representation of data to be hashed i.e iData |
|
104 DoUpdate(aMessage.Ptr(),aMessage.Size()); |
|
105 //Does the padding and does the block operation on the final 512 bit block. |
|
106 DoFinal(); |
|
107 //Resets the values of iA, iB, iC and iD, iNh, iNl |
|
108 Reset(); |
|
109 return iHash; |
|
110 } |
|
111 |
|
112 EXPORT_C TPtrC8 CMD4::Final() |
|
113 { |
|
114 //Does the padding and does the block operation on the final 512 bit block. |
|
115 DoFinal(); |
|
116 //Resets the values of iA, iB, iC and iD, iNh, iNl |
|
117 Reset(); |
|
118 return iHash; |
|
119 } |
|
120 |
|
121 void CMD4::DoUpdate(const TUint8* aData,TUint aLength) |
|
122 { |
|
123 const TUint8* pend=aData+aLength; |
|
124 for (const TUint8* paData=aData;paData<pend;paData++) |
|
125 { |
|
126 const TUint8 byte=*paData; |
|
127 switch (iNl&3) |
|
128 { |
|
129 case 0: |
|
130 iData[iNl>>2]=byte; |
|
131 break; |
|
132 case 1: |
|
133 iData[iNl>>2]|=byte<<8; |
|
134 break; |
|
135 case 2: |
|
136 iData[iNl>>2]|=byte<<16; |
|
137 break; |
|
138 case 3: |
|
139 iData[iNl>>2]|=byte<<24; |
|
140 break; |
|
141 default: |
|
142 break; |
|
143 }; |
|
144 if(++iNl==64) |
|
145 { |
|
146 Block(); |
|
147 iNh+=64; |
|
148 iNl=0; |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 static inline TUint CMD4_F(TUint x,TUint y,TUint z) |
|
154 { |
|
155 return ((x)&(y)) | ((~x)&(z)); |
|
156 } |
|
157 |
|
158 static inline TUint CMD4_G(TUint x,TUint y,TUint z) |
|
159 { |
|
160 return ((x)&(y)) | ((x)&(z)) | ((y)&(z)); |
|
161 } |
|
162 |
|
163 static inline TUint CMD4_H(TUint x,TUint y,TUint z) |
|
164 { |
|
165 return (x)^(y)^(z); |
|
166 } |
|
167 |
|
168 |
|
169 #ifdef NOREFS |
|
170 static inline TUint CMD4_FF(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) |
|
171 { |
|
172 a+=CMD4_F(b,c,d) + x; |
|
173 a=CMD_R(a,s); |
|
174 return a; |
|
175 } |
|
176 |
|
177 static inline TUint CMD4_GG(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) |
|
178 { |
|
179 a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999; |
|
180 a=CMD_R(a,s); |
|
181 return a; |
|
182 } |
|
183 |
|
184 static inline TUint CMD4_HH(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) |
|
185 { |
|
186 a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1; |
|
187 a=CMD_R(a,s); |
|
188 return a; |
|
189 } |
|
190 |
|
191 void CMD4::Block() |
|
192 { |
|
193 register TUint tempA=iA; |
|
194 register TUint tempB=iB; |
|
195 register TUint tempC=iC; |
|
196 register TUint tempD=iD; |
|
197 |
|
198 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
199 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7); |
|
200 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11); |
|
201 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19); |
|
202 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3); |
|
203 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7); |
|
204 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11); |
|
205 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19); |
|
206 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3); |
|
207 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7); |
|
208 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11); |
|
209 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19); |
|
210 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3); |
|
211 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7); |
|
212 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11); |
|
213 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19); |
|
214 |
|
215 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
216 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5); |
|
217 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9); |
|
218 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13); |
|
219 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3); |
|
220 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5); |
|
221 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9); |
|
222 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13); |
|
223 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3); |
|
224 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5); |
|
225 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9); |
|
226 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13); |
|
227 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3); |
|
228 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5); |
|
229 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9); |
|
230 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13); |
|
231 |
|
232 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
233 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9); |
|
234 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11); |
|
235 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15); |
|
236 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3); |
|
237 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9); |
|
238 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11); |
|
239 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15); |
|
240 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3); |
|
241 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9); |
|
242 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11); |
|
243 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15); |
|
244 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3); |
|
245 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9); |
|
246 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11); |
|
247 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15); |
|
248 |
|
249 iA+=tempA; |
|
250 iB+=tempB; |
|
251 iC+=tempC; |
|
252 iD+=tempD; |
|
253 } |
|
254 |
|
255 #else |
|
256 #ifdef MACRO |
|
257 #define CMD4_FF(a, b, c, d, x, s) (CMD_R(a += CMD4_F(b,c,d) + x, s)) |
|
258 #define CMD4_GG(a, b, c, d, x, s) (CMD_R(a += CMD4_G(b,c,d) + x + (TUint32)0x5a827999, s)) |
|
259 #define CMD4_HH(a, b, c, d, x, s) (CMD_R(a += CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1, s)) |
|
260 void CMD4::Block() |
|
261 { |
|
262 register TUint tempA=iA; |
|
263 register TUint tempB=iB; |
|
264 register TUint tempC=iC; |
|
265 register TUint tempD=iD; |
|
266 |
|
267 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
268 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7); |
|
269 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11); |
|
270 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19); |
|
271 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3); |
|
272 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7); |
|
273 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11); |
|
274 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19); |
|
275 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3); |
|
276 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7); |
|
277 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11); |
|
278 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19); |
|
279 tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3); |
|
280 tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7); |
|
281 tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11); |
|
282 tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19); |
|
283 |
|
284 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
285 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5); |
|
286 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9); |
|
287 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13); |
|
288 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3); |
|
289 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5); |
|
290 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9); |
|
291 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13); |
|
292 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3); |
|
293 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5); |
|
294 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9); |
|
295 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13); |
|
296 tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3); |
|
297 tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5); |
|
298 tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9); |
|
299 tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13); |
|
300 |
|
301 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
302 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9); |
|
303 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11); |
|
304 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15); |
|
305 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3); |
|
306 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9); |
|
307 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11); |
|
308 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15); |
|
309 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3); |
|
310 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9); |
|
311 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11); |
|
312 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15); |
|
313 tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3); |
|
314 tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9); |
|
315 tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11); |
|
316 tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15); |
|
317 |
|
318 iA+=tempA; |
|
319 iB+=tempB; |
|
320 iC+=tempC; |
|
321 iD+=tempD; |
|
322 } |
|
323 |
|
324 #else |
|
325 static inline void CMD4_FF(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) |
|
326 { |
|
327 a+=CMD4_F(b,c,d) + x; |
|
328 a=CMD_R(a,s); |
|
329 } |
|
330 |
|
331 static inline void CMD4_GG(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) |
|
332 { |
|
333 a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999; |
|
334 a=CMD_R(a,s); |
|
335 } |
|
336 |
|
337 static inline void CMD4_HH(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) |
|
338 { |
|
339 a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1; |
|
340 a=CMD_R(a,s); |
|
341 } |
|
342 |
|
343 void CMD4::Block() |
|
344 { |
|
345 register TUint tempA=iA; |
|
346 register TUint tempB=iB; |
|
347 register TUint tempC=iC; |
|
348 register TUint tempD=iD; |
|
349 |
|
350 CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
351 CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7); |
|
352 CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11); |
|
353 CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19); |
|
354 CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3); |
|
355 CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7); |
|
356 CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11); |
|
357 CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19); |
|
358 CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3); |
|
359 CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7); |
|
360 CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11); |
|
361 CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19); |
|
362 CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3); |
|
363 CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7); |
|
364 CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11); |
|
365 CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19); |
|
366 |
|
367 CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
368 CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5); |
|
369 CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9); |
|
370 CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13); |
|
371 CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3); |
|
372 CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5); |
|
373 CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9); |
|
374 CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13); |
|
375 CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3); |
|
376 CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5); |
|
377 CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9); |
|
378 CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13); |
|
379 CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3); |
|
380 CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5); |
|
381 CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9); |
|
382 CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13); |
|
383 |
|
384 CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3); |
|
385 CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9); |
|
386 CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11); |
|
387 CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15); |
|
388 CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3); |
|
389 CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9); |
|
390 CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11); |
|
391 CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15); |
|
392 CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3); |
|
393 CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9); |
|
394 CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11); |
|
395 CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15); |
|
396 CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3); |
|
397 CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9); |
|
398 CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11); |
|
399 CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15); |
|
400 |
|
401 iA+=tempA; |
|
402 iB+=tempB; |
|
403 iC+=tempC; |
|
404 iD+=tempD; |
|
405 } |
|
406 #endif |
|
407 #endif |
|
408 |
|
409 void CMD4::DoFinal(void) |
|
410 { |
|
411 iNh += iNl; |
|
412 const TUint ul128=128; |
|
413 switch (iNl&3) |
|
414 { |
|
415 case 0: |
|
416 iData[iNl>>2] = ul128; |
|
417 break; |
|
418 case 1: |
|
419 iData[iNl>>2] += ul128<<8; |
|
420 break; |
|
421 case 2: |
|
422 iData[iNl>>2] += ul128<<16; |
|
423 break; |
|
424 case 3: |
|
425 iData[iNl>>2] += ul128<<24; |
|
426 break; |
|
427 default: |
|
428 break; |
|
429 }; |
|
430 if (iNl>=56) |
|
431 { |
|
432 if (iNl<60) |
|
433 iData[15]=0; |
|
434 Block(); |
|
435 Mem::FillZ(iData,14*sizeof(TUint)); |
|
436 } |
|
437 else |
|
438 { |
|
439 const TUint offset=(iNl+4)>>2; |
|
440 Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint)); |
|
441 } |
|
442 |
|
443 iData[14]=iNh<<3;//number in bits |
|
444 // this will fail if the total input length is longer than 2^32 in bits |
|
445 //(2^31 in bytes) which is roughly half a gig. |
|
446 iData[15]=0; |
|
447 |
|
448 Block(); |
|
449 // |
|
450 // Generate hash value into iHash |
|
451 // |
|
452 TUint tmp=iA; |
|
453 iHash[0]=(TUint8)(tmp & 255); |
|
454 iHash[1]=(TUint8)((tmp >>= 8) & 255); |
|
455 iHash[2]=(TUint8)((tmp >>= 8) & 255); |
|
456 iHash[3]=(TUint8)((tmp >>= 8) & 255); |
|
457 |
|
458 tmp=iB; |
|
459 iHash[4]=(TUint8)(tmp & 255); |
|
460 iHash[5]=(TUint8)((tmp >>= 8) & 255); |
|
461 iHash[6]=(TUint8)((tmp >>= 8) & 255); |
|
462 iHash[7]=(TUint8)((tmp >>= 8) & 255); |
|
463 |
|
464 tmp=iC; |
|
465 iHash[8]=(TUint8)(tmp & 255); |
|
466 iHash[9]=(TUint8)((tmp >>= 8) & 255); |
|
467 iHash[10]=(TUint8)((tmp >>= 8) & 255); |
|
468 iHash[11]=(TUint8)((tmp >>= 8) & 255); |
|
469 |
|
470 tmp=iD; |
|
471 iHash[12]=(TUint8)(tmp & 255); |
|
472 iHash[13]=(TUint8)((tmp >>= 8) & 255); |
|
473 iHash[14]=(TUint8)((tmp >>= 8) & 255); |
|
474 iHash[15]=(TUint8)((tmp >>= 8) & 255); |
|
475 } |
|
476 |
|
477 void CMD4::RestoreState() |
|
478 { |
|
479 iA = iACopy; |
|
480 iB = iBCopy; |
|
481 iC = iCCopy; |
|
482 iD = iDCopy; |
|
483 iNl = iNlCopy; |
|
484 iNh = iNhCopy; |
|
485 Mem::Copy(&iData[0], &iDataCopy[0], MD4_LBLOCK*sizeof(TUint)); |
|
486 } |
|
487 |
|
488 void CMD4::StoreState() |
|
489 { |
|
490 iACopy = iA; |
|
491 iBCopy = iB; |
|
492 iCCopy = iC; |
|
493 iDCopy = iD; |
|
494 iNlCopy = iNl; |
|
495 iNhCopy = iNh; |
|
496 Mem::Copy(&iDataCopy[0], &iData[0], MD4_LBLOCK*sizeof(TUint)); |
|
497 } |