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

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

There is a newer version: 1.0.6
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