mac

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Poly1305KeySize is the size in bytes of the one-time key accepted by Poly1305.
	Poly1305KeySize = 32
	// Poly1305TagSize is the size in bytes of the authenticator produced by Poly1305.
	Poly1305TagSize = internal.TagSize
)

Variables

This section is empty.

Functions

func KMAC128

func KMAC128(key, customization, msg []byte, outLen int) []byte

KMAC128 computes a single-shot KMAC128 MAC of the provided message.

func KMAC256

func KMAC256(key, customization, msg []byte, outLen int) []byte

KMAC256 computes a single-shot KMAC256 MAC of the provided message.

func NewKMAC128

func NewKMAC128(key, customization []byte) stdhash.Hash

NewKMAC128 constructs a streaming KMAC128 instance producing a 32-byte MAC.

func NewKMAC128WithSize

func NewKMAC128WithSize(key, customization []byte, outLen int) stdhash.Hash

NewKMAC128WithSize constructs a streaming KMAC128 instance with a custom output length.

func NewKMAC256

func NewKMAC256(key, customization []byte) stdhash.Hash

NewKMAC256 constructs a streaming KMAC256 instance producing a 64-byte MAC.

func NewKMAC256WithSize

func NewKMAC256WithSize(key, customization []byte, outLen int) stdhash.Hash

NewKMAC256WithSize constructs a streaming KMAC256 instance with a custom output length.

func Sum

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

Sum computes HMAC-SHA256 over data using key and returns the resulting MAC.

func SumPoly1305

func SumPoly1305(key, msg []byte) ([]byte, error)

SumPoly1305 computes a Poly1305 authenticator over msg with the provided one-time key and returns the 16-byte tag. The key must be used only once.

func Verify

func Verify(key, data, mac []byte) bool

Verify recomputes HMAC-SHA256 over data and compares it with mac in constant time. It returns true if and only if the MACs match.

func VerifyPoly1305

func VerifyPoly1305(key, msg, tag []byte) (bool, error)

VerifyPoly1305 recomputes the Poly1305 authenticator for msg and compares it to tag using constant-time comparison.

Types

type KMAC

type KMAC struct {
	// contains filtered or unexported fields
}

KMAC implements the SP 800-185 KMAC construction backed by cSHAKE.

func (*KMAC) BlockSize

func (k *KMAC) BlockSize() int

BlockSize returns the rate of the underlying cSHAKE permutation.

func (*KMAC) Reset

func (k *KMAC) Reset()

Reset restores the MAC to its initial state, ready to absorb a new message.

func (*KMAC) Size

func (k *KMAC) Size() int

Size reports the size in bytes of the final MAC output.

func (*KMAC) Sum

func (k *KMAC) Sum(b []byte) []byte

Sum finalises the computation and appends the resulting MAC to b.

func (*KMAC) Write

func (k *KMAC) Write(p []byte) (int, error)

Write absorbs data into the MAC state.

type Poly1305

type Poly1305 struct {
	// contains filtered or unexported fields
}

Poly1305 provides a minimal helper for computing standalone Poly1305 MACs.

The helper wraps the internal Poly1305 implementation reused by the AEAD constructions. Callers must supply a unique one-time key for every message.

func NewPoly1305

func NewPoly1305(key []byte) (*Poly1305, error)

NewPoly1305 initialises a Poly1305 helper with the provided one-time key. The key must be exactly 32 bytes as specified by RFC 7539.

func (*Poly1305) Sum

func (p *Poly1305) Sum() []byte

Sum finalises the MAC and returns the authenticator. Further writes will panic, matching the behaviour of the underlying implementation.

func (*Poly1305) Verify

func (p *Poly1305) Verify(expected []byte) bool

Verify finalises the MAC and compares it with expected in constant time.

func (*Poly1305) Write

func (p *Poly1305) Write(data []byte) (int, error)

Write appends data to the running authenticator. It mirrors the semantics of hash.Hash Write but Poly1305 keys must never be reused across messages.

Jump to

Keyboard shortcuts

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