hash

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Lengths of hash outputs in bytes
	HashLenSha2_256 = 32
	HashLenSha2_384 = 48
	HashLenSha3_256 = 32
	HashLenSha3_384 = 48
	// KMAC
	// the parameter maximum bytes-length as defined in NIST SP 800-185
	KmacMaxParamsLen = 2040 / 8
)

Variables

This section is empty.

Functions

func HashesToBytes

func HashesToBytes(hashes []Hash) [][]byte

HashesToBytes converts a slice of hashes to a slice of byte slices.

Types

type Hash

type Hash []byte

Hash is the hash algorithms output types

func BytesToHash

func BytesToHash(b []byte) Hash

func (Hash) Equal

func (h Hash) Equal(input Hash) bool

Equal checks if a hash is equal to a given hash

func (Hash) Hex

func (h Hash) Hex() string

Hex returns the hex string representation of the hash.

func (Hash) String

func (h Hash) String() string

String returns the hex string representation of the hash.

type Hasher

type Hasher interface {
	// Algorithm returns the hashing algorithm for this hasher.
	Algorithm() HashingAlgorithm
	// Size returns the hash output length
	Size() int
	// ComputeHash returns the hash output regardless of the hash state
	ComputeHash([]byte) Hash
	// Write([]bytes) (using the io.Writer interface) adds more bytes to the
	// current hash state
	io.Writer
	// SumHash returns the hash output and resets the hash state
	SumHash() Hash
	// Reset resets the hash state
	Reset()
}

Hasher interface

func NewKMAC_128

func NewKMAC_128(key []byte, customizer []byte, outputSize int) (Hasher, error)

NewKMAC_128 returns a new KMAC instance

  • key is the KMAC key (the key length is not compared to the security level, if the parameter is used as a security key and not a domain tag, the caller must make sure the key length is larger than the security level)
  • customizer is the customization string. It can be left empty if no customizer is required.

func NewSHA2_256

func NewSHA2_256() Hasher

NewSHA2_256 returns a new instance of SHA2-256 hasher

func NewSHA2_384

func NewSHA2_384() Hasher

NewSHA2_384 returns a new instance of SHA2-384 hasher

func NewSHA3_256

func NewSHA3_256() Hasher

NewSHA3_256 returns a new instance of SHA3-256 hasher

func NewSHA3_384

func NewSHA3_384() Hasher

NewSHA3_384 returns a new instance of SHA3-384 hasher

type HashingAlgorithm

type HashingAlgorithm int

HashingAlgorithm is an identifier for a hashing algorithm.

const (
	// Supported hashing algorithms
	UnknownHashingAlgorithm HashingAlgorithm = iota
	SHA2_256
	SHA2_384
	SHA3_256
	SHA3_384
	KMAC128
)

func (HashingAlgorithm) String

func (f HashingAlgorithm) String() string

String returns the string representation of this hashing algorithm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL