OLD | NEW |
(Empty) | |
| 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 defines the ShakeHash interface, and provides |
| 8 // functions for creating SHAKE instances, as well as utility |
| 9 // functions for hashing bytes to arbitrary-length output. |
| 10 |
| 11 import ( |
| 12 "io" |
| 13 ) |
| 14 |
| 15 // Shake defines the interface to hash functions that |
| 16 // support arbitrary-length output. |
| 17 type ShakeHash interface { |
| 18 // Write absorbs more data into the hash's state. |
| 19 // It never returns an error. |
| 20 io.Writer |
| 21 // Read reads more output from the hash; reading affects the hash's |
| 22 // state. (Shake.Read is thus very different from Hash.Sum) |
| 23 // It never returns an error. |
| 24 io.Reader |
| 25 |
| 26 // Barrier overwrites (200 - rate) bytes of the hash's state |
| 27 // with zeros, making it computationally infeasible to recover |
| 28 // previous inputs. |
| 29 Barrier() |
| 30 |
| 31 // Reset resets the Hash to its initial state. |
| 32 Reset() |
| 33 } |
| 34 |
| 35 // NewShake128 creates a new SHAKE128 variable-output-length Sponge. |
| 36 // Its generic security strength is 128 bits against all attacks if at |
| 37 // least 32 bytes of its output are used. |
| 38 func NewShake128() ShakeHash { return &state{rate: 168, dsbyte: 0x1f} } |
| 39 |
| 40 // NewShake256 creates a new SHAKE128 variable-output-length Sponge. |
| 41 // Its generic security strength is 256 bits against all attacks if |
| 42 // at least 64 bytes of its output are used. |
| 43 func NewShake256() ShakeHash { return &state{rate: 136, dsbyte: 0x1f} } |
| 44 |
| 45 // ShakeSum128 writes an arbitrary-length digest of data into hash. |
| 46 func ShakeSum128(hash, data []byte) { |
| 47 h := NewShake128() |
| 48 h.Write(data) |
| 49 h.Read(hash) |
| 50 } |
| 51 |
| 52 // ShakeSum256 writes an arbitrary-length digest of data into hash. |
| 53 func ShakeSum256(hash, data []byte) { |
| 54 h := NewShake256() |
| 55 h.Write(data) |
| 56 h.Read(hash) |
| 57 } |
OLD | NEW |