package hmac
import "crypto/hmac"
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:
// CheckMAC reports whether messageMAC is a valid HMAC tag for message. func CheckMAC(message, messageMAC, key []byte) bool { mac := hmac.New(sha256.New, key) mac.Write(message) expectedMAC := mac.Sum(nil) return hmac.Equal(messageMAC, expectedMAC) }
Index ¶
Functions ¶
func Equal ¶
Equal compares two MACs for equality without leaking timing information.
func New ¶
New returns a new HMAC hash using the given hash.Hash type and key.
Source Files ¶
- Version
- v1.8.0-beta.1
- Published
- Dec 1, 2016
- Platform
- darwin/amd64
- Imports
- 2 packages
- Last checked
- 35 seconds ago –
Tools for package owners.