~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to src/org/bouncycastle/crypto/tls/CombinedHash.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.bouncycastle.crypto.tls;
 
2
 
 
3
import org.bouncycastle.crypto.Digest;
 
4
import org.bouncycastle.crypto.digests.MD5Digest;
 
5
import org.bouncycastle.crypto.digests.SHA1Digest;
 
6
 
 
7
/**
 
8
 * A combined hash, which implements md5(m) || sha1(m).
 
9
 */
 
10
class CombinedHash implements Digest
 
11
{
 
12
    private MD5Digest md5;
 
13
    private SHA1Digest sha1;
 
14
 
 
15
    CombinedHash()
 
16
    {
 
17
        this.md5 = new MD5Digest();
 
18
        this.sha1 = new SHA1Digest();
 
19
    }
 
20
 
 
21
    CombinedHash(CombinedHash t)
 
22
    {
 
23
        this.md5 = new MD5Digest(t.md5);
 
24
        this.sha1 = new SHA1Digest(t.sha1);
 
25
    }
 
26
 
 
27
    /**
 
28
     * @see org.bouncycastle.crypto.Digest#getAlgorithmName()
 
29
     */
 
30
    public String getAlgorithmName()
 
31
    {
 
32
        return md5.getAlgorithmName() + " and " + sha1.getAlgorithmName() + " for TLS 1.0";
 
33
    }
 
34
 
 
35
    /**
 
36
     * @see org.bouncycastle.crypto.Digest#getDigestSize()
 
37
     */
 
38
    public int getDigestSize()
 
39
    {
 
40
        return 16 + 20;
 
41
    }
 
42
 
 
43
    /**
 
44
     * @see org.bouncycastle.crypto.Digest#update(byte)
 
45
     */
 
46
    public void update(byte in)
 
47
    {
 
48
        md5.update(in);
 
49
        sha1.update(in);
 
50
    }
 
51
 
 
52
    /**
 
53
     * @see org.bouncycastle.crypto.Digest#update(byte[],int,int)
 
54
     */
 
55
    public void update(byte[] in, int inOff, int len)
 
56
    {
 
57
        md5.update(in, inOff, len);
 
58
        sha1.update(in, inOff, len);
 
59
    }
 
60
 
 
61
    /**
 
62
     * @see org.bouncycastle.crypto.Digest#doFinal(byte[],int)
 
63
     */
 
64
    public int doFinal(byte[] out, int outOff)
 
65
    {
 
66
        int i1 = md5.doFinal(out, outOff);
 
67
        int i2 = sha1.doFinal(out, outOff + 16);
 
68
        return i1 + i2;
 
69
    }
 
70
 
 
71
    /**
 
72
     * @see org.bouncycastle.crypto.Digest#reset()
 
73
     */
 
74
    public void reset()
 
75
    {
 
76
        md5.reset();
 
77
        sha1.reset();
 
78
    }
 
79
 
 
80
}