github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/crypto/sha3/hashes.go (about) 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 // This file provides functions for creating instances of the SHA-3 8 // and SHAKE hash functions, as well as utility functions for hashing 9 // bytes. 10 11 import ( 12 "hash" 13 ) 14 15 // New224 creates a new SHA3-224 hash. 16 // Its generic security strength is 224 bits against preimage attacks, 17 // and 112 bits against collision attacks. 18 func New224() hash.Hash { return &state{rate: 144, outputLen: 28, dsbyte: 0x06} } 19 20 // New256 creates a new SHA3-256 hash. 21 // Its generic security strength is 256 bits against preimage attacks, 22 // and 128 bits against collision attacks. 23 func New256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x06} } 24 25 // New384 creates a new SHA3-384 hash. 26 // Its generic security strength is 384 bits against preimage attacks, 27 // and 192 bits against collision attacks. 28 func New384() hash.Hash { return &state{rate: 104, outputLen: 48, dsbyte: 0x06} } 29 30 // New512 creates a new SHA3-512 hash. 31 // Its generic security strength is 512 bits against preimage attacks, 32 // and 256 bits against collision attacks. 33 func New512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x06} } 34 35 // Sum224 returns the SHA3-224 digest of the data. 36 func Sum224(data []byte) (digest [28]byte) { 37 h := New224() 38 h.Write(data) 39 h.Sum(digest[:0]) 40 return 41 } 42 43 // Sum256 returns the SHA3-256 digest of the data. 44 func Sum256(data []byte) (digest [32]byte) { 45 h := New256() 46 h.Write(data) 47 h.Sum(digest[:0]) 48 return 49 } 50 51 // Sum384 returns the SHA3-384 digest of the data. 52 func Sum384(data []byte) (digest [48]byte) { 53 h := New384() 54 h.Write(data) 55 h.Sum(digest[:0]) 56 return 57 } 58 59 // Sum512 returns the SHA3-512 digest of the data. 60 func Sum512(data []byte) (digest [64]byte) { 61 h := New512() 62 h.Write(data) 63 h.Sum(digest[:0]) 64 return 65 }