package xargon2

import "git.sr.ht/~jamesponddotco/xstd-go/xcrypto/xargon2"

Package xargon2 provides functions and utilities to extend Go's argon2 module.

Index

Constants

const (
	// ErrInvalidPassword is returned when the provided password is invalid.
	ErrInvalidPassword xerrors.Error = "invalid password"

	// ErrInvalidHash is returned when the provided hash is invalid.
	ErrInvalidHash xerrors.Error = "invalid hash format"

	// ErrInvalidHashLength is returned when the provided hash length is invalid.
	ErrInvalidHashLength xerrors.Error = "invalid hash length"

	// ErrParseHashParameters is returned when CompareHashAndPassword fails to
	// parse the hash parameters.
	ErrParseHashParameters xerrors.Error = "failed to parse hash parameters"

	// ErrDecode is returned when CompareHashAndPassword fails to decode the
	// hash or salt.
	ErrDecode xerrors.Error = "failed to decode"
)
const DefaultSaltAndPepperLength int = 16

DefaultSaltAndPepperLength is the default length of the salt and pepper used by the HashPassword method in bytes.

Functions

func CompareHashAndPassword

func CompareHashAndPassword(hash, password string, pepper []byte) error

CompareHashAndPassword compares an argon2id hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.

func GenerateFromPassword

func GenerateFromPassword(password string, parameters Parameters, salt, pepper []byte) string

GenerateFromPassword returns the argon2id hash of the given password using the Argon2id hashing algorithm with the given configuration, and the optional salt and pepper.

If salt is nil, a random salt is generated using crypto/rand.

Types

type Parameters

type Parameters struct {
	// Threads is the number of threads used by the Argon2 hashing algorithm for
	// computing the hash. It should be less than or equal to runtime.NumCPU().
	Threads uint8

	// Time is the computational cost factor used by the Argon2 hashing algorithm.
	Time uint32

	// Memory is the amount of memory used by the Argon2 hashing algorithm in KiB.
	Memory uint32

	// KeyLen is the length of the generated key in bytes.
	KeyLen uint32
}

Parameters holds the configuration parameters for the Argon2 hashing algorithm.

func NewParameters

func NewParameters() Parameters

NewParameters returns a new Parameters instance with default values.

Source Files

xargon2.go

Version
v0.13.1 (latest)
Published
Jan 29, 2025
Platform
linux/amd64
Imports
9 packages
Last checked
4 days ago

Tools for package owners.