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