1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This package implements the SHA384 and SHA512 hash algorithms as defined in FIPS 180-2.
15 crypto.RegisterHash(crypto.SHA384, New384)
16 crypto.RegisterHash(crypto.SHA512, New)
19 // The size of a SHA512 checksum in bytes.
22 // The size of a SHA384 checksum in bytes.
27 _Init0 = 0x6a09e667f3bcc908
28 _Init1 = 0xbb67ae8584caa73b
29 _Init2 = 0x3c6ef372fe94f82b
30 _Init3 = 0xa54ff53a5f1d36f1
31 _Init4 = 0x510e527fade682d1
32 _Init5 = 0x9b05688c2b3e6c1f
33 _Init6 = 0x1f83d9abfb41bd6b
34 _Init7 = 0x5be0cd19137e2179
35 _Init0_384 = 0xcbbb9d5dc1059ed8
36 _Init1_384 = 0x629a292a367cd507
37 _Init2_384 = 0x9159015a3070dd17
38 _Init3_384 = 0x152fecd8f70e5939
39 _Init4_384 = 0x67332667ffc00b31
40 _Init5_384 = 0x8eb44a8768581511
41 _Init6_384 = 0xdb0c2e0d64f98fa7
42 _Init7_384 = 0x47b5481dbefa4fa4
45 // digest represents the partial evaluation of a checksum.
51 is384 bool // mark if this digest is SHA-384
54 func (d *digest) Reset() {
78 // New returns a new hash.Hash computing the SHA512 checksum.
79 func New() hash.Hash {
85 // New384 returns a new hash.Hash computing the SHA384 checksum.
86 func New384() hash.Hash {
93 func (d *digest) Size() int {
100 func (d *digest) Write(p []byte) (nn int, err os.Error) {
108 for i := 0; i < n; i++ {
121 d.nx = copy(d.x[:], p)
126 func (d0 *digest) Sum() []byte {
127 // Make a copy of d0 so that caller can keep writing and summing.
131 // Padding. Add a 1 bit and 0 bits until 112 bytes mod 128.
136 d.Write(tmp[0 : 112-len%128])
138 d.Write(tmp[0 : 128+112-len%128])
143 for i := uint(0); i < 16; i++ {
144 tmp[i] = byte(len >> (120 - 8*i))
152 p := make([]byte, 64)
154 for _, s := range d.h {
155 p[j+0] = byte(s >> 56)
156 p[j+1] = byte(s >> 48)
157 p[j+2] = byte(s >> 40)
158 p[j+3] = byte(s >> 32)
159 p[j+4] = byte(s >> 24)
160 p[j+5] = byte(s >> 16)
161 p[j+6] = byte(s >> 8)
162 p[j+7] = byte(s >> 0)