Methods Summary |
---|
private long | Ch(long x, long y, long z)
return ((x & y) ^ ((~x) & z));
|
private long | Maj(long x, long y, long z)
return ((x & y) ^ (x & z) ^ (y & z));
|
private long | Sigma0(long x)
return rotateRight(x, 1) ^ rotateRight(x, 8) ^ (x >>> 7);
|
private long | Sigma1(long x)
return rotateRight(x, 19) ^ rotateRight(x, 61) ^ (x >>> 6);
|
private long | Sum0(long x)
return rotateRight(x, 28) ^ rotateRight(x, 34) ^ rotateRight(x, 39);
|
private long | Sum1(long x)
return rotateRight(x, 14) ^ rotateRight(x, 18) ^ rotateRight(x, 41);
|
private void | adjustByteCounts()adjust the byte counts so that byteCount2 represents the
upper long (less 3 bits) word of the byte count.
if (byteCount1 > 0x1fffffffffffffffL)
{
byteCount2 += (byteCount1 >>> 61);
byteCount1 &= 0x1fffffffffffffffL;
}
|
public void | finish()
adjustByteCounts();
long lowBitLength = byteCount1 << 3;
long hiBitLength = byteCount2;
//
// add the pad bytes.
//
update((byte)128);
while (xBufOff != 0)
{
update((byte)0);
}
processLength(lowBitLength, hiBitLength);
processBlock();
|
protected void | processBlock()
adjustByteCounts();
//
// expand 16 word block into 80 word blocks.
//
for (int t = 16; t <= 79; t++)
{
W[t] = Sigma1(W[t - 2]) + W[t - 7] + Sigma0(W[t - 15]) + W[t - 16];
}
//
// set up working variables.
//
long a = H1;
long b = H2;
long c = H3;
long d = H4;
long e = H5;
long f = H6;
long g = H7;
long h = H8;
for (int t = 0; t <= 79; t++)
{
long T1, T2;
T1 = h + Sum1(e) + Ch(e, f, g) + K[t] + W[t];
T2 = Sum0(a) + Maj(a, b, c);
h = g;
g = f;
f = e;
e = d + T1;
d = c;
c = b;
b = a;
a = T1 + T2;
}
H1 += a;
H2 += b;
H3 += c;
H4 += d;
H5 += e;
H6 += f;
H7 += g;
H8 += h;
//
// reset the offset and clean out the word buffer.
//
wOff = 0;
for (int i = 0; i != W.length; i++)
{
W[i] = 0;
}
|
protected void | processLength(long lowW, long hiW)
if (wOff > 14)
{
processBlock();
}
W[14] = hiW;
W[15] = lowW;
|
protected void | processWord(byte[] in, int inOff)
W[wOff++] = ((long)(in[inOff] & 0xff) << 56)
| ((long)(in[inOff + 1] & 0xff) << 48)
| ((long)(in[inOff + 2] & 0xff) << 40)
| ((long)(in[inOff + 3] & 0xff) << 32)
| ((long)(in[inOff + 4] & 0xff) << 24)
| ((long)(in[inOff + 5] & 0xff) << 16)
| ((long)(in[inOff + 6] & 0xff) << 8)
| ((in[inOff + 7] & 0xff));
if (wOff == 16)
{
processBlock();
}
|
public void | reset()
byteCount1 = 0;
byteCount2 = 0;
xBufOff = 0;
for ( int i = 0; i < xBuf.length; i++ ) {
xBuf[i] = 0;
}
wOff = 0;
for (int i = 0; i != W.length; i++)
{
W[i] = 0;
}
|
private long | rotateRight(long x, int n)
return (x >>> n) | (x << (64 - n));
|
protected void | unpackWord(long word, byte[] out, int outOff)
out[outOff] = (byte)(word >>> 56);
out[outOff + 1] = (byte)(word >>> 48);
out[outOff + 2] = (byte)(word >>> 40);
out[outOff + 3] = (byte)(word >>> 32);
out[outOff + 4] = (byte)(word >>> 24);
out[outOff + 5] = (byte)(word >>> 16);
out[outOff + 6] = (byte)(word >>> 8);
out[outOff + 7] = (byte)word;
|
public void | update(byte in)
xBuf[xBufOff++] = in;
if (xBufOff == xBuf.length)
{
processWord(xBuf, 0);
xBufOff = 0;
}
byteCount1++;
|
public void | update(byte[] in, int inOff, int len)
//
// fill the current word
//
while ((xBufOff != 0) && (len > 0))
{
update(in[inOff]);
inOff++;
len--;
}
//
// process whole words.
//
while (len > xBuf.length)
{
processWord(in, inOff);
inOff += xBuf.length;
len -= xBuf.length;
byteCount1 += xBuf.length;
}
//
// load in the remainder.
//
while (len > 0)
{
update(in[inOff]);
inOff++;
len--;
}
|