SHA384Digest.java revision a198e1ecc615e26a167d0f2dca9fa7e5fc62de10
1package org.bouncycastle.crypto.digests;
2
3import org.bouncycastle.crypto.util.Pack;
4import org.bouncycastle.util.Memoable;
5
6
7/**
8 * FIPS 180-2 implementation of SHA-384.
9 *
10 * <pre>
11 *         block  word  digest
12 * SHA-1   512    32    160
13 * SHA-256 512    32    256
14 * SHA-384 1024   64    384
15 * SHA-512 1024   64    512
16 * </pre>
17 */
18public class SHA384Digest
19    extends LongDigest
20{
21    private static final int    DIGEST_LENGTH = 48;
22
23    /**
24     * Standard constructor
25     */
26    public SHA384Digest()
27    {
28    }
29
30    /**
31     * Copy constructor.  This will copy the state of the provided
32     * message digest.
33     */
34    public SHA384Digest(SHA384Digest t)
35    {
36        super(t);
37    }
38
39    public String getAlgorithmName()
40    {
41        return "SHA-384";
42    }
43
44    public int getDigestSize()
45    {
46        return DIGEST_LENGTH;
47    }
48
49    public int doFinal(
50        byte[]  out,
51        int     outOff)
52    {
53        finish();
54
55        Pack.longToBigEndian(H1, out, outOff);
56        Pack.longToBigEndian(H2, out, outOff + 8);
57        Pack.longToBigEndian(H3, out, outOff + 16);
58        Pack.longToBigEndian(H4, out, outOff + 24);
59        Pack.longToBigEndian(H5, out, outOff + 32);
60        Pack.longToBigEndian(H6, out, outOff + 40);
61
62        reset();
63
64        return DIGEST_LENGTH;
65    }
66
67    /**
68     * reset the chaining variables
69     */
70    public void reset()
71    {
72        super.reset();
73
74        /* SHA-384 initial hash value
75         * The first 64 bits of the fractional parts of the square roots
76         * of the 9th through 16th prime numbers
77         */
78        H1 = 0xcbbb9d5dc1059ed8l;
79        H2 = 0x629a292a367cd507l;
80        H3 = 0x9159015a3070dd17l;
81        H4 = 0x152fecd8f70e5939l;
82        H5 = 0x67332667ffc00b31l;
83        H6 = 0x8eb44a8768581511l;
84        H7 = 0xdb0c2e0d64f98fa7l;
85        H8 = 0x47b5481dbefa4fa4l;
86    }
87
88    public Memoable copy()
89    {
90        return new SHA384Digest(this);
91    }
92
93    public void reset(Memoable other)
94    {
95        SHA384Digest d = (SHA384Digest)other;
96
97        super.copyIn(d);
98    }
99}
100