hmacutil

package
v0.511.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package hmacutil computes and verifies HMAC-SHA1/SHA256/SHA512 message authentication codes. It is the keyed-MAC tier of the toolkit — the API/webhook-auth analogue of jwt_verify: verify or forge a webhook signature (GitHub X-Hub-Signature-256, Stripe-Signature, generic API request signing) with a known or leaked secret, or check a protocol's HMAC auth tag. It complements the unkeyed checksum tools (crc_compute / checksum_compute).

Wrap-vs-native judgement

Native. HMAC is crypto/hmac over crypto/sha*; this is a thin, deterministic wrapper plus a named-algorithm table and a constant-time verify. Nothing to wrap.

Verifiable / no confidently-wrong output

The strongest verification class: RFC 4231 publishes exact HMAC test vectors, and the unit tests assert this package reproduces them (e.g. HMAC-SHA256 with key "Jefe" over "what do ya want for nothing?" = 5bdcc146…ec3843). Verify uses a constant-time comparison.

Covered / deferred

Covered: HMAC-SHA1 / SHA256 / SHA512, compute and verify. HMAC-MD5 (legacy, omitted on purpose), keyed BLAKE2, and the full AWS SigV4 multi-step signing flow are out of scope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compute

func Compute(algo string, key, data []byte) ([]byte, error)

Compute returns the HMAC of data under key for the given algorithm.

func HashFor

func HashFor(algo string) (func() hash.Hash, error)

HashFor maps an algorithm name to its hash constructor.

func Verify

func Verify(algo string, key, data []byte, expectedHex string) (bool, error)

Verify reports whether expected (a hex MAC) matches the HMAC of data under key, using a constant-time comparison.

Types

This section is empty.

Jump to

Keyboard shortcuts

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