Argon2
This is the reference C implementation of Argon2, the password-hashing function that won the Password Hashing Competition (PHC).
Argon2 is a password-hashing function that summarizes the state of the art in the design of memory-hard functions and can be used to hash passwords for credential storage, key derivation, or other applications.
It has a simple design aimed at the highest memory filling rate and effective use of multiple computing units, while still providing defense against tradeoff attacks (by exploiting the cache and memory organization of the recent processors).
Argon2 has three variants: Argon2i, Argon2d, and Argon2id. Argon2d is faster and uses data-depending memory access, which makes it highly resistant against GPU cracking attacks and suitable for applications with no threats from side-channel timing attacks (eg. cryptocurrencies). Argon2i instead uses data-independent memory access, which is preferred for password hashing and password-based key derivation, but it is slower as it makes more passes over the memory to protect from tradeoff attacks. Argon2id is a hybrid of Argon2i and Argon2d, using a combination of data-depending and data-independent memory accesses, which gives some of Argon2i's resistance to side-channel cache timing attacks and much of Argon2d's resistance to GPU cracking attacks.
Argon2i, Argon2d, and Argon2id are parametrized by:
- A time cost, which defines the amount of computation realized and
therefore the execution time, given in number of iterations
- A memory cost, which defines the memory usage, given in kibibytes
- A parallelism degree, which defines the number of parallel threads
The Argon2 document gives detailed specs and design rationale.
Please report bugs as issues on this repository.
Usage
make builds the executable argon2, the static library libargon2.a, and the shared library libargon2.so (or on macOS, the dynamic library libargon2.dylib -- make sure to specify the installation prefix when you compile: make PREFIX=/usr). Make sure to run make test to verify that your build produces valid results. sudo make install PREFIX=/usr installs it to your system.
Command-line utility
argon2 is a command-line utility to test specific Argon2 instances on your system. To show usage instructions, run ./argon2 -h as
Usage: ./argon2 [-h] salt [-i|-d|-id] [-t iterations] [-m memory] [-p parallelism] [-l hash length] [-e|-r] [-v (10|13)]
Password is read from stdin
Parameters:
salt The salt to use, at least 8 characters
-i Use Argon2i (this is the default)
-d Use Argon2d instead of Argon2i
-id Use Argon2id instead of Argon2i
-t N Sets the number of iterations to N (default = 3)
-m N Sets the memory usage of 2^N KiB (default 12)
-p N Sets parallelism to N threads (default 1)
-l N Sets hash output length to N bytes (default 32)
-e Output only encoded hash-v (10|13) Argon2 version (defaults to the most recent version, currently 13) -h Print argon2 usage
For example, to hash "password" using "somesalt" as a salt and doing 2
iterations, consuming 64 MiB, using four parallel threads and an output hash
of 24 bytes