hash

package
v0.0.0-...-2243100 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2021 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MACSize represents the size of a 16 byte MAC.
	MACSize = 16

	// KeySize represents the size of a 32 byte key.
	KeySize = 32
)

Variables

This section is empty.

Functions

func Blake2bKDF

func Blake2bKDF(key []byte, size uint32, salt, info []byte) ([]byte, error)

Blake2bKDF is a key derivation function. It's suitable to be used with keys with uniform entropy and not for use with passwords/passphrases. salt and info are optional and must be less than 64 bytes in total. NOTE: I SUGGEST NOT USING THIS - instead use HKDF-SHA256.

func Blake2bMAC

func Blake2bMAC(key, data []byte) []byte

Blake2bMAC is a MAC that uses Blake2b's keyed hash mechanism instead of an HMAC construction. The output is of size MACSize.

func HMACSHA256

func HMACSHA256(message, key []byte) []byte

HMACSHA256 returns the HMAC-SHA256 authentication code for the given message and key.

func Hash

func Hash(contextInfo string, data []byte) ([]byte, error)

Hash hashes the data with contextInfo used as the key for blake2's keying mechanism. contextInfo is meant to be a human readable string that ensures each use case of the hash function will have different outputs.

func HashPassword

func HashPassword(password, salt []byte) []byte

HashPassword returns a 32 byte cryptographic key given a password and an entropic salt.

func KDF

func KDF(secret, salt, info []byte, keysNum, keySize int) ([][]byte, error)

KDF returns a slice of derive keysNum number of derived keys of size keySize. The given secret must be a uniform entropy secret (ie not a password) and info is an optional non-secret which may be omitted.

Note: in practice you probably don't want to use this particular function but instead use the HKDF directly where you need it.

func SimplexHash

func SimplexHash(data []byte) []byte

SimplexHash is the simplest usage of a hash function and is suitable if you only have one use case.

func ValidBlake2bMAC

func ValidBlake2bMAC(message, messageMAC, key []byte) bool

ValidBlake2bMAC reports whether Blake2b messageMAC is a valid MAC tag for message.

func ValidHMACSHA256

func ValidHMACSHA256(message, messageMAC, key []byte) bool

ValidMAC reports whether messageMAC is a valid HMAC tag for message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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