Documentation
¶
Overview ¶
Package hash provides password hashing (argon2id) and HMAC signature helpers.
Passwords: use HashPassword to produce a self-describing hash string (parameters + salt embedded), and VerifyPassword to check. The string format matches the standard PHC (argon2id) encoding used by every modern library, so it is portable across languages.
HMAC: HMACSHA256 and HMACSHA512 return hex-encoded MACs. VerifyHMAC uses constant-time comparison.
Index ¶
- Variables
- func HMACSHA256(key, msg []byte) string
- func HMACSHA512(key, msg []byte) string
- func HashPassword(password string) (string, error)
- func HashPasswordWith(password string, p argon2Params) (string, error)
- func VerifyHMACSHA256(key, msg []byte, mac string) bool
- func VerifyHMACSHA512(key, msg []byte, mac string) bool
- func VerifyPassword(password, encoded string) error
Constants ¶
This section is empty.
Variables ¶
var DefaultArgon2Params = argon2Params{ // contains filtered or unexported fields }
DefaultArgon2Params are the OWASP-recommended defaults. Exposed so consumers running on slow hardware can dial down; production should dial up when possible.
var ErrMismatch = errors.New("hash: password mismatch")
ErrMismatch is returned by VerifyPassword when the password does not match the encoded hash. Distinct from format-parsing errors so callers can react (e.g. increment failure counters) only for real mismatches.
Functions ¶
func HMACSHA256 ¶
HMACSHA256 returns hex(HMAC-SHA256(key, msg)).
func HMACSHA512 ¶
HMACSHA512 returns hex(HMAC-SHA512(key, msg)).
func HashPassword ¶
HashPassword returns the PHC-encoded argon2id hash of password.
func HashPasswordWith ¶
HashPasswordWith is HashPassword with explicit params.
func VerifyHMACSHA256 ¶
VerifyHMACSHA256 constant-time compares mac (hex string) against the HMAC of msg under key.
func VerifyHMACSHA512 ¶
VerifyHMACSHA512 constant-time compares mac (hex string) against the HMAC of msg under key.
func VerifyPassword ¶
VerifyPassword returns nil if password hashes to encoded (which must be a PHC-format string produced by HashPassword or any argon2id-compatible tool). Errors on malformed input; ErrMismatch on wrong password.
Types ¶
This section is empty.