blake2b

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb.

For a detailed specification of BLAKE2b see https://blake2.net/blake2.pdf and for BLAKE2Xb see https://blake2.net/blake2x.pdf

If you aren't sure which function you need, use BLAKE2b (Sum512 or New512). If you need a secret-key MAC (message authentication code), use the New512 function with a non-nil key.

BLAKE2X is a construction to compute hash values larger than 64 bytes. It can produce hash values between 0 and 4 GiB.

Index

Constants

View Source
const (
	// The blocksize of BLAKE2b in bytes.
	BlockSize = 128
	// The hash size of BLAKE2b-512 in bytes.
	Size = 64
	// The hash size of BLAKE2b-384 in bytes.
	Size384 = 48
	// The hash size of BLAKE2b-256 in bytes.
	Size256 = 32
)
View Source
const OutputLengthUnknown = 0

OutputLengthUnknown can be used as the size argument to NewXOF to indicate the length of the output is not known in advance.

Variables

This section is empty.

Functions

func F

func F(h *[8]uint64, m [16]uint64, c [2]uint64, final bool, rounds uint32)

F is a compression function for BLAKE2b. It takes as an argument the state vector `h`, message block vector `m`, offset counter `t`, final block indicator flag `f`, and number of rounds `rounds`. The state vector provided as the first parameter is modified by the function.

func New

func New(size int, key []byte) (hash.Hash, error)

New returns a new hash.Hash computing the BLAKE2b checksum with a custom length. A non-nil key turns the hash into a MAC. The key must be between zero and 64 bytes long. The hash size can be a value between 1 and 64 but it is highly recommended to use values equal or greater than: - 32 if BLAKE2b is used as a hash function (The key is zero bytes long). - 16 if BLAKE2b is used as a MAC function (The key is at least 16 bytes long). When the key is nil, the returned hash.Hash implements BinaryMarshaler and BinaryUnmarshaler for state (de)serialization as documented by hash.Hash.

func New256

func New256(key []byte) (hash.Hash, error)

New256 returns a new hash.Hash computing the BLAKE2b-256 checksum. A non-nil key turns the hash into a MAC. The key must be between zero and 64 bytes long.

func New384

func New384(key []byte) (hash.Hash, error)

New384 returns a new hash.Hash computing the BLAKE2b-384 checksum. A non-nil key turns the hash into a MAC. The key must be between zero and 64 bytes long.

func New512

func New512(key []byte) (hash.Hash, error)

New512 returns a new hash.Hash computing the BLAKE2b-512 checksum. A non-nil key turns the hash into a MAC. The key must be between zero and 64 bytes long.

func Sum256

func Sum256(data []byte) [Size256]byte

Sum256 returns the BLAKE2b-256 checksum of the data.

func Sum384

func Sum384(data []byte) [Size384]byte

Sum384 returns the BLAKE2b-384 checksum of the data.

func Sum512

func Sum512(data []byte) [Size]byte

Sum512 returns the BLAKE2b-512 checksum of the data.

Types

type XOF

type XOF interface {
	// Write absorbs more data into the hash's state. It panics if called
	// after Read.
	io.Writer

	// Read reads more output from the hash. It returns io.EOF if the limit
	// has been reached.
	io.Reader

	// Clone returns a copy of the XOF in its current state.
	Clone() XOF

	// Reset resets the XOF to its initial state.
	Reset()
}

XOF defines the interface to hash functions that support arbitrary-length output.

func NewXOF

func NewXOF(size uint32, key []byte) (XOF, error)

NewXOF creates a new variable-output-length hash. The hash either produce a known number of bytes (1 <= size < 2**32-1), or an unknown number of bytes (size == OutputLengthUnknown). In the latter case, an absolute limit of 256GiB applies.

A non-nil key turns the hash into a MAC. The key must between zero and 32 bytes long.

Jump to

Keyboard shortcuts

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