Documentation
¶
Index ¶
Constants ¶
View Source
const ( // ModeArgon2id is the default mode, recommended by NIST. ModeArgon2id = "argon2id" // ModeArgon2i is optimized to resist side-channel attacks. ModeArgon2i = "argon2i" )
View Source
const ( // DefaultMemory is the default memory (in kibibytes) used by the algorithm (64 MB). DefaultMemory = 64 * 1024 // DefaultIterations is the default number of passes over the memory. DefaultIterations = 1 // DefaultParallelism is the default number of threads (or lanes) used by the algorithm. DefaultParallelism = 4 // DefaultSaltLength is the default length of the random salt. DefaultSaltLength = 16 // DefaultKeyLength is the default length of the generated key. DefaultKeyLength = 32 )
Variables ¶
View Source
var ( // ErrInvalidHash is returned when the hash is not in the correct format. ErrInvalidHash = errors.New("argon: hash is not in the correct format") // ErrIncompatibleVersion is returned when the hash version is not supported. ErrIncompatibleVersion = errors.New("argon: incompatible version of argon2") // ErrUnsupportedMode is returned when the mode is not supported. ErrUnsupportedMode = errors.New("argon: unsupported argon2 mode") )
Functions ¶
func HashWithParams ¶
HashWithParams returns a matchable PHC string using the provided configuration.
Types ¶
type Params ¶
type Params struct {
// The amount of memory used by the algorithm (in kibibytes).
Memory uint32
// The number of passes over the memory.
Iterations uint32
// The number of threads (or lanes) used by the algorithm.
Parallelism uint8
// The length of the random salt. 16 bytes is recommended for password hashing.
SaltLength uint32
// The length of the generated key (or password hash). 32 bytes or more is recommended.
KeyLength uint32
// The mode of Argon2 to use (argon2id or argon2i).
Mode string
}
Params describes the input parameters used by the Argon2id algorithm. The params are set to satisfy NIST recommendations for password hashing.
func DefaultParams ¶
func DefaultParams() *Params
DefaultParams returns the parameters recommended for interactive logins according to NIST and OWASP guidelines (2024/2025).
Current defaults:
- Memory: 64 MB (64 * 1024)
- Iterations: 1
- Parallelism: up to 4 (uses runtime.NumCPU() if less than 4, but always capped at 4) This cap is intended to avoid excessive resource usage on high-core-count systems for typical authentication scenarios, and to provide consistent default behavior. Note: On systems with more than 4 CPUs, this may result in underutilization of available CPU cores. If higher parallelism is desired, set the Parallelism field manually.
- SaltLength: 16 bytes
- KeyLength: 32 bytes
- Mode: argon2id
Click to show internal directories.
Click to hide internal directories.