1
2
3
4
5
6
7 package sha256
8
9 import (
10 "crypto"
11 "crypto/internal/boring"
12 _ "crypto/internal/fips/check"
13 "crypto/internal/fips/sha256"
14 "hash"
15 )
16
17 func init() {
18 crypto.RegisterHash(crypto.SHA224, New224)
19 crypto.RegisterHash(crypto.SHA256, New)
20 }
21
22
23 const Size = 32
24
25
26 const Size224 = 28
27
28
29 const BlockSize = 64
30
31
32
33
34
35 func New() hash.Hash {
36 if boring.Enabled {
37 return boring.NewSHA256()
38 }
39 return sha256.New()
40 }
41
42
43
44
45
46 func New224() hash.Hash {
47 if boring.Enabled {
48 return boring.NewSHA224()
49 }
50 return sha256.New224()
51 }
52
53
54 func Sum256(data []byte) [Size]byte {
55 if boring.Enabled {
56 return boring.SHA256(data)
57 }
58 h := New()
59 h.Write(data)
60 var sum [Size]byte
61 h.Sum(sum[:0])
62 return sum
63 }
64
65
66 func Sum224(data []byte) [Size224]byte {
67 if boring.Enabled {
68 return boring.SHA224(data)
69 }
70 h := New224()
71 h.Write(data)
72 var sum [Size224]byte
73 h.Sum(sum[:0])
74 return sum
75 }
76
View as plain text