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 implements the SHA-3 hash algorithms and the SHAKE extendable
6 // output functions defined in FIPS 202.
7 //
8 // Most of this package is a wrapper around the crypto/sha3 package in the
9 // standard library. The only exception is the legacy Keccak hash functions.
10 package sha3
11 12 import (
13 "crypto/sha3"
14 "hash"
15 )
16 17 // New224 creates a new SHA3-224 hash.
18 // Its generic security strength is 224 bits against preimage attacks,
19 // and 112 bits against collision attacks.
20 //
21 // It is a wrapper for the [sha3.New224] function in the standard library.
22 //
23 //go:fix inline
24 func New224() hash.Hash {
25 return sha3.New224()
26 }
27 28 // New256 creates a new SHA3-256 hash.
29 // Its generic security strength is 256 bits against preimage attacks,
30 // and 128 bits against collision attacks.
31 //
32 // It is a wrapper for the [sha3.New256] function in the standard library.
33 //
34 //go:fix inline
35 func New256() hash.Hash {
36 return sha3.New256()
37 }
38 39 // New384 creates a new SHA3-384 hash.
40 // Its generic security strength is 384 bits against preimage attacks,
41 // and 192 bits against collision attacks.
42 //
43 // It is a wrapper for the [sha3.New384] function in the standard library.
44 //
45 //go:fix inline
46 func New384() hash.Hash {
47 return sha3.New384()
48 }
49 50 // New512 creates a new SHA3-512 hash.
51 // Its generic security strength is 512 bits against preimage attacks,
52 // and 256 bits against collision attacks.
53 //
54 // It is a wrapper for the [sha3.New512] function in the standard library.
55 //
56 //go:fix inline
57 func New512() hash.Hash {
58 return sha3.New512()
59 }
60 61 // Sum224 returns the SHA3-224 digest of the data.
62 //
63 // It is a wrapper for the [sha3.Sum224] function in the standard library.
64 //
65 //go:fix inline
66 func Sum224(data []byte) [28]byte {
67 return sha3.Sum224(data)
68 }
69 70 // Sum256 returns the SHA3-256 digest of the data.
71 //
72 // It is a wrapper for the [sha3.Sum256] function in the standard library.
73 //
74 //go:fix inline
75 func Sum256(data []byte) [32]byte {
76 return sha3.Sum256(data)
77 }
78 79 // Sum384 returns the SHA3-384 digest of the data.
80 //
81 // It is a wrapper for the [sha3.Sum384] function in the standard library.
82 //
83 //go:fix inline
84 func Sum384(data []byte) [48]byte {
85 return sha3.Sum384(data)
86 }
87 88 // Sum512 returns the SHA3-512 digest of the data.
89 //
90 // It is a wrapper for the [sha3.Sum512] function in the standard library.
91 //
92 //go:fix inline
93 func Sum512(data []byte) [64]byte {
94 return sha3.Sum512(data)
95 }
96