passhash

package
v0.4.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package passhash hashes and verifies argon2id passwords in the PHC string format "$argon2id$v=19$m=...,t=...,p=...$salt$hash", shared by the account service's player passwords and the admin package's operator passwords.

Index

Constants

View Source
const (
	// MaxTime is the most passes over memory.
	MaxTime = 16
	// MaxMemoryKiB is the most memory one hash uses, in KiB: 4 GiB.
	MaxMemoryKiB = 4 << 20
	// MaxThreads is the most lanes.
	MaxThreads = 16
	// SaltLen is the length of the random salt Hash draws, in bytes.
	SaltLen = 16
	// KeyLen is the length of the hash Hash derives, in bytes.
	KeyLen = 32
)

Bounds of a hash's cost. Parse refuses a hash outside them, so a tampered record cannot make a check exhaust memory.

Variables

View Source
var ErrFormat = errors.New("passhash: malformed password hash")

ErrFormat reports a string that is not an argon2id hash within the bounds above.

Functions

func Hash

func Hash(password string, p Params, r io.Reader) (string, error)

Hash returns the argon2id hash of password with cost p and a random salt read from r. The caller validates p and the password's length first.

Types

type Params

type Params struct {
	// Time is the number of passes over memory, 1 to MaxTime.
	Time uint32
	// MemoryKiB is the memory one hash uses, in KiB, from 8*Threads to MaxMemoryKiB.
	MemoryKiB uint32
	// Threads is the parallelism (lanes), 1 to MaxThreads.
	Threads uint8
}

Params is the cost of a hash.

func Cost

func Cost(encoded string) (Params, error)

Cost returns the cost encoded was made with, or ErrFormat when it is not a well-formed argon2id hash within the bounds, without computing the hash.

func Verify

func Verify(password, encoded string) (bool, Params, error)

Verify reports whether password matches encoded, comparing in constant time, and returns the cost the hash was made with. A malformed hash gives ErrFormat.

func (Params) Valid

func (p Params) Valid() bool

Valid reports whether p is within argon2id's limits and the bounds above.

Jump to

Keyboard shortcuts

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