1
2
3
4
5 package sha3
6
7
8
9
10
11 import (
12 "crypto"
13 "hash"
14 )
15
16
17
18
19 func New224() hash.Hash {
20 return new224()
21 }
22
23
24
25
26 func New256() hash.Hash {
27 return new256()
28 }
29
30
31
32
33 func New384() hash.Hash {
34 return new384()
35 }
36
37
38
39
40 func New512() hash.Hash {
41 return new512()
42 }
43
44 func init() {
45 crypto.RegisterHash(crypto.SHA3_224, New224)
46 crypto.RegisterHash(crypto.SHA3_256, New256)
47 crypto.RegisterHash(crypto.SHA3_384, New384)
48 crypto.RegisterHash(crypto.SHA3_512, New512)
49 }
50
51 func new224Generic() *state {
52 return &state{rate: 144, outputLen: 28, dsbyte: 0x06}
53 }
54
55 func new256Generic() *state {
56 return &state{rate: 136, outputLen: 32, dsbyte: 0x06}
57 }
58
59 func new384Generic() *state {
60 return &state{rate: 104, outputLen: 48, dsbyte: 0x06}
61 }
62
63 func new512Generic() *state {
64 return &state{rate: 72, outputLen: 64, dsbyte: 0x06}
65 }
66
67
68
69
70
71 func NewLegacyKeccak256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x01} }
72
73
74
75
76
77 func NewLegacyKeccak512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x01} }
78
79
80 func Sum224(data []byte) (digest [28]byte) {
81 h := New224()
82 h.Write(data)
83 h.Sum(digest[:0])
84 return
85 }
86
87
88 func Sum256(data []byte) (digest [32]byte) {
89 h := New256()
90 h.Write(data)
91 h.Sum(digest[:0])
92 return
93 }
94
95
96 func Sum384(data []byte) (digest [48]byte) {
97 h := New384()
98 h.Write(data)
99 h.Sum(digest[:0])
100 return
101 }
102
103
104 func Sum512(data []byte) (digest [64]byte) {
105 h := New512()
106 h.Write(data)
107 h.Sum(digest[:0])
108 return
109 }
110
View as plain text