|
|
1.1.1.6 root 1: // RIPEMD-160 written and placed in the public domain by Wei Dai
2:
1.1 root 3: /*
1.1.1.6 root 4: * This code implements the MD4 message-digest algorithm.
5: * The algorithm is due to Ron Rivest. This code was
6: * written by Colin Plumb in 1993, no copyright is claimed.
7: * This code is in the public domain; do with it what you wish.
1.1 root 8: */
9:
1.1.1.9 root 10: /* Adapted for TrueCrypt */
1.1.1.3 root 11:
1.1 root 12: #include <memory.h>
1.1.1.6 root 13: #include "Common/Tcdefs.h"
14: #include "Common/Endian.h"
15: #include "Rmd160.h"
1.1 root 16:
1.1.1.6 root 17: #define F(x, y, z) (x ^ y ^ z)
18: #define G(x, y, z) (z ^ (x & (y^z)))
19: #define H(x, y, z) (z ^ (x | ~y))
20: #define I(x, y, z) (y ^ (z & (x^y)))
21: #define J(x, y, z) (x ^ (y | ~z))
22:
23: #define PUT_64BIT_LE(cp, value) do { \
24: (cp)[7] = (byte) ((value) >> 56); \
25: (cp)[6] = (byte) ((value) >> 48); \
26: (cp)[5] = (byte) ((value) >> 40); \
27: (cp)[4] = (byte) ((value) >> 32); \
28: (cp)[3] = (byte) ((value) >> 24); \
29: (cp)[2] = (byte) ((value) >> 16); \
30: (cp)[1] = (byte) ((value) >> 8); \
31: (cp)[0] = (byte) (value); } while (0)
32:
33: #define PUT_32BIT_LE(cp, value) do { \
34: (cp)[3] = (byte) ((value) >> 24); \
35: (cp)[2] = (byte) ((value) >> 16); \
36: (cp)[1] = (byte) ((value) >> 8); \
37: (cp)[0] = (byte) (value); } while (0)
1.1 root 38:
1.1.1.3 root 39: #ifndef TC_MINIMIZE_CODE_SIZE
40:
1.1.1.6 root 41: static byte PADDING[64] = {
1.1 root 42: 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
45: };
46:
1.1.1.3 root 47: #else
48:
1.1.1.6 root 49: static byte PADDING[64];
1.1.1.3 root 50:
1.1.1.6 root 51: #endif
1.1.1.3 root 52:
1.1.1.6 root 53: void RMD160Init (RMD160_CTX *ctx)
1.1 root 54: {
55: ctx->count = 0;
1.1.1.6 root 56: ctx->state[0] = 0x67452301;
57: ctx->state[1] = 0xefcdab89;
58: ctx->state[2] = 0x98badcfe;
59: ctx->state[3] = 0x10325476;
60: ctx->state[4] = 0xc3d2e1f0;
1.1.1.3 root 61: PADDING[0] = 0x80;
1.1 root 62: }
63:
1.1.1.6 root 64: /*
65: * Update context to reflect the concatenation of another buffer full
66: * of bytes.
67: */
1.1.1.8 root 68: void RMD160Update (RMD160_CTX *ctx, const unsigned char *input, unsigned __int32 lenArg)
1.1 root 69: {
1.1.1.8 root 70: #ifndef TC_WINDOWS_BOOT
71: uint64 len = lenArg, have, need;
72: #else
73: uint16 len = (uint16) lenArg, have, need;
74: #endif
1.1.1.6 root 75:
76: /* Check how many bytes we already have and how many more we need. */
1.1.1.8 root 77: have = ((ctx->count >> 3) & (RIPEMD160_BLOCK_LENGTH - 1));
1.1.1.6 root 78: need = RIPEMD160_BLOCK_LENGTH - have;
1.1 root 79:
1.1.1.6 root 80: /* Update bitcount */
1.1.1.8 root 81: ctx->count += len << 3;
1.1 root 82:
83: if (len >= need) {
1.1.1.6 root 84: if (have != 0) {
1.1.1.8 root 85: memcpy (ctx->buffer + have, input, (size_t) need);
1.1.1.6 root 86: RMD160Transform ((uint32 *) ctx->state, (const uint32 *) ctx->buffer);
87: input += need;
88: len -= need;
1.1 root 89: have = 0;
90: }
1.1.1.6 root 91:
92: /* Process data in RIPEMD160_BLOCK_LENGTH-byte chunks. */
93: while (len >= RIPEMD160_BLOCK_LENGTH) {
94: RMD160Transform ((uint32 *) ctx->state, (const uint32 *) input);
95: input += RIPEMD160_BLOCK_LENGTH;
96: len -= RIPEMD160_BLOCK_LENGTH;
1.1 root 97: }
98: }
1.1.1.6 root 99:
100: /* Handle any remaining bytes of data. */
101: if (len != 0)
102: memcpy (ctx->buffer + have, input, (size_t) len);
1.1 root 103: }
104:
1.1.1.6 root 105: /*
106: * Pad pad to 64-byte boundary with the bit pattern
107: * 1 0* (64-bit count of bits processed, MSB-first)
108: */
109: static void RMD160Pad(RMD160_CTX *ctx)
1.1 root 110: {
1.1.1.6 root 111: byte count[8];
1.1.1.8 root 112: uint32 padlen;
1.1.1.6 root 113:
114: /* Convert count to 8 bytes in little endian order. */
1.1 root 115:
1.1.1.8 root 116: #ifndef TC_WINDOWS_BOOT
1.1.1.6 root 117: PUT_64BIT_LE(count, ctx->count);
1.1.1.3 root 118: #else
1.1.1.8 root 119: *(uint32 *) (count + 4) = 0;
120: *(uint16 *) (count + 2) = 0;
121: *(uint16 *) (count + 0) = ctx->count;
1.1.1.3 root 122: #endif
1.1.1.6 root 123:
124: /* Pad out to 56 mod 64. */
125: padlen = RIPEMD160_BLOCK_LENGTH -
1.1.1.8 root 126: (uint32)((ctx->count >> 3) & (RIPEMD160_BLOCK_LENGTH - 1));
1.1 root 127: if (padlen < 1 + 8)
1.1.1.6 root 128: padlen += RIPEMD160_BLOCK_LENGTH;
129: RMD160Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */
130: RMD160Update(ctx, count, 8);
131: }
1.1 root 132:
1.1.1.6 root 133: /*
134: * Final wrapup--call RMD160Pad, fill in digest and zero out ctx.
135: */
136: void RMD160Final(unsigned char *digest, RMD160_CTX *ctx)
137: {
138: int i;
1.1 root 139:
1.1.1.6 root 140: RMD160Pad(ctx);
141: if (digest) {
142: for (i = 0; i < 5; i++)
143: PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
144: memset (ctx, 0, sizeof(*ctx));
145: }
1.1 root 146: }
147:
1.1.1.6 root 148:
1.1.1.3 root 149: #ifndef TC_MINIMIZE_CODE_SIZE
150:
1.1.1.6 root 151: #define word32 unsigned __int32
152:
153: #define k0 0
154: #define k1 0x5a827999UL
155: #define k2 0x6ed9eba1UL
156: #define k3 0x8f1bbcdcUL
157: #define k4 0xa953fd4eUL
158: #define k5 0x50a28be6UL
159: #define k6 0x5c4dd124UL
160: #define k7 0x6d703ef3UL
161: #define k8 0x7a6d76e9UL
162: #define k9 0
163:
164: static word32 rotlFixed (word32 x, unsigned int y)
1.1 root 165: {
1.1.1.6 root 166: return (word32)((x<<y) | (x>>(sizeof(word32)*8-y)));
167: }
1.1 root 168:
1.1.1.6 root 169: #define Subround(f, a, b, c, d, e, x, s, k) \
170: a += f(b, c, d) + x + k;\
171: a = rotlFixed((word32)a, s) + e;\
172: c = rotlFixed((word32)c, 10U)
173:
174: void RMD160Transform (unsigned __int32 *digest, const unsigned __int32 *data)
175: {
1.1 root 176: #if BYTE_ORDER == LITTLE_ENDIAN
1.1.1.6 root 177: const word32 *X = data;
1.1 root 178: #else
1.1.1.6 root 179: word32 X[16];
1.1 root 180: int i;
181: #endif
182:
1.1.1.6 root 183: word32 a1, b1, c1, d1, e1, a2, b2, c2, d2, e2;
184: a1 = a2 = digest[0];
185: b1 = b2 = digest[1];
186: c1 = c2 = digest[2];
187: d1 = d2 = digest[3];
188: e1 = e2 = digest[4];
1.1 root 189:
1.1.1.6 root 190: #if BYTE_ORDER == BIG_ENDIAN
191: for (i = 0; i < 16; i++)
192: {
193: X[i] = LE32 (data[i]);
194: }
195: #endif
1.1 root 196:
1.1.1.6 root 197: Subround(F, a1, b1, c1, d1, e1, X[ 0], 11, k0);
198: Subround(F, e1, a1, b1, c1, d1, X[ 1], 14, k0);
199: Subround(F, d1, e1, a1, b1, c1, X[ 2], 15, k0);
200: Subround(F, c1, d1, e1, a1, b1, X[ 3], 12, k0);
201: Subround(F, b1, c1, d1, e1, a1, X[ 4], 5, k0);
202: Subround(F, a1, b1, c1, d1, e1, X[ 5], 8, k0);
203: Subround(F, e1, a1, b1, c1, d1, X[ 6], 7, k0);
204: Subround(F, d1, e1, a1, b1, c1, X[ 7], 9, k0);
205: Subround(F, c1, d1, e1, a1, b1, X[ 8], 11, k0);
206: Subround(F, b1, c1, d1, e1, a1, X[ 9], 13, k0);
207: Subround(F, a1, b1, c1, d1, e1, X[10], 14, k0);
208: Subround(F, e1, a1, b1, c1, d1, X[11], 15, k0);
209: Subround(F, d1, e1, a1, b1, c1, X[12], 6, k0);
210: Subround(F, c1, d1, e1, a1, b1, X[13], 7, k0);
211: Subround(F, b1, c1, d1, e1, a1, X[14], 9, k0);
212: Subround(F, a1, b1, c1, d1, e1, X[15], 8, k0);
213:
214: Subround(G, e1, a1, b1, c1, d1, X[ 7], 7, k1);
215: Subround(G, d1, e1, a1, b1, c1, X[ 4], 6, k1);
216: Subround(G, c1, d1, e1, a1, b1, X[13], 8, k1);
217: Subround(G, b1, c1, d1, e1, a1, X[ 1], 13, k1);
218: Subround(G, a1, b1, c1, d1, e1, X[10], 11, k1);
219: Subround(G, e1, a1, b1, c1, d1, X[ 6], 9, k1);
220: Subround(G, d1, e1, a1, b1, c1, X[15], 7, k1);
221: Subround(G, c1, d1, e1, a1, b1, X[ 3], 15, k1);
222: Subround(G, b1, c1, d1, e1, a1, X[12], 7, k1);
223: Subround(G, a1, b1, c1, d1, e1, X[ 0], 12, k1);
224: Subround(G, e1, a1, b1, c1, d1, X[ 9], 15, k1);
225: Subround(G, d1, e1, a1, b1, c1, X[ 5], 9, k1);
226: Subround(G, c1, d1, e1, a1, b1, X[ 2], 11, k1);
227: Subround(G, b1, c1, d1, e1, a1, X[14], 7, k1);
228: Subround(G, a1, b1, c1, d1, e1, X[11], 13, k1);
229: Subround(G, e1, a1, b1, c1, d1, X[ 8], 12, k1);
230:
231: Subround(H, d1, e1, a1, b1, c1, X[ 3], 11, k2);
232: Subround(H, c1, d1, e1, a1, b1, X[10], 13, k2);
233: Subround(H, b1, c1, d1, e1, a1, X[14], 6, k2);
234: Subround(H, a1, b1, c1, d1, e1, X[ 4], 7, k2);
235: Subround(H, e1, a1, b1, c1, d1, X[ 9], 14, k2);
236: Subround(H, d1, e1, a1, b1, c1, X[15], 9, k2);
237: Subround(H, c1, d1, e1, a1, b1, X[ 8], 13, k2);
238: Subround(H, b1, c1, d1, e1, a1, X[ 1], 15, k2);
239: Subround(H, a1, b1, c1, d1, e1, X[ 2], 14, k2);
240: Subround(H, e1, a1, b1, c1, d1, X[ 7], 8, k2);
241: Subround(H, d1, e1, a1, b1, c1, X[ 0], 13, k2);
242: Subround(H, c1, d1, e1, a1, b1, X[ 6], 6, k2);
243: Subround(H, b1, c1, d1, e1, a1, X[13], 5, k2);
244: Subround(H, a1, b1, c1, d1, e1, X[11], 12, k2);
245: Subround(H, e1, a1, b1, c1, d1, X[ 5], 7, k2);
246: Subround(H, d1, e1, a1, b1, c1, X[12], 5, k2);
247:
248: Subround(I, c1, d1, e1, a1, b1, X[ 1], 11, k3);
249: Subround(I, b1, c1, d1, e1, a1, X[ 9], 12, k3);
250: Subround(I, a1, b1, c1, d1, e1, X[11], 14, k3);
251: Subround(I, e1, a1, b1, c1, d1, X[10], 15, k3);
252: Subround(I, d1, e1, a1, b1, c1, X[ 0], 14, k3);
253: Subround(I, c1, d1, e1, a1, b1, X[ 8], 15, k3);
254: Subround(I, b1, c1, d1, e1, a1, X[12], 9, k3);
255: Subround(I, a1, b1, c1, d1, e1, X[ 4], 8, k3);
256: Subround(I, e1, a1, b1, c1, d1, X[13], 9, k3);
257: Subround(I, d1, e1, a1, b1, c1, X[ 3], 14, k3);
258: Subround(I, c1, d1, e1, a1, b1, X[ 7], 5, k3);
259: Subround(I, b1, c1, d1, e1, a1, X[15], 6, k3);
260: Subround(I, a1, b1, c1, d1, e1, X[14], 8, k3);
261: Subround(I, e1, a1, b1, c1, d1, X[ 5], 6, k3);
262: Subround(I, d1, e1, a1, b1, c1, X[ 6], 5, k3);
263: Subround(I, c1, d1, e1, a1, b1, X[ 2], 12, k3);
264:
265: Subround(J, b1, c1, d1, e1, a1, X[ 4], 9, k4);
266: Subround(J, a1, b1, c1, d1, e1, X[ 0], 15, k4);
267: Subround(J, e1, a1, b1, c1, d1, X[ 5], 5, k4);
268: Subround(J, d1, e1, a1, b1, c1, X[ 9], 11, k4);
269: Subround(J, c1, d1, e1, a1, b1, X[ 7], 6, k4);
270: Subround(J, b1, c1, d1, e1, a1, X[12], 8, k4);
271: Subround(J, a1, b1, c1, d1, e1, X[ 2], 13, k4);
272: Subround(J, e1, a1, b1, c1, d1, X[10], 12, k4);
273: Subround(J, d1, e1, a1, b1, c1, X[14], 5, k4);
274: Subround(J, c1, d1, e1, a1, b1, X[ 1], 12, k4);
275: Subround(J, b1, c1, d1, e1, a1, X[ 3], 13, k4);
276: Subround(J, a1, b1, c1, d1, e1, X[ 8], 14, k4);
277: Subround(J, e1, a1, b1, c1, d1, X[11], 11, k4);
278: Subround(J, d1, e1, a1, b1, c1, X[ 6], 8, k4);
279: Subround(J, c1, d1, e1, a1, b1, X[15], 5, k4);
280: Subround(J, b1, c1, d1, e1, a1, X[13], 6, k4);
281:
282: Subround(J, a2, b2, c2, d2, e2, X[ 5], 8, k5);
283: Subround(J, e2, a2, b2, c2, d2, X[14], 9, k5);
284: Subround(J, d2, e2, a2, b2, c2, X[ 7], 9, k5);
285: Subround(J, c2, d2, e2, a2, b2, X[ 0], 11, k5);
286: Subround(J, b2, c2, d2, e2, a2, X[ 9], 13, k5);
287: Subround(J, a2, b2, c2, d2, e2, X[ 2], 15, k5);
288: Subround(J, e2, a2, b2, c2, d2, X[11], 15, k5);
289: Subround(J, d2, e2, a2, b2, c2, X[ 4], 5, k5);
290: Subround(J, c2, d2, e2, a2, b2, X[13], 7, k5);
291: Subround(J, b2, c2, d2, e2, a2, X[ 6], 7, k5);
292: Subround(J, a2, b2, c2, d2, e2, X[15], 8, k5);
293: Subround(J, e2, a2, b2, c2, d2, X[ 8], 11, k5);
294: Subround(J, d2, e2, a2, b2, c2, X[ 1], 14, k5);
295: Subround(J, c2, d2, e2, a2, b2, X[10], 14, k5);
296: Subround(J, b2, c2, d2, e2, a2, X[ 3], 12, k5);
297: Subround(J, a2, b2, c2, d2, e2, X[12], 6, k5);
298:
299: Subround(I, e2, a2, b2, c2, d2, X[ 6], 9, k6);
300: Subround(I, d2, e2, a2, b2, c2, X[11], 13, k6);
301: Subround(I, c2, d2, e2, a2, b2, X[ 3], 15, k6);
302: Subround(I, b2, c2, d2, e2, a2, X[ 7], 7, k6);
303: Subround(I, a2, b2, c2, d2, e2, X[ 0], 12, k6);
304: Subround(I, e2, a2, b2, c2, d2, X[13], 8, k6);
305: Subround(I, d2, e2, a2, b2, c2, X[ 5], 9, k6);
306: Subround(I, c2, d2, e2, a2, b2, X[10], 11, k6);
307: Subround(I, b2, c2, d2, e2, a2, X[14], 7, k6);
308: Subround(I, a2, b2, c2, d2, e2, X[15], 7, k6);
309: Subround(I, e2, a2, b2, c2, d2, X[ 8], 12, k6);
310: Subround(I, d2, e2, a2, b2, c2, X[12], 7, k6);
311: Subround(I, c2, d2, e2, a2, b2, X[ 4], 6, k6);
312: Subround(I, b2, c2, d2, e2, a2, X[ 9], 15, k6);
313: Subround(I, a2, b2, c2, d2, e2, X[ 1], 13, k6);
314: Subround(I, e2, a2, b2, c2, d2, X[ 2], 11, k6);
315:
316: Subround(H, d2, e2, a2, b2, c2, X[15], 9, k7);
317: Subround(H, c2, d2, e2, a2, b2, X[ 5], 7, k7);
318: Subround(H, b2, c2, d2, e2, a2, X[ 1], 15, k7);
319: Subround(H, a2, b2, c2, d2, e2, X[ 3], 11, k7);
320: Subround(H, e2, a2, b2, c2, d2, X[ 7], 8, k7);
321: Subround(H, d2, e2, a2, b2, c2, X[14], 6, k7);
322: Subround(H, c2, d2, e2, a2, b2, X[ 6], 6, k7);
323: Subround(H, b2, c2, d2, e2, a2, X[ 9], 14, k7);
324: Subround(H, a2, b2, c2, d2, e2, X[11], 12, k7);
325: Subround(H, e2, a2, b2, c2, d2, X[ 8], 13, k7);
326: Subround(H, d2, e2, a2, b2, c2, X[12], 5, k7);
327: Subround(H, c2, d2, e2, a2, b2, X[ 2], 14, k7);
328: Subround(H, b2, c2, d2, e2, a2, X[10], 13, k7);
329: Subround(H, a2, b2, c2, d2, e2, X[ 0], 13, k7);
330: Subround(H, e2, a2, b2, c2, d2, X[ 4], 7, k7);
331: Subround(H, d2, e2, a2, b2, c2, X[13], 5, k7);
332:
333: Subround(G, c2, d2, e2, a2, b2, X[ 8], 15, k8);
334: Subround(G, b2, c2, d2, e2, a2, X[ 6], 5, k8);
335: Subround(G, a2, b2, c2, d2, e2, X[ 4], 8, k8);
336: Subround(G, e2, a2, b2, c2, d2, X[ 1], 11, k8);
337: Subround(G, d2, e2, a2, b2, c2, X[ 3], 14, k8);
338: Subround(G, c2, d2, e2, a2, b2, X[11], 14, k8);
339: Subround(G, b2, c2, d2, e2, a2, X[15], 6, k8);
340: Subround(G, a2, b2, c2, d2, e2, X[ 0], 14, k8);
341: Subround(G, e2, a2, b2, c2, d2, X[ 5], 6, k8);
342: Subround(G, d2, e2, a2, b2, c2, X[12], 9, k8);
343: Subround(G, c2, d2, e2, a2, b2, X[ 2], 12, k8);
344: Subround(G, b2, c2, d2, e2, a2, X[13], 9, k8);
345: Subround(G, a2, b2, c2, d2, e2, X[ 9], 12, k8);
346: Subround(G, e2, a2, b2, c2, d2, X[ 7], 5, k8);
347: Subround(G, d2, e2, a2, b2, c2, X[10], 15, k8);
348: Subround(G, c2, d2, e2, a2, b2, X[14], 8, k8);
349:
350: Subround(F, b2, c2, d2, e2, a2, X[12], 8, k9);
351: Subround(F, a2, b2, c2, d2, e2, X[15], 5, k9);
352: Subround(F, e2, a2, b2, c2, d2, X[10], 12, k9);
353: Subround(F, d2, e2, a2, b2, c2, X[ 4], 9, k9);
354: Subround(F, c2, d2, e2, a2, b2, X[ 1], 12, k9);
355: Subround(F, b2, c2, d2, e2, a2, X[ 5], 5, k9);
356: Subround(F, a2, b2, c2, d2, e2, X[ 8], 14, k9);
357: Subround(F, e2, a2, b2, c2, d2, X[ 7], 6, k9);
358: Subround(F, d2, e2, a2, b2, c2, X[ 6], 8, k9);
359: Subround(F, c2, d2, e2, a2, b2, X[ 2], 13, k9);
360: Subround(F, b2, c2, d2, e2, a2, X[13], 6, k9);
361: Subround(F, a2, b2, c2, d2, e2, X[14], 5, k9);
362: Subround(F, e2, a2, b2, c2, d2, X[ 0], 15, k9);
363: Subround(F, d2, e2, a2, b2, c2, X[ 3], 13, k9);
364: Subround(F, c2, d2, e2, a2, b2, X[ 9], 11, k9);
365: Subround(F, b2, c2, d2, e2, a2, X[11], 11, k9);
366:
367: c1 = digest[1] + c1 + d2;
368: digest[1] = digest[2] + d1 + e2;
369: digest[2] = digest[3] + e1 + a2;
370: digest[3] = digest[4] + a1 + b2;
371: digest[4] = digest[0] + b1 + c2;
372: digest[0] = c1;
1.1 root 373: }
1.1.1.3 root 374:
375: #else // TC_MINIMIZE_CODE_SIZE
376:
377: /*
1.1.1.9 root 378: Copyright (c) 2008 TrueCrypt Developers Association. All rights reserved.
1.1.1.3 root 379:
1.1.1.10! root 380: Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.9 root 381: the file License.txt included in TrueCrypt binary and source code distribution
382: packages.
1.1.1.3 root 383: */
384:
1.1.1.4 root 385: #pragma optimize ("tl", on)
386:
1.1.1.3 root 387: typedef unsigned __int32 uint32;
388: typedef unsigned __int8 byte;
389:
1.1.1.6 root 390: #include <stdlib.h>
391: #pragma intrinsic (_lrotl)
392:
1.1.1.3 root 393: static const byte OrderTab[] = {
394: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
395: 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
396: 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
397: 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
398: 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13,
399: 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
400: 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
401: 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
402: 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
403: 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
404: };
405:
406: static const byte RolTab[] = {
407: 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
408: 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
409: 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
410: 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
411: 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6,
412: 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
413: 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
414: 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
415: 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
416: 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
417: };
418:
419: static const uint32 KTab[] = {
420: 0x00000000UL,
421: 0x5A827999UL,
422: 0x6ED9EBA1UL,
423: 0x8F1BBCDCUL,
424: 0xA953FD4EUL,
425: 0x50A28BE6UL,
426: 0x5C4DD124UL,
427: 0x6D703EF3UL,
428: 0x7A6D76E9UL,
429: 0x00000000UL
430: };
431:
432:
1.1.1.6 root 433: void RMD160Transform (unsigned __int32 *state, const unsigned __int32 *data)
1.1.1.3 root 434: {
435: uint32 a, b, c, d, e;
436: uint32 a2, b2, c2, d2, e2;
437: byte pos;
438: uint32 tmp;
439:
440: a = state[0];
441: b = state[1];
442: c = state[2];
443: d = state[3];
444: e = state[4];
445:
446: for (pos = 0; pos < 160; ++pos)
447: {
448: tmp = a + data[OrderTab[pos]] + KTab[pos >> 4];
449:
450: switch (pos >> 4)
451: {
1.1.1.6 root 452: case 0: case 9: tmp += F (b, c, d); break;
453: case 1: case 8: tmp += G (b, c, d); break;
454: case 2: case 7: tmp += H (b, c, d); break;
455: case 3: case 6: tmp += I (b, c, d); break;
456: case 4: case 5: tmp += J (b, c, d); break;
1.1.1.3 root 457: }
458:
1.1.1.6 root 459: tmp = _lrotl (tmp, RolTab[pos]) + e;
1.1.1.3 root 460: a = e;
461: e = d;
1.1.1.6 root 462: d = _lrotl (c, 10);
1.1.1.3 root 463: c = b;
464: b = tmp;
465:
466: if (pos == 79)
467: {
468: a2 = a;
469: b2 = b;
470: c2 = c;
471: d2 = d;
472: e2 = e;
473:
474: a = state[0];
475: b = state[1];
476: c = state[2];
477: d = state[3];
478: e = state[4];
479: }
480: }
481:
482: tmp = state[1] + c2 + d;
483: state[1] = state[2] + d2 + e;
484: state[2] = state[3] + e2 + a;
485: state[3] = state[4] + a2 + b;
486: state[4] = state[0] + b2 + c;
487: state[0] = tmp;
488: }
489:
490: #endif // TC_MINIMIZE_CODE_SIZE
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.