using System; using Org.BouncyCastle.Crypto.Digests; namespace Org.BouncyCastle.Crypto.Tls { /// A combined hash, which implements md5(m) || sha1(m). public class CombinedHash : IDigest { private IDigest md5 = new MD5Digest(); private IDigest sha1 = new Sha1Digest(); /// public string AlgorithmName { get { return md5.AlgorithmName + " and " + sha1.AlgorithmName + " for TLS 1.0"; } } /// public int GetByteLength() { return System.Math.Max(md5.GetByteLength(), sha1.GetByteLength()); } /// public int GetDigestSize() { return md5.GetDigestSize() + sha1.GetDigestSize(); } /// public void Update( byte input) { md5.Update(input); sha1.Update(input); } /// public void BlockUpdate( byte[] input, int inOff, int len) { md5.BlockUpdate(input, inOff, len); sha1.BlockUpdate(input, inOff, len); } /// public int DoFinal( byte[] output, int outOff) { int i1 = md5.DoFinal(output, outOff); int i2 = sha1.DoFinal(output, outOff + i1); return i1 + i2; } /// public void Reset() { md5.Reset(); sha1.Reset(); } } }