crypto

package
v0.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package crypto holds the password hashing and token primitives of Auth-All.

Index

Constants

View Source
const (
	RecoveryCodeGroups    = 2
	RecoveryCodeGroupSize = 5
)

RecoveryCodeGroups and RecoveryCodeGroupSize describe the shape of one code. Two groups of five characters read well from paper.

View Source
const TokenBytes = 32

TokenBytes is the entropy of every generated token. 32 bytes is 256 bits.

Variables

View Source
var ErrInvalidHash = errors.New("authall: the stored password hash is invalid")

ErrInvalidHash reports a stored hash that cannot be decoded.

Functions

func HashPassword

func HashPassword(password string, p Argon2Params) (string, error)

HashPassword returns a PHC encoded Argon2id hash.

func HashToken

func HashToken(token string) string

HashToken returns the hex encoded SHA-256 hash of a token. Auth-All stores only this value.

func NeedsRehash

func NeedsRehash(stored Argon2Params, want Argon2Params) bool

NeedsRehash reports whether a stored hash uses different parameters than the configured ones. A successful sign-in then rehashes the password.

func NewPKCEVerifier

func NewPKCEVerifier() (string, error)

NewPKCEVerifier returns a PKCE code verifier.

func NewRecoveryCodes added in v0.2.0

func NewRecoveryCodes(n int) ([]string, error)

NewRecoveryCodes returns n random recovery codes in the form abcde-fghij.

A code is a second factor and a first factor at the same time, so treat the returned values like a password reset token. Show them one time and store only the hash.

func NewToken

func NewToken() (string, error)

NewToken returns a URL-safe random token with at least 256 bits of entropy.

func NormalizeRecoveryCode added in v0.2.0

func NormalizeRecoveryCode(code string) string

NormalizeRecoveryCode returns the comparable form of a recovery code.

A person retypes a code from paper, so the case, the separator, and the spaces vary. The stored hash covers this form, so every variant of one code matches.

func PKCEChallenge

func PKCEChallenge(verifier string) string

PKCEChallenge returns the S256 challenge for a verifier.

Types

type Argon2Params

type Argon2Params struct {
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	SaltLength  uint32
	KeyLength   uint32
}

Argon2Params holds the Argon2id cost parameters. Every stored hash encodes the parameters that produced it.

func DefaultArgon2Params

func DefaultArgon2Params() Argon2Params

DefaultArgon2Params returns the secure default cost parameters.

func VerifyPassword

func VerifyPassword(password, encoded string) (bool, Argon2Params, error)

VerifyPassword reports whether the password matches the encoded hash. It also returns the parameters that produced the stored hash.

Jump to

Keyboard shortcuts

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