MD2Digestpublic class MD2Digest extends Object implements ExtendedDigestimplementation of MD2
as outlined in RFC1319 by B.Kaliski from RSA Laboratories April 1992 |
Fields Summary |
---|
private static final int | DIGEST_LENGTH | private byte[] | X | private int | xOff | private byte[] | M | private int | mOff | private byte[] | C | private int | COff | private static final byte[] | S |
Constructors Summary |
---|
public MD2Digest()
reset();
| public MD2Digest(MD2Digest t)
System.arraycopy(t.X, 0, X, 0, t.X.length);
xOff = t.xOff;
System.arraycopy(t.M, 0, M, 0, t.M.length);
mOff = t.mOff;
System.arraycopy(t.C, 0, C, 0, t.C.length);
COff = t.COff;
|
Methods Summary |
---|
public int | doFinal(byte[] out, int outOff)close the digest, producing the final digest value. The doFinal
call leaves the digest reset.
// add padding
byte paddingByte = (byte)(M.length-mOff);
for (int i=mOff;i<M.length;i++)
{
M[i] = paddingByte;
}
//do final check sum
processCheckSum(M);
// do final block process
processBlock(M);
processBlock(C);
System.arraycopy(X,xOff,out,outOff,16);
reset();
return DIGEST_LENGTH;
| public java.lang.String | getAlgorithmName()return the algorithm name
return "MD2";
| public int | getByteLength()
return 16;
| public int | getDigestSize()return the size, in bytes, of the digest produced by this message digest.
return DIGEST_LENGTH;
| protected void | processBlock(byte[] m)
for (int i=0;i<16;i++)
{
X[i+16] = m[i];
X[i+32] = (byte)(m[i] ^ X[i]);
}
// encrypt block
int t = 0;
for (int j=0;j<18;j++)
{
for (int k=0;k<48;k++)
{
t = X[k] ^= S[t];
t = t & 0xff;
}
t = (t + j)%256;
}
| protected void | processCheckSum(byte[] m)
int L = C[15];
for (int i=0;i<16;i++)
{
C[i] ^= S[(m[i] ^ L) & 0xff];
L = C[i];
}
| public void | reset()reset the digest back to it's initial state.
xOff = 0;
for (int i = 0; i != X.length; i++)
{
X[i] = 0;
}
mOff = 0;
for (int i = 0; i != M.length; i++)
{
M[i] = 0;
}
COff = 0;
for (int i = 0; i != C.length; i++)
{
C[i] = 0;
}
| public void | update(byte in)update the message digest with a single byte.
M[mOff++] = in;
if (mOff == 16)
{
processCheckSum(M);
processBlock(M);
mOff = 0;
}
| public void | update(byte[] in, int inOff, int len)update the message digest with a block of bytes.
//
// fill the current word
//
while ((mOff != 0) && (len > 0))
{
update(in[inOff]);
inOff++;
len--;
}
//
// process whole words.
//
while (len > 16)
{
System.arraycopy(in,inOff,M,0,16);
processCheckSum(M);
processBlock(M);
len -= 16;
inOff += 16;
}
//
// load in the remainder.
//
while (len > 0)
{
update(in[inOff]);
inOff++;
len--;
}
|
|