hash

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func HMACSHA256(key, msg []byte) string

HMACSHA256 returns hex(HMAC-SHA256(key, msg)).

func HMACSHA512

func HMACSHA512(key, msg []byte) string

HMACSHA512 returns hex(HMAC-SHA512(key, msg)).

func HashPassword

func HashPassword(password string) (string, error)

HashPassword returns the PHC-encoded argon2id hash of password.

func HashPasswordWith

func HashPasswordWith(password string, p argon2Params) (string, error)

HashPasswordWith is HashPassword with explicit params.

func VerifyHMACSHA256

func VerifyHMACSHA256(key, msg []byte, mac string) bool

VerifyHMACSHA256 constant-time compares mac (hex string) against the HMAC of msg under key.

func VerifyHMACSHA512

func VerifyHMACSHA512(key, msg []byte, mac string) bool

VerifyHMACSHA512 constant-time compares mac (hex string) against the HMAC of msg under key.

func VerifyPassword

func VerifyPassword(password, encoded string) error

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.

Jump to

Keyboard shortcuts

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