crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

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

Index

Constants

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 NewToken

func NewToken() (string, error)

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

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