Source file src/vendor/golang.org/x/crypto/sha3/hashes.go
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 { 19 return new224() 20 } 21 22 // New256 creates a new SHA3-256 hash. 23 // Its generic security strength is 256 bits against preimage attacks, 24 // and 128 bits against collision attacks. 25 func New256() hash.Hash { 26 return new256() 27 } 28 29 // New384 creates a new SHA3-384 hash. 30 // Its generic security strength is 384 bits against preimage attacks, 31 // and 192 bits against collision attacks. 32 func New384() hash.Hash { 33 return new384() 34 } 35 36 // New512 creates a new SHA3-512 hash. 37 // Its generic security strength is 512 bits against preimage attacks, 38 // and 256 bits against collision attacks. 39 func New512() hash.Hash { 40 return new512() 41 } 42 43 func new224Generic() *state { 44 return &state{rate: 144, outputLen: 28, dsbyte: 0x06} 45 } 46 47 func new256Generic() *state { 48 return &state{rate: 136, outputLen: 32, dsbyte: 0x06} 49 } 50 51 func new384Generic() *state { 52 return &state{rate: 104, outputLen: 48, dsbyte: 0x06} 53 } 54 55 func new512Generic() *state { 56 return &state{rate: 72, outputLen: 64, dsbyte: 0x06} 57 } 58 59 // NewLegacyKeccak256 creates a new Keccak-256 hash. 60 // 61 // Only use this function if you require compatibility with an existing cryptosystem 62 // that uses non-standard padding. All other users should use New256 instead. 63 func NewLegacyKeccak256() hash.Hash { return &state{rate: 136, outputLen: 32, dsbyte: 0x01} } 64 65 // NewLegacyKeccak512 creates a new Keccak-512 hash. 66 // 67 // Only use this function if you require compatibility with an existing cryptosystem 68 // that uses non-standard padding. All other users should use New512 instead. 69 func NewLegacyKeccak512() hash.Hash { return &state{rate: 72, outputLen: 64, dsbyte: 0x01} } 70 71 // Sum224 returns the SHA3-224 digest of the data. 72 func Sum224(data []byte) (digest [28]byte) { 73 h := New224() 74 h.Write(data) 75 h.Sum(digest[:0]) 76 return 77 } 78 79 // Sum256 returns the SHA3-256 digest of the data. 80 func Sum256(data []byte) (digest [32]byte) { 81 h := New256() 82 h.Write(data) 83 h.Sum(digest[:0]) 84 return 85 } 86 87 // Sum384 returns the SHA3-384 digest of the data. 88 func Sum384(data []byte) (digest [48]byte) { 89 h := New384() 90 h.Write(data) 91 h.Sum(digest[:0]) 92 return 93 } 94 95 // Sum512 returns the SHA3-512 digest of the data. 96 func Sum512(data []byte) (digest [64]byte) { 97 h := New512() 98 h.Write(data) 99 h.Sum(digest[:0]) 100 return 101 } 102