mac

package
v0.0.0-...-2514748 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mac implements Families 3 and 4 (MAC and MAC with IV). Family 3: mac(), mac_verify() — HMAC-SHA256/384/512, HMAC-SHA3-256, AES-CMAC. Family 4: mac_iv(), mac_iv_verify() — AES-GMAC (requires nonce).

Index

Constants

View Source
const (
	AlgorithmHMACSHA256   = "HMAC-SHA256"
	AlgorithmHMACSHA384   = "HMAC-SHA384"
	AlgorithmHMACSHA512   = "HMAC-SHA512"
	AlgorithmHMACSHA3_256 = "HMAC-SHA3-256"
	AlgorithmAESCMAC      = "AES-CMAC"
	AlgorithmAESGMAC      = "AES-GMAC"
)

MAC algorithm identifiers.

Variables

This section is empty.

Functions

func Mac

func Mac(key []byte, data []byte, algorithm string) ([]byte, error)

Mac computes a message authentication code over data using key and algorithm. Family 3: mac(key []byte, data []byte, algorithm string) ([]byte, error)

Supported algorithms: HMAC-SHA256, HMAC-SHA384, HMAC-SHA512, HMAC-SHA3-256, AES-CMAC.

func MacIV

func MacIV(key []byte, data []byte, algorithm string) (tag []byte, nonce []byte, err error)

MacIV computes a GMAC tag and generates a nonce internally. Family 4: mac_iv(key []byte, data []byte, algorithm string) (tag []byte, nonce []byte, error)

Only algorithm: AES-GMAC. nonce is 12 bytes, generated internally. Caller must store and provide nonce on verify.

func MacIVVerify

func MacIVVerify(key []byte, data []byte, nonce []byte, tag []byte, algorithm string) (bool, error)

MacIVVerify verifies a GMAC tag with the nonce that was generated by MacIV. Family 4: mac_iv_verify(key, data, nonce, tag, algorithm) (bool, error)

func MacVerify

func MacVerify(key []byte, data []byte, tag []byte, algorithm string) (bool, error)

MacVerify verifies a MAC tag using constant-time comparison. Family 3: mac_verify(key []byte, data []byte, tag []byte, algorithm string) (bool, error)

func NewCMAC

func NewCMAC(block cipher.Block) (*cmac, error)

NewCMAC creates a new AES-CMAC instance using the given AES cipher block.

Types

This section is empty.

Jump to

Keyboard shortcuts

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