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

org.bouncycastle.tls.crypto.impl.bc.BcTlsHash 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.Digest;
import org.bouncycastle.tls.crypto.TlsHash;

final class BcTlsHash
    implements TlsHash
{
    private final BcTlsCrypto crypto;
    private final int cryptoHashAlgorithm;
    private final Digest digest;

    BcTlsHash(BcTlsCrypto crypto, int cryptoHashAlgorithm)
    {
        this(crypto, cryptoHashAlgorithm, crypto.createDigest(cryptoHashAlgorithm));
    }

    private BcTlsHash(BcTlsCrypto crypto, int cryptoHashAlgorithm, Digest digest)
    {
        this.crypto = crypto;
        this.cryptoHashAlgorithm = cryptoHashAlgorithm;
        this.digest = digest;
    }

    public void update(byte[] data, int offSet, int length)
    {
        digest.update(data, offSet, length);
    }

    public byte[] calculateHash()
    {
        byte[] rv = new byte[digest.getDigestSize()];
        digest.doFinal(rv, 0);
        return rv;
    }

    public TlsHash cloneHash()
    {
        return new BcTlsHash(crypto, cryptoHashAlgorithm, crypto.cloneDigest(cryptoHashAlgorithm, digest));
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy