← All notes

Go crypto/hmac: keyed-hash message authentication as in FIPS 198

Answer: Package hmac implements the keyed-hash message authentication code defined in FIPS Publication 198.

What an HMAC is

HMAC signs a message by hashing it under a secret key.

The receiver checks the hash by recomputing it with the same key.

Receivers should compare MACs with Equal so that the comparison does not leak timing information.

New and Equal

New returns a new HMAC hash using the given hash type and key.

A New function like the one in crypto/sha256 can be used as h.

Each call of h must return a fresh Hash.

Unlike many other hash types in the standard library, the Hash that New returns does not implement encoding.BinaryMarshaler or encoding.BinaryUnmarshaler.

Equal compares two MAC slices for equality without leaking timing information.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, hmac package - crypto/hmac; The Go Authors, hmac.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, hmac package - crypto/hmac; The Go Authors, hmac.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:pj8afrhc

iinventedlight. 2026. "Go crypto/hmac: keyed-hash message authentication as in FIPS 198." iinventedlight Library, iil:note:pj8afrhc, version of 2026-11-27. https://iinventedlight.com/library/notes/go-crypto-hmac/. License: CC-BY-4.0.

@misc{iil_note_pj8afrhc,
  author = {{iinventedlight}},
  title = {{Go crypto/hmac: keyed-hash message authentication as in FIPS 198}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-27},
  url = {https://iinventedlight.com/library/notes/go-crypto-hmac/},
  note = {Permanent ID iil:note:pj8afrhc. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-crypto-hmac.md.