All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.tls.crypto.impl.bc.BcTlsHMAC Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for the TLS, including a JSSE provider. The APIs are designed primarily to be used in conjunction with the BC LTS provider but may also be used with other providers providing cryptographic services.

There is a newer version: 2.73.7
Show newest version
package org.bouncycastle.tls.crypto.impl.bc;

import org.bouncycastle.crypto.ExtendedDigest;
import org.bouncycastle.crypto.macs.HMac;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.tls.crypto.TlsHMAC;

final class BcTlsHMAC
    implements TlsHMAC
{
    private final HMac hmac;

    BcTlsHMAC(HMac hmac)
    {
        this.hmac = hmac;
    }

    public void setKey(byte[] key, int keyOff, int keyLen)
    {
        hmac.init(new KeyParameter(key, keyOff, keyLen));
    }

    public void update(byte[] input, int inOff, int length)
    {
        hmac.update(input, inOff, length);
    }

    public byte[] calculateMAC()
    {
        byte[] rv = new byte[hmac.getMacSize()];

        hmac.doFinal(rv, 0);

        return rv;
    }

    public void calculateMAC(byte[] output, int outOff)
    {
        hmac.doFinal(output, outOff);
    }

    public int getInternalBlockSize()
    {
        return ((ExtendedDigest)hmac.getUnderlyingDigest()).getByteLength();
    }

    public int getMacLength()
    {
        return hmac.getMacSize();
    }

    public void reset()
    {
        hmac.reset();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy