argon

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package argon provides secure Argon2 password hashing functionality. It supports both Argon2id (recommended) and Argon2i variants with configurable parameters.

Argon2 is a memory-hard key derivation function that won the Password Hashing Competition and is resistant to both time-memory trade-off attacks and side-channel attacks.

Example usage:

// Hash a password with default configuration
hash, err := argon.GenerateHashedPassword("mypassword", argon.DefaultConfig)
if err != nil {
	log.Fatal(err)
}

// Verify a password
valid, err := argon.CompareHashAndPassword(hash, "mypassword")
if err != nil {
	log.Fatal(err)
}
if valid {
	fmt.Println("Password is correct")
}

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHashFormat = errors.New("invalid password hash format")
	ErrVersionMismatch   = errors.New("argon2 version mismatch")
	ErrInvalidPassword   = errors.New("password does not match")
)

Exported error types for use in conditional handling

View Source
var DefaultConfig = Config{
	Type:        "argon2id",
	Memory:      128 * 1024,
	Iterations:  4,
	Parallelism: uint8(runtime.NumCPU()),
	SaltLength:  32,
	KeyLength:   32,
}

DefaultConfig provides sane, secure default values.

Functions

func CompareHashAndPassword

func CompareHashAndPassword(storedHash, password string) (bool, error)

CompareHashAndPassword verifies a password against a stored hash.

func GenerateHashedPassword

func GenerateHashedPassword(password string, cfg Config) (string, error)

GenerateHashedPassword hashes the given password using the provided Argon2 configuration.

Types

type Config

type Config struct {
	Type        string // "argon2id" or "argon2i"
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	SaltLength  uint32
	KeyLength   uint32
}

Config defines tunable parameters for Argon2 password hashing.

Jump to

Keyboard shortcuts

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