FileDocCategorySizeDatePackage
GeneralDigest.javaAPI DocAndroid 1.5 API2611Wed May 06 22:41:06 BST 2009org.bouncycastle.crypto.digests

GeneralDigest

public abstract class GeneralDigest extends Object implements org.bouncycastle.crypto.ExtendedDigest
base implementation of MD4 family style digest as outlined in "Handbook of Applied Cryptography", pages 344 - 347.

Fields Summary
private static final int
BYTE_LENGTH
private byte[]
xBuf
private int
xBufOff
private long
byteCount
Constructors Summary
protected GeneralDigest()
Standard constructor


           
     
    
        xBuf = new byte[4];
        xBufOff = 0;
    
protected GeneralDigest(GeneralDigest t)
Copy constructor. We are using copy constructors in place of the Object.clone() interface as this interface is not supported by J2ME.

        xBuf = new byte[t.xBuf.length];
        System.arraycopy(t.xBuf, 0, xBuf, 0, t.xBuf.length);

        xBufOff = t.xBufOff;
        byteCount = t.byteCount;
    
Methods Summary
public voidfinish()

        long    bitLength = (byteCount << 3);

        //
        // add the pad bytes.
        //
        update((byte)128);

        while (xBufOff != 0)
        {
            update((byte)0);
        }

        processLength(bitLength);

        processBlock();
    
public intgetByteLength()

        return BYTE_LENGTH;
    
protected abstract voidprocessBlock()

protected abstract voidprocessLength(long bitLength)

protected abstract voidprocessWord(byte[] in, int inOff)

public voidreset()

        byteCount = 0;

        xBufOff = 0;
        for (int i = 0; i < xBuf.length; i++)
        {
            xBuf[i] = 0;
        }
    
public voidupdate(byte in)

        xBuf[xBufOff++] = in;

        if (xBufOff == xBuf.length)
        {
            processWord(xBuf, 0);
            xBufOff = 0;
        }

        byteCount++;
    
public voidupdate(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;
            byteCount += xBuf.length;
        }

        //
        // load in the remainder.
        //
        while (len > 0)
        {
            update(in[inOff]);

            inOff++;
            len--;
        }