FileDocCategorySizeDatePackage
OldHMac.javaAPI DocAndroid 1.5 API2982Wed May 06 22:41:06 BST 2009org.bouncycastle.crypto.macs

OldHMac

public class OldHMac extends Object implements org.bouncycastle.crypto.Mac
HMAC implementation based on RFC2104 H(K XOR opad, H(K XOR ipad, text))

Fields Summary
private static final int
BLOCK_LENGTH
private static final byte
IPAD
private static final byte
OPAD
private org.bouncycastle.crypto.Digest
digest
private int
digestSize
private byte[]
inputPad
private byte[]
outputPad
Constructors Summary
public OldHMac(org.bouncycastle.crypto.Digest digest)

deprecated
uses incorrect pad for SHA-512 and SHA-384 use HMac.


                   
     
         
    
        this.digest = digest;
        digestSize = digest.getDigestSize();
    
Methods Summary
public intdoFinal(byte[] out, int outOff)

        byte[] tmp = new byte[digestSize];
        digest.doFinal(tmp, 0);

        digest.update(outputPad, 0, outputPad.length);
        digest.update(tmp, 0, tmp.length);

        int     len = digest.doFinal(out, outOff);

        reset();

        return len;
    
public java.lang.StringgetAlgorithmName()

        return digest.getAlgorithmName() + "/HMAC";
    
public intgetMacSize()

        return digestSize;
    
public org.bouncycastle.crypto.DigestgetUnderlyingDigest()

        return digest;
    
public voidinit(org.bouncycastle.crypto.CipherParameters params)

        digest.reset();

        byte[] key = ((KeyParameter)params).getKey();

        if (key.length > BLOCK_LENGTH)
        {
            digest.update(key, 0, key.length);
            digest.doFinal(inputPad, 0);
            for (int i = digestSize; i < inputPad.length; i++)
            {
                inputPad[i] = 0;
            }
        }
        else
        {
            System.arraycopy(key, 0, inputPad, 0, key.length);
            for (int i = key.length; i < inputPad.length; i++)
            {
                inputPad[i] = 0;
            }
        }

        outputPad = new byte[inputPad.length];
        System.arraycopy(inputPad, 0, outputPad, 0, inputPad.length);

        for (int i = 0; i < inputPad.length; i++)
        {
            inputPad[i] ^= IPAD;
        }

        for (int i = 0; i < outputPad.length; i++)
        {
            outputPad[i] ^= OPAD;
        }

        digest.update(inputPad, 0, inputPad.length);
    
public voidreset()
Reset the mac generator.

        /*
         * reset the underlying digest.
         */
        digest.reset();

        /*
         * reinitialize the digest.
         */
        digest.update(inputPad, 0, inputPad.length);
    
public voidupdate(byte in)

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

        digest.update(in, inOff, len);