hmac

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message. The receiver verifies the hash by recomputing it using the same key.

Receivers should be careful to use Equal to compare MACs in order to avoid timing side-channels:

// ValidMAC reports whether messageMAC is a valid HMAC tag for message.
func ValidMAC(message, messageMAC, key []byte) bool {
	mac := hmac.New(sha256.New, key)
	mac.Write(message)
	expectedMAC := mac.Sum(nil)
	return hmac.Equal(messageMAC, expectedMAC)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireSHA1

func AcquireSHA1(key []byte) hash.Hash

AcquireSHA1 returns new HMAC from pool.

func AcquireSHA256

func AcquireSHA256(key []byte) hash.Hash

AcquireSHA256 returns new HMAC from SHA256 pool.

func Equal

func Equal(mac1, mac2 []byte) bool

Equal compares two MACs for equality without leaking timing information.

func New

func New(h func() hash.Hash, key []byte) hash.Hash

New returns a new HMAC hash using the given hash.Hash type and key. Note that unlike other hash implementations in the standard library, the returned Hash does not implement encoding.BinaryMarshaler or encoding.BinaryUnmarshaler.

func PutSHA1

func PutSHA1(h hash.Hash)

PutSHA1 puts h to pool.

func PutSHA256

func PutSHA256(h hash.Hash)

PutSHA256 puts h to SHA256 pool.

Types

This section is empty.

Jump to

Keyboard shortcuts

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