hash

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (

	// Lengths of hash outputs in bytes
	HashLenSHA2_256   = 32
	HashLenSHA2_384   = 48
	HashLenSHA3_256   = 32
	HashLenSHA3_384   = 48
	HashLenKeccak_256 = 32

	// KMAC
	// the minimum key length in bytes
	KmacMinKeyLen = securityBits / 8
)

Variables

This section is empty.

Functions

func ComputeSHA2_256

func ComputeSHA2_256(result *[HashLenSHA2_256]byte, data []byte)

ComputeSHA2_256 computes the SHA2-256 (commonly known as SHA256) digest of data and copies the result to the result buffer.

The function is not part of the Hasher API. It is a pure function for simple computation of a hash with minimal heap allocations.

func ComputeSHA3_256

func ComputeSHA3_256(result *[HashLenSHA3_256]byte, data []byte)

ComputeSHA3_256 computes the SHA3-256 digest of data and copies the result to the result buffer.

The function is not part of the Hasher API. It is a pure function for simple computation of a hash with minimal heap allocations.

Types

type Hash

type Hash []byte

Hash is the hash algorithms output types

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 of the hasher.
	Algorithm() HashingAlgorithm
	// Size returns the hash output length in bytes.
	Size() int
	// ComputeHash returns the hash output regardless of the existing hash state.
	// It may update the state or not depending on the implementation. Thread safety
	// also depends on the implementation.
	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.
	// It may update the state or not depending on the implementation.
	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 size is compared to the security level, although the parameter is used as a domain tag in Flow and not as a security key).
  • customizer is the customization string. It can be left empty if no customizer is required.

func NewKeccak_256

func NewKeccak_256() Hasher

NewKeccak_256 returns a new instance of legacy Keccak-256 hasher.

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
	// SHA-2
	SHA2_256
	SHA2_384
	// SHA-3
	SHA3_256
	SHA3_384
	// KMAC (Keccak based MAC algorithm)
	KMAC128
	// legacy Keccak
	Keccak_256
)

func (HashingAlgorithm) String

func (h 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