File: | sal/rtl/source/digest.cxx |
Location: | line 2064, column 48 |
Description: | Assigned value is garbage or undefined |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /************************************************************************* | |||
3 | * | |||
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||
5 | * | |||
6 | * Copyright 2000, 2010 Oracle and/or its affiliates. | |||
7 | * | |||
8 | * OpenOffice.org - a multi-platform office productivity suite | |||
9 | * | |||
10 | * This file is part of OpenOffice.org. | |||
11 | * | |||
12 | * OpenOffice.org is free software: you can redistribute it and/or modify | |||
13 | * it under the terms of the GNU Lesser General Public License version 3 | |||
14 | * only, as published by the Free Software Foundation. | |||
15 | * | |||
16 | * OpenOffice.org is distributed in the hope that it will be useful, | |||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
19 | * GNU Lesser General Public License version 3 for more details | |||
20 | * (a copy is included in the LICENSE file that accompanied this code). | |||
21 | * | |||
22 | * You should have received a copy of the GNU Lesser General Public License | |||
23 | * version 3 along with OpenOffice.org. If not, see | |||
24 | * <http://www.openoffice.org/license.html> | |||
25 | * for a copy of the LGPLv3 License. | |||
26 | * | |||
27 | ************************************************************************/ | |||
28 | ||||
29 | #include <string.h> | |||
30 | ||||
31 | #include <sal/types.h> | |||
32 | #include <sal/macros.h> | |||
33 | #include <osl/endian.h> | |||
34 | #include <rtl/alloc.h> | |||
35 | #include <rtl/memory.h> | |||
36 | #include <rtl/digest.h> | |||
37 | ||||
38 | /*======================================================================== | |||
39 | * | |||
40 | * rtlDigest internals. | |||
41 | * | |||
42 | *======================================================================*/ | |||
43 | #define RTL_DIGEST_CREATE(T)((T*)(rtl_allocateZeroMemory(sizeof(T)))) ((T*)(rtl_allocateZeroMemory(sizeof(T)))) | |||
44 | ||||
45 | #define RTL_DIGEST_ROTL(a,n)(((a) << (n)) | ((a) >> (32 - (n)))) (((a) << (n)) | ((a) >> (32 - (n)))) | |||
46 | ||||
47 | #define RTL_DIGEST_HTONL(l,c)(*((c)++) = (sal_uInt8)(((l) >> 24L) & 0xff), *((c) ++) = (sal_uInt8)(((l) >> 16L) & 0xff), *((c)++) = ( sal_uInt8)(((l) >> 8L) & 0xff), *((c)++) = (sal_uInt8 )(((l) ) & 0xff)) \ | |||
48 | (*((c)++) = (sal_uInt8)(((l) >> 24L) & 0xff), \ | |||
49 | *((c)++) = (sal_uInt8)(((l) >> 16L) & 0xff), \ | |||
50 | *((c)++) = (sal_uInt8)(((l) >> 8L) & 0xff), \ | |||
51 | *((c)++) = (sal_uInt8)(((l) ) & 0xff)) | |||
52 | ||||
53 | #define RTL_DIGEST_LTOC(l,c)(*((c)++) = (sal_uInt8)(((l) ) & 0xff), *((c)++) = (sal_uInt8 )(((l) >> 8L) & 0xff), *((c)++) = (sal_uInt8)(((l) >> 16L) & 0xff), *((c)++) = (sal_uInt8)(((l) >> 24L) & 0xff)) \ | |||
54 | (*((c)++) = (sal_uInt8)(((l) ) & 0xff), \ | |||
55 | *((c)++) = (sal_uInt8)(((l) >> 8L) & 0xff), \ | |||
56 | *((c)++) = (sal_uInt8)(((l) >> 16L) & 0xff), \ | |||
57 | *((c)++) = (sal_uInt8)(((l) >> 24L) & 0xff)) | |||
58 | ||||
59 | typedef rtlDigestError (SAL_CALL Digest_init_t) ( | |||
60 | void *ctx, const sal_uInt8 *Data, sal_uInt32 DatLen); | |||
61 | ||||
62 | typedef void (SAL_CALL Digest_delete_t) (void *ctx); | |||
63 | ||||
64 | typedef rtlDigestError (SAL_CALL Digest_update_t) ( | |||
65 | void *ctx, const void *Data, sal_uInt32 DatLen); | |||
66 | ||||
67 | typedef rtlDigestError (SAL_CALL Digest_get_t) ( | |||
68 | void *ctx, sal_uInt8 *Buffer, sal_uInt32 BufLen); | |||
69 | ||||
70 | struct Digest_Impl | |||
71 | { | |||
72 | rtlDigestAlgorithm m_algorithm; | |||
73 | sal_uInt32 m_length; | |||
74 | ||||
75 | Digest_init_t *m_init; | |||
76 | Digest_delete_t *m_delete; | |||
77 | Digest_update_t *m_update; | |||
78 | Digest_get_t *m_get; | |||
79 | }; | |||
80 | ||||
81 | /* | |||
82 | * __rtl_digest_swapLong. | |||
83 | */ | |||
84 | static void __rtl_digest_swapLong (sal_uInt32 *pData, sal_uInt32 nDatLen) | |||
85 | { | |||
86 | sal_uInt32 *X; | |||
87 | int i, n; | |||
88 | ||||
89 | X = pData; | |||
90 | n = nDatLen; | |||
91 | ||||
92 | for (i = 0; i < n; i++) | |||
93 | X[i] = OSL_SWAPDWORD(X[i])((sal_uInt32)((((sal_uInt16)((((sal_uInt8)(((sal_uInt16)(((sal_uInt16 )(((sal_uInt32)(X[i]) >> 16) & 0xFFFF))) >> 8 ) & 0xFF))) & 0xFF) | (((sal_uInt16)(((sal_uInt8)((sal_uInt16 )(((sal_uInt16)(((sal_uInt32)(X[i]) >> 16) & 0xFFFF ))) & 0xFF))) & 0xFF) << 8))) & 0xFFFF) | ( ((sal_uInt32)(((sal_uInt16)((((sal_uInt8)(((sal_uInt16)(((sal_uInt16 )((sal_uInt32)(X[i]) & 0xFFFF))) >> 8) & 0xFF)) ) & 0xFF) | (((sal_uInt16)(((sal_uInt8)((sal_uInt16)(((sal_uInt16 )((sal_uInt32)(X[i]) & 0xFFFF))) & 0xFF))) & 0xFF ) << 8))) & 0xFFFF) << 16)); | |||
94 | } | |||
95 | ||||
96 | /*======================================================================== | |||
97 | * | |||
98 | * rtlDigest implementation. | |||
99 | * | |||
100 | *======================================================================*/ | |||
101 | /* | |||
102 | * rtl_digest_create. | |||
103 | */ | |||
104 | rtlDigest SAL_CALL rtl_digest_create (rtlDigestAlgorithm Algorithm) | |||
105 | SAL_THROW_EXTERN_C()throw () | |||
106 | { | |||
107 | rtlDigest Digest = (rtlDigest)NULL__null; | |||
108 | switch (Algorithm) | |||
109 | { | |||
110 | case rtl_Digest_AlgorithmMD2: | |||
111 | Digest = rtl_digest_createMD2(); | |||
112 | break; | |||
113 | ||||
114 | case rtl_Digest_AlgorithmMD5: | |||
115 | Digest = rtl_digest_createMD5(); | |||
116 | break; | |||
117 | ||||
118 | case rtl_Digest_AlgorithmSHA: | |||
119 | Digest = rtl_digest_createSHA(); | |||
120 | break; | |||
121 | ||||
122 | case rtl_Digest_AlgorithmSHA1: | |||
123 | Digest = rtl_digest_createSHA1(); | |||
124 | break; | |||
125 | ||||
126 | case rtl_Digest_AlgorithmHMAC_MD5: | |||
127 | Digest = rtl_digest_createHMAC_MD5(); | |||
128 | break; | |||
129 | ||||
130 | case rtl_Digest_AlgorithmHMAC_SHA1: | |||
131 | Digest = rtl_digest_createHMAC_SHA1(); | |||
132 | break; | |||
133 | ||||
134 | default: /* rtl_Digest_AlgorithmInvalid */ | |||
135 | break; | |||
136 | } | |||
137 | return Digest; | |||
138 | } | |||
139 | ||||
140 | /* | |||
141 | * rtl_digest_queryAlgorithm. | |||
142 | */ | |||
143 | rtlDigestAlgorithm SAL_CALL rtl_digest_queryAlgorithm (rtlDigest Digest) | |||
144 | SAL_THROW_EXTERN_C()throw () | |||
145 | { | |||
146 | Digest_Impl *pImpl = (Digest_Impl *)Digest; | |||
147 | if (pImpl) | |||
148 | return pImpl->m_algorithm; | |||
149 | else | |||
150 | return rtl_Digest_AlgorithmInvalid; | |||
151 | } | |||
152 | ||||
153 | /* | |||
154 | * rtl_digest_queryLength. | |||
155 | */ | |||
156 | sal_uInt32 SAL_CALL rtl_digest_queryLength (rtlDigest Digest) | |||
157 | SAL_THROW_EXTERN_C()throw () | |||
158 | { | |||
159 | Digest_Impl *pImpl = (Digest_Impl *)Digest; | |||
160 | if (pImpl) | |||
161 | return pImpl->m_length; | |||
162 | else | |||
163 | return 0; | |||
164 | } | |||
165 | ||||
166 | /* | |||
167 | * rtl_digest_init. | |||
168 | */ | |||
169 | rtlDigestError SAL_CALL rtl_digest_init ( | |||
170 | rtlDigest Digest, const sal_uInt8 *pData, sal_uInt32 nDatLen) | |||
171 | SAL_THROW_EXTERN_C()throw () | |||
172 | { | |||
173 | Digest_Impl *pImpl = (Digest_Impl *)Digest; | |||
174 | if (pImpl) | |||
175 | { | |||
176 | if (pImpl->m_init) | |||
177 | return pImpl->m_init (Digest, pData, nDatLen); | |||
178 | else | |||
179 | return rtl_Digest_E_None; | |||
180 | } | |||
181 | return rtl_Digest_E_Argument; | |||
182 | } | |||
183 | ||||
184 | /* | |||
185 | * rtl_digest_update. | |||
186 | */ | |||
187 | rtlDigestError SAL_CALL rtl_digest_update ( | |||
188 | rtlDigest Digest, const void *pData, sal_uInt32 nDatLen) | |||
189 | SAL_THROW_EXTERN_C()throw () | |||
190 | { | |||
191 | Digest_Impl *pImpl = (Digest_Impl *)Digest; | |||
192 | if (pImpl && pImpl->m_update) | |||
193 | return pImpl->m_update (Digest, pData, nDatLen); | |||
194 | else | |||
195 | return rtl_Digest_E_Argument; | |||
196 | } | |||
197 | ||||
198 | /* | |||
199 | * rtl_digest_get. | |||
200 | */ | |||
201 | rtlDigestError SAL_CALL rtl_digest_get ( | |||
202 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
203 | SAL_THROW_EXTERN_C()throw () | |||
204 | { | |||
205 | Digest_Impl *pImpl = (Digest_Impl *)Digest; | |||
206 | if (pImpl && pImpl->m_get) | |||
207 | return pImpl->m_get (Digest, pBuffer, nBufLen); | |||
208 | else | |||
209 | return rtl_Digest_E_Argument; | |||
210 | } | |||
211 | ||||
212 | /* | |||
213 | * rtl_digest_destroy. | |||
214 | */ | |||
215 | void SAL_CALL rtl_digest_destroy (rtlDigest Digest) SAL_THROW_EXTERN_C()throw () | |||
216 | { | |||
217 | Digest_Impl *pImpl = (Digest_Impl *)Digest; | |||
218 | if (pImpl && pImpl->m_delete) | |||
219 | pImpl->m_delete (Digest); | |||
220 | } | |||
221 | ||||
222 | /*======================================================================== | |||
223 | * | |||
224 | * rtl_digest_MD2 internals. | |||
225 | * | |||
226 | *======================================================================*/ | |||
227 | #define DIGEST_CBLOCK_MD216 16 | |||
228 | #define DIGEST_LBLOCK_MD216 16 | |||
229 | ||||
230 | struct DigestContextMD2 | |||
231 | { | |||
232 | sal_uInt32 m_nDatLen; | |||
233 | sal_uInt8 m_pData[DIGEST_CBLOCK_MD216]; | |||
234 | sal_uInt32 m_state[DIGEST_LBLOCK_MD216]; | |||
235 | sal_uInt32 m_chksum[DIGEST_LBLOCK_MD216]; | |||
236 | }; | |||
237 | ||||
238 | struct DigestMD2_Impl | |||
239 | { | |||
240 | Digest_Impl m_digest; | |||
241 | DigestContextMD2 m_context; | |||
242 | }; | |||
243 | ||||
244 | static void __rtl_digest_initMD2 (DigestContextMD2 *ctx); | |||
245 | static void __rtl_digest_updateMD2 (DigestContextMD2 *ctx); | |||
246 | static void __rtl_digest_endMD2 (DigestContextMD2 *ctx); | |||
247 | ||||
248 | static const sal_uInt32 S[256] = | |||
249 | { | |||
250 | 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, | |||
251 | 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, | |||
252 | 0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C, | |||
253 | 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA, | |||
254 | 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16, | |||
255 | 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12, | |||
256 | 0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49, | |||
257 | 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A, | |||
258 | 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F, | |||
259 | 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21, | |||
260 | 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27, | |||
261 | 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03, | |||
262 | 0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1, | |||
263 | 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6, | |||
264 | 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6, | |||
265 | 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1, | |||
266 | 0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20, | |||
267 | 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02, | |||
268 | 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6, | |||
269 | 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F, | |||
270 | 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A, | |||
271 | 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26, | |||
272 | 0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09, | |||
273 | 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52, | |||
274 | 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA, | |||
275 | 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A, | |||
276 | 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, | |||
277 | 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39, | |||
278 | 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4, | |||
279 | 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A, | |||
280 | 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, | |||
281 | 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14, | |||
282 | }; | |||
283 | ||||
284 | /* | |||
285 | * __rtl_digest_MD2. | |||
286 | */ | |||
287 | static const Digest_Impl __rtl_digest_MD2 = | |||
288 | { | |||
289 | rtl_Digest_AlgorithmMD2, | |||
290 | RTL_DIGEST_LENGTH_MD216, | |||
291 | ||||
292 | NULL__null, | |||
293 | rtl_digest_destroyMD2, | |||
294 | rtl_digest_updateMD2, | |||
295 | rtl_digest_getMD2 | |||
296 | }; | |||
297 | ||||
298 | /* | |||
299 | * __rtl_digest_initMD2. | |||
300 | */ | |||
301 | static void __rtl_digest_initMD2 (DigestContextMD2 *ctx) | |||
302 | { | |||
303 | memset (ctx, 0, sizeof (DigestContextMD2)); | |||
304 | } | |||
305 | ||||
306 | /* | |||
307 | * __rtl_digest_updateMD2. | |||
308 | */ | |||
309 | static void __rtl_digest_updateMD2 (DigestContextMD2 *ctx) | |||
310 | { | |||
311 | sal_uInt8 *X; | |||
312 | sal_uInt32 *sp1, *sp2; | |||
313 | sal_uInt32 i, k, t; | |||
314 | ||||
315 | sal_uInt32 state[48]; | |||
316 | ||||
317 | X = ctx->m_pData; | |||
318 | sp1 = ctx->m_state; | |||
319 | sp2 = ctx->m_chksum; | |||
320 | ||||
321 | k = sp2[DIGEST_LBLOCK_MD216 - 1]; | |||
322 | for (i = 0; i < 16; i++) | |||
323 | { | |||
324 | state[i + 0] = sp1[i]; | |||
325 | state[i + 16] = t = X[i]; | |||
326 | state[i + 32] = t ^ sp1[i]; | |||
327 | k = sp2[i] ^= S[t^k]; | |||
328 | } | |||
329 | ||||
330 | t = 0; | |||
331 | for (i = 0; i < 18; i++) | |||
332 | { | |||
333 | for (k = 0; k < 48; k += 8) | |||
334 | { | |||
335 | t = state[k + 0] ^= S[t]; | |||
336 | t = state[k + 1] ^= S[t]; | |||
337 | t = state[k + 2] ^= S[t]; | |||
338 | t = state[k + 3] ^= S[t]; | |||
339 | t = state[k + 4] ^= S[t]; | |||
340 | t = state[k + 5] ^= S[t]; | |||
341 | t = state[k + 6] ^= S[t]; | |||
342 | t = state[k + 7] ^= S[t]; | |||
343 | } | |||
344 | t = ((t + i) & 0xff); | |||
345 | } | |||
346 | ||||
347 | memcpy (sp1, state, 16 * sizeof(sal_uInt32)); | |||
348 | memset (state, 0, 48 * sizeof(sal_uInt32)); | |||
349 | } | |||
350 | ||||
351 | /* | |||
352 | * __rtl_digest_endMD2. | |||
353 | */ | |||
354 | static void __rtl_digest_endMD2 (DigestContextMD2 *ctx) | |||
355 | { | |||
356 | sal_uInt8 *X; | |||
357 | sal_uInt32 *C; | |||
358 | sal_uInt32 i, n; | |||
359 | ||||
360 | X = ctx->m_pData; | |||
361 | C = ctx->m_chksum; | |||
362 | n = DIGEST_CBLOCK_MD216 - ctx->m_nDatLen; | |||
363 | ||||
364 | for (i = ctx->m_nDatLen; i < DIGEST_CBLOCK_MD216; i++) | |||
365 | X[i] = (sal_uInt8)(n & 0xff); | |||
366 | __rtl_digest_updateMD2 (ctx); | |||
367 | ||||
368 | for (i = 0; i < DIGEST_CBLOCK_MD216; i++) | |||
369 | X[i] = (sal_uInt8)(C[i] & 0xff); | |||
370 | __rtl_digest_updateMD2 (ctx); | |||
371 | } | |||
372 | ||||
373 | /*======================================================================== | |||
374 | * | |||
375 | * rtl_digest_MD2 implementation. | |||
376 | * | |||
377 | *======================================================================*/ | |||
378 | /* | |||
379 | * rtl_digest_MD2. | |||
380 | */ | |||
381 | rtlDigestError SAL_CALL rtl_digest_MD2 ( | |||
382 | const void *pData, sal_uInt32 nDatLen, | |||
383 | sal_uInt8 *pBuffer, sal_uInt32 nBufLen) SAL_THROW_EXTERN_C()throw () | |||
384 | { | |||
385 | DigestMD2_Impl digest; | |||
386 | rtlDigestError result; | |||
387 | ||||
388 | digest.m_digest = __rtl_digest_MD2; | |||
389 | __rtl_digest_initMD2 (&(digest.m_context)); | |||
390 | ||||
391 | result = rtl_digest_updateMD2 (&digest, pData, nDatLen); | |||
392 | if (result == rtl_Digest_E_None) | |||
393 | result = rtl_digest_getMD2 (&digest, pBuffer, nBufLen); | |||
394 | ||||
395 | memset (&digest, 0, sizeof (digest)); | |||
396 | return (result); | |||
397 | } | |||
398 | ||||
399 | /* | |||
400 | * rtl_digest_createMD2. | |||
401 | */ | |||
402 | rtlDigest SAL_CALL rtl_digest_createMD2() SAL_THROW_EXTERN_C()throw () | |||
403 | { | |||
404 | DigestMD2_Impl *pImpl = (DigestMD2_Impl*)NULL__null; | |||
405 | pImpl = RTL_DIGEST_CREATE(DigestMD2_Impl)((DigestMD2_Impl*)(rtl_allocateZeroMemory(sizeof(DigestMD2_Impl )))); | |||
406 | if (pImpl) | |||
407 | { | |||
408 | pImpl->m_digest = __rtl_digest_MD2; | |||
409 | __rtl_digest_initMD2 (&(pImpl->m_context)); | |||
410 | } | |||
411 | return ((rtlDigest)pImpl); | |||
412 | } | |||
413 | ||||
414 | /* | |||
415 | * rtl_digest_updateMD2. | |||
416 | */ | |||
417 | rtlDigestError SAL_CALL rtl_digest_updateMD2 ( | |||
418 | rtlDigest Digest, const void *pData, sal_uInt32 nDatLen) | |||
419 | SAL_THROW_EXTERN_C()throw () | |||
420 | { | |||
421 | DigestMD2_Impl *pImpl = (DigestMD2_Impl *)Digest; | |||
422 | const sal_uInt8 *d = (const sal_uInt8 *)pData; | |||
423 | ||||
424 | DigestContextMD2 *ctx; | |||
425 | ||||
426 | if ((pImpl == NULL__null) || (pData == NULL__null)) | |||
427 | return rtl_Digest_E_Argument; | |||
428 | ||||
429 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD2)) | |||
430 | return rtl_Digest_E_Algorithm; | |||
431 | ||||
432 | if (nDatLen == 0) | |||
433 | return rtl_Digest_E_None; | |||
434 | ||||
435 | ctx = &(pImpl->m_context); | |||
436 | ||||
437 | if (ctx->m_nDatLen) | |||
438 | { | |||
439 | sal_uInt8 *p = ctx->m_pData + ctx->m_nDatLen; | |||
440 | sal_uInt32 n = DIGEST_CBLOCK_MD216 - ctx->m_nDatLen; | |||
441 | ||||
442 | if (nDatLen < n) | |||
443 | { | |||
444 | memcpy (p, d, nDatLen); | |||
445 | ctx->m_nDatLen += nDatLen; | |||
446 | ||||
447 | return rtl_Digest_E_None; | |||
448 | } | |||
449 | ||||
450 | memcpy (p, d, n); | |||
451 | d += n; | |||
452 | nDatLen -= n; | |||
453 | ||||
454 | __rtl_digest_updateMD2 (ctx); | |||
455 | ctx->m_nDatLen = 0; | |||
456 | } | |||
457 | ||||
458 | while (nDatLen >= DIGEST_CBLOCK_MD216) | |||
459 | { | |||
460 | memcpy (ctx->m_pData, d, DIGEST_CBLOCK_MD216); | |||
461 | d += DIGEST_CBLOCK_MD216; | |||
462 | nDatLen -= DIGEST_CBLOCK_MD216; | |||
463 | ||||
464 | __rtl_digest_updateMD2 (ctx); | |||
465 | } | |||
466 | ||||
467 | memcpy (ctx->m_pData, d, nDatLen); | |||
468 | ctx->m_nDatLen = nDatLen; | |||
469 | ||||
470 | return rtl_Digest_E_None; | |||
471 | } | |||
472 | ||||
473 | /* | |||
474 | * rtl_digest_getMD2. | |||
475 | */ | |||
476 | rtlDigestError SAL_CALL rtl_digest_getMD2 ( | |||
477 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
478 | SAL_THROW_EXTERN_C()throw () | |||
479 | { | |||
480 | DigestMD2_Impl *pImpl = (DigestMD2_Impl *)Digest; | |||
481 | sal_uInt32 i; | |||
482 | ||||
483 | DigestContextMD2 *ctx; | |||
484 | ||||
485 | if ((pImpl == NULL__null) || (pBuffer == NULL__null)) | |||
486 | return rtl_Digest_E_Argument; | |||
487 | ||||
488 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD2)) | |||
489 | return rtl_Digest_E_Algorithm; | |||
490 | ||||
491 | if (!(pImpl->m_digest.m_length <= nBufLen)) | |||
492 | return rtl_Digest_E_BufferSize; | |||
493 | ||||
494 | ctx = &(pImpl->m_context); | |||
495 | ||||
496 | __rtl_digest_endMD2 (ctx); | |||
497 | for (i = 0; i < DIGEST_CBLOCK_MD216; i++) | |||
498 | pBuffer[i] = (sal_uInt8)(ctx->m_state[i] & 0xff); | |||
499 | __rtl_digest_initMD2 (ctx); | |||
500 | ||||
501 | return rtl_Digest_E_None; | |||
502 | } | |||
503 | ||||
504 | /* | |||
505 | * rtl_digest_destroyMD2. | |||
506 | */ | |||
507 | void SAL_CALL rtl_digest_destroyMD2 (rtlDigest Digest) SAL_THROW_EXTERN_C()throw () | |||
508 | { | |||
509 | DigestMD2_Impl *pImpl = (DigestMD2_Impl *)Digest; | |||
510 | if (pImpl) | |||
511 | { | |||
512 | if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD2) | |||
513 | rtl_freeZeroMemory (pImpl, sizeof (DigestMD2_Impl)); | |||
514 | else | |||
515 | rtl_freeMemory (pImpl); | |||
516 | } | |||
517 | } | |||
518 | ||||
519 | /*======================================================================== | |||
520 | * | |||
521 | * rtl_digest_MD5 internals. | |||
522 | * | |||
523 | *======================================================================*/ | |||
524 | #define DIGEST_CBLOCK_MD564 64 | |||
525 | #define DIGEST_LBLOCK_MD516 16 | |||
526 | ||||
527 | struct DigestContextMD5 | |||
528 | { | |||
529 | sal_uInt32 m_nDatLen; | |||
530 | sal_uInt32 m_pData[DIGEST_LBLOCK_MD516]; | |||
531 | sal_uInt32 m_nA, m_nB, m_nC, m_nD; | |||
532 | sal_uInt32 m_nL, m_nH; | |||
533 | }; | |||
534 | ||||
535 | struct DigestMD5_Impl | |||
536 | { | |||
537 | Digest_Impl m_digest; | |||
538 | DigestContextMD5 m_context; | |||
539 | }; | |||
540 | ||||
541 | static void __rtl_digest_initMD5 (DigestContextMD5 *ctx); | |||
542 | static void __rtl_digest_updateMD5 (DigestContextMD5 *ctx); | |||
543 | static void __rtl_digest_endMD5 (DigestContextMD5 *ctx); | |||
544 | ||||
545 | #define F(x,y,z)((((y) ^ (z)) & (x)) ^ (z)) ((((y) ^ (z)) & (x)) ^ (z)) | |||
546 | #define G(x,y,z)((((x) ^ (y)) & (z)) ^ (y)) ((((x) ^ (y)) & (z)) ^ (y)) | |||
547 | #define H(x,y,z)((x) ^ (y) ^ (z)) ((x) ^ (y) ^ (z)) | |||
548 | #define I(x,y,z)(((x) | (~(z))) ^ (y)) (((x) | (~(z))) ^ (y)) | |||
549 | ||||
550 | #define R0(a,b,c,d,k,s,t){ a += ((k) + (t) + (((((c)) ^ ((d))) & ((b))) ^ ((d)))); a = (((a) << (s)) | ((a) >> (32 - (s)))); a += b ; } { \ | |||
551 | a += ((k) + (t) + F((b), (c), (d))(((((c)) ^ ((d))) & ((b))) ^ ((d)))); \ | |||
552 | a = RTL_DIGEST_ROTL(a, s)(((a) << (s)) | ((a) >> (32 - (s)))); \ | |||
553 | a += b; } | |||
554 | ||||
555 | #define R1(a,b,c,d,k,s,t){ a += ((k) + (t) + (((((b)) ^ ((c))) & ((d))) ^ ((c)))); a = (((a) << (s)) | ((a) >> (32 - (s)))); a += b ; } { \ | |||
556 | a += ((k) + (t) + G((b), (c), (d))(((((b)) ^ ((c))) & ((d))) ^ ((c)))); \ | |||
557 | a = RTL_DIGEST_ROTL(a, s)(((a) << (s)) | ((a) >> (32 - (s)))); \ | |||
558 | a += b; } | |||
559 | ||||
560 | #define R2(a,b,c,d,k,s,t){ a += ((k) + (t) + (((b)) ^ ((c)) ^ ((d)))); a = (((a) << (s)) | ((a) >> (32 - (s)))); a += b; } { \ | |||
561 | a += ((k) + (t) + H((b), (c), (d))(((b)) ^ ((c)) ^ ((d)))); \ | |||
562 | a = RTL_DIGEST_ROTL(a, s)(((a) << (s)) | ((a) >> (32 - (s)))); \ | |||
563 | a += b; } | |||
564 | ||||
565 | #define R3(a,b,c,d,k,s,t){ a += ((k) + (t) + ((((b)) | (~((d)))) ^ ((c)))); a = (((a) << (s)) | ((a) >> (32 - (s)))); a += b; } { \ | |||
566 | a += ((k) + (t) + I((b), (c), (d))((((b)) | (~((d)))) ^ ((c)))); \ | |||
567 | a = RTL_DIGEST_ROTL(a, s)(((a) << (s)) | ((a) >> (32 - (s)))); \ | |||
568 | a += b; } | |||
569 | ||||
570 | /* | |||
571 | * __rtl_digest_MD5. | |||
572 | */ | |||
573 | static const Digest_Impl __rtl_digest_MD5 = | |||
574 | { | |||
575 | rtl_Digest_AlgorithmMD5, | |||
576 | RTL_DIGEST_LENGTH_MD516, | |||
577 | ||||
578 | NULL__null, | |||
579 | rtl_digest_destroyMD5, | |||
580 | rtl_digest_updateMD5, | |||
581 | rtl_digest_getMD5 | |||
582 | }; | |||
583 | ||||
584 | /* | |||
585 | * __rtl_digest_initMD5. | |||
586 | */ | |||
587 | static void __rtl_digest_initMD5 (DigestContextMD5 *ctx) | |||
588 | { | |||
589 | memset (ctx, 0, sizeof (DigestContextMD5)); | |||
590 | ||||
591 | ctx->m_nA = (sal_uInt32)0x67452301L; | |||
592 | ctx->m_nB = (sal_uInt32)0xefcdab89L; | |||
593 | ctx->m_nC = (sal_uInt32)0x98badcfeL; | |||
594 | ctx->m_nD = (sal_uInt32)0x10325476L; | |||
595 | } | |||
596 | ||||
597 | /* | |||
598 | * __rtl_digest_updateMD5. | |||
599 | */ | |||
600 | static void __rtl_digest_updateMD5 (DigestContextMD5 *ctx) | |||
601 | { | |||
602 | sal_uInt32 A, B, C, D; | |||
603 | sal_uInt32 *X; | |||
604 | ||||
605 | A = ctx->m_nA; | |||
606 | B = ctx->m_nB; | |||
607 | C = ctx->m_nC; | |||
608 | D = ctx->m_nD; | |||
609 | X = ctx->m_pData; | |||
610 | ||||
611 | R0 (A, B, C, D, X[ 0], 7, 0xd76aa478L){ A += ((X[ 0]) + (0xd76aa478L) + (((((C)) ^ ((D))) & ((B ))) ^ ((D)))); A = (((A) << (7)) | ((A) >> (32 - ( 7)))); A += B; }; | |||
612 | R0 (D, A, B, C, X[ 1], 12, 0xe8c7b756L){ D += ((X[ 1]) + (0xe8c7b756L) + (((((B)) ^ ((C))) & ((A ))) ^ ((C)))); D = (((D) << (12)) | ((D) >> (32 - (12)))); D += A; }; | |||
613 | R0 (C, D, A, B, X[ 2], 17, 0x242070dbL){ C += ((X[ 2]) + (0x242070dbL) + (((((A)) ^ ((B))) & ((D ))) ^ ((B)))); C = (((C) << (17)) | ((C) >> (32 - (17)))); C += D; }; | |||
614 | R0 (B, C, D, A, X[ 3], 22, 0xc1bdceeeL){ B += ((X[ 3]) + (0xc1bdceeeL) + (((((D)) ^ ((A))) & ((C ))) ^ ((A)))); B = (((B) << (22)) | ((B) >> (32 - (22)))); B += C; }; | |||
615 | R0 (A, B, C, D, X[ 4], 7, 0xf57c0fafL){ A += ((X[ 4]) + (0xf57c0fafL) + (((((C)) ^ ((D))) & ((B ))) ^ ((D)))); A = (((A) << (7)) | ((A) >> (32 - ( 7)))); A += B; }; | |||
616 | R0 (D, A, B, C, X[ 5], 12, 0x4787c62aL){ D += ((X[ 5]) + (0x4787c62aL) + (((((B)) ^ ((C))) & ((A ))) ^ ((C)))); D = (((D) << (12)) | ((D) >> (32 - (12)))); D += A; }; | |||
617 | R0 (C, D, A, B, X[ 6], 17, 0xa8304613L){ C += ((X[ 6]) + (0xa8304613L) + (((((A)) ^ ((B))) & ((D ))) ^ ((B)))); C = (((C) << (17)) | ((C) >> (32 - (17)))); C += D; }; | |||
618 | R0 (B, C, D, A, X[ 7], 22, 0xfd469501L){ B += ((X[ 7]) + (0xfd469501L) + (((((D)) ^ ((A))) & ((C ))) ^ ((A)))); B = (((B) << (22)) | ((B) >> (32 - (22)))); B += C; }; | |||
619 | R0 (A, B, C, D, X[ 8], 7, 0x698098d8L){ A += ((X[ 8]) + (0x698098d8L) + (((((C)) ^ ((D))) & ((B ))) ^ ((D)))); A = (((A) << (7)) | ((A) >> (32 - ( 7)))); A += B; }; | |||
620 | R0 (D, A, B, C, X[ 9], 12, 0x8b44f7afL){ D += ((X[ 9]) + (0x8b44f7afL) + (((((B)) ^ ((C))) & ((A ))) ^ ((C)))); D = (((D) << (12)) | ((D) >> (32 - (12)))); D += A; }; | |||
621 | R0 (C, D, A, B, X[10], 17, 0xffff5bb1L){ C += ((X[10]) + (0xffff5bb1L) + (((((A)) ^ ((B))) & ((D ))) ^ ((B)))); C = (((C) << (17)) | ((C) >> (32 - (17)))); C += D; }; | |||
622 | R0 (B, C, D, A, X[11], 22, 0x895cd7beL){ B += ((X[11]) + (0x895cd7beL) + (((((D)) ^ ((A))) & ((C ))) ^ ((A)))); B = (((B) << (22)) | ((B) >> (32 - (22)))); B += C; }; | |||
623 | R0 (A, B, C, D, X[12], 7, 0x6b901122L){ A += ((X[12]) + (0x6b901122L) + (((((C)) ^ ((D))) & ((B ))) ^ ((D)))); A = (((A) << (7)) | ((A) >> (32 - ( 7)))); A += B; }; | |||
624 | R0 (D, A, B, C, X[13], 12, 0xfd987193L){ D += ((X[13]) + (0xfd987193L) + (((((B)) ^ ((C))) & ((A ))) ^ ((C)))); D = (((D) << (12)) | ((D) >> (32 - (12)))); D += A; }; | |||
625 | R0 (C, D, A, B, X[14], 17, 0xa679438eL){ C += ((X[14]) + (0xa679438eL) + (((((A)) ^ ((B))) & ((D ))) ^ ((B)))); C = (((C) << (17)) | ((C) >> (32 - (17)))); C += D; }; | |||
626 | R0 (B, C, D, A, X[15], 22, 0x49b40821L){ B += ((X[15]) + (0x49b40821L) + (((((D)) ^ ((A))) & ((C ))) ^ ((A)))); B = (((B) << (22)) | ((B) >> (32 - (22)))); B += C; }; | |||
627 | ||||
628 | R1 (A, B, C, D, X[ 1], 5, 0xf61e2562L){ A += ((X[ 1]) + (0xf61e2562L) + (((((B)) ^ ((C))) & ((D ))) ^ ((C)))); A = (((A) << (5)) | ((A) >> (32 - ( 5)))); A += B; }; | |||
629 | R1 (D, A, B, C, X[ 6], 9, 0xc040b340L){ D += ((X[ 6]) + (0xc040b340L) + (((((A)) ^ ((B))) & ((C ))) ^ ((B)))); D = (((D) << (9)) | ((D) >> (32 - ( 9)))); D += A; }; | |||
630 | R1 (C, D, A, B, X[11], 14, 0x265e5a51L){ C += ((X[11]) + (0x265e5a51L) + (((((D)) ^ ((A))) & ((B ))) ^ ((A)))); C = (((C) << (14)) | ((C) >> (32 - (14)))); C += D; }; | |||
631 | R1 (B, C, D, A, X[ 0], 20, 0xe9b6c7aaL){ B += ((X[ 0]) + (0xe9b6c7aaL) + (((((C)) ^ ((D))) & ((A ))) ^ ((D)))); B = (((B) << (20)) | ((B) >> (32 - (20)))); B += C; }; | |||
632 | R1 (A, B, C, D, X[ 5], 5, 0xd62f105dL){ A += ((X[ 5]) + (0xd62f105dL) + (((((B)) ^ ((C))) & ((D ))) ^ ((C)))); A = (((A) << (5)) | ((A) >> (32 - ( 5)))); A += B; }; | |||
633 | R1 (D, A, B, C, X[10], 9, 0x02441453L){ D += ((X[10]) + (0x02441453L) + (((((A)) ^ ((B))) & ((C ))) ^ ((B)))); D = (((D) << (9)) | ((D) >> (32 - ( 9)))); D += A; }; | |||
634 | R1 (C, D, A, B, X[15], 14, 0xd8a1e681L){ C += ((X[15]) + (0xd8a1e681L) + (((((D)) ^ ((A))) & ((B ))) ^ ((A)))); C = (((C) << (14)) | ((C) >> (32 - (14)))); C += D; }; | |||
635 | R1 (B, C, D, A, X[ 4], 20, 0xe7d3fbc8L){ B += ((X[ 4]) + (0xe7d3fbc8L) + (((((C)) ^ ((D))) & ((A ))) ^ ((D)))); B = (((B) << (20)) | ((B) >> (32 - (20)))); B += C; }; | |||
636 | R1 (A, B, C, D, X[ 9], 5, 0x21e1cde6L){ A += ((X[ 9]) + (0x21e1cde6L) + (((((B)) ^ ((C))) & ((D ))) ^ ((C)))); A = (((A) << (5)) | ((A) >> (32 - ( 5)))); A += B; }; | |||
637 | R1 (D, A, B, C, X[14], 9, 0xc33707d6L){ D += ((X[14]) + (0xc33707d6L) + (((((A)) ^ ((B))) & ((C ))) ^ ((B)))); D = (((D) << (9)) | ((D) >> (32 - ( 9)))); D += A; }; | |||
638 | R1 (C, D, A, B, X[ 3], 14, 0xf4d50d87L){ C += ((X[ 3]) + (0xf4d50d87L) + (((((D)) ^ ((A))) & ((B ))) ^ ((A)))); C = (((C) << (14)) | ((C) >> (32 - (14)))); C += D; }; | |||
639 | R1 (B, C, D, A, X[ 8], 20, 0x455a14edL){ B += ((X[ 8]) + (0x455a14edL) + (((((C)) ^ ((D))) & ((A ))) ^ ((D)))); B = (((B) << (20)) | ((B) >> (32 - (20)))); B += C; }; | |||
640 | R1 (A, B, C, D, X[13], 5, 0xa9e3e905L){ A += ((X[13]) + (0xa9e3e905L) + (((((B)) ^ ((C))) & ((D ))) ^ ((C)))); A = (((A) << (5)) | ((A) >> (32 - ( 5)))); A += B; }; | |||
641 | R1 (D, A, B, C, X[ 2], 9, 0xfcefa3f8L){ D += ((X[ 2]) + (0xfcefa3f8L) + (((((A)) ^ ((B))) & ((C ))) ^ ((B)))); D = (((D) << (9)) | ((D) >> (32 - ( 9)))); D += A; }; | |||
642 | R1 (C, D, A, B, X[ 7], 14, 0x676f02d9L){ C += ((X[ 7]) + (0x676f02d9L) + (((((D)) ^ ((A))) & ((B ))) ^ ((A)))); C = (((C) << (14)) | ((C) >> (32 - (14)))); C += D; }; | |||
643 | R1 (B, C, D, A, X[12], 20, 0x8d2a4c8aL){ B += ((X[12]) + (0x8d2a4c8aL) + (((((C)) ^ ((D))) & ((A ))) ^ ((D)))); B = (((B) << (20)) | ((B) >> (32 - (20)))); B += C; }; | |||
644 | ||||
645 | R2 (A, B, C, D, X[ 5], 4, 0xfffa3942L){ A += ((X[ 5]) + (0xfffa3942L) + (((B)) ^ ((C)) ^ ((D)))); A = (((A) << (4)) | ((A) >> (32 - (4)))); A += B; }; | |||
646 | R2 (D, A, B, C, X[ 8], 11, 0x8771f681L){ D += ((X[ 8]) + (0x8771f681L) + (((A)) ^ ((B)) ^ ((C)))); D = (((D) << (11)) | ((D) >> (32 - (11)))); D += A ; }; | |||
647 | R2 (C, D, A, B, X[11], 16, 0x6d9d6122L){ C += ((X[11]) + (0x6d9d6122L) + (((D)) ^ ((A)) ^ ((B)))); C = (((C) << (16)) | ((C) >> (32 - (16)))); C += D ; }; | |||
648 | R2 (B, C, D, A, X[14], 23, 0xfde5380cL){ B += ((X[14]) + (0xfde5380cL) + (((C)) ^ ((D)) ^ ((A)))); B = (((B) << (23)) | ((B) >> (32 - (23)))); B += C ; }; | |||
649 | R2 (A, B, C, D, X[ 1], 4, 0xa4beea44L){ A += ((X[ 1]) + (0xa4beea44L) + (((B)) ^ ((C)) ^ ((D)))); A = (((A) << (4)) | ((A) >> (32 - (4)))); A += B; }; | |||
650 | R2 (D, A, B, C, X[ 4], 11, 0x4bdecfa9L){ D += ((X[ 4]) + (0x4bdecfa9L) + (((A)) ^ ((B)) ^ ((C)))); D = (((D) << (11)) | ((D) >> (32 - (11)))); D += A ; }; | |||
651 | R2 (C, D, A, B, X[ 7], 16, 0xf6bb4b60L){ C += ((X[ 7]) + (0xf6bb4b60L) + (((D)) ^ ((A)) ^ ((B)))); C = (((C) << (16)) | ((C) >> (32 - (16)))); C += D ; }; | |||
652 | R2 (B, C, D, A, X[10], 23, 0xbebfbc70L){ B += ((X[10]) + (0xbebfbc70L) + (((C)) ^ ((D)) ^ ((A)))); B = (((B) << (23)) | ((B) >> (32 - (23)))); B += C ; }; | |||
653 | R2 (A, B, C, D, X[13], 4, 0x289b7ec6L){ A += ((X[13]) + (0x289b7ec6L) + (((B)) ^ ((C)) ^ ((D)))); A = (((A) << (4)) | ((A) >> (32 - (4)))); A += B; }; | |||
654 | R2 (D, A, B, C, X[ 0], 11, 0xeaa127faL){ D += ((X[ 0]) + (0xeaa127faL) + (((A)) ^ ((B)) ^ ((C)))); D = (((D) << (11)) | ((D) >> (32 - (11)))); D += A ; }; | |||
655 | R2 (C, D, A, B, X[ 3], 16, 0xd4ef3085L){ C += ((X[ 3]) + (0xd4ef3085L) + (((D)) ^ ((A)) ^ ((B)))); C = (((C) << (16)) | ((C) >> (32 - (16)))); C += D ; }; | |||
656 | R2 (B, C, D, A, X[ 6], 23, 0x04881d05L){ B += ((X[ 6]) + (0x04881d05L) + (((C)) ^ ((D)) ^ ((A)))); B = (((B) << (23)) | ((B) >> (32 - (23)))); B += C ; }; | |||
657 | R2 (A, B, C, D, X[ 9], 4, 0xd9d4d039L){ A += ((X[ 9]) + (0xd9d4d039L) + (((B)) ^ ((C)) ^ ((D)))); A = (((A) << (4)) | ((A) >> (32 - (4)))); A += B; }; | |||
658 | R2 (D, A, B, C, X[12], 11, 0xe6db99e5L){ D += ((X[12]) + (0xe6db99e5L) + (((A)) ^ ((B)) ^ ((C)))); D = (((D) << (11)) | ((D) >> (32 - (11)))); D += A ; }; | |||
659 | R2 (C, D, A, B, X[15], 16, 0x1fa27cf8L){ C += ((X[15]) + (0x1fa27cf8L) + (((D)) ^ ((A)) ^ ((B)))); C = (((C) << (16)) | ((C) >> (32 - (16)))); C += D ; }; | |||
660 | R2 (B, C, D, A, X[ 2], 23, 0xc4ac5665L){ B += ((X[ 2]) + (0xc4ac5665L) + (((C)) ^ ((D)) ^ ((A)))); B = (((B) << (23)) | ((B) >> (32 - (23)))); B += C ; }; | |||
661 | ||||
662 | R3 (A, B, C, D, X[ 0], 6, 0xf4292244L){ A += ((X[ 0]) + (0xf4292244L) + ((((B)) | (~((D)))) ^ ((C)) )); A = (((A) << (6)) | ((A) >> (32 - (6)))); A += B; }; | |||
663 | R3 (D, A, B, C, X[ 7], 10, 0x432aff97L){ D += ((X[ 7]) + (0x432aff97L) + ((((A)) | (~((C)))) ^ ((B)) )); D = (((D) << (10)) | ((D) >> (32 - (10)))); D += A; }; | |||
664 | R3 (C, D, A, B, X[14], 15, 0xab9423a7L){ C += ((X[14]) + (0xab9423a7L) + ((((D)) | (~((B)))) ^ ((A)) )); C = (((C) << (15)) | ((C) >> (32 - (15)))); C += D; }; | |||
665 | R3 (B, C, D, A, X[ 5], 21, 0xfc93a039L){ B += ((X[ 5]) + (0xfc93a039L) + ((((C)) | (~((A)))) ^ ((D)) )); B = (((B) << (21)) | ((B) >> (32 - (21)))); B += C; }; | |||
666 | R3 (A, B, C, D, X[12], 6, 0x655b59c3L){ A += ((X[12]) + (0x655b59c3L) + ((((B)) | (~((D)))) ^ ((C)) )); A = (((A) << (6)) | ((A) >> (32 - (6)))); A += B; }; | |||
667 | R3 (D, A, B, C, X[ 3], 10, 0x8f0ccc92L){ D += ((X[ 3]) + (0x8f0ccc92L) + ((((A)) | (~((C)))) ^ ((B)) )); D = (((D) << (10)) | ((D) >> (32 - (10)))); D += A; }; | |||
668 | R3 (C, D, A, B, X[10], 15, 0xffeff47dL){ C += ((X[10]) + (0xffeff47dL) + ((((D)) | (~((B)))) ^ ((A)) )); C = (((C) << (15)) | ((C) >> (32 - (15)))); C += D; }; | |||
669 | R3 (B, C, D, A, X[ 1], 21, 0x85845dd1L){ B += ((X[ 1]) + (0x85845dd1L) + ((((C)) | (~((A)))) ^ ((D)) )); B = (((B) << (21)) | ((B) >> (32 - (21)))); B += C; }; | |||
670 | R3 (A, B, C, D, X[ 8], 6, 0x6fa87e4fL){ A += ((X[ 8]) + (0x6fa87e4fL) + ((((B)) | (~((D)))) ^ ((C)) )); A = (((A) << (6)) | ((A) >> (32 - (6)))); A += B; }; | |||
671 | R3 (D, A, B, C, X[15], 10, 0xfe2ce6e0L){ D += ((X[15]) + (0xfe2ce6e0L) + ((((A)) | (~((C)))) ^ ((B)) )); D = (((D) << (10)) | ((D) >> (32 - (10)))); D += A; }; | |||
672 | R3 (C, D, A, B, X[ 6], 15, 0xa3014314L){ C += ((X[ 6]) + (0xa3014314L) + ((((D)) | (~((B)))) ^ ((A)) )); C = (((C) << (15)) | ((C) >> (32 - (15)))); C += D; }; | |||
673 | R3 (B, C, D, A, X[13], 21, 0x4e0811a1L){ B += ((X[13]) + (0x4e0811a1L) + ((((C)) | (~((A)))) ^ ((D)) )); B = (((B) << (21)) | ((B) >> (32 - (21)))); B += C; }; | |||
674 | R3 (A, B, C, D, X[ 4], 6, 0xf7537e82L){ A += ((X[ 4]) + (0xf7537e82L) + ((((B)) | (~((D)))) ^ ((C)) )); A = (((A) << (6)) | ((A) >> (32 - (6)))); A += B; }; | |||
675 | R3 (D, A, B, C, X[11], 10, 0xbd3af235L){ D += ((X[11]) + (0xbd3af235L) + ((((A)) | (~((C)))) ^ ((B)) )); D = (((D) << (10)) | ((D) >> (32 - (10)))); D += A; }; | |||
676 | R3 (C, D, A, B, X[ 2], 15, 0x2ad7d2bbL){ C += ((X[ 2]) + (0x2ad7d2bbL) + ((((D)) | (~((B)))) ^ ((A)) )); C = (((C) << (15)) | ((C) >> (32 - (15)))); C += D; }; | |||
677 | R3 (B, C, D, A, X[ 9], 21, 0xeb86d391L){ B += ((X[ 9]) + (0xeb86d391L) + ((((C)) | (~((A)))) ^ ((D)) )); B = (((B) << (21)) | ((B) >> (32 - (21)))); B += C; }; | |||
678 | ||||
679 | ctx->m_nA += A; | |||
680 | ctx->m_nB += B; | |||
681 | ctx->m_nC += C; | |||
682 | ctx->m_nD += D; | |||
683 | } | |||
684 | ||||
685 | /* | |||
686 | * __rtl_digest_endMD5. | |||
687 | */ | |||
688 | static void __rtl_digest_endMD5 (DigestContextMD5 *ctx) | |||
689 | { | |||
690 | static const sal_uInt8 end[4] = | |||
691 | { | |||
692 | 0x80, 0x00, 0x00, 0x00 | |||
693 | }; | |||
694 | const sal_uInt8 *p = end; | |||
695 | ||||
696 | sal_uInt32 *X; | |||
697 | int i; | |||
698 | ||||
699 | X = ctx->m_pData; | |||
700 | i = (ctx->m_nDatLen >> 2); | |||
701 | ||||
702 | #ifdef OSL_BIGENDIAN | |||
703 | __rtl_digest_swapLong (X, i + 1); | |||
704 | #endif /* OSL_BIGENDIAN */ | |||
705 | ||||
706 | switch (ctx->m_nDatLen & 0x03) | |||
707 | { | |||
708 | case 1: X[i] &= 0x000000ff; break; | |||
709 | case 2: X[i] &= 0x0000ffff; break; | |||
710 | case 3: X[i] &= 0x00ffffff; break; | |||
711 | } | |||
712 | ||||
713 | switch (ctx->m_nDatLen & 0x03) | |||
714 | { | |||
715 | case 0: X[i] = ((sal_uInt32)(*(p++))) << 0L; | |||
716 | case 1: X[i] |= ((sal_uInt32)(*(p++))) << 8L; | |||
717 | case 2: X[i] |= ((sal_uInt32)(*(p++))) << 16L; | |||
718 | case 3: X[i] |= ((sal_uInt32)(*p)) << 24L; | |||
719 | } | |||
720 | ||||
721 | i += 1; | |||
722 | ||||
723 | if (i >= (DIGEST_LBLOCK_MD516 - 2)) | |||
724 | { | |||
725 | for (; i < DIGEST_LBLOCK_MD516; i++) | |||
726 | X[i] = 0; | |||
727 | __rtl_digest_updateMD5 (ctx); | |||
728 | i = 0; | |||
729 | } | |||
730 | ||||
731 | for (; i < (DIGEST_LBLOCK_MD516 - 2); i++) | |||
732 | X[i] = 0; | |||
733 | ||||
734 | X[DIGEST_LBLOCK_MD516 - 2] = ctx->m_nL; | |||
735 | X[DIGEST_LBLOCK_MD516 - 1] = ctx->m_nH; | |||
736 | ||||
737 | __rtl_digest_updateMD5 (ctx); | |||
738 | } | |||
739 | ||||
740 | /*======================================================================== | |||
741 | * | |||
742 | * rtl_digest_MD5 implementation. | |||
743 | * | |||
744 | *======================================================================*/ | |||
745 | /* | |||
746 | * rtl_digest_MD5. | |||
747 | */ | |||
748 | rtlDigestError SAL_CALL rtl_digest_MD5 ( | |||
749 | const void *pData, sal_uInt32 nDatLen, | |||
750 | sal_uInt8 *pBuffer, sal_uInt32 nBufLen) SAL_THROW_EXTERN_C()throw () | |||
751 | { | |||
752 | DigestMD5_Impl digest; | |||
753 | rtlDigestError result; | |||
754 | ||||
755 | digest.m_digest = __rtl_digest_MD5; | |||
756 | __rtl_digest_initMD5 (&(digest.m_context)); | |||
757 | ||||
758 | result = rtl_digest_update (&digest, pData, nDatLen); | |||
759 | if (result == rtl_Digest_E_None) | |||
760 | result = rtl_digest_getMD5 (&digest, pBuffer, nBufLen); | |||
761 | ||||
762 | memset (&digest, 0, sizeof (digest)); | |||
763 | return (result); | |||
764 | } | |||
765 | ||||
766 | /* | |||
767 | * rtl_digest_createMD5. | |||
768 | */ | |||
769 | rtlDigest SAL_CALL rtl_digest_createMD5() SAL_THROW_EXTERN_C()throw () | |||
770 | { | |||
771 | DigestMD5_Impl *pImpl = (DigestMD5_Impl*)NULL__null; | |||
772 | pImpl = RTL_DIGEST_CREATE(DigestMD5_Impl)((DigestMD5_Impl*)(rtl_allocateZeroMemory(sizeof(DigestMD5_Impl )))); | |||
773 | if (pImpl) | |||
774 | { | |||
775 | pImpl->m_digest = __rtl_digest_MD5; | |||
776 | __rtl_digest_initMD5 (&(pImpl->m_context)); | |||
777 | } | |||
778 | return ((rtlDigest)pImpl); | |||
779 | } | |||
780 | ||||
781 | /* | |||
782 | * rtl_digest_updateMD5. | |||
783 | */ | |||
784 | rtlDigestError SAL_CALL rtl_digest_updateMD5 ( | |||
785 | rtlDigest Digest, const void *pData, sal_uInt32 nDatLen) | |||
786 | SAL_THROW_EXTERN_C()throw () | |||
787 | { | |||
788 | DigestMD5_Impl *pImpl = (DigestMD5_Impl *)Digest; | |||
789 | const sal_uInt8 *d = (const sal_uInt8 *)pData; | |||
790 | ||||
791 | DigestContextMD5 *ctx; | |||
792 | sal_uInt32 len; | |||
793 | ||||
794 | if ((pImpl == NULL__null) || (pData == NULL__null)) | |||
795 | return rtl_Digest_E_Argument; | |||
796 | ||||
797 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD5)) | |||
798 | return rtl_Digest_E_Algorithm; | |||
799 | ||||
800 | if (nDatLen == 0) | |||
801 | return rtl_Digest_E_None; | |||
802 | ||||
803 | ctx = &(pImpl->m_context); | |||
804 | ||||
805 | len = ctx->m_nL + (nDatLen << 3); | |||
806 | if (len < ctx->m_nL) ctx->m_nH += 1; | |||
807 | ctx->m_nH += (nDatLen >> 29); | |||
808 | ctx->m_nL = len; | |||
809 | ||||
810 | if (ctx->m_nDatLen) | |||
811 | { | |||
812 | sal_uInt8 *p = (sal_uInt8 *)(ctx->m_pData) + ctx->m_nDatLen; | |||
813 | sal_uInt32 n = DIGEST_CBLOCK_MD564 - ctx->m_nDatLen; | |||
814 | ||||
815 | if (nDatLen < n) | |||
816 | { | |||
817 | memcpy (p, d, nDatLen); | |||
818 | ctx->m_nDatLen += nDatLen; | |||
819 | ||||
820 | return rtl_Digest_E_None; | |||
821 | } | |||
822 | ||||
823 | memcpy (p, d, n); | |||
824 | d += n; | |||
825 | nDatLen -= n; | |||
826 | ||||
827 | #ifdef OSL_BIGENDIAN | |||
828 | __rtl_digest_swapLong (ctx->m_pData, DIGEST_LBLOCK_MD516); | |||
829 | #endif /* OSL_BIGENDIAN */ | |||
830 | ||||
831 | __rtl_digest_updateMD5 (ctx); | |||
832 | ctx->m_nDatLen = 0; | |||
833 | } | |||
834 | ||||
835 | while (nDatLen >= DIGEST_CBLOCK_MD564) | |||
836 | { | |||
837 | memcpy (ctx->m_pData, d, DIGEST_CBLOCK_MD564); | |||
838 | d += DIGEST_CBLOCK_MD564; | |||
839 | nDatLen -= DIGEST_CBLOCK_MD564; | |||
840 | ||||
841 | #ifdef OSL_BIGENDIAN | |||
842 | __rtl_digest_swapLong (ctx->m_pData, DIGEST_LBLOCK_MD516); | |||
843 | #endif /* OSL_BIGENDIAN */ | |||
844 | ||||
845 | __rtl_digest_updateMD5 (ctx); | |||
846 | } | |||
847 | ||||
848 | memcpy (ctx->m_pData, d, nDatLen); | |||
849 | ctx->m_nDatLen = nDatLen; | |||
850 | ||||
851 | return rtl_Digest_E_None; | |||
852 | } | |||
853 | ||||
854 | /* | |||
855 | * rtl_digest_getMD5. | |||
856 | */ | |||
857 | rtlDigestError SAL_CALL rtl_digest_getMD5 ( | |||
858 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
859 | SAL_THROW_EXTERN_C()throw () | |||
860 | { | |||
861 | DigestMD5_Impl *pImpl = (DigestMD5_Impl *)Digest; | |||
862 | sal_uInt8 *p = pBuffer; | |||
863 | ||||
864 | DigestContextMD5 *ctx; | |||
865 | ||||
866 | if ((pImpl == NULL__null) || (pBuffer == NULL__null)) | |||
867 | return rtl_Digest_E_Argument; | |||
868 | ||||
869 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD5)) | |||
870 | return rtl_Digest_E_Algorithm; | |||
871 | ||||
872 | if (!(pImpl->m_digest.m_length <= nBufLen)) | |||
873 | return rtl_Digest_E_BufferSize; | |||
874 | ||||
875 | ctx = &(pImpl->m_context); | |||
876 | ||||
877 | __rtl_digest_endMD5 (ctx); | |||
878 | RTL_DIGEST_LTOC (ctx->m_nA, p)(*((p)++) = (sal_uInt8)(((ctx->m_nA) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nA) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nA) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nA) >> 24L) & 0xff )); | |||
879 | RTL_DIGEST_LTOC (ctx->m_nB, p)(*((p)++) = (sal_uInt8)(((ctx->m_nB) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nB) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nB) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nB) >> 24L) & 0xff )); | |||
880 | RTL_DIGEST_LTOC (ctx->m_nC, p)(*((p)++) = (sal_uInt8)(((ctx->m_nC) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nC) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nC) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nC) >> 24L) & 0xff )); | |||
881 | RTL_DIGEST_LTOC (ctx->m_nD, p)(*((p)++) = (sal_uInt8)(((ctx->m_nD) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nD) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nD) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nD) >> 24L) & 0xff )); | |||
882 | __rtl_digest_initMD5 (ctx); | |||
883 | ||||
884 | return rtl_Digest_E_None; | |||
885 | } | |||
886 | ||||
887 | /* | |||
888 | * rtl_digest_rawMD5. | |||
889 | */ | |||
890 | rtlDigestError SAL_CALL rtl_digest_rawMD5 ( | |||
891 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
892 | SAL_THROW_EXTERN_C()throw () | |||
893 | { | |||
894 | DigestMD5_Impl *pImpl = (DigestMD5_Impl *)Digest; | |||
895 | sal_uInt8 *p = pBuffer; | |||
896 | ||||
897 | DigestContextMD5 *ctx; | |||
898 | ||||
899 | if ((pImpl == NULL__null) || (pBuffer == NULL__null)) | |||
900 | return rtl_Digest_E_Argument; | |||
901 | ||||
902 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD5)) | |||
903 | return rtl_Digest_E_Algorithm; | |||
904 | ||||
905 | if (!(pImpl->m_digest.m_length <= nBufLen)) | |||
906 | return rtl_Digest_E_BufferSize; | |||
907 | ||||
908 | ctx = &(pImpl->m_context); | |||
909 | ||||
910 | /* __rtl_digest_endMD5 (ctx); *//* not finalized */ | |||
911 | RTL_DIGEST_LTOC (ctx->m_nA, p)(*((p)++) = (sal_uInt8)(((ctx->m_nA) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nA) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nA) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nA) >> 24L) & 0xff )); | |||
912 | RTL_DIGEST_LTOC (ctx->m_nB, p)(*((p)++) = (sal_uInt8)(((ctx->m_nB) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nB) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nB) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nB) >> 24L) & 0xff )); | |||
913 | RTL_DIGEST_LTOC (ctx->m_nC, p)(*((p)++) = (sal_uInt8)(((ctx->m_nC) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nC) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nC) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nC) >> 24L) & 0xff )); | |||
914 | RTL_DIGEST_LTOC (ctx->m_nD, p)(*((p)++) = (sal_uInt8)(((ctx->m_nD) ) & 0xff), *((p)++ ) = (sal_uInt8)(((ctx->m_nD) >> 8L) & 0xff), *(( p)++) = (sal_uInt8)(((ctx->m_nD) >> 16L) & 0xff) , *((p)++) = (sal_uInt8)(((ctx->m_nD) >> 24L) & 0xff )); | |||
915 | __rtl_digest_initMD5 (ctx); | |||
916 | ||||
917 | return rtl_Digest_E_None; | |||
918 | } | |||
919 | ||||
920 | /* | |||
921 | * rtl_digest_destroyMD5. | |||
922 | */ | |||
923 | void SAL_CALL rtl_digest_destroyMD5 (rtlDigest Digest) SAL_THROW_EXTERN_C()throw () | |||
924 | { | |||
925 | DigestMD5_Impl *pImpl = (DigestMD5_Impl *)Digest; | |||
926 | if (pImpl) | |||
927 | { | |||
928 | if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmMD5) | |||
929 | rtl_freeZeroMemory (pImpl, sizeof (DigestMD5_Impl)); | |||
930 | else | |||
931 | rtl_freeMemory (pImpl); | |||
932 | } | |||
933 | } | |||
934 | ||||
935 | /*======================================================================== | |||
936 | * | |||
937 | * rtl_digest_(SHA|SHA1) common internals. | |||
938 | * | |||
939 | *======================================================================*/ | |||
940 | #define DIGEST_CBLOCK_SHA64 64 | |||
941 | #define DIGEST_LBLOCK_SHA16 16 | |||
942 | ||||
943 | typedef sal_uInt32 DigestSHA_update_t (sal_uInt32 x); | |||
944 | ||||
945 | static sal_uInt32 __rtl_digest_updateSHA_0 (sal_uInt32 x); | |||
946 | static sal_uInt32 __rtl_digest_updateSHA_1 (sal_uInt32 x); | |||
947 | ||||
948 | struct DigestContextSHA | |||
949 | { | |||
950 | DigestSHA_update_t *m_update; | |||
951 | sal_uInt32 m_nDatLen; | |||
952 | sal_uInt32 m_pData[DIGEST_LBLOCK_SHA16]; | |||
953 | sal_uInt32 m_nA, m_nB, m_nC, m_nD, m_nE; | |||
954 | sal_uInt32 m_nL, m_nH; | |||
955 | }; | |||
956 | ||||
957 | struct DigestSHA_Impl | |||
958 | { | |||
959 | Digest_Impl m_digest; | |||
960 | DigestContextSHA m_context; | |||
961 | }; | |||
962 | ||||
963 | static void __rtl_digest_initSHA ( | |||
964 | DigestContextSHA *ctx, DigestSHA_update_t *fct); | |||
965 | ||||
966 | static void __rtl_digest_updateSHA (DigestContextSHA *ctx); | |||
967 | static void __rtl_digest_endSHA (DigestContextSHA *ctx); | |||
968 | ||||
969 | #define K_00_19(sal_uInt32)0x5a827999L (sal_uInt32)0x5a827999L | |||
970 | #define K_20_39(sal_uInt32)0x6ed9eba1L (sal_uInt32)0x6ed9eba1L | |||
971 | #define K_40_59(sal_uInt32)0x8f1bbcdcL (sal_uInt32)0x8f1bbcdcL | |||
972 | #define K_60_79(sal_uInt32)0xca62c1d6L (sal_uInt32)0xca62c1d6L | |||
973 | ||||
974 | #define F_00_19(b,c,d)((((c) ^ (d)) & (b)) ^ (d)) ((((c) ^ (d)) & (b)) ^ (d)) | |||
975 | #define F_20_39(b,c,d)((b) ^ (c) ^ (d)) ((b) ^ (c) ^ (d)) | |||
976 | #define F_40_59(b,c,d)(((b) & (c)) | ((b) & (d)) | ((c) & (d))) (((b) & (c)) | ((b) & (d)) | ((c) & (d))) | |||
977 | #define F_60_79(b,c,d)((b) ^ (c) ^ (d)) F_20_39(b,c,d)((b) ^ (c) ^ (d)) | |||
978 | ||||
979 | #define BODY_X(i)(X[(i)&0x0f] ^ X[((i)+2)&0x0f] ^ X[((i)+8)&0x0f] ^ X[((i)+13)&0x0f]) \ | |||
980 | (X[(i)&0x0f] ^ X[((i)+2)&0x0f] ^ X[((i)+8)&0x0f] ^ X[((i)+13)&0x0f]) | |||
981 | ||||
982 | #define BODY_00_15(u,i,a,b,c,d,e,f)(f) = X[i]; (f) += (e) + (sal_uInt32)0x5a827999L + ((((a)) << (5)) | (((a)) >> (32 - (5)))) + (((((c)) ^ ((d))) & ((b))) ^ ((d))); (b) = ((((b)) << (30)) | (((b)) >> (32 - (30)))); \ | |||
983 | (f) = X[i]; \ | |||
984 | (f) += (e) + K_00_19(sal_uInt32)0x5a827999L + RTL_DIGEST_ROTL((a), 5)((((a)) << (5)) | (((a)) >> (32 - (5)))) + F_00_19((b), (c), (d))(((((c)) ^ ((d))) & ((b))) ^ ((d))); \ | |||
985 | (b) = RTL_DIGEST_ROTL((b), 30)((((b)) << (30)) | (((b)) >> (32 - (30)))); | |||
986 | ||||
987 | #define BODY_16_19(u,i,a,b,c,d,e,f)(f) = (X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8 )&0x0f] ^ X[(((i))+13)&0x0f]); (f) = X[(i)&0x0f] = (u)((f)); (f) += (e) + (sal_uInt32)0x5a827999L + ((((a)) << (5)) | (((a)) >> (32 - (5)))) + (((((c)) ^ ((d))) & ((b))) ^ ((d))); (b) = ((((b)) << (30)) | (((b)) >> (32 - (30)))); \ | |||
988 | (f) = BODY_X((i))(X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8)& 0x0f] ^ X[(((i))+13)&0x0f]); \ | |||
989 | (f) = X[(i)&0x0f] = (u)((f)); \ | |||
990 | (f) += (e) + K_00_19(sal_uInt32)0x5a827999L + RTL_DIGEST_ROTL((a), 5)((((a)) << (5)) | (((a)) >> (32 - (5)))) + F_00_19((b), (c), (d))(((((c)) ^ ((d))) & ((b))) ^ ((d))); \ | |||
991 | (b) = RTL_DIGEST_ROTL((b), 30)((((b)) << (30)) | (((b)) >> (32 - (30)))); | |||
992 | ||||
993 | #define BODY_20_39(u,i,a,b,c,d,e,f)(f) = (X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8 )&0x0f] ^ X[(((i))+13)&0x0f]); (f) = X[(i)&0x0f] = (u)((f)); (f) += (e) + (sal_uInt32)0x6ed9eba1L + ((((a)) << (5)) | (((a)) >> (32 - (5)))) + (((b)) ^ ((c)) ^ ((d)) ); (b) = ((((b)) << (30)) | (((b)) >> (32 - (30)) )); \ | |||
994 | (f) = BODY_X((i))(X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8)& 0x0f] ^ X[(((i))+13)&0x0f]); \ | |||
995 | (f) = X[(i)&0x0f] = (u)((f)); \ | |||
996 | (f) += (e) + K_20_39(sal_uInt32)0x6ed9eba1L + RTL_DIGEST_ROTL((a), 5)((((a)) << (5)) | (((a)) >> (32 - (5)))) + F_20_39((b), (c), (d))(((b)) ^ ((c)) ^ ((d))); \ | |||
997 | (b) = RTL_DIGEST_ROTL((b), 30)((((b)) << (30)) | (((b)) >> (32 - (30)))); | |||
998 | ||||
999 | #define BODY_40_59(u,i,a,b,c,d,e,f)(f) = (X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8 )&0x0f] ^ X[(((i))+13)&0x0f]); (f) = X[(i)&0x0f] = (u)((f)); (f) += (e) + (sal_uInt32)0x8f1bbcdcL + ((((a)) << (5)) | (((a)) >> (32 - (5)))) + ((((b)) & ((c))) | (((b)) & ((d))) | (((c)) & ((d)))); (b) = ((((b)) << (30)) | (((b)) >> (32 - (30)))); \ | |||
1000 | (f) = BODY_X((i))(X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8)& 0x0f] ^ X[(((i))+13)&0x0f]); \ | |||
1001 | (f) = X[(i)&0x0f] = (u)((f)); \ | |||
1002 | (f) += (e) + K_40_59(sal_uInt32)0x8f1bbcdcL + RTL_DIGEST_ROTL((a), 5)((((a)) << (5)) | (((a)) >> (32 - (5)))) + F_40_59((b), (c), (d))((((b)) & ((c))) | (((b)) & ((d))) | (((c)) & ((d )))); \ | |||
1003 | (b) = RTL_DIGEST_ROTL((b), 30)((((b)) << (30)) | (((b)) >> (32 - (30)))); | |||
1004 | ||||
1005 | #define BODY_60_79(u,i,a,b,c,d,e,f)(f) = (X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8 )&0x0f] ^ X[(((i))+13)&0x0f]); (f) = X[(i)&0x0f] = (u)((f)); (f) += (e) + (sal_uInt32)0xca62c1d6L + ((((a)) << (5)) | (((a)) >> (32 - (5)))) + (((b)) ^ ((c)) ^ ((d)) ); (b) = ((((b)) << (30)) | (((b)) >> (32 - (30)) )); \ | |||
1006 | (f) = BODY_X((i))(X[((i))&0x0f] ^ X[(((i))+2)&0x0f] ^ X[(((i))+8)& 0x0f] ^ X[(((i))+13)&0x0f]); \ | |||
1007 | (f) = X[(i)&0x0f] = (u)((f)); \ | |||
1008 | (f) += (e) + K_60_79(sal_uInt32)0xca62c1d6L + RTL_DIGEST_ROTL((a), 5)((((a)) << (5)) | (((a)) >> (32 - (5)))) + F_60_79((b), (c), (d))(((b)) ^ ((c)) ^ ((d))); \ | |||
1009 | (b) = RTL_DIGEST_ROTL((b), 30)((((b)) << (30)) | (((b)) >> (32 - (30)))); | |||
1010 | ||||
1011 | /* | |||
1012 | * __rtl_digest_initSHA. | |||
1013 | */ | |||
1014 | static void __rtl_digest_initSHA ( | |||
1015 | DigestContextSHA *ctx, DigestSHA_update_t *fct) | |||
1016 | { | |||
1017 | memset (ctx, 0, sizeof (DigestContextSHA)); | |||
1018 | ctx->m_update = fct; | |||
1019 | ||||
1020 | ctx->m_nA = (sal_uInt32)0x67452301L; | |||
1021 | ctx->m_nB = (sal_uInt32)0xefcdab89L; | |||
1022 | ctx->m_nC = (sal_uInt32)0x98badcfeL; | |||
1023 | ctx->m_nD = (sal_uInt32)0x10325476L; | |||
1024 | ctx->m_nE = (sal_uInt32)0xc3d2e1f0L; | |||
1025 | } | |||
1026 | ||||
1027 | /* | |||
1028 | * __rtl_digest_updateSHA. | |||
1029 | */ | |||
1030 | static void __rtl_digest_updateSHA (DigestContextSHA *ctx) | |||
1031 | { | |||
1032 | sal_uInt32 A, B, C, D, E, T; | |||
1033 | sal_uInt32 *X; | |||
1034 | ||||
1035 | DigestSHA_update_t *U; | |||
1036 | U = ctx->m_update; | |||
1037 | ||||
1038 | A = ctx->m_nA; | |||
1039 | B = ctx->m_nB; | |||
1040 | C = ctx->m_nC; | |||
1041 | D = ctx->m_nD; | |||
1042 | E = ctx->m_nE; | |||
1043 | X = ctx->m_pData; | |||
1044 | ||||
1045 | BODY_00_15 (U, 0, A, B, C, D, E, T)(T) = X[0]; (T) += (E) + (sal_uInt32)0x5a827999L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((((C)) ^ ((D))) & ((B))) ^ ((D))); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30))));; | |||
1046 | BODY_00_15 (U, 1, T, A, B, C, D, E)(E) = X[1]; (E) += (D) + (sal_uInt32)0x5a827999L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((((B)) ^ ((C))) & ((A))) ^ ((C))); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30))));; | |||
1047 | BODY_00_15 (U, 2, E, T, A, B, C, D)(D) = X[2]; (D) += (C) + (sal_uInt32)0x5a827999L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((((A)) ^ ((B))) & ((T))) ^ ((B))); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30))));; | |||
1048 | BODY_00_15 (U, 3, D, E, T, A, B, C)(C) = X[3]; (C) += (B) + (sal_uInt32)0x5a827999L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((((T)) ^ ((A))) & ((E))) ^ ((A))); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30))));; | |||
1049 | BODY_00_15 (U, 4, C, D, E, T, A, B)(B) = X[4]; (B) += (A) + (sal_uInt32)0x5a827999L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((((E)) ^ ((T))) & ((D))) ^ ((T))); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30))));; | |||
1050 | BODY_00_15 (U, 5, B, C, D, E, T, A)(A) = X[5]; (A) += (T) + (sal_uInt32)0x5a827999L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((((D)) ^ ((E))) & ((C))) ^ ((E))); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30))));; | |||
1051 | BODY_00_15 (U, 6, A, B, C, D, E, T)(T) = X[6]; (T) += (E) + (sal_uInt32)0x5a827999L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((((C)) ^ ((D))) & ((B))) ^ ((D))); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30))));; | |||
1052 | BODY_00_15 (U, 7, T, A, B, C, D, E)(E) = X[7]; (E) += (D) + (sal_uInt32)0x5a827999L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((((B)) ^ ((C))) & ((A))) ^ ((C))); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30))));; | |||
1053 | BODY_00_15 (U, 8, E, T, A, B, C, D)(D) = X[8]; (D) += (C) + (sal_uInt32)0x5a827999L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((((A)) ^ ((B))) & ((T))) ^ ((B))); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30))));; | |||
1054 | BODY_00_15 (U, 9, D, E, T, A, B, C)(C) = X[9]; (C) += (B) + (sal_uInt32)0x5a827999L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((((T)) ^ ((A))) & ((E))) ^ ((A))); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30))));; | |||
1055 | BODY_00_15 (U, 10, C, D, E, T, A, B)(B) = X[10]; (B) += (A) + (sal_uInt32)0x5a827999L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((((E)) ^ ((T))) & ((D))) ^ ((T))); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30))));; | |||
1056 | BODY_00_15 (U, 11, B, C, D, E, T, A)(A) = X[11]; (A) += (T) + (sal_uInt32)0x5a827999L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((((D)) ^ ((E))) & ((C))) ^ ((E))); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30))));; | |||
1057 | BODY_00_15 (U, 12, A, B, C, D, E, T)(T) = X[12]; (T) += (E) + (sal_uInt32)0x5a827999L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((((C)) ^ ((D))) & ((B))) ^ ((D))); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30))));; | |||
1058 | BODY_00_15 (U, 13, T, A, B, C, D, E)(E) = X[13]; (E) += (D) + (sal_uInt32)0x5a827999L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((((B)) ^ ((C))) & ((A))) ^ ((C))); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30))));; | |||
1059 | BODY_00_15 (U, 14, E, T, A, B, C, D)(D) = X[14]; (D) += (C) + (sal_uInt32)0x5a827999L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((((A)) ^ ((B))) & ((T))) ^ ((B))); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30))));; | |||
1060 | BODY_00_15 (U, 15, D, E, T, A, B, C)(C) = X[15]; (C) += (B) + (sal_uInt32)0x5a827999L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((((T)) ^ ((A))) & ((E))) ^ ((A))); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30))));; | |||
1061 | BODY_16_19 (U, 16, C, D, E, T, A, B)(B) = (X[((16))&0x0f] ^ X[(((16))+2)&0x0f] ^ X[(((16) )+8)&0x0f] ^ X[(((16))+13)&0x0f]); (B) = X[(16)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x5a827999L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((((E)) ^ ((T))) & ((D))) ^ ((T))); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30))));; | |||
1062 | BODY_16_19 (U, 17, B, C, D, E, T, A)(A) = (X[((17))&0x0f] ^ X[(((17))+2)&0x0f] ^ X[(((17) )+8)&0x0f] ^ X[(((17))+13)&0x0f]); (A) = X[(17)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x5a827999L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((((D)) ^ ((E))) & ((C))) ^ ((E))); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30))));; | |||
1063 | BODY_16_19 (U, 18, A, B, C, D, E, T)(T) = (X[((18))&0x0f] ^ X[(((18))+2)&0x0f] ^ X[(((18) )+8)&0x0f] ^ X[(((18))+13)&0x0f]); (T) = X[(18)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0x5a827999L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((((C)) ^ ((D))) & ((B))) ^ ((D))); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30))));; | |||
1064 | BODY_16_19 (U, 19, T, A, B, C, D, E)(E) = (X[((19))&0x0f] ^ X[(((19))+2)&0x0f] ^ X[(((19) )+8)&0x0f] ^ X[(((19))+13)&0x0f]); (E) = X[(19)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0x5a827999L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((((B)) ^ ((C))) & ((A))) ^ ((C))); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30))));; | |||
1065 | ||||
1066 | BODY_20_39 (U, 20, E, T, A, B, C, D)(D) = (X[((20))&0x0f] ^ X[(((20))+2)&0x0f] ^ X[(((20) )+8)&0x0f] ^ X[(((20))+13)&0x0f]); (D) = X[(20)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0x6ed9eba1L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((T)) ^ ((A)) ^ ((B)) ); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30)) ));; | |||
1067 | BODY_20_39 (U, 21, D, E, T, A, B, C)(C) = (X[((21))&0x0f] ^ X[(((21))+2)&0x0f] ^ X[(((21) )+8)&0x0f] ^ X[(((21))+13)&0x0f]); (C) = X[(21)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0x6ed9eba1L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((E)) ^ ((T)) ^ ((A)) ); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30)) ));; | |||
1068 | BODY_20_39 (U, 22, C, D, E, T, A, B)(B) = (X[((22))&0x0f] ^ X[(((22))+2)&0x0f] ^ X[(((22) )+8)&0x0f] ^ X[(((22))+13)&0x0f]); (B) = X[(22)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x6ed9eba1L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((D)) ^ ((E)) ^ ((T)) ); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30)) ));; | |||
1069 | BODY_20_39 (U, 23, B, C, D, E, T, A)(A) = (X[((23))&0x0f] ^ X[(((23))+2)&0x0f] ^ X[(((23) )+8)&0x0f] ^ X[(((23))+13)&0x0f]); (A) = X[(23)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x6ed9eba1L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((C)) ^ ((D)) ^ ((E)) ); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30)) ));; | |||
1070 | BODY_20_39 (U, 24, A, B, C, D, E, T)(T) = (X[((24))&0x0f] ^ X[(((24))+2)&0x0f] ^ X[(((24) )+8)&0x0f] ^ X[(((24))+13)&0x0f]); (T) = X[(24)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0x6ed9eba1L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((B)) ^ ((C)) ^ ((D)) ); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30)) ));; | |||
1071 | BODY_20_39 (U, 25, T, A, B, C, D, E)(E) = (X[((25))&0x0f] ^ X[(((25))+2)&0x0f] ^ X[(((25) )+8)&0x0f] ^ X[(((25))+13)&0x0f]); (E) = X[(25)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0x6ed9eba1L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((A)) ^ ((B)) ^ ((C)) ); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30)) ));; | |||
1072 | BODY_20_39 (U, 26, E, T, A, B, C, D)(D) = (X[((26))&0x0f] ^ X[(((26))+2)&0x0f] ^ X[(((26) )+8)&0x0f] ^ X[(((26))+13)&0x0f]); (D) = X[(26)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0x6ed9eba1L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((T)) ^ ((A)) ^ ((B)) ); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30)) ));; | |||
1073 | BODY_20_39 (U, 27, D, E, T, A, B, C)(C) = (X[((27))&0x0f] ^ X[(((27))+2)&0x0f] ^ X[(((27) )+8)&0x0f] ^ X[(((27))+13)&0x0f]); (C) = X[(27)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0x6ed9eba1L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((E)) ^ ((T)) ^ ((A)) ); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30)) ));; | |||
1074 | BODY_20_39 (U, 28, C, D, E, T, A, B)(B) = (X[((28))&0x0f] ^ X[(((28))+2)&0x0f] ^ X[(((28) )+8)&0x0f] ^ X[(((28))+13)&0x0f]); (B) = X[(28)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x6ed9eba1L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((D)) ^ ((E)) ^ ((T)) ); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30)) ));; | |||
1075 | BODY_20_39 (U, 29, B, C, D, E, T, A)(A) = (X[((29))&0x0f] ^ X[(((29))+2)&0x0f] ^ X[(((29) )+8)&0x0f] ^ X[(((29))+13)&0x0f]); (A) = X[(29)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x6ed9eba1L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((C)) ^ ((D)) ^ ((E)) ); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30)) ));; | |||
1076 | BODY_20_39 (U, 30, A, B, C, D, E, T)(T) = (X[((30))&0x0f] ^ X[(((30))+2)&0x0f] ^ X[(((30) )+8)&0x0f] ^ X[(((30))+13)&0x0f]); (T) = X[(30)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0x6ed9eba1L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((B)) ^ ((C)) ^ ((D)) ); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30)) ));; | |||
1077 | BODY_20_39 (U, 31, T, A, B, C, D, E)(E) = (X[((31))&0x0f] ^ X[(((31))+2)&0x0f] ^ X[(((31) )+8)&0x0f] ^ X[(((31))+13)&0x0f]); (E) = X[(31)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0x6ed9eba1L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((A)) ^ ((B)) ^ ((C)) ); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30)) ));; | |||
1078 | BODY_20_39 (U, 32, E, T, A, B, C, D)(D) = (X[((32))&0x0f] ^ X[(((32))+2)&0x0f] ^ X[(((32) )+8)&0x0f] ^ X[(((32))+13)&0x0f]); (D) = X[(32)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0x6ed9eba1L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((T)) ^ ((A)) ^ ((B)) ); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30)) ));; | |||
1079 | BODY_20_39 (U, 33, D, E, T, A, B, C)(C) = (X[((33))&0x0f] ^ X[(((33))+2)&0x0f] ^ X[(((33) )+8)&0x0f] ^ X[(((33))+13)&0x0f]); (C) = X[(33)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0x6ed9eba1L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((E)) ^ ((T)) ^ ((A)) ); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30)) ));; | |||
1080 | BODY_20_39 (U, 34, C, D, E, T, A, B)(B) = (X[((34))&0x0f] ^ X[(((34))+2)&0x0f] ^ X[(((34) )+8)&0x0f] ^ X[(((34))+13)&0x0f]); (B) = X[(34)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x6ed9eba1L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((D)) ^ ((E)) ^ ((T)) ); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30)) ));; | |||
1081 | BODY_20_39 (U, 35, B, C, D, E, T, A)(A) = (X[((35))&0x0f] ^ X[(((35))+2)&0x0f] ^ X[(((35) )+8)&0x0f] ^ X[(((35))+13)&0x0f]); (A) = X[(35)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x6ed9eba1L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((C)) ^ ((D)) ^ ((E)) ); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30)) ));; | |||
1082 | BODY_20_39 (U, 36, A, B, C, D, E, T)(T) = (X[((36))&0x0f] ^ X[(((36))+2)&0x0f] ^ X[(((36) )+8)&0x0f] ^ X[(((36))+13)&0x0f]); (T) = X[(36)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0x6ed9eba1L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((B)) ^ ((C)) ^ ((D)) ); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30)) ));; | |||
1083 | BODY_20_39 (U, 37, T, A, B, C, D, E)(E) = (X[((37))&0x0f] ^ X[(((37))+2)&0x0f] ^ X[(((37) )+8)&0x0f] ^ X[(((37))+13)&0x0f]); (E) = X[(37)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0x6ed9eba1L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((A)) ^ ((B)) ^ ((C)) ); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30)) ));; | |||
1084 | BODY_20_39 (U, 38, E, T, A, B, C, D)(D) = (X[((38))&0x0f] ^ X[(((38))+2)&0x0f] ^ X[(((38) )+8)&0x0f] ^ X[(((38))+13)&0x0f]); (D) = X[(38)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0x6ed9eba1L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((T)) ^ ((A)) ^ ((B)) ); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30)) ));; | |||
1085 | BODY_20_39 (U, 39, D, E, T, A, B, C)(C) = (X[((39))&0x0f] ^ X[(((39))+2)&0x0f] ^ X[(((39) )+8)&0x0f] ^ X[(((39))+13)&0x0f]); (C) = X[(39)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0x6ed9eba1L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((E)) ^ ((T)) ^ ((A)) ); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30)) ));; | |||
1086 | ||||
1087 | BODY_40_59 (U, 40, C, D, E, T, A, B)(B) = (X[((40))&0x0f] ^ X[(((40))+2)&0x0f] ^ X[(((40) )+8)&0x0f] ^ X[(((40))+13)&0x0f]); (B) = X[(40)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x8f1bbcdcL + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + ((((D)) & ((E))) | (((D)) & ((T))) | (((E)) & ((T)))); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30))));; | |||
1088 | BODY_40_59 (U, 41, B, C, D, E, T, A)(A) = (X[((41))&0x0f] ^ X[(((41))+2)&0x0f] ^ X[(((41) )+8)&0x0f] ^ X[(((41))+13)&0x0f]); (A) = X[(41)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x8f1bbcdcL + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + ((((C)) & ((D))) | (((C)) & ((E))) | (((D)) & ((E)))); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30))));; | |||
1089 | BODY_40_59 (U, 42, A, B, C, D, E, T)(T) = (X[((42))&0x0f] ^ X[(((42))+2)&0x0f] ^ X[(((42) )+8)&0x0f] ^ X[(((42))+13)&0x0f]); (T) = X[(42)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0x8f1bbcdcL + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + ((((B)) & ((C))) | (((B)) & ((D))) | (((C)) & ((D)))); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30))));; | |||
1090 | BODY_40_59 (U, 43, T, A, B, C, D, E)(E) = (X[((43))&0x0f] ^ X[(((43))+2)&0x0f] ^ X[(((43) )+8)&0x0f] ^ X[(((43))+13)&0x0f]); (E) = X[(43)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0x8f1bbcdcL + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + ((((A)) & ((B))) | (((A)) & ((C))) | (((B)) & ((C)))); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30))));; | |||
1091 | BODY_40_59 (U, 44, E, T, A, B, C, D)(D) = (X[((44))&0x0f] ^ X[(((44))+2)&0x0f] ^ X[(((44) )+8)&0x0f] ^ X[(((44))+13)&0x0f]); (D) = X[(44)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0x8f1bbcdcL + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + ((((T)) & ((A))) | (((T)) & ((B))) | (((A)) & ((B)))); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30))));; | |||
1092 | BODY_40_59 (U, 45, D, E, T, A, B, C)(C) = (X[((45))&0x0f] ^ X[(((45))+2)&0x0f] ^ X[(((45) )+8)&0x0f] ^ X[(((45))+13)&0x0f]); (C) = X[(45)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0x8f1bbcdcL + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + ((((E)) & ((T))) | (((E)) & ((A))) | (((T)) & ((A)))); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30))));; | |||
1093 | BODY_40_59 (U, 46, C, D, E, T, A, B)(B) = (X[((46))&0x0f] ^ X[(((46))+2)&0x0f] ^ X[(((46) )+8)&0x0f] ^ X[(((46))+13)&0x0f]); (B) = X[(46)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x8f1bbcdcL + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + ((((D)) & ((E))) | (((D)) & ((T))) | (((E)) & ((T)))); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30))));; | |||
1094 | BODY_40_59 (U, 47, B, C, D, E, T, A)(A) = (X[((47))&0x0f] ^ X[(((47))+2)&0x0f] ^ X[(((47) )+8)&0x0f] ^ X[(((47))+13)&0x0f]); (A) = X[(47)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x8f1bbcdcL + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + ((((C)) & ((D))) | (((C)) & ((E))) | (((D)) & ((E)))); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30))));; | |||
1095 | BODY_40_59 (U, 48, A, B, C, D, E, T)(T) = (X[((48))&0x0f] ^ X[(((48))+2)&0x0f] ^ X[(((48) )+8)&0x0f] ^ X[(((48))+13)&0x0f]); (T) = X[(48)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0x8f1bbcdcL + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + ((((B)) & ((C))) | (((B)) & ((D))) | (((C)) & ((D)))); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30))));; | |||
1096 | BODY_40_59 (U, 49, T, A, B, C, D, E)(E) = (X[((49))&0x0f] ^ X[(((49))+2)&0x0f] ^ X[(((49) )+8)&0x0f] ^ X[(((49))+13)&0x0f]); (E) = X[(49)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0x8f1bbcdcL + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + ((((A)) & ((B))) | (((A)) & ((C))) | (((B)) & ((C)))); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30))));; | |||
1097 | BODY_40_59 (U, 50, E, T, A, B, C, D)(D) = (X[((50))&0x0f] ^ X[(((50))+2)&0x0f] ^ X[(((50) )+8)&0x0f] ^ X[(((50))+13)&0x0f]); (D) = X[(50)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0x8f1bbcdcL + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + ((((T)) & ((A))) | (((T)) & ((B))) | (((A)) & ((B)))); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30))));; | |||
1098 | BODY_40_59 (U, 51, D, E, T, A, B, C)(C) = (X[((51))&0x0f] ^ X[(((51))+2)&0x0f] ^ X[(((51) )+8)&0x0f] ^ X[(((51))+13)&0x0f]); (C) = X[(51)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0x8f1bbcdcL + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + ((((E)) & ((T))) | (((E)) & ((A))) | (((T)) & ((A)))); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30))));; | |||
1099 | BODY_40_59 (U, 52, C, D, E, T, A, B)(B) = (X[((52))&0x0f] ^ X[(((52))+2)&0x0f] ^ X[(((52) )+8)&0x0f] ^ X[(((52))+13)&0x0f]); (B) = X[(52)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x8f1bbcdcL + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + ((((D)) & ((E))) | (((D)) & ((T))) | (((E)) & ((T)))); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30))));; | |||
1100 | BODY_40_59 (U, 53, B, C, D, E, T, A)(A) = (X[((53))&0x0f] ^ X[(((53))+2)&0x0f] ^ X[(((53) )+8)&0x0f] ^ X[(((53))+13)&0x0f]); (A) = X[(53)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x8f1bbcdcL + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + ((((C)) & ((D))) | (((C)) & ((E))) | (((D)) & ((E)))); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30))));; | |||
1101 | BODY_40_59 (U, 54, A, B, C, D, E, T)(T) = (X[((54))&0x0f] ^ X[(((54))+2)&0x0f] ^ X[(((54) )+8)&0x0f] ^ X[(((54))+13)&0x0f]); (T) = X[(54)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0x8f1bbcdcL + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + ((((B)) & ((C))) | (((B)) & ((D))) | (((C)) & ((D)))); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30))));; | |||
1102 | BODY_40_59 (U, 55, T, A, B, C, D, E)(E) = (X[((55))&0x0f] ^ X[(((55))+2)&0x0f] ^ X[(((55) )+8)&0x0f] ^ X[(((55))+13)&0x0f]); (E) = X[(55)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0x8f1bbcdcL + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + ((((A)) & ((B))) | (((A)) & ((C))) | (((B)) & ((C)))); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30))));; | |||
1103 | BODY_40_59 (U, 56, E, T, A, B, C, D)(D) = (X[((56))&0x0f] ^ X[(((56))+2)&0x0f] ^ X[(((56) )+8)&0x0f] ^ X[(((56))+13)&0x0f]); (D) = X[(56)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0x8f1bbcdcL + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + ((((T)) & ((A))) | (((T)) & ((B))) | (((A)) & ((B)))); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30))));; | |||
1104 | BODY_40_59 (U, 57, D, E, T, A, B, C)(C) = (X[((57))&0x0f] ^ X[(((57))+2)&0x0f] ^ X[(((57) )+8)&0x0f] ^ X[(((57))+13)&0x0f]); (C) = X[(57)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0x8f1bbcdcL + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + ((((E)) & ((T))) | (((E)) & ((A))) | (((T)) & ((A)))); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30))));; | |||
1105 | BODY_40_59 (U, 58, C, D, E, T, A, B)(B) = (X[((58))&0x0f] ^ X[(((58))+2)&0x0f] ^ X[(((58) )+8)&0x0f] ^ X[(((58))+13)&0x0f]); (B) = X[(58)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0x8f1bbcdcL + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + ((((D)) & ((E))) | (((D)) & ((T))) | (((E)) & ((T)))); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30))));; | |||
1106 | BODY_40_59 (U, 59, B, C, D, E, T, A)(A) = (X[((59))&0x0f] ^ X[(((59))+2)&0x0f] ^ X[(((59) )+8)&0x0f] ^ X[(((59))+13)&0x0f]); (A) = X[(59)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0x8f1bbcdcL + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + ((((C)) & ((D))) | (((C)) & ((E))) | (((D)) & ((E)))); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30))));; | |||
1107 | ||||
1108 | BODY_60_79 (U, 60, A, B, C, D, E, T)(T) = (X[((60))&0x0f] ^ X[(((60))+2)&0x0f] ^ X[(((60) )+8)&0x0f] ^ X[(((60))+13)&0x0f]); (T) = X[(60)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0xca62c1d6L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((B)) ^ ((C)) ^ ((D)) ); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30)) ));; | |||
1109 | BODY_60_79 (U, 61, T, A, B, C, D, E)(E) = (X[((61))&0x0f] ^ X[(((61))+2)&0x0f] ^ X[(((61) )+8)&0x0f] ^ X[(((61))+13)&0x0f]); (E) = X[(61)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0xca62c1d6L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((A)) ^ ((B)) ^ ((C)) ); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30)) ));; | |||
1110 | BODY_60_79 (U, 62, E, T, A, B, C, D)(D) = (X[((62))&0x0f] ^ X[(((62))+2)&0x0f] ^ X[(((62) )+8)&0x0f] ^ X[(((62))+13)&0x0f]); (D) = X[(62)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0xca62c1d6L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((T)) ^ ((A)) ^ ((B)) ); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30)) ));; | |||
1111 | BODY_60_79 (U, 63, D, E, T, A, B, C)(C) = (X[((63))&0x0f] ^ X[(((63))+2)&0x0f] ^ X[(((63) )+8)&0x0f] ^ X[(((63))+13)&0x0f]); (C) = X[(63)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0xca62c1d6L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((E)) ^ ((T)) ^ ((A)) ); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30)) ));; | |||
1112 | BODY_60_79 (U, 64, C, D, E, T, A, B)(B) = (X[((64))&0x0f] ^ X[(((64))+2)&0x0f] ^ X[(((64) )+8)&0x0f] ^ X[(((64))+13)&0x0f]); (B) = X[(64)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0xca62c1d6L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((D)) ^ ((E)) ^ ((T)) ); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30)) ));; | |||
1113 | BODY_60_79 (U, 65, B, C, D, E, T, A)(A) = (X[((65))&0x0f] ^ X[(((65))+2)&0x0f] ^ X[(((65) )+8)&0x0f] ^ X[(((65))+13)&0x0f]); (A) = X[(65)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0xca62c1d6L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((C)) ^ ((D)) ^ ((E)) ); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30)) ));; | |||
1114 | BODY_60_79 (U, 66, A, B, C, D, E, T)(T) = (X[((66))&0x0f] ^ X[(((66))+2)&0x0f] ^ X[(((66) )+8)&0x0f] ^ X[(((66))+13)&0x0f]); (T) = X[(66)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0xca62c1d6L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((B)) ^ ((C)) ^ ((D)) ); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30)) ));; | |||
1115 | BODY_60_79 (U, 67, T, A, B, C, D, E)(E) = (X[((67))&0x0f] ^ X[(((67))+2)&0x0f] ^ X[(((67) )+8)&0x0f] ^ X[(((67))+13)&0x0f]); (E) = X[(67)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0xca62c1d6L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((A)) ^ ((B)) ^ ((C)) ); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30)) ));; | |||
1116 | BODY_60_79 (U, 68, E, T, A, B, C, D)(D) = (X[((68))&0x0f] ^ X[(((68))+2)&0x0f] ^ X[(((68) )+8)&0x0f] ^ X[(((68))+13)&0x0f]); (D) = X[(68)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0xca62c1d6L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((T)) ^ ((A)) ^ ((B)) ); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30)) ));; | |||
1117 | BODY_60_79 (U, 69, D, E, T, A, B, C)(C) = (X[((69))&0x0f] ^ X[(((69))+2)&0x0f] ^ X[(((69) )+8)&0x0f] ^ X[(((69))+13)&0x0f]); (C) = X[(69)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0xca62c1d6L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((E)) ^ ((T)) ^ ((A)) ); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30)) ));; | |||
1118 | BODY_60_79 (U, 70, C, D, E, T, A, B)(B) = (X[((70))&0x0f] ^ X[(((70))+2)&0x0f] ^ X[(((70) )+8)&0x0f] ^ X[(((70))+13)&0x0f]); (B) = X[(70)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0xca62c1d6L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((D)) ^ ((E)) ^ ((T)) ); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30)) ));; | |||
1119 | BODY_60_79 (U, 71, B, C, D, E, T, A)(A) = (X[((71))&0x0f] ^ X[(((71))+2)&0x0f] ^ X[(((71) )+8)&0x0f] ^ X[(((71))+13)&0x0f]); (A) = X[(71)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0xca62c1d6L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((C)) ^ ((D)) ^ ((E)) ); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30)) ));; | |||
1120 | BODY_60_79 (U, 72, A, B, C, D, E, T)(T) = (X[((72))&0x0f] ^ X[(((72))+2)&0x0f] ^ X[(((72) )+8)&0x0f] ^ X[(((72))+13)&0x0f]); (T) = X[(72)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0xca62c1d6L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((B)) ^ ((C)) ^ ((D)) ); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30)) ));; | |||
1121 | BODY_60_79 (U, 73, T, A, B, C, D, E)(E) = (X[((73))&0x0f] ^ X[(((73))+2)&0x0f] ^ X[(((73) )+8)&0x0f] ^ X[(((73))+13)&0x0f]); (E) = X[(73)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0xca62c1d6L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((A)) ^ ((B)) ^ ((C)) ); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30)) ));; | |||
1122 | BODY_60_79 (U, 74, E, T, A, B, C, D)(D) = (X[((74))&0x0f] ^ X[(((74))+2)&0x0f] ^ X[(((74) )+8)&0x0f] ^ X[(((74))+13)&0x0f]); (D) = X[(74)&0x0f ] = (U)((D)); (D) += (C) + (sal_uInt32)0xca62c1d6L + ((((E)) << (5)) | (((E)) >> (32 - (5)))) + (((T)) ^ ((A)) ^ ((B)) ); (T) = ((((T)) << (30)) | (((T)) >> (32 - (30)) ));; | |||
1123 | BODY_60_79 (U, 75, D, E, T, A, B, C)(C) = (X[((75))&0x0f] ^ X[(((75))+2)&0x0f] ^ X[(((75) )+8)&0x0f] ^ X[(((75))+13)&0x0f]); (C) = X[(75)&0x0f ] = (U)((C)); (C) += (B) + (sal_uInt32)0xca62c1d6L + ((((D)) << (5)) | (((D)) >> (32 - (5)))) + (((E)) ^ ((T)) ^ ((A)) ); (E) = ((((E)) << (30)) | (((E)) >> (32 - (30)) ));; | |||
1124 | BODY_60_79 (U, 76, C, D, E, T, A, B)(B) = (X[((76))&0x0f] ^ X[(((76))+2)&0x0f] ^ X[(((76) )+8)&0x0f] ^ X[(((76))+13)&0x0f]); (B) = X[(76)&0x0f ] = (U)((B)); (B) += (A) + (sal_uInt32)0xca62c1d6L + ((((C)) << (5)) | (((C)) >> (32 - (5)))) + (((D)) ^ ((E)) ^ ((T)) ); (D) = ((((D)) << (30)) | (((D)) >> (32 - (30)) ));; | |||
1125 | BODY_60_79 (U, 77, B, C, D, E, T, A)(A) = (X[((77))&0x0f] ^ X[(((77))+2)&0x0f] ^ X[(((77) )+8)&0x0f] ^ X[(((77))+13)&0x0f]); (A) = X[(77)&0x0f ] = (U)((A)); (A) += (T) + (sal_uInt32)0xca62c1d6L + ((((B)) << (5)) | (((B)) >> (32 - (5)))) + (((C)) ^ ((D)) ^ ((E)) ); (C) = ((((C)) << (30)) | (((C)) >> (32 - (30)) ));; | |||
1126 | BODY_60_79 (U, 78, A, B, C, D, E, T)(T) = (X[((78))&0x0f] ^ X[(((78))+2)&0x0f] ^ X[(((78) )+8)&0x0f] ^ X[(((78))+13)&0x0f]); (T) = X[(78)&0x0f ] = (U)((T)); (T) += (E) + (sal_uInt32)0xca62c1d6L + ((((A)) << (5)) | (((A)) >> (32 - (5)))) + (((B)) ^ ((C)) ^ ((D)) ); (B) = ((((B)) << (30)) | (((B)) >> (32 - (30)) ));; | |||
1127 | BODY_60_79 (U, 79, T, A, B, C, D, E)(E) = (X[((79))&0x0f] ^ X[(((79))+2)&0x0f] ^ X[(((79) )+8)&0x0f] ^ X[(((79))+13)&0x0f]); (E) = X[(79)&0x0f ] = (U)((E)); (E) += (D) + (sal_uInt32)0xca62c1d6L + ((((T)) << (5)) | (((T)) >> (32 - (5)))) + (((A)) ^ ((B)) ^ ((C)) ); (A) = ((((A)) << (30)) | (((A)) >> (32 - (30)) ));; | |||
1128 | ||||
1129 | ctx->m_nA += E; | |||
1130 | ctx->m_nB += T; | |||
1131 | ctx->m_nC += A; | |||
1132 | ctx->m_nD += B; | |||
1133 | ctx->m_nE += C; | |||
1134 | } | |||
1135 | ||||
1136 | /* | |||
1137 | * __rtl_digest_endSHA. | |||
1138 | */ | |||
1139 | static void __rtl_digest_endSHA (DigestContextSHA *ctx) | |||
1140 | { | |||
1141 | static const sal_uInt8 end[4] = | |||
1142 | { | |||
1143 | 0x80, 0x00, 0x00, 0x00 | |||
1144 | }; | |||
1145 | const sal_uInt8 *p = end; | |||
1146 | ||||
1147 | sal_uInt32 *X; | |||
1148 | int i; | |||
1149 | ||||
1150 | X = ctx->m_pData; | |||
1151 | i = (ctx->m_nDatLen >> 2); | |||
1152 | ||||
1153 | #ifdef OSL_BIGENDIAN | |||
1154 | __rtl_digest_swapLong (X, i + 1); | |||
1155 | #endif /* OSL_BIGENDIAN */ | |||
1156 | ||||
1157 | switch (ctx->m_nDatLen & 0x03) | |||
1158 | { | |||
1159 | case 1: X[i] &= 0x000000ff; break; | |||
1160 | case 2: X[i] &= 0x0000ffff; break; | |||
1161 | case 3: X[i] &= 0x00ffffff; break; | |||
1162 | } | |||
1163 | ||||
1164 | switch (ctx->m_nDatLen & 0x03) | |||
1165 | { | |||
1166 | case 0: X[i] = ((sal_uInt32)(*(p++))) << 0L; | |||
1167 | case 1: X[i] |= ((sal_uInt32)(*(p++))) << 8L; | |||
1168 | case 2: X[i] |= ((sal_uInt32)(*(p++))) << 16L; | |||
1169 | case 3: X[i] |= ((sal_uInt32)(*(p++))) << 24L; | |||
1170 | } | |||
1171 | ||||
1172 | __rtl_digest_swapLong (X, i + 1); | |||
1173 | ||||
1174 | i += 1; | |||
1175 | ||||
1176 | if (i >= (DIGEST_LBLOCK_SHA16 - 2)) | |||
1177 | { | |||
1178 | for (; i < DIGEST_LBLOCK_SHA16; i++) | |||
1179 | X[i] = 0; | |||
1180 | __rtl_digest_updateSHA (ctx); | |||
1181 | i = 0; | |||
1182 | } | |||
1183 | ||||
1184 | for (; i < (DIGEST_LBLOCK_SHA16 - 2); i++) | |||
1185 | X[i] = 0; | |||
1186 | ||||
1187 | X[DIGEST_LBLOCK_SHA16 - 2] = ctx->m_nH; | |||
1188 | X[DIGEST_LBLOCK_SHA16 - 1] = ctx->m_nL; | |||
1189 | ||||
1190 | __rtl_digest_updateSHA (ctx); | |||
1191 | } | |||
1192 | ||||
1193 | /*======================================================================== | |||
1194 | * | |||
1195 | * rtl_digest_SHA internals. | |||
1196 | * | |||
1197 | *======================================================================*/ | |||
1198 | /* | |||
1199 | * __rtl_digest_SHA_0. | |||
1200 | */ | |||
1201 | static const Digest_Impl __rtl_digest_SHA_0 = | |||
1202 | { | |||
1203 | rtl_Digest_AlgorithmSHA, | |||
1204 | RTL_DIGEST_LENGTH_SHA20, | |||
1205 | ||||
1206 | NULL__null, | |||
1207 | rtl_digest_destroySHA, | |||
1208 | rtl_digest_updateSHA, | |||
1209 | rtl_digest_getSHA | |||
1210 | }; | |||
1211 | ||||
1212 | /* | |||
1213 | * __rtl_digest_updateSHA_0. | |||
1214 | */ | |||
1215 | static sal_uInt32 __rtl_digest_updateSHA_0 (sal_uInt32 x) | |||
1216 | { | |||
1217 | return x; | |||
1218 | } | |||
1219 | ||||
1220 | /*======================================================================== | |||
1221 | * | |||
1222 | * rtl_digest_SHA implementation. | |||
1223 | * | |||
1224 | *======================================================================*/ | |||
1225 | /* | |||
1226 | * rtl_digest_SHA. | |||
1227 | */ | |||
1228 | rtlDigestError SAL_CALL rtl_digest_SHA ( | |||
1229 | const void *pData, sal_uInt32 nDatLen, | |||
1230 | sal_uInt8 *pBuffer, sal_uInt32 nBufLen) SAL_THROW_EXTERN_C()throw () | |||
1231 | { | |||
1232 | DigestSHA_Impl digest; | |||
1233 | rtlDigestError result; | |||
1234 | ||||
1235 | digest.m_digest = __rtl_digest_SHA_0; | |||
1236 | __rtl_digest_initSHA (&(digest.m_context), __rtl_digest_updateSHA_0); | |||
1237 | ||||
1238 | result = rtl_digest_updateSHA (&digest, pData, nDatLen); | |||
1239 | if (result == rtl_Digest_E_None) | |||
1240 | result = rtl_digest_getSHA (&digest, pBuffer, nBufLen); | |||
1241 | ||||
1242 | memset (&digest, 0, sizeof (digest)); | |||
1243 | return (result); | |||
1244 | } | |||
1245 | ||||
1246 | /* | |||
1247 | * rtl_digest_createSHA. | |||
1248 | */ | |||
1249 | rtlDigest SAL_CALL rtl_digest_createSHA() SAL_THROW_EXTERN_C()throw () | |||
1250 | { | |||
1251 | DigestSHA_Impl *pImpl = (DigestSHA_Impl*)NULL__null; | |||
1252 | pImpl = RTL_DIGEST_CREATE(DigestSHA_Impl)((DigestSHA_Impl*)(rtl_allocateZeroMemory(sizeof(DigestSHA_Impl )))); | |||
1253 | if (pImpl) | |||
1254 | { | |||
1255 | pImpl->m_digest = __rtl_digest_SHA_0; | |||
1256 | __rtl_digest_initSHA (&(pImpl->m_context), __rtl_digest_updateSHA_0); | |||
1257 | } | |||
1258 | return ((rtlDigest)pImpl); | |||
1259 | } | |||
1260 | ||||
1261 | /* | |||
1262 | * rtl_digest_updateSHA. | |||
1263 | */ | |||
1264 | rtlDigestError SAL_CALL rtl_digest_updateSHA ( | |||
1265 | rtlDigest Digest, const void *pData, sal_uInt32 nDatLen) | |||
1266 | SAL_THROW_EXTERN_C()throw () | |||
1267 | { | |||
1268 | DigestSHA_Impl *pImpl = (DigestSHA_Impl *)Digest; | |||
1269 | const sal_uInt8 *d = (const sal_uInt8 *)pData; | |||
1270 | ||||
1271 | DigestContextSHA *ctx; | |||
1272 | sal_uInt32 len; | |||
1273 | ||||
1274 | if ((pImpl == NULL__null) || (pData == NULL__null)) | |||
1275 | return rtl_Digest_E_Argument; | |||
1276 | ||||
1277 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA)) | |||
1278 | return rtl_Digest_E_Algorithm; | |||
1279 | ||||
1280 | if (nDatLen == 0) | |||
1281 | return rtl_Digest_E_None; | |||
1282 | ||||
1283 | ctx = &(pImpl->m_context); | |||
1284 | ||||
1285 | len = ctx->m_nL + (nDatLen << 3); | |||
1286 | if (len < ctx->m_nL) ctx->m_nH += 1; | |||
1287 | ctx->m_nH += (nDatLen >> 29); | |||
1288 | ctx->m_nL = len; | |||
1289 | ||||
1290 | if (ctx->m_nDatLen) | |||
1291 | { | |||
1292 | sal_uInt8 *p = (sal_uInt8 *)(ctx->m_pData) + ctx->m_nDatLen; | |||
1293 | sal_uInt32 n = DIGEST_CBLOCK_SHA64 - ctx->m_nDatLen; | |||
1294 | ||||
1295 | if (nDatLen < n) | |||
1296 | { | |||
1297 | memcpy (p, d, nDatLen); | |||
1298 | ctx->m_nDatLen += nDatLen; | |||
1299 | ||||
1300 | return rtl_Digest_E_None; | |||
1301 | } | |||
1302 | ||||
1303 | memcpy (p, d, n); | |||
1304 | d += n; | |||
1305 | nDatLen -= n; | |||
1306 | ||||
1307 | #ifndef OSL_BIGENDIAN | |||
1308 | __rtl_digest_swapLong (ctx->m_pData, DIGEST_LBLOCK_SHA16); | |||
1309 | #endif /* OSL_BIGENDIAN */ | |||
1310 | ||||
1311 | __rtl_digest_updateSHA (ctx); | |||
1312 | ctx->m_nDatLen = 0; | |||
1313 | } | |||
1314 | ||||
1315 | while (nDatLen >= DIGEST_CBLOCK_SHA64) | |||
1316 | { | |||
1317 | memcpy (ctx->m_pData, d, DIGEST_CBLOCK_SHA64); | |||
1318 | d += DIGEST_CBLOCK_SHA64; | |||
1319 | nDatLen -= DIGEST_CBLOCK_SHA64; | |||
1320 | ||||
1321 | #ifndef OSL_BIGENDIAN | |||
1322 | __rtl_digest_swapLong (ctx->m_pData, DIGEST_LBLOCK_SHA16); | |||
1323 | #endif /* OSL_BIGENDIAN */ | |||
1324 | ||||
1325 | __rtl_digest_updateSHA (ctx); | |||
1326 | } | |||
1327 | ||||
1328 | memcpy (ctx->m_pData, d, nDatLen); | |||
1329 | ctx->m_nDatLen = nDatLen; | |||
1330 | ||||
1331 | return rtl_Digest_E_None; | |||
1332 | } | |||
1333 | ||||
1334 | /* | |||
1335 | * rtl_digest_getSHA. | |||
1336 | */ | |||
1337 | rtlDigestError SAL_CALL rtl_digest_getSHA ( | |||
1338 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
1339 | SAL_THROW_EXTERN_C()throw () | |||
1340 | { | |||
1341 | DigestSHA_Impl *pImpl = (DigestSHA_Impl *)Digest; | |||
1342 | sal_uInt8 *p = pBuffer; | |||
1343 | ||||
1344 | DigestContextSHA *ctx; | |||
1345 | ||||
1346 | if ((pImpl == NULL__null) || (pBuffer == NULL__null)) | |||
1347 | return rtl_Digest_E_Argument; | |||
1348 | ||||
1349 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA)) | |||
1350 | return rtl_Digest_E_Algorithm; | |||
1351 | ||||
1352 | if (!(pImpl->m_digest.m_length <= nBufLen)) | |||
1353 | return rtl_Digest_E_BufferSize; | |||
1354 | ||||
1355 | ctx = &(pImpl->m_context); | |||
1356 | ||||
1357 | __rtl_digest_endSHA (ctx); | |||
1358 | RTL_DIGEST_HTONL (ctx->m_nA, p)(*((p)++) = (sal_uInt8)(((ctx->m_nA) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nA) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nA) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nA) ) & 0xff)); | |||
1359 | RTL_DIGEST_HTONL (ctx->m_nB, p)(*((p)++) = (sal_uInt8)(((ctx->m_nB) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nB) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nB) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nB) ) & 0xff)); | |||
1360 | RTL_DIGEST_HTONL (ctx->m_nC, p)(*((p)++) = (sal_uInt8)(((ctx->m_nC) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nC) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nC) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nC) ) & 0xff)); | |||
1361 | RTL_DIGEST_HTONL (ctx->m_nD, p)(*((p)++) = (sal_uInt8)(((ctx->m_nD) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nD) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nD) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nD) ) & 0xff)); | |||
1362 | RTL_DIGEST_HTONL (ctx->m_nE, p)(*((p)++) = (sal_uInt8)(((ctx->m_nE) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nE) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nE) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nE) ) & 0xff)); | |||
1363 | __rtl_digest_initSHA (ctx, __rtl_digest_updateSHA_0); | |||
1364 | ||||
1365 | return rtl_Digest_E_None; | |||
1366 | } | |||
1367 | ||||
1368 | /* | |||
1369 | * rtl_digest_destroySHA. | |||
1370 | */ | |||
1371 | void SAL_CALL rtl_digest_destroySHA (rtlDigest Digest) SAL_THROW_EXTERN_C()throw () | |||
1372 | { | |||
1373 | DigestSHA_Impl *pImpl = (DigestSHA_Impl *)Digest; | |||
1374 | if (pImpl) | |||
1375 | { | |||
1376 | if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA) | |||
1377 | rtl_freeZeroMemory (pImpl, sizeof (DigestSHA_Impl)); | |||
1378 | else | |||
1379 | rtl_freeMemory (pImpl); | |||
1380 | } | |||
1381 | } | |||
1382 | ||||
1383 | /*======================================================================== | |||
1384 | * | |||
1385 | * rtl_digest_SHA1 internals. | |||
1386 | * | |||
1387 | *======================================================================*/ | |||
1388 | /* | |||
1389 | * __rtl_digest_SHA_1. | |||
1390 | */ | |||
1391 | static const Digest_Impl __rtl_digest_SHA_1 = | |||
1392 | { | |||
1393 | rtl_Digest_AlgorithmSHA1, | |||
1394 | RTL_DIGEST_LENGTH_SHA120, | |||
1395 | ||||
1396 | NULL__null, | |||
1397 | rtl_digest_destroySHA1, | |||
1398 | rtl_digest_updateSHA1, | |||
1399 | rtl_digest_getSHA1 | |||
1400 | }; | |||
1401 | ||||
1402 | /* | |||
1403 | * __rtl_digest_updateSHA_1. | |||
1404 | */ | |||
1405 | static sal_uInt32 __rtl_digest_updateSHA_1 (sal_uInt32 x) | |||
1406 | { | |||
1407 | return RTL_DIGEST_ROTL (x, 1)(((x) << (1)) | ((x) >> (32 - (1)))); | |||
1408 | } | |||
1409 | ||||
1410 | /*======================================================================== | |||
1411 | * | |||
1412 | * rtl_digest_SHA1 implementation. | |||
1413 | * | |||
1414 | *======================================================================*/ | |||
1415 | /* | |||
1416 | * rtl_digest_SHA1. | |||
1417 | */ | |||
1418 | rtlDigestError SAL_CALL rtl_digest_SHA1 ( | |||
1419 | const void *pData, sal_uInt32 nDatLen, | |||
1420 | sal_uInt8 *pBuffer, sal_uInt32 nBufLen) SAL_THROW_EXTERN_C()throw () | |||
1421 | { | |||
1422 | DigestSHA_Impl digest; | |||
1423 | rtlDigestError result; | |||
1424 | ||||
1425 | digest.m_digest = __rtl_digest_SHA_1; | |||
1426 | __rtl_digest_initSHA (&(digest.m_context), __rtl_digest_updateSHA_1); | |||
1427 | ||||
1428 | result = rtl_digest_updateSHA1 (&digest, pData, nDatLen); | |||
1429 | if (result == rtl_Digest_E_None) | |||
1430 | result = rtl_digest_getSHA1 (&digest, pBuffer, nBufLen); | |||
1431 | ||||
1432 | memset (&digest, 0, sizeof (digest)); | |||
1433 | return (result); | |||
1434 | } | |||
1435 | ||||
1436 | /* | |||
1437 | * rtl_digest_createSHA1. | |||
1438 | */ | |||
1439 | rtlDigest SAL_CALL rtl_digest_createSHA1() SAL_THROW_EXTERN_C()throw () | |||
1440 | { | |||
1441 | DigestSHA_Impl *pImpl = (DigestSHA_Impl*)NULL__null; | |||
1442 | pImpl = RTL_DIGEST_CREATE(DigestSHA_Impl)((DigestSHA_Impl*)(rtl_allocateZeroMemory(sizeof(DigestSHA_Impl )))); | |||
1443 | if (pImpl) | |||
1444 | { | |||
1445 | pImpl->m_digest = __rtl_digest_SHA_1; | |||
1446 | __rtl_digest_initSHA (&(pImpl->m_context), __rtl_digest_updateSHA_1); | |||
1447 | } | |||
1448 | return ((rtlDigest)pImpl); | |||
1449 | } | |||
1450 | ||||
1451 | /* | |||
1452 | * rtl_digest_updateSHA1. | |||
1453 | */ | |||
1454 | rtlDigestError SAL_CALL rtl_digest_updateSHA1 ( | |||
1455 | rtlDigest Digest, const void *pData, sal_uInt32 nDatLen) | |||
1456 | SAL_THROW_EXTERN_C()throw () | |||
1457 | { | |||
1458 | DigestSHA_Impl *pImpl = (DigestSHA_Impl *)Digest; | |||
1459 | const sal_uInt8 *d = (const sal_uInt8 *)pData; | |||
1460 | ||||
1461 | DigestContextSHA *ctx; | |||
1462 | sal_uInt32 len; | |||
1463 | ||||
1464 | if ((pImpl == NULL__null) || (pData == NULL__null)) | |||
1465 | return rtl_Digest_E_Argument; | |||
1466 | ||||
1467 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA1)) | |||
1468 | return rtl_Digest_E_Algorithm; | |||
1469 | ||||
1470 | if (nDatLen == 0) | |||
1471 | return rtl_Digest_E_None; | |||
1472 | ||||
1473 | ctx = &(pImpl->m_context); | |||
1474 | ||||
1475 | len = ctx->m_nL + (nDatLen << 3); | |||
1476 | if (len < ctx->m_nL) ctx->m_nH += 1; | |||
1477 | ctx->m_nH += (nDatLen >> 29); | |||
1478 | ctx->m_nL = len; | |||
1479 | ||||
1480 | if (ctx->m_nDatLen) | |||
1481 | { | |||
1482 | sal_uInt8 *p = (sal_uInt8 *)(ctx->m_pData) + ctx->m_nDatLen; | |||
1483 | sal_uInt32 n = DIGEST_CBLOCK_SHA64 - ctx->m_nDatLen; | |||
1484 | ||||
1485 | if (nDatLen < n) | |||
1486 | { | |||
1487 | memcpy (p, d, nDatLen); | |||
1488 | ctx->m_nDatLen += nDatLen; | |||
1489 | ||||
1490 | return rtl_Digest_E_None; | |||
1491 | } | |||
1492 | ||||
1493 | memcpy (p, d, n); | |||
1494 | d += n; | |||
1495 | nDatLen -= n; | |||
1496 | ||||
1497 | #ifndef OSL_BIGENDIAN | |||
1498 | __rtl_digest_swapLong (ctx->m_pData, DIGEST_LBLOCK_SHA16); | |||
1499 | #endif /* OSL_BIGENDIAN */ | |||
1500 | ||||
1501 | __rtl_digest_updateSHA (ctx); | |||
1502 | ctx->m_nDatLen = 0; | |||
1503 | } | |||
1504 | ||||
1505 | while (nDatLen >= DIGEST_CBLOCK_SHA64) | |||
1506 | { | |||
1507 | memcpy (ctx->m_pData, d, DIGEST_CBLOCK_SHA64); | |||
1508 | d += DIGEST_CBLOCK_SHA64; | |||
1509 | nDatLen -= DIGEST_CBLOCK_SHA64; | |||
1510 | ||||
1511 | #ifndef OSL_BIGENDIAN | |||
1512 | __rtl_digest_swapLong (ctx->m_pData, DIGEST_LBLOCK_SHA16); | |||
1513 | #endif /* OSL_BIGENDIAN */ | |||
1514 | ||||
1515 | __rtl_digest_updateSHA (ctx); | |||
1516 | } | |||
1517 | ||||
1518 | memcpy (ctx->m_pData, d, nDatLen); | |||
1519 | ctx->m_nDatLen = nDatLen; | |||
1520 | ||||
1521 | return rtl_Digest_E_None; | |||
1522 | } | |||
1523 | ||||
1524 | /* | |||
1525 | * rtl_digest_getSHA1. | |||
1526 | */ | |||
1527 | rtlDigestError SAL_CALL rtl_digest_getSHA1 ( | |||
1528 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
1529 | SAL_THROW_EXTERN_C()throw () | |||
1530 | { | |||
1531 | DigestSHA_Impl *pImpl = (DigestSHA_Impl *)Digest; | |||
1532 | sal_uInt8 *p = pBuffer; | |||
1533 | ||||
1534 | DigestContextSHA *ctx; | |||
1535 | ||||
1536 | if ((pImpl == NULL__null) || (pBuffer == NULL__null)) | |||
1537 | return rtl_Digest_E_Argument; | |||
1538 | ||||
1539 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA1)) | |||
1540 | return rtl_Digest_E_Algorithm; | |||
1541 | ||||
1542 | if (!(pImpl->m_digest.m_length <= nBufLen)) | |||
1543 | return rtl_Digest_E_BufferSize; | |||
1544 | ||||
1545 | ctx = &(pImpl->m_context); | |||
1546 | ||||
1547 | __rtl_digest_endSHA (ctx); | |||
1548 | RTL_DIGEST_HTONL (ctx->m_nA, p)(*((p)++) = (sal_uInt8)(((ctx->m_nA) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nA) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nA) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nA) ) & 0xff)); | |||
1549 | RTL_DIGEST_HTONL (ctx->m_nB, p)(*((p)++) = (sal_uInt8)(((ctx->m_nB) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nB) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nB) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nB) ) & 0xff)); | |||
1550 | RTL_DIGEST_HTONL (ctx->m_nC, p)(*((p)++) = (sal_uInt8)(((ctx->m_nC) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nC) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nC) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nC) ) & 0xff)); | |||
1551 | RTL_DIGEST_HTONL (ctx->m_nD, p)(*((p)++) = (sal_uInt8)(((ctx->m_nD) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nD) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nD) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nD) ) & 0xff)); | |||
1552 | RTL_DIGEST_HTONL (ctx->m_nE, p)(*((p)++) = (sal_uInt8)(((ctx->m_nE) >> 24L) & 0xff ), *((p)++) = (sal_uInt8)(((ctx->m_nE) >> 16L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nE) >> 8L) & 0xff), *((p)++) = (sal_uInt8)(((ctx->m_nE) ) & 0xff)); | |||
1553 | __rtl_digest_initSHA (ctx, __rtl_digest_updateSHA_1); | |||
1554 | ||||
1555 | return rtl_Digest_E_None; | |||
1556 | } | |||
1557 | ||||
1558 | /* | |||
1559 | * rtl_digest_destroySHA1. | |||
1560 | */ | |||
1561 | void SAL_CALL rtl_digest_destroySHA1 (rtlDigest Digest) SAL_THROW_EXTERN_C()throw () | |||
1562 | { | |||
1563 | DigestSHA_Impl *pImpl = (DigestSHA_Impl *)Digest; | |||
1564 | if (pImpl) | |||
1565 | { | |||
1566 | if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmSHA1) | |||
1567 | rtl_freeZeroMemory (pImpl, sizeof (DigestSHA_Impl)); | |||
1568 | else | |||
1569 | rtl_freeMemory (pImpl); | |||
1570 | } | |||
1571 | } | |||
1572 | ||||
1573 | /*======================================================================== | |||
1574 | * | |||
1575 | * rtl_digest_HMAC_MD5 internals. | |||
1576 | * | |||
1577 | *======================================================================*/ | |||
1578 | #define DIGEST_CBLOCK_HMAC_MD564 64 | |||
1579 | ||||
1580 | struct ContextHMAC_MD5 | |||
1581 | { | |||
1582 | DigestMD5_Impl m_hash; | |||
1583 | sal_uInt8 m_opad[DIGEST_CBLOCK_HMAC_MD564]; | |||
1584 | }; | |||
1585 | ||||
1586 | struct DigestHMAC_MD5_Impl | |||
1587 | { | |||
1588 | Digest_Impl m_digest; | |||
1589 | ContextHMAC_MD5 m_context; | |||
1590 | }; | |||
1591 | ||||
1592 | static void __rtl_digest_initHMAC_MD5 (ContextHMAC_MD5 * ctx); | |||
1593 | static void __rtl_digest_ipadHMAC_MD5 (ContextHMAC_MD5 * ctx); | |||
1594 | static void __rtl_digest_opadHMAC_MD5 (ContextHMAC_MD5 * ctx); | |||
1595 | ||||
1596 | /* | |||
1597 | * __rtl_digest_HMAC_MD5. | |||
1598 | */ | |||
1599 | static const Digest_Impl __rtl_digest_HMAC_MD5 = | |||
1600 | { | |||
1601 | rtl_Digest_AlgorithmHMAC_MD5, | |||
1602 | RTL_DIGEST_LENGTH_MD516, | |||
1603 | ||||
1604 | rtl_digest_initHMAC_MD5, | |||
1605 | rtl_digest_destroyHMAC_MD5, | |||
1606 | rtl_digest_updateHMAC_MD5, | |||
1607 | rtl_digest_getHMAC_MD5 | |||
1608 | }; | |||
1609 | ||||
1610 | /* | |||
1611 | * __rtl_digest_initHMAC_MD5. | |||
1612 | */ | |||
1613 | static void __rtl_digest_initHMAC_MD5 (ContextHMAC_MD5 * ctx) | |||
1614 | { | |||
1615 | DigestMD5_Impl *pImpl = &(ctx->m_hash); | |||
1616 | ||||
1617 | pImpl->m_digest = __rtl_digest_MD5; | |||
1618 | __rtl_digest_initMD5 (&(pImpl->m_context)); | |||
1619 | ||||
1620 | memset (ctx->m_opad, 0, DIGEST_CBLOCK_HMAC_MD564); | |||
1621 | } | |||
1622 | ||||
1623 | /* | |||
1624 | * __rtl_digest_ipadHMAC_MD5. | |||
1625 | */ | |||
1626 | static void __rtl_digest_ipadHMAC_MD5 (ContextHMAC_MD5 * ctx) | |||
1627 | { | |||
1628 | sal_uInt32 i; | |||
1629 | ||||
1630 | for (i = 0; i < DIGEST_CBLOCK_HMAC_MD564; i++) | |||
1631 | ctx->m_opad[i] ^= 0x36; | |||
1632 | rtl_digest_updateMD5 ( | |||
1633 | &(ctx->m_hash), ctx->m_opad, DIGEST_CBLOCK_HMAC_MD564); | |||
1634 | for (i = 0; i < DIGEST_CBLOCK_HMAC_MD564; i++) | |||
1635 | ctx->m_opad[i] ^= 0x36; | |||
1636 | } | |||
1637 | ||||
1638 | /* | |||
1639 | * __rtl_digest_opadHMAC_MD5. | |||
1640 | */ | |||
1641 | static void __rtl_digest_opadHMAC_MD5 (ContextHMAC_MD5 * ctx) | |||
1642 | { | |||
1643 | sal_uInt32 i; | |||
1644 | ||||
1645 | for (i = 0; i < DIGEST_CBLOCK_HMAC_MD564; i++) | |||
1646 | ctx->m_opad[i] ^= 0x5c; | |||
1647 | } | |||
1648 | ||||
1649 | /*======================================================================== | |||
1650 | * | |||
1651 | * rtl_digest_HMAC_MD5 implementation. | |||
1652 | * | |||
1653 | *======================================================================*/ | |||
1654 | /* | |||
1655 | * rtl_digest_HMAC_MD5. | |||
1656 | */ | |||
1657 | rtlDigestError SAL_CALL rtl_digest_HMAC_MD5 ( | |||
1658 | const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen, | |||
1659 | const void *pData, sal_uInt32 nDatLen, | |||
1660 | sal_uInt8 *pBuffer, sal_uInt32 nBufLen) SAL_THROW_EXTERN_C()throw () | |||
1661 | { | |||
1662 | DigestHMAC_MD5_Impl digest; | |||
1663 | rtlDigestError result; | |||
1664 | ||||
1665 | digest.m_digest = __rtl_digest_HMAC_MD5; | |||
1666 | ||||
1667 | result = rtl_digest_initHMAC_MD5 (&digest, pKeyData, nKeyLen); | |||
1668 | if (result == rtl_Digest_E_None) | |||
1669 | { | |||
1670 | result = rtl_digest_updateHMAC_MD5 (&digest, pData, nDatLen); | |||
1671 | if (result == rtl_Digest_E_None) | |||
1672 | result = rtl_digest_getHMAC_MD5 (&digest, pBuffer, nBufLen); | |||
1673 | } | |||
1674 | ||||
1675 | memset (&digest, 0, sizeof (digest)); | |||
1676 | return (result); | |||
1677 | } | |||
1678 | ||||
1679 | /* | |||
1680 | * rtl_digest_createHMAC_MD5. | |||
1681 | */ | |||
1682 | rtlDigest SAL_CALL rtl_digest_createHMAC_MD5() SAL_THROW_EXTERN_C()throw () | |||
1683 | { | |||
1684 | DigestHMAC_MD5_Impl *pImpl = (DigestHMAC_MD5_Impl*)NULL__null; | |||
1685 | pImpl = RTL_DIGEST_CREATE(DigestHMAC_MD5_Impl)((DigestHMAC_MD5_Impl*)(rtl_allocateZeroMemory(sizeof(DigestHMAC_MD5_Impl )))); | |||
1686 | if (pImpl) | |||
1687 | { | |||
1688 | pImpl->m_digest = __rtl_digest_HMAC_MD5; | |||
1689 | __rtl_digest_initHMAC_MD5 (&(pImpl->m_context)); | |||
1690 | } | |||
1691 | return ((rtlDigest)pImpl); | |||
1692 | } | |||
1693 | ||||
1694 | /* | |||
1695 | * rtl_digest_initHMAC_MD5. | |||
1696 | */ | |||
1697 | rtlDigestError SAL_CALL rtl_digest_initHMAC_MD5 ( | |||
1698 | rtlDigest Digest, const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen) | |||
1699 | SAL_THROW_EXTERN_C()throw () | |||
1700 | { | |||
1701 | DigestHMAC_MD5_Impl *pImpl = (DigestHMAC_MD5_Impl*)Digest; | |||
1702 | ContextHMAC_MD5 *ctx; | |||
1703 | ||||
1704 | if ((pImpl == NULL__null) || (pKeyData == NULL__null)) | |||
1705 | return rtl_Digest_E_Argument; | |||
1706 | ||||
1707 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_MD5)) | |||
1708 | return rtl_Digest_E_Algorithm; | |||
1709 | ||||
1710 | ctx = &(pImpl->m_context); | |||
1711 | __rtl_digest_initHMAC_MD5 (ctx); | |||
1712 | ||||
1713 | if (nKeyLen > DIGEST_CBLOCK_HMAC_MD564) | |||
1714 | { | |||
1715 | /* Initialize 'opad' with hashed 'KeyData' */ | |||
1716 | rtl_digest_updateMD5 ( | |||
1717 | &(ctx->m_hash), pKeyData, nKeyLen); | |||
1718 | rtl_digest_getMD5 ( | |||
1719 | &(ctx->m_hash), ctx->m_opad, RTL_DIGEST_LENGTH_MD516); | |||
1720 | } | |||
1721 | else | |||
1722 | { | |||
1723 | /* Initialize 'opad' with plain 'KeyData' */ | |||
1724 | memcpy (ctx->m_opad, pKeyData, nKeyLen); | |||
1725 | } | |||
1726 | ||||
1727 | __rtl_digest_ipadHMAC_MD5 (ctx); | |||
1728 | __rtl_digest_opadHMAC_MD5 (ctx); | |||
1729 | ||||
1730 | return rtl_Digest_E_None; | |||
1731 | } | |||
1732 | ||||
1733 | /* | |||
1734 | * rtl_digest_updateHMAC_MD5. | |||
1735 | */ | |||
1736 | rtlDigestError SAL_CALL rtl_digest_updateHMAC_MD5 ( | |||
1737 | rtlDigest Digest, const void *pData, sal_uInt32 nDatLen) | |||
1738 | SAL_THROW_EXTERN_C()throw () | |||
1739 | { | |||
1740 | DigestHMAC_MD5_Impl *pImpl = (DigestHMAC_MD5_Impl*)Digest; | |||
1741 | ContextHMAC_MD5 *ctx; | |||
1742 | ||||
1743 | if ((pImpl == NULL__null) || (pData == NULL__null)) | |||
1744 | return rtl_Digest_E_Argument; | |||
1745 | ||||
1746 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_MD5)) | |||
1747 | return rtl_Digest_E_Algorithm; | |||
1748 | ||||
1749 | ctx = &(pImpl->m_context); | |||
1750 | rtl_digest_updateMD5 (&(ctx->m_hash), pData, nDatLen); | |||
1751 | ||||
1752 | return rtl_Digest_E_None; | |||
1753 | } | |||
1754 | ||||
1755 | /* | |||
1756 | * rtl_digest_getHMAC_MD5. | |||
1757 | */ | |||
1758 | rtlDigestError SAL_CALL rtl_digest_getHMAC_MD5 ( | |||
1759 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
1760 | SAL_THROW_EXTERN_C()throw () | |||
1761 | { | |||
1762 | DigestHMAC_MD5_Impl *pImpl = (DigestHMAC_MD5_Impl*)Digest; | |||
1763 | ContextHMAC_MD5 *ctx; | |||
1764 | ||||
1765 | if ((pImpl == NULL__null) || (pBuffer == NULL__null)) | |||
1766 | return rtl_Digest_E_Argument; | |||
1767 | ||||
1768 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_MD5)) | |||
1769 | return rtl_Digest_E_Algorithm; | |||
1770 | ||||
1771 | if (!(pImpl->m_digest.m_length <= nBufLen)) | |||
1772 | return rtl_Digest_E_BufferSize; | |||
1773 | ||||
1774 | nBufLen = pImpl->m_digest.m_length; | |||
1775 | ||||
1776 | ctx = &(pImpl->m_context); | |||
1777 | rtl_digest_getMD5 (&(ctx->m_hash), pBuffer, nBufLen); | |||
1778 | ||||
1779 | rtl_digest_updateMD5 (&(ctx->m_hash), ctx->m_opad, 64); | |||
1780 | rtl_digest_updateMD5 (&(ctx->m_hash), pBuffer, nBufLen); | |||
1781 | rtl_digest_getMD5 (&(ctx->m_hash), pBuffer, nBufLen); | |||
1782 | ||||
1783 | __rtl_digest_opadHMAC_MD5 (ctx); | |||
1784 | __rtl_digest_ipadHMAC_MD5 (ctx); | |||
1785 | __rtl_digest_opadHMAC_MD5 (ctx); | |||
1786 | ||||
1787 | return rtl_Digest_E_None; | |||
1788 | } | |||
1789 | ||||
1790 | /* | |||
1791 | * rtl_digest_destroyHMAC_MD5. | |||
1792 | */ | |||
1793 | void SAL_CALL rtl_digest_destroyHMAC_MD5 (rtlDigest Digest) SAL_THROW_EXTERN_C()throw () | |||
1794 | { | |||
1795 | DigestHMAC_MD5_Impl *pImpl = (DigestHMAC_MD5_Impl*)Digest; | |||
1796 | if (pImpl) | |||
1797 | { | |||
1798 | if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_MD5) | |||
1799 | rtl_freeZeroMemory (pImpl, sizeof (DigestHMAC_MD5_Impl)); | |||
1800 | else | |||
1801 | rtl_freeMemory (pImpl); | |||
1802 | } | |||
1803 | } | |||
1804 | ||||
1805 | /*======================================================================== | |||
1806 | * | |||
1807 | * rtl_digest_HMAC_SHA1 internals. | |||
1808 | * | |||
1809 | *======================================================================*/ | |||
1810 | #define DIGEST_CBLOCK_HMAC_SHA164 64 | |||
1811 | ||||
1812 | struct ContextHMAC_SHA1 | |||
1813 | { | |||
1814 | DigestSHA_Impl m_hash; | |||
1815 | sal_uInt8 m_opad[DIGEST_CBLOCK_HMAC_SHA164]; | |||
1816 | }; | |||
1817 | ||||
1818 | struct DigestHMAC_SHA1_Impl | |||
1819 | { | |||
1820 | Digest_Impl m_digest; | |||
1821 | ContextHMAC_SHA1 m_context; | |||
1822 | }; | |||
1823 | ||||
1824 | static void __rtl_digest_initHMAC_SHA1 (ContextHMAC_SHA1 * ctx); | |||
1825 | static void __rtl_digest_ipadHMAC_SHA1 (ContextHMAC_SHA1 * ctx); | |||
1826 | static void __rtl_digest_opadHMAC_SHA1 (ContextHMAC_SHA1 * ctx); | |||
1827 | ||||
1828 | /* | |||
1829 | * __rtl_digest_HMAC_SHA1. | |||
1830 | */ | |||
1831 | static const Digest_Impl __rtl_digest_HMAC_SHA1 = | |||
1832 | { | |||
1833 | rtl_Digest_AlgorithmHMAC_SHA1, | |||
1834 | RTL_DIGEST_LENGTH_SHA120, | |||
1835 | ||||
1836 | rtl_digest_initHMAC_SHA1, | |||
1837 | rtl_digest_destroyHMAC_SHA1, | |||
1838 | rtl_digest_updateHMAC_SHA1, | |||
1839 | rtl_digest_getHMAC_SHA1 | |||
1840 | }; | |||
1841 | ||||
1842 | /* | |||
1843 | * __rtl_digest_initHMAC_SHA1. | |||
1844 | */ | |||
1845 | static void __rtl_digest_initHMAC_SHA1 (ContextHMAC_SHA1 * ctx) | |||
1846 | { | |||
1847 | DigestSHA_Impl *pImpl = &(ctx->m_hash); | |||
1848 | ||||
1849 | pImpl->m_digest = __rtl_digest_SHA_1; | |||
1850 | __rtl_digest_initSHA (&(pImpl->m_context), __rtl_digest_updateSHA_1); | |||
1851 | ||||
1852 | memset (ctx->m_opad, 0, DIGEST_CBLOCK_HMAC_SHA164); | |||
1853 | } | |||
1854 | ||||
1855 | /* | |||
1856 | * __rtl_digest_ipadHMAC_SHA1. | |||
1857 | */ | |||
1858 | static void __rtl_digest_ipadHMAC_SHA1 (ContextHMAC_SHA1 * ctx) | |||
1859 | { | |||
1860 | sal_uInt32 i; | |||
1861 | ||||
1862 | for (i = 0; i < DIGEST_CBLOCK_HMAC_SHA164; i++) | |||
1863 | ctx->m_opad[i] ^= 0x36; | |||
1864 | rtl_digest_updateSHA1 ( | |||
1865 | &(ctx->m_hash), ctx->m_opad, DIGEST_CBLOCK_HMAC_SHA164); | |||
1866 | for (i = 0; i < DIGEST_CBLOCK_HMAC_SHA164; i++) | |||
1867 | ctx->m_opad[i] ^= 0x36; | |||
1868 | } | |||
1869 | ||||
1870 | /* | |||
1871 | * __rtl_digest_opadHMAC_SHA1. | |||
1872 | */ | |||
1873 | static void __rtl_digest_opadHMAC_SHA1 (ContextHMAC_SHA1 * ctx) | |||
1874 | { | |||
1875 | sal_uInt32 i; | |||
1876 | ||||
1877 | for (i = 0; i < DIGEST_CBLOCK_HMAC_SHA164; i++) | |||
1878 | ctx->m_opad[i] ^= 0x5c; | |||
1879 | } | |||
1880 | ||||
1881 | /*======================================================================== | |||
1882 | * | |||
1883 | * rtl_digest_HMAC_SHA1 implementation. | |||
1884 | * | |||
1885 | *======================================================================*/ | |||
1886 | /* | |||
1887 | * rtl_digest_HMAC_SHA1. | |||
1888 | */ | |||
1889 | rtlDigestError SAL_CALL rtl_digest_HMAC_SHA1 ( | |||
1890 | const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen, | |||
1891 | const void *pData, sal_uInt32 nDatLen, | |||
1892 | sal_uInt8 *pBuffer, sal_uInt32 nBufLen) SAL_THROW_EXTERN_C()throw () | |||
1893 | { | |||
1894 | DigestHMAC_SHA1_Impl digest; | |||
1895 | rtlDigestError result; | |||
1896 | ||||
1897 | digest.m_digest = __rtl_digest_HMAC_SHA1; | |||
1898 | ||||
1899 | result = rtl_digest_initHMAC_SHA1 (&digest, pKeyData, nKeyLen); | |||
1900 | if (result == rtl_Digest_E_None) | |||
1901 | { | |||
1902 | result = rtl_digest_updateHMAC_SHA1 (&digest, pData, nDatLen); | |||
1903 | if (result == rtl_Digest_E_None) | |||
1904 | result = rtl_digest_getHMAC_SHA1 (&digest, pBuffer, nBufLen); | |||
1905 | } | |||
1906 | ||||
1907 | memset (&digest, 0, sizeof (digest)); | |||
1908 | return (result); | |||
1909 | } | |||
1910 | ||||
1911 | /* | |||
1912 | * rtl_digest_createHMAC_SHA1. | |||
1913 | */ | |||
1914 | rtlDigest SAL_CALL rtl_digest_createHMAC_SHA1() SAL_THROW_EXTERN_C()throw () | |||
1915 | { | |||
1916 | DigestHMAC_SHA1_Impl *pImpl = (DigestHMAC_SHA1_Impl*)NULL__null; | |||
1917 | pImpl = RTL_DIGEST_CREATE(DigestHMAC_SHA1_Impl)((DigestHMAC_SHA1_Impl*)(rtl_allocateZeroMemory(sizeof(DigestHMAC_SHA1_Impl )))); | |||
1918 | if (pImpl) | |||
1919 | { | |||
1920 | pImpl->m_digest = __rtl_digest_HMAC_SHA1; | |||
1921 | __rtl_digest_initHMAC_SHA1 (&(pImpl->m_context)); | |||
1922 | } | |||
1923 | return ((rtlDigest)pImpl); | |||
1924 | } | |||
1925 | ||||
1926 | /* | |||
1927 | * rtl_digest_initHMAC_SHA1. | |||
1928 | */ | |||
1929 | rtlDigestError SAL_CALL rtl_digest_initHMAC_SHA1 ( | |||
1930 | rtlDigest Digest, const sal_uInt8 *pKeyData, sal_uInt32 nKeyLen) | |||
1931 | SAL_THROW_EXTERN_C()throw () | |||
1932 | { | |||
1933 | DigestHMAC_SHA1_Impl *pImpl = (DigestHMAC_SHA1_Impl*)Digest; | |||
1934 | ContextHMAC_SHA1 *ctx; | |||
1935 | ||||
1936 | if ((pImpl == NULL__null) || (pKeyData == NULL__null)) | |||
1937 | return rtl_Digest_E_Argument; | |||
1938 | ||||
1939 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_SHA1)) | |||
1940 | return rtl_Digest_E_Algorithm; | |||
1941 | ||||
1942 | ctx = &(pImpl->m_context); | |||
1943 | __rtl_digest_initHMAC_SHA1 (ctx); | |||
1944 | ||||
1945 | if (nKeyLen > DIGEST_CBLOCK_HMAC_SHA164) | |||
1946 | { | |||
1947 | /* Initialize 'opad' with hashed 'KeyData' */ | |||
1948 | rtl_digest_updateSHA1 ( | |||
1949 | &(ctx->m_hash), pKeyData, nKeyLen); | |||
1950 | rtl_digest_getSHA1 ( | |||
1951 | &(ctx->m_hash), ctx->m_opad, RTL_DIGEST_LENGTH_SHA120); | |||
1952 | } | |||
1953 | else | |||
1954 | { | |||
1955 | /* Initialize 'opad' with plain 'KeyData' */ | |||
1956 | memcpy (ctx->m_opad, pKeyData, nKeyLen); | |||
1957 | } | |||
1958 | ||||
1959 | __rtl_digest_ipadHMAC_SHA1 (ctx); | |||
1960 | __rtl_digest_opadHMAC_SHA1 (ctx); | |||
1961 | ||||
1962 | return rtl_Digest_E_None; | |||
1963 | } | |||
1964 | ||||
1965 | /* | |||
1966 | * rtl_digest_updateHMAC_SHA1. | |||
1967 | */ | |||
1968 | rtlDigestError SAL_CALL rtl_digest_updateHMAC_SHA1 ( | |||
1969 | rtlDigest Digest, const void *pData, sal_uInt32 nDatLen) | |||
1970 | SAL_THROW_EXTERN_C()throw () | |||
1971 | { | |||
1972 | DigestHMAC_SHA1_Impl *pImpl = (DigestHMAC_SHA1_Impl*)Digest; | |||
1973 | ContextHMAC_SHA1 *ctx; | |||
1974 | ||||
1975 | if ((pImpl == NULL__null) || (pData == NULL__null)) | |||
1976 | return rtl_Digest_E_Argument; | |||
1977 | ||||
1978 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_SHA1)) | |||
1979 | return rtl_Digest_E_Algorithm; | |||
1980 | ||||
1981 | ctx = &(pImpl->m_context); | |||
1982 | rtl_digest_updateSHA1 (&(ctx->m_hash), pData, nDatLen); | |||
1983 | ||||
1984 | return rtl_Digest_E_None; | |||
1985 | } | |||
1986 | ||||
1987 | /* | |||
1988 | * rtl_digest_getHMAC_SHA1. | |||
1989 | */ | |||
1990 | rtlDigestError SAL_CALL rtl_digest_getHMAC_SHA1 ( | |||
1991 | rtlDigest Digest, sal_uInt8 *pBuffer, sal_uInt32 nBufLen) | |||
1992 | SAL_THROW_EXTERN_C()throw () | |||
1993 | { | |||
1994 | DigestHMAC_SHA1_Impl *pImpl = (DigestHMAC_SHA1_Impl*)Digest; | |||
1995 | ContextHMAC_SHA1 *ctx; | |||
1996 | ||||
1997 | if ((pImpl == NULL__null) || (pBuffer == NULL__null)) | |||
1998 | return rtl_Digest_E_Argument; | |||
1999 | ||||
2000 | if (!(pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_SHA1)) | |||
2001 | return rtl_Digest_E_Algorithm; | |||
2002 | ||||
2003 | if (!(pImpl->m_digest.m_length <= nBufLen)) | |||
2004 | return rtl_Digest_E_BufferSize; | |||
2005 | ||||
2006 | nBufLen = pImpl->m_digest.m_length; | |||
2007 | ||||
2008 | ctx = &(pImpl->m_context); | |||
2009 | rtl_digest_getSHA1 (&(ctx->m_hash), pBuffer, nBufLen); | |||
2010 | ||||
2011 | rtl_digest_updateSHA1 (&(ctx->m_hash), ctx->m_opad, sizeof(ctx->m_opad)); | |||
2012 | rtl_digest_updateSHA1 (&(ctx->m_hash), pBuffer, nBufLen); | |||
2013 | rtl_digest_getSHA1 (&(ctx->m_hash), pBuffer, nBufLen); | |||
2014 | ||||
2015 | __rtl_digest_opadHMAC_SHA1 (ctx); | |||
2016 | __rtl_digest_ipadHMAC_SHA1 (ctx); | |||
2017 | __rtl_digest_opadHMAC_SHA1 (ctx); | |||
2018 | ||||
2019 | return rtl_Digest_E_None; | |||
2020 | } | |||
2021 | ||||
2022 | /* | |||
2023 | * rtl_digest_destroyHMAC_SHA1. | |||
2024 | */ | |||
2025 | void SAL_CALL rtl_digest_destroyHMAC_SHA1 (rtlDigest Digest) | |||
2026 | SAL_THROW_EXTERN_C()throw () | |||
2027 | { | |||
2028 | DigestHMAC_SHA1_Impl *pImpl = (DigestHMAC_SHA1_Impl*)Digest; | |||
2029 | if (pImpl) | |||
2030 | { | |||
2031 | if (pImpl->m_digest.m_algorithm == rtl_Digest_AlgorithmHMAC_SHA1) | |||
2032 | rtl_freeZeroMemory (pImpl, sizeof (DigestHMAC_SHA1_Impl)); | |||
2033 | else | |||
2034 | rtl_freeMemory (pImpl); | |||
2035 | } | |||
2036 | } | |||
2037 | ||||
2038 | /*======================================================================== | |||
2039 | * | |||
2040 | * rtl_digest_PBKDF2 internals. | |||
2041 | * | |||
2042 | *======================================================================*/ | |||
2043 | #define DIGEST_CBLOCK_PBKDF220 RTL_DIGEST_LENGTH_HMAC_SHA120 | |||
2044 | ||||
2045 | /* | |||
2046 | * __rtl_digest_updatePBKDF2. | |||
2047 | */ | |||
2048 | static void __rtl_digest_updatePBKDF2 ( | |||
2049 | rtlDigest hDigest, | |||
2050 | sal_uInt8 T[DIGEST_CBLOCK_PBKDF220], | |||
2051 | const sal_uInt8 *pSaltData, sal_uInt32 nSaltLen, | |||
2052 | sal_uInt32 nCount, sal_uInt32 nIndex) | |||
2053 | { | |||
2054 | /* T_i = F (P, S, c, i) */ | |||
2055 | sal_uInt8 U[DIGEST_CBLOCK_PBKDF220]; | |||
2056 | sal_uInt32 i, k; | |||
2057 | ||||
2058 | /* U_(1) = PRF (P, S || INDEX) */ | |||
2059 | rtl_digest_updateHMAC_SHA1 (hDigest, pSaltData, nSaltLen); | |||
2060 | rtl_digest_updateHMAC_SHA1 (hDigest, &nIndex, sizeof(nIndex)); | |||
2061 | rtl_digest_getHMAC_SHA1 (hDigest, U, DIGEST_CBLOCK_PBKDF220); | |||
2062 | ||||
2063 | /* T = U_(1) */ | |||
2064 | for (k = 0; k < DIGEST_CBLOCK_PBKDF220; k++) T[k] = U[k]; | |||
| ||||
2065 | ||||
2066 | /* T ^= U_(2) ^ ... ^ U_(c) */ | |||
2067 | for (i = 1; i < nCount; i++) | |||
2068 | { | |||
2069 | /* U_(i) = PRF (P, U_(i-1)) */ | |||
2070 | rtl_digest_updateHMAC_SHA1 (hDigest, U, DIGEST_CBLOCK_PBKDF220); | |||
2071 | rtl_digest_getHMAC_SHA1 (hDigest, U, DIGEST_CBLOCK_PBKDF220); | |||
2072 | ||||
2073 | /* T ^= U_(i) */ | |||
2074 | for (k = 0; k < DIGEST_CBLOCK_PBKDF220; k++) T[k] ^= U[k]; | |||
2075 | } | |||
2076 | ||||
2077 | memset (U, 0, DIGEST_CBLOCK_PBKDF220); | |||
2078 | } | |||
2079 | ||||
2080 | /*======================================================================== | |||
2081 | * | |||
2082 | * rtl_digest_PBKDF2 implementation. | |||
2083 | * | |||
2084 | *======================================================================*/ | |||
2085 | /* | |||
2086 | * rtl_digest_PBKDF2. | |||
2087 | */ | |||
2088 | rtlDigestError SAL_CALL rtl_digest_PBKDF2 ( | |||
2089 | sal_uInt8 *pKeyData , sal_uInt32 nKeyLen, | |||
2090 | const sal_uInt8 *pPassData, sal_uInt32 nPassLen, | |||
2091 | const sal_uInt8 *pSaltData, sal_uInt32 nSaltLen, | |||
2092 | sal_uInt32 nCount) SAL_THROW_EXTERN_C()throw () | |||
2093 | { | |||
2094 | DigestHMAC_SHA1_Impl digest; | |||
2095 | sal_uInt32 i = 1; | |||
2096 | ||||
2097 | if ((pKeyData == NULL__null) || (pPassData == NULL__null) || (pSaltData == NULL__null)) | |||
| ||||
2098 | return rtl_Digest_E_Argument; | |||
2099 | ||||
2100 | digest.m_digest = __rtl_digest_HMAC_SHA1; | |||
2101 | rtl_digest_initHMAC_SHA1 (&digest, pPassData, nPassLen); | |||
2102 | ||||
2103 | /* DK = T_(1) || T_(2) || ... || T_(l) */ | |||
2104 | while (nKeyLen >= DIGEST_CBLOCK_PBKDF220) | |||
2105 | { | |||
2106 | /* T_(i) = F (P, S, c, i); DK ||= T_(i) */ | |||
2107 | __rtl_digest_updatePBKDF2 ( | |||
2108 | &digest, pKeyData, | |||
2109 | pSaltData, nSaltLen, | |||
2110 | nCount, OSL_NETDWORD(i)((sal_uInt32)((((sal_uInt16)((((sal_uInt8)(((sal_uInt16)(((sal_uInt16 )(((sal_uInt32)(i) >> 16) & 0xFFFF))) >> 8) & 0xFF))) & 0xFF) | (((sal_uInt16)(((sal_uInt8)((sal_uInt16 )(((sal_uInt16)(((sal_uInt32)(i) >> 16) & 0xFFFF))) & 0xFF))) & 0xFF) << 8))) & 0xFFFF) | (((sal_uInt32 )(((sal_uInt16)((((sal_uInt8)(((sal_uInt16)(((sal_uInt16)((sal_uInt32 )(i) & 0xFFFF))) >> 8) & 0xFF))) & 0xFF) | ( ((sal_uInt16)(((sal_uInt8)((sal_uInt16)(((sal_uInt16)((sal_uInt32 )(i) & 0xFFFF))) & 0xFF))) & 0xFF) << 8))) & 0xFFFF) << 16))); | |||
2111 | ||||
2112 | /* Next 'KeyData' block */ | |||
2113 | pKeyData += DIGEST_CBLOCK_PBKDF220; | |||
2114 | nKeyLen -= DIGEST_CBLOCK_PBKDF220; | |||
2115 | i += 1; | |||
2116 | } | |||
2117 | if (nKeyLen > 0) | |||
2118 | { | |||
2119 | /* Last 'KeyData' block */ | |||
2120 | sal_uInt8 T[DIGEST_CBLOCK_PBKDF220]; | |||
2121 | ||||
2122 | /* T_i = F (P, S, c, i) */ | |||
2123 | __rtl_digest_updatePBKDF2 ( | |||
2124 | &digest, T, | |||
2125 | pSaltData, nSaltLen, | |||
2126 | nCount, OSL_NETDWORD(i)((sal_uInt32)((((sal_uInt16)((((sal_uInt8)(((sal_uInt16)(((sal_uInt16 )(((sal_uInt32)(i) >> 16) & 0xFFFF))) >> 8) & 0xFF))) & 0xFF) | (((sal_uInt16)(((sal_uInt8)((sal_uInt16 )(((sal_uInt16)(((sal_uInt32)(i) >> 16) & 0xFFFF))) & 0xFF))) & 0xFF) << 8))) & 0xFFFF) | (((sal_uInt32 )(((sal_uInt16)((((sal_uInt8)(((sal_uInt16)(((sal_uInt16)((sal_uInt32 )(i) & 0xFFFF))) >> 8) & 0xFF))) & 0xFF) | ( ((sal_uInt16)(((sal_uInt8)((sal_uInt16)(((sal_uInt16)((sal_uInt32 )(i) & 0xFFFF))) & 0xFF))) & 0xFF) << 8))) & 0xFFFF) << 16))); | |||
2127 | ||||
2128 | /* DK ||= T_(i) */ | |||
2129 | memcpy (pKeyData, T, nKeyLen); | |||
2130 | memset (T, 0, DIGEST_CBLOCK_PBKDF220); | |||
2131 | } | |||
2132 | ||||
2133 | memset (&digest, 0, sizeof (digest)); | |||
2134 | return rtl_Digest_E_None; | |||
2135 | } | |||
2136 | ||||
2137 | /*======================================================================== | |||
2138 | * | |||
2139 | * The End. | |||
2140 | * | |||
2141 | *======================================================================*/ | |||
2142 | ||||
2143 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |