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

ShortenedDigest

public class ShortenedDigest extends Object implements org.bouncycastle.crypto.ExtendedDigest
Wrapper class that reduces the output length of a particular digest to only the first n bytes of the digest function.

Fields Summary
private org.bouncycastle.crypto.ExtendedDigest
baseDigest
private int
length
Constructors Summary
public ShortenedDigest(org.bouncycastle.crypto.ExtendedDigest baseDigest, int length)
Base constructor.

param
baseDigest underlying digest to use.
param
length length in bytes of the output of doFinal.
exception
IllegalArgumentException if baseDigest is null, or length is greater than baseDigest.getDigestSize().

        if (baseDigest == null)
        {
            throw new IllegalArgumentException("baseDigest must not be null");
        }
        
        if (length > baseDigest.getDigestSize())
        {
            throw new IllegalArgumentException("baseDigest output not large enough to support length");
        }
        
        this.baseDigest = baseDigest;
        this.length = length;
    
Methods Summary
public intdoFinal(byte[] out, int outOff)

        byte[] tmp = new byte[baseDigest.getDigestSize()];
        
        baseDigest.doFinal(tmp, 0);
        
        System.arraycopy(tmp, 0, out, outOff, length);
        
        return length;
    
public java.lang.StringgetAlgorithmName()

        return baseDigest.getAlgorithmName() + "(" + length * 8 + ")";
    
public intgetByteLength()

        return baseDigest.getByteLength();
    
public intgetDigestSize()

        return length;
    
public voidreset()

        baseDigest.reset();
    
public voidupdate(byte in)

        baseDigest.update(in);
    
public voidupdate(byte[] in, int inOff, int len)

        baseDigest.update(in, inOff, len);