xargon2

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
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"
)
View Source
const DefaultSaltAndPepperLength int = 16

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

Variables

This section is empty.

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.

Jump to

Keyboard shortcuts

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