Пример #1
0
	return s.cipher.Read(dst)
}

func (s *shake) Clone() ShakeHash {
	ns := *s
	ns.cipher = s.cipher.Clone()
	return &ns
}

func (s *shake) Reset() {
	s.cipher = cipher.FromSponge(s.sponge(), abstract.NoKey,
		cipher.Padding(0x1f))
	s.squeezing = false
}

var shakeOpts = []interface{}{cipher.Padding(0x1f)}

// NewShakeCipher128 creates a Cipher implementing the SHAKE128 algorithm,
// which provides 128-bit security against all known attacks.
func NewShakeCipher128(key []byte, options ...interface{}) abstract.Cipher {
	return cipher.FromSponge(newKeccak256(), key,
		append(shakeOpts, options...)...)
}

// NewShakeCipher256 creates a Cipher implementing the SHAKE256 algorithm,
// which provides 256-bit security against all known attacks.
func NewShakeCipher256(key []byte, options ...interface{}) abstract.Cipher {
	return cipher.FromSponge(newKeccak512(), key,
		append(shakeOpts, options...)...)
}
Пример #2
0
func (s *shake) Reset() {
	s.cipher = cipher.FromSponge(s.sponge(), abstract.NoKey,
		cipher.Padding(0x1f))
	s.squeezing = false
}
Пример #3
0
// license that can be found in the LICENSE file.

package sha3

// This file provides functions for creating instances of the SHA-3
// and SHAKE hash functions, as well as utility functions for hashing
// bytes.

import (
	"hash"

	"github.com/dedis/crypto/abstract"
	"github.com/dedis/crypto/cipher"
)

var sha3opts = []interface{}{cipher.Padding(0x06)}

// NewCipher224 creates a Cipher implementing the SHA3-224 algorithm,
// which provides 224-bit security against preimage attacks
// and 112-bit security against collisions.
func NewCipher224(key []byte, options ...interface{}) abstract.Cipher {
	return cipher.FromSponge(newKeccak448(), key,
		append(sha3opts, options...)...)
}

// NewCipher256 creates a Cipher implementing the SHA3-256 algorithm,
// which provides 256-bit security against preimage attacks
// and 128-bit security against collisions.
func NewCipher256(key []byte, options ...interface{}) abstract.Cipher {
	return cipher.FromSponge(newKeccak512(), key,
		append(sha3opts, options...)...)