01: package org.bouncycastle.crypto.tls;
02:
03: import org.bouncycastle.crypto.Digest;
04: import org.bouncycastle.crypto.digests.MD5Digest;
05: import org.bouncycastle.crypto.digests.SHA1Digest;
06:
07: /**
08: * A combined hash, which implements md5(m) || sha1(m).
09: */
10: public class CombinedHash implements Digest {
11: private Digest md5 = new MD5Digest();
12: private Digest sha1 = new SHA1Digest();
13:
14: /**
15: * @see org.bouncycastle.crypto.Digest#getAlgorithmName()
16: */
17: public String getAlgorithmName() {
18: return md5.getAlgorithmName() + " and "
19: + sha1.getAlgorithmName() + " for TLS 1.0";
20: }
21:
22: /**
23: * @see org.bouncycastle.crypto.Digest#getDigestSize()
24: */
25: public int getDigestSize() {
26: return 16 + 20;
27: }
28:
29: /**
30: * @see org.bouncycastle.crypto.Digest#update(byte)
31: */
32: public void update(byte in) {
33: md5.update(in);
34: sha1.update(in);
35: }
36:
37: /**
38: * @see org.bouncycastle.crypto.Digest#update(byte[],int,int)
39: */
40: public void update(byte[] in, int inOff, int len) {
41: md5.update(in, inOff, len);
42: sha1.update(in, inOff, len);
43: }
44:
45: /**
46: * @see org.bouncycastle.crypto.Digest#doFinal(byte[],int)
47: */
48: public int doFinal(byte[] out, int outOff) {
49: int i1 = md5.doFinal(out, outOff);
50: int i2 = sha1.doFinal(out, outOff + 16);
51: return i1 + i2;
52: }
53:
54: /**
55: * @see org.bouncycastle.crypto.Digest#reset()
56: */
57: public void reset() {
58: md5.reset();
59: sha1.reset();
60: }
61:
62: }
|