Debian Codegraph @

src/crypto/internal/fips140/sha3/hashes.go

raw
1 // Copyright 2014 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.
4
5 package sha3
6
7 // New224 returns a new Digest computing the SHA3-224 hash.
8 func New224() *Digest {
9 return &Digest{rate: rateK448, outputLen: 28, dsbyte: dsbyteSHA3}
10 }
11
12 // New256 returns a new Digest computing the SHA3-256 hash.
13 func New256() *Digest {
14 return &Digest{rate: rateK512, outputLen: 32, dsbyte: dsbyteSHA3}
15 }
16
17 // New384 returns a new Digest computing the SHA3-384 hash.
18 func New384() *Digest {
19 return &Digest{rate: rateK768, outputLen: 48, dsbyte: dsbyteSHA3}
20 }
21
22 // New512 returns a new Digest computing the SHA3-512 hash.
23 func New512() *Digest {
24 return &Digest{rate: rateK1024, outputLen: 64, dsbyte: dsbyteSHA3}
25 }
26
27 const (
28 dsbyteSHA3 = 0b00000110
29 dsbyteKeccak = 0b00000001
30 dsbyteShake = 0b00011111
31 dsbyteCShake = 0b00000100
32
33 // rateK[c] is the rate in bytes for Keccak[c] where c is the capacity in
34 // bits. Given the sponge size is 1600 bits, the rate is 1600 - c bits.
35 rateK256 = (1600 - 256) / 8
36 rateK448 = (1600 - 448) / 8
37 rateK512 = (1600 - 512) / 8
38 rateK768 = (1600 - 768) / 8
39 rateK1024 = (1600 - 1024) / 8
40 )
41
42 // NewLegacyKeccak256 returns a new Digest computing the legacy, non-standard
43 // Keccak-256 hash.
44 func NewLegacyKeccak256() *Digest {
45 return &Digest{rate: rateK512, outputLen: 32, dsbyte: dsbyteKeccak}
46 }
47
48 // NewLegacyKeccak512 returns a new Digest computing the legacy, non-standard
49 // Keccak-512 hash.
50 func NewLegacyKeccak512() *Digest {
51 return &Digest{rate: rateK1024, outputLen: 64, dsbyte: dsbyteKeccak}
52 }