org.spongycastle.crypto.tls.CombinedHash Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scprov-jdk15 Show documentation
Show all versions of scprov-jdk15 Show documentation
Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android.
Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add
an alternative (updated/complete) Bouncy Castle jar.
This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.
package org.spongycastle.crypto.tls;
import org.spongycastle.crypto.Digest;
import org.spongycastle.crypto.digests.MD5Digest;
import org.spongycastle.crypto.digests.SHA1Digest;
/**
* A combined hash, which implements md5(m) || sha1(m).
*/
class CombinedHash implements Digest
{
private MD5Digest md5;
private SHA1Digest sha1;
CombinedHash()
{
this.md5 = new MD5Digest();
this.sha1 = new SHA1Digest();
}
CombinedHash(CombinedHash t)
{
this.md5 = new MD5Digest(t.md5);
this.sha1 = new SHA1Digest(t.sha1);
}
/**
* @see org.spongycastle.crypto.Digest#getAlgorithmName()
*/
public String getAlgorithmName()
{
return md5.getAlgorithmName() + " and " + sha1.getAlgorithmName() + " for TLS 1.0";
}
/**
* @see org.spongycastle.crypto.Digest#getDigestSize()
*/
public int getDigestSize()
{
return 16 + 20;
}
/**
* @see org.spongycastle.crypto.Digest#update(byte)
*/
public void update(byte in)
{
md5.update(in);
sha1.update(in);
}
/**
* @see org.spongycastle.crypto.Digest#update(byte[],int,int)
*/
public void update(byte[] in, int inOff, int len)
{
md5.update(in, inOff, len);
sha1.update(in, inOff, len);
}
/**
* @see org.spongycastle.crypto.Digest#doFinal(byte[],int)
*/
public int doFinal(byte[] out, int outOff)
{
int i1 = md5.doFinal(out, outOff);
int i2 = sha1.doFinal(out, outOff + 16);
return i1 + i2;
}
/**
* @see org.spongycastle.crypto.Digest#reset()
*/
public void reset()
{
md5.reset();
sha1.reset();
}
}