Documentation ¶
Overview ¶
Package shake provides implementation of SHA-3 and cSHAKE This code has been copied from golang.org/x/crypto/sha3 and heavily modified. This version doesn't use heap when computing cSHAKE. It makes it possible to allocate heap once when object is created and then reuse heap allocated structures in subsequent calls.
Example (Mac) ¶
k := []byte("this is a secret key; you should generate a strong random key that's at least 32 bytes long") buf := []byte("and this is some data to authenticate") // A MAC with 32 bytes of output has 256-bit security strength -- if you use at least a 32-byte-long key. h := make([]byte, 32) d := NewShake256() // Write the key into the hash. _, _ = d.Write(k) // Now write the data. _, _ = d.Write(buf) // Read 32 bytes of output from the hash into h. _, _ = d.Read(h) fmt.Printf("%x\n", h)
Output: 78de2974bd2711d5549ffd32b753ef0f5fa80a0db2556db60f0987eb8a9218ff
Example (Sum) ¶
buf := []byte("some data to hash") // A hash needs to be 64 bytes long to have 256-bit collision resistance. h := make([]byte, 64) // Compute a 64-byte hash of buf and put it in h. shake := NewShake256() _, _ = shake.Write(buf) _, _ = shake.Read(h) fmt.Printf("%x\n", h)
Output: 0f65fe41fc353e52c55667bb9e2b27bfcc8476f2c413e9437d272ee3194a4e3146d05ec04a25d16b8f577c19b82d16b1424c3e022e783d2b4da98de3658d363d
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var RC = [24]uint64{
0x0000000000000001,
0x0000000000008082,
0x800000000000808A,
0x8000000080008000,
0x000000000000808B,
0x0000000080000001,
0x8000000080008081,
0x8000000000008009,
0x000000000000008A,
0x0000000000000088,
0x0000000080008009,
0x000000008000000A,
0x000000008000808B,
0x800000000000008B,
0x8000000000008089,
0x8000000000008003,
0x8000000000008002,
0x8000000000000080,
0x000000000000800A,
0x800000008000000A,
0x8000000080008081,
0x8000000000008080,
0x0000000080000001,
0x8000000080008008,
}
RC stores the round constants for use in the ι step.
Functions ¶
func KeccakF1600 ¶
func KeccakF1600(a *[25]uint64)
func NewLegacyKeccak256 ¶
Only use this function if you require compatibility with an existing cryptosystem that uses non-standard padding. All other users should use New256 instead.
Types ¶
type Shake ¶
type Shake struct {
// contains filtered or unexported fields
}
Example ¶
out := make([]byte, 32) msg := []byte("The quick brown fox jumps over the lazy dog") // Example 1: Simple Shake c1 := NewShake256() _, _ = c1.Write(msg) _, _ = c1.Read(out) fmt.Println(hex.EncodeToString(out))
Output: 2f671343d9b2e1604dc9dcf0753e5fe15c7c64a0d283cbbf722d411a0e36f6ca
func NewShake128 ¶
func NewShake128() Shake
NewShake128 creates a new SHAKE128 variable-output-length Shake. Its generic security strength is 128 bits against all attacks if at least 32 bytes of its output are used.
func NewShake256 ¶
func NewShake256() Shake
NewShake256 creates a new SHAKE256 variable-output-length Shake. Its generic security strength is 256 bits against all attacks if at least 64 bytes of its output are used.
func (*Shake) Reset ¶
func (d *Shake) Reset()
Reset clears the internal state by zeroing the sponge state and the byte buffer, and setting Sponge.state to absorbing.