001: package org.bouncycastle.crypto.digests;
002:
003: /**
004: * implementation of RIPEMD see,
005: * http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
006: */
007: public class RIPEMD160Digest extends GeneralDigest {
008: private static final int DIGEST_LENGTH = 20;
009:
010: private int H0, H1, H2, H3, H4; // IV's
011:
012: private int[] X = new int[16];
013: private int xOff;
014:
015: /**
016: * Standard constructor
017: */
018: public RIPEMD160Digest() {
019: reset();
020: }
021:
022: /**
023: * Copy constructor. This will copy the state of the provided
024: * message digest.
025: */
026: public RIPEMD160Digest(RIPEMD160Digest t) {
027: super (t);
028:
029: H0 = t.H0;
030: H1 = t.H1;
031: H2 = t.H2;
032: H3 = t.H3;
033: H4 = t.H4;
034:
035: System.arraycopy(t.X, 0, X, 0, t.X.length);
036: xOff = t.xOff;
037: }
038:
039: public String getAlgorithmName() {
040: return "RIPEMD160";
041: }
042:
043: public int getDigestSize() {
044: return DIGEST_LENGTH;
045: }
046:
047: protected void processWord(byte[] in, int inOff) {
048: X[xOff++] = (in[inOff] & 0xff) | ((in[inOff + 1] & 0xff) << 8)
049: | ((in[inOff + 2] & 0xff) << 16)
050: | ((in[inOff + 3] & 0xff) << 24);
051:
052: if (xOff == 16) {
053: processBlock();
054: }
055: }
056:
057: protected void processLength(long bitLength) {
058: if (xOff > 14) {
059: processBlock();
060: }
061:
062: X[14] = (int) (bitLength & 0xffffffff);
063: X[15] = (int) (bitLength >>> 32);
064: }
065:
066: private void unpackWord(int word, byte[] out, int outOff) {
067: out[outOff] = (byte) word;
068: out[outOff + 1] = (byte) (word >>> 8);
069: out[outOff + 2] = (byte) (word >>> 16);
070: out[outOff + 3] = (byte) (word >>> 24);
071: }
072:
073: public int doFinal(byte[] out, int outOff) {
074: finish();
075:
076: unpackWord(H0, out, outOff);
077: unpackWord(H1, out, outOff + 4);
078: unpackWord(H2, out, outOff + 8);
079: unpackWord(H3, out, outOff + 12);
080: unpackWord(H4, out, outOff + 16);
081:
082: reset();
083:
084: return DIGEST_LENGTH;
085: }
086:
087: /**
088: * reset the chaining variables to the IV values.
089: */
090: public void reset() {
091: super .reset();
092:
093: H0 = 0x67452301;
094: H1 = 0xefcdab89;
095: H2 = 0x98badcfe;
096: H3 = 0x10325476;
097: H4 = 0xc3d2e1f0;
098:
099: xOff = 0;
100:
101: for (int i = 0; i != X.length; i++) {
102: X[i] = 0;
103: }
104: }
105:
106: /*
107: * rotate int x left n bits.
108: */
109: private final int RL(int x, int n) {
110: return (x << n) | (x >>> (32 - n));
111: }
112:
113: /*
114: * f1,f2,f3,f4,f5 are the basic RIPEMD160 functions.
115: */
116:
117: /*
118: * rounds 0-15
119: */
120: private final int f1(int x, int y, int z) {
121: return x ^ y ^ z;
122: }
123:
124: /*
125: * rounds 16-31
126: */
127: private final int f2(int x, int y, int z) {
128: return (x & y) | (~x & z);
129: }
130:
131: /*
132: * rounds 32-47
133: */
134: private final int f3(int x, int y, int z) {
135: return (x | ~y) ^ z;
136: }
137:
138: /*
139: * rounds 48-63
140: */
141: private final int f4(int x, int y, int z) {
142: return (x & z) | (y & ~z);
143: }
144:
145: /*
146: * rounds 64-79
147: */
148: private final int f5(int x, int y, int z) {
149: return x ^ (y | ~z);
150: }
151:
152: protected void processBlock() {
153: int a, aa;
154: int b, bb;
155: int c, cc;
156: int d, dd;
157: int e, ee;
158:
159: a = aa = H0;
160: b = bb = H1;
161: c = cc = H2;
162: d = dd = H3;
163: e = ee = H4;
164:
165: //
166: // Rounds 1 - 16
167: //
168: // left
169: a = RL(a + f1(b, c, d) + X[0], 11) + e;
170: c = RL(c, 10);
171: e = RL(e + f1(a, b, c) + X[1], 14) + d;
172: b = RL(b, 10);
173: d = RL(d + f1(e, a, b) + X[2], 15) + c;
174: a = RL(a, 10);
175: c = RL(c + f1(d, e, a) + X[3], 12) + b;
176: e = RL(e, 10);
177: b = RL(b + f1(c, d, e) + X[4], 5) + a;
178: d = RL(d, 10);
179: a = RL(a + f1(b, c, d) + X[5], 8) + e;
180: c = RL(c, 10);
181: e = RL(e + f1(a, b, c) + X[6], 7) + d;
182: b = RL(b, 10);
183: d = RL(d + f1(e, a, b) + X[7], 9) + c;
184: a = RL(a, 10);
185: c = RL(c + f1(d, e, a) + X[8], 11) + b;
186: e = RL(e, 10);
187: b = RL(b + f1(c, d, e) + X[9], 13) + a;
188: d = RL(d, 10);
189: a = RL(a + f1(b, c, d) + X[10], 14) + e;
190: c = RL(c, 10);
191: e = RL(e + f1(a, b, c) + X[11], 15) + d;
192: b = RL(b, 10);
193: d = RL(d + f1(e, a, b) + X[12], 6) + c;
194: a = RL(a, 10);
195: c = RL(c + f1(d, e, a) + X[13], 7) + b;
196: e = RL(e, 10);
197: b = RL(b + f1(c, d, e) + X[14], 9) + a;
198: d = RL(d, 10);
199: a = RL(a + f1(b, c, d) + X[15], 8) + e;
200: c = RL(c, 10);
201:
202: // right
203: aa = RL(aa + f5(bb, cc, dd) + X[5] + 0x50a28be6, 8) + ee;
204: cc = RL(cc, 10);
205: ee = RL(ee + f5(aa, bb, cc) + X[14] + 0x50a28be6, 9) + dd;
206: bb = RL(bb, 10);
207: dd = RL(dd + f5(ee, aa, bb) + X[7] + 0x50a28be6, 9) + cc;
208: aa = RL(aa, 10);
209: cc = RL(cc + f5(dd, ee, aa) + X[0] + 0x50a28be6, 11) + bb;
210: ee = RL(ee, 10);
211: bb = RL(bb + f5(cc, dd, ee) + X[9] + 0x50a28be6, 13) + aa;
212: dd = RL(dd, 10);
213: aa = RL(aa + f5(bb, cc, dd) + X[2] + 0x50a28be6, 15) + ee;
214: cc = RL(cc, 10);
215: ee = RL(ee + f5(aa, bb, cc) + X[11] + 0x50a28be6, 15) + dd;
216: bb = RL(bb, 10);
217: dd = RL(dd + f5(ee, aa, bb) + X[4] + 0x50a28be6, 5) + cc;
218: aa = RL(aa, 10);
219: cc = RL(cc + f5(dd, ee, aa) + X[13] + 0x50a28be6, 7) + bb;
220: ee = RL(ee, 10);
221: bb = RL(bb + f5(cc, dd, ee) + X[6] + 0x50a28be6, 7) + aa;
222: dd = RL(dd, 10);
223: aa = RL(aa + f5(bb, cc, dd) + X[15] + 0x50a28be6, 8) + ee;
224: cc = RL(cc, 10);
225: ee = RL(ee + f5(aa, bb, cc) + X[8] + 0x50a28be6, 11) + dd;
226: bb = RL(bb, 10);
227: dd = RL(dd + f5(ee, aa, bb) + X[1] + 0x50a28be6, 14) + cc;
228: aa = RL(aa, 10);
229: cc = RL(cc + f5(dd, ee, aa) + X[10] + 0x50a28be6, 14) + bb;
230: ee = RL(ee, 10);
231: bb = RL(bb + f5(cc, dd, ee) + X[3] + 0x50a28be6, 12) + aa;
232: dd = RL(dd, 10);
233: aa = RL(aa + f5(bb, cc, dd) + X[12] + 0x50a28be6, 6) + ee;
234: cc = RL(cc, 10);
235:
236: //
237: // Rounds 16-31
238: //
239: // left
240: e = RL(e + f2(a, b, c) + X[7] + 0x5a827999, 7) + d;
241: b = RL(b, 10);
242: d = RL(d + f2(e, a, b) + X[4] + 0x5a827999, 6) + c;
243: a = RL(a, 10);
244: c = RL(c + f2(d, e, a) + X[13] + 0x5a827999, 8) + b;
245: e = RL(e, 10);
246: b = RL(b + f2(c, d, e) + X[1] + 0x5a827999, 13) + a;
247: d = RL(d, 10);
248: a = RL(a + f2(b, c, d) + X[10] + 0x5a827999, 11) + e;
249: c = RL(c, 10);
250: e = RL(e + f2(a, b, c) + X[6] + 0x5a827999, 9) + d;
251: b = RL(b, 10);
252: d = RL(d + f2(e, a, b) + X[15] + 0x5a827999, 7) + c;
253: a = RL(a, 10);
254: c = RL(c + f2(d, e, a) + X[3] + 0x5a827999, 15) + b;
255: e = RL(e, 10);
256: b = RL(b + f2(c, d, e) + X[12] + 0x5a827999, 7) + a;
257: d = RL(d, 10);
258: a = RL(a + f2(b, c, d) + X[0] + 0x5a827999, 12) + e;
259: c = RL(c, 10);
260: e = RL(e + f2(a, b, c) + X[9] + 0x5a827999, 15) + d;
261: b = RL(b, 10);
262: d = RL(d + f2(e, a, b) + X[5] + 0x5a827999, 9) + c;
263: a = RL(a, 10);
264: c = RL(c + f2(d, e, a) + X[2] + 0x5a827999, 11) + b;
265: e = RL(e, 10);
266: b = RL(b + f2(c, d, e) + X[14] + 0x5a827999, 7) + a;
267: d = RL(d, 10);
268: a = RL(a + f2(b, c, d) + X[11] + 0x5a827999, 13) + e;
269: c = RL(c, 10);
270: e = RL(e + f2(a, b, c) + X[8] + 0x5a827999, 12) + d;
271: b = RL(b, 10);
272:
273: // right
274: ee = RL(ee + f4(aa, bb, cc) + X[6] + 0x5c4dd124, 9) + dd;
275: bb = RL(bb, 10);
276: dd = RL(dd + f4(ee, aa, bb) + X[11] + 0x5c4dd124, 13) + cc;
277: aa = RL(aa, 10);
278: cc = RL(cc + f4(dd, ee, aa) + X[3] + 0x5c4dd124, 15) + bb;
279: ee = RL(ee, 10);
280: bb = RL(bb + f4(cc, dd, ee) + X[7] + 0x5c4dd124, 7) + aa;
281: dd = RL(dd, 10);
282: aa = RL(aa + f4(bb, cc, dd) + X[0] + 0x5c4dd124, 12) + ee;
283: cc = RL(cc, 10);
284: ee = RL(ee + f4(aa, bb, cc) + X[13] + 0x5c4dd124, 8) + dd;
285: bb = RL(bb, 10);
286: dd = RL(dd + f4(ee, aa, bb) + X[5] + 0x5c4dd124, 9) + cc;
287: aa = RL(aa, 10);
288: cc = RL(cc + f4(dd, ee, aa) + X[10] + 0x5c4dd124, 11) + bb;
289: ee = RL(ee, 10);
290: bb = RL(bb + f4(cc, dd, ee) + X[14] + 0x5c4dd124, 7) + aa;
291: dd = RL(dd, 10);
292: aa = RL(aa + f4(bb, cc, dd) + X[15] + 0x5c4dd124, 7) + ee;
293: cc = RL(cc, 10);
294: ee = RL(ee + f4(aa, bb, cc) + X[8] + 0x5c4dd124, 12) + dd;
295: bb = RL(bb, 10);
296: dd = RL(dd + f4(ee, aa, bb) + X[12] + 0x5c4dd124, 7) + cc;
297: aa = RL(aa, 10);
298: cc = RL(cc + f4(dd, ee, aa) + X[4] + 0x5c4dd124, 6) + bb;
299: ee = RL(ee, 10);
300: bb = RL(bb + f4(cc, dd, ee) + X[9] + 0x5c4dd124, 15) + aa;
301: dd = RL(dd, 10);
302: aa = RL(aa + f4(bb, cc, dd) + X[1] + 0x5c4dd124, 13) + ee;
303: cc = RL(cc, 10);
304: ee = RL(ee + f4(aa, bb, cc) + X[2] + 0x5c4dd124, 11) + dd;
305: bb = RL(bb, 10);
306:
307: //
308: // Rounds 32-47
309: //
310: // left
311: d = RL(d + f3(e, a, b) + X[3] + 0x6ed9eba1, 11) + c;
312: a = RL(a, 10);
313: c = RL(c + f3(d, e, a) + X[10] + 0x6ed9eba1, 13) + b;
314: e = RL(e, 10);
315: b = RL(b + f3(c, d, e) + X[14] + 0x6ed9eba1, 6) + a;
316: d = RL(d, 10);
317: a = RL(a + f3(b, c, d) + X[4] + 0x6ed9eba1, 7) + e;
318: c = RL(c, 10);
319: e = RL(e + f3(a, b, c) + X[9] + 0x6ed9eba1, 14) + d;
320: b = RL(b, 10);
321: d = RL(d + f3(e, a, b) + X[15] + 0x6ed9eba1, 9) + c;
322: a = RL(a, 10);
323: c = RL(c + f3(d, e, a) + X[8] + 0x6ed9eba1, 13) + b;
324: e = RL(e, 10);
325: b = RL(b + f3(c, d, e) + X[1] + 0x6ed9eba1, 15) + a;
326: d = RL(d, 10);
327: a = RL(a + f3(b, c, d) + X[2] + 0x6ed9eba1, 14) + e;
328: c = RL(c, 10);
329: e = RL(e + f3(a, b, c) + X[7] + 0x6ed9eba1, 8) + d;
330: b = RL(b, 10);
331: d = RL(d + f3(e, a, b) + X[0] + 0x6ed9eba1, 13) + c;
332: a = RL(a, 10);
333: c = RL(c + f3(d, e, a) + X[6] + 0x6ed9eba1, 6) + b;
334: e = RL(e, 10);
335: b = RL(b + f3(c, d, e) + X[13] + 0x6ed9eba1, 5) + a;
336: d = RL(d, 10);
337: a = RL(a + f3(b, c, d) + X[11] + 0x6ed9eba1, 12) + e;
338: c = RL(c, 10);
339: e = RL(e + f3(a, b, c) + X[5] + 0x6ed9eba1, 7) + d;
340: b = RL(b, 10);
341: d = RL(d + f3(e, a, b) + X[12] + 0x6ed9eba1, 5) + c;
342: a = RL(a, 10);
343:
344: // right
345: dd = RL(dd + f3(ee, aa, bb) + X[15] + 0x6d703ef3, 9) + cc;
346: aa = RL(aa, 10);
347: cc = RL(cc + f3(dd, ee, aa) + X[5] + 0x6d703ef3, 7) + bb;
348: ee = RL(ee, 10);
349: bb = RL(bb + f3(cc, dd, ee) + X[1] + 0x6d703ef3, 15) + aa;
350: dd = RL(dd, 10);
351: aa = RL(aa + f3(bb, cc, dd) + X[3] + 0x6d703ef3, 11) + ee;
352: cc = RL(cc, 10);
353: ee = RL(ee + f3(aa, bb, cc) + X[7] + 0x6d703ef3, 8) + dd;
354: bb = RL(bb, 10);
355: dd = RL(dd + f3(ee, aa, bb) + X[14] + 0x6d703ef3, 6) + cc;
356: aa = RL(aa, 10);
357: cc = RL(cc + f3(dd, ee, aa) + X[6] + 0x6d703ef3, 6) + bb;
358: ee = RL(ee, 10);
359: bb = RL(bb + f3(cc, dd, ee) + X[9] + 0x6d703ef3, 14) + aa;
360: dd = RL(dd, 10);
361: aa = RL(aa + f3(bb, cc, dd) + X[11] + 0x6d703ef3, 12) + ee;
362: cc = RL(cc, 10);
363: ee = RL(ee + f3(aa, bb, cc) + X[8] + 0x6d703ef3, 13) + dd;
364: bb = RL(bb, 10);
365: dd = RL(dd + f3(ee, aa, bb) + X[12] + 0x6d703ef3, 5) + cc;
366: aa = RL(aa, 10);
367: cc = RL(cc + f3(dd, ee, aa) + X[2] + 0x6d703ef3, 14) + bb;
368: ee = RL(ee, 10);
369: bb = RL(bb + f3(cc, dd, ee) + X[10] + 0x6d703ef3, 13) + aa;
370: dd = RL(dd, 10);
371: aa = RL(aa + f3(bb, cc, dd) + X[0] + 0x6d703ef3, 13) + ee;
372: cc = RL(cc, 10);
373: ee = RL(ee + f3(aa, bb, cc) + X[4] + 0x6d703ef3, 7) + dd;
374: bb = RL(bb, 10);
375: dd = RL(dd + f3(ee, aa, bb) + X[13] + 0x6d703ef3, 5) + cc;
376: aa = RL(aa, 10);
377:
378: //
379: // Rounds 48-63
380: //
381: // left
382: c = RL(c + f4(d, e, a) + X[1] + 0x8f1bbcdc, 11) + b;
383: e = RL(e, 10);
384: b = RL(b + f4(c, d, e) + X[9] + 0x8f1bbcdc, 12) + a;
385: d = RL(d, 10);
386: a = RL(a + f4(b, c, d) + X[11] + 0x8f1bbcdc, 14) + e;
387: c = RL(c, 10);
388: e = RL(e + f4(a, b, c) + X[10] + 0x8f1bbcdc, 15) + d;
389: b = RL(b, 10);
390: d = RL(d + f4(e, a, b) + X[0] + 0x8f1bbcdc, 14) + c;
391: a = RL(a, 10);
392: c = RL(c + f4(d, e, a) + X[8] + 0x8f1bbcdc, 15) + b;
393: e = RL(e, 10);
394: b = RL(b + f4(c, d, e) + X[12] + 0x8f1bbcdc, 9) + a;
395: d = RL(d, 10);
396: a = RL(a + f4(b, c, d) + X[4] + 0x8f1bbcdc, 8) + e;
397: c = RL(c, 10);
398: e = RL(e + f4(a, b, c) + X[13] + 0x8f1bbcdc, 9) + d;
399: b = RL(b, 10);
400: d = RL(d + f4(e, a, b) + X[3] + 0x8f1bbcdc, 14) + c;
401: a = RL(a, 10);
402: c = RL(c + f4(d, e, a) + X[7] + 0x8f1bbcdc, 5) + b;
403: e = RL(e, 10);
404: b = RL(b + f4(c, d, e) + X[15] + 0x8f1bbcdc, 6) + a;
405: d = RL(d, 10);
406: a = RL(a + f4(b, c, d) + X[14] + 0x8f1bbcdc, 8) + e;
407: c = RL(c, 10);
408: e = RL(e + f4(a, b, c) + X[5] + 0x8f1bbcdc, 6) + d;
409: b = RL(b, 10);
410: d = RL(d + f4(e, a, b) + X[6] + 0x8f1bbcdc, 5) + c;
411: a = RL(a, 10);
412: c = RL(c + f4(d, e, a) + X[2] + 0x8f1bbcdc, 12) + b;
413: e = RL(e, 10);
414:
415: // right
416: cc = RL(cc + f2(dd, ee, aa) + X[8] + 0x7a6d76e9, 15) + bb;
417: ee = RL(ee, 10);
418: bb = RL(bb + f2(cc, dd, ee) + X[6] + 0x7a6d76e9, 5) + aa;
419: dd = RL(dd, 10);
420: aa = RL(aa + f2(bb, cc, dd) + X[4] + 0x7a6d76e9, 8) + ee;
421: cc = RL(cc, 10);
422: ee = RL(ee + f2(aa, bb, cc) + X[1] + 0x7a6d76e9, 11) + dd;
423: bb = RL(bb, 10);
424: dd = RL(dd + f2(ee, aa, bb) + X[3] + 0x7a6d76e9, 14) + cc;
425: aa = RL(aa, 10);
426: cc = RL(cc + f2(dd, ee, aa) + X[11] + 0x7a6d76e9, 14) + bb;
427: ee = RL(ee, 10);
428: bb = RL(bb + f2(cc, dd, ee) + X[15] + 0x7a6d76e9, 6) + aa;
429: dd = RL(dd, 10);
430: aa = RL(aa + f2(bb, cc, dd) + X[0] + 0x7a6d76e9, 14) + ee;
431: cc = RL(cc, 10);
432: ee = RL(ee + f2(aa, bb, cc) + X[5] + 0x7a6d76e9, 6) + dd;
433: bb = RL(bb, 10);
434: dd = RL(dd + f2(ee, aa, bb) + X[12] + 0x7a6d76e9, 9) + cc;
435: aa = RL(aa, 10);
436: cc = RL(cc + f2(dd, ee, aa) + X[2] + 0x7a6d76e9, 12) + bb;
437: ee = RL(ee, 10);
438: bb = RL(bb + f2(cc, dd, ee) + X[13] + 0x7a6d76e9, 9) + aa;
439: dd = RL(dd, 10);
440: aa = RL(aa + f2(bb, cc, dd) + X[9] + 0x7a6d76e9, 12) + ee;
441: cc = RL(cc, 10);
442: ee = RL(ee + f2(aa, bb, cc) + X[7] + 0x7a6d76e9, 5) + dd;
443: bb = RL(bb, 10);
444: dd = RL(dd + f2(ee, aa, bb) + X[10] + 0x7a6d76e9, 15) + cc;
445: aa = RL(aa, 10);
446: cc = RL(cc + f2(dd, ee, aa) + X[14] + 0x7a6d76e9, 8) + bb;
447: ee = RL(ee, 10);
448:
449: //
450: // Rounds 64-79
451: //
452: // left
453: b = RL(b + f5(c, d, e) + X[4] + 0xa953fd4e, 9) + a;
454: d = RL(d, 10);
455: a = RL(a + f5(b, c, d) + X[0] + 0xa953fd4e, 15) + e;
456: c = RL(c, 10);
457: e = RL(e + f5(a, b, c) + X[5] + 0xa953fd4e, 5) + d;
458: b = RL(b, 10);
459: d = RL(d + f5(e, a, b) + X[9] + 0xa953fd4e, 11) + c;
460: a = RL(a, 10);
461: c = RL(c + f5(d, e, a) + X[7] + 0xa953fd4e, 6) + b;
462: e = RL(e, 10);
463: b = RL(b + f5(c, d, e) + X[12] + 0xa953fd4e, 8) + a;
464: d = RL(d, 10);
465: a = RL(a + f5(b, c, d) + X[2] + 0xa953fd4e, 13) + e;
466: c = RL(c, 10);
467: e = RL(e + f5(a, b, c) + X[10] + 0xa953fd4e, 12) + d;
468: b = RL(b, 10);
469: d = RL(d + f5(e, a, b) + X[14] + 0xa953fd4e, 5) + c;
470: a = RL(a, 10);
471: c = RL(c + f5(d, e, a) + X[1] + 0xa953fd4e, 12) + b;
472: e = RL(e, 10);
473: b = RL(b + f5(c, d, e) + X[3] + 0xa953fd4e, 13) + a;
474: d = RL(d, 10);
475: a = RL(a + f5(b, c, d) + X[8] + 0xa953fd4e, 14) + e;
476: c = RL(c, 10);
477: e = RL(e + f5(a, b, c) + X[11] + 0xa953fd4e, 11) + d;
478: b = RL(b, 10);
479: d = RL(d + f5(e, a, b) + X[6] + 0xa953fd4e, 8) + c;
480: a = RL(a, 10);
481: c = RL(c + f5(d, e, a) + X[15] + 0xa953fd4e, 5) + b;
482: e = RL(e, 10);
483: b = RL(b + f5(c, d, e) + X[13] + 0xa953fd4e, 6) + a;
484: d = RL(d, 10);
485:
486: // right
487: bb = RL(bb + f1(cc, dd, ee) + X[12], 8) + aa;
488: dd = RL(dd, 10);
489: aa = RL(aa + f1(bb, cc, dd) + X[15], 5) + ee;
490: cc = RL(cc, 10);
491: ee = RL(ee + f1(aa, bb, cc) + X[10], 12) + dd;
492: bb = RL(bb, 10);
493: dd = RL(dd + f1(ee, aa, bb) + X[4], 9) + cc;
494: aa = RL(aa, 10);
495: cc = RL(cc + f1(dd, ee, aa) + X[1], 12) + bb;
496: ee = RL(ee, 10);
497: bb = RL(bb + f1(cc, dd, ee) + X[5], 5) + aa;
498: dd = RL(dd, 10);
499: aa = RL(aa + f1(bb, cc, dd) + X[8], 14) + ee;
500: cc = RL(cc, 10);
501: ee = RL(ee + f1(aa, bb, cc) + X[7], 6) + dd;
502: bb = RL(bb, 10);
503: dd = RL(dd + f1(ee, aa, bb) + X[6], 8) + cc;
504: aa = RL(aa, 10);
505: cc = RL(cc + f1(dd, ee, aa) + X[2], 13) + bb;
506: ee = RL(ee, 10);
507: bb = RL(bb + f1(cc, dd, ee) + X[13], 6) + aa;
508: dd = RL(dd, 10);
509: aa = RL(aa + f1(bb, cc, dd) + X[14], 5) + ee;
510: cc = RL(cc, 10);
511: ee = RL(ee + f1(aa, bb, cc) + X[0], 15) + dd;
512: bb = RL(bb, 10);
513: dd = RL(dd + f1(ee, aa, bb) + X[3], 13) + cc;
514: aa = RL(aa, 10);
515: cc = RL(cc + f1(dd, ee, aa) + X[9], 11) + bb;
516: ee = RL(ee, 10);
517: bb = RL(bb + f1(cc, dd, ee) + X[11], 11) + aa;
518: dd = RL(dd, 10);
519:
520: dd += c + H1;
521: H1 = H2 + d + ee;
522: H2 = H3 + e + aa;
523: H3 = H4 + a + bb;
524: H4 = H0 + b + cc;
525: H0 = dd;
526:
527: //
528: // reset the offset and clean out the word buffer.
529: //
530: xOff = 0;
531: for (int i = 0; i != X.length; i++) {
532: X[i] = 0;
533: }
534: }
535: }
|