|
| 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 keccak |
| 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 | +const ( |
| 16 | + dsbyteSHA3 = 0b00000110 |
| 17 | + dsbyteKeccak = 0b00000001 |
| 18 | + dsbyteShake = 0b00011111 |
| 19 | + dsbyteCShake = 0b00000100 |
| 20 | + |
| 21 | + // rateK[c] is the rate in bytes for Keccak[c] where c is the capacity in |
| 22 | + // bits. Given the sponge size is 1600 bits, the rate is 1600 - c bits. |
| 23 | + rateK256 = (1600 - 256) / 8 |
| 24 | + rateK448 = (1600 - 448) / 8 |
| 25 | + rateK512 = (1600 - 512) / 8 |
| 26 | + rateK768 = (1600 - 768) / 8 |
| 27 | + rateK1024 = (1600 - 1024) / 8 |
| 28 | +) |
| 29 | + |
| 30 | +// NewLegacyKeccak256 creates a new Keccak-256 hash. |
| 31 | +// |
| 32 | +// Only use this function if you require compatibility with an existing cryptosystem |
| 33 | +// that uses non-standard padding. All other users should use New256 instead. |
| 34 | +func NewLegacyKeccak256() hash.Hash { |
| 35 | + return &state{rate: rateK512, outputLen: 32, dsbyte: dsbyteKeccak} |
| 36 | +} |
| 37 | + |
| 38 | +// NewLegacyKeccak512 creates a new Keccak-512 hash. |
| 39 | +// |
| 40 | +// Only use this function if you require compatibility with an existing cryptosystem |
| 41 | +// that uses non-standard padding. All other users should use New512 instead. |
| 42 | +func NewLegacyKeccak512() hash.Hash { |
| 43 | + return &state{rate: rateK1024, outputLen: 64, dsbyte: dsbyteKeccak} |
| 44 | +} |
0 commit comments