Argon2

On this page 7

Argon2 is a memory-hard password hashing and key derivation function designed to make brute-force guessing of passwords slow and expensive, even for attackers equipped with GPUs or custom hardware. In cryptography, it is the winner of the Password Hashing Competition (2015) and is specified in RFC 9106, which makes it the reference choice for storing passwords and deriving keys from human-chosen secrets.

Unlike a general-purpose hash function such as SHA-256, which is built to be fast, Argon2 is deliberately costly in both time and memory. That cost is tunable, so defenders can choose a level that is barely noticeable for a single login yet prohibitive for billions of guesses.

How Argon2 makes password guessing expensive

Argon2 works by filling a large block of memory with pseudorandom data derived from the password and salt, then repeatedly reading and mixing that memory before producing the final tag. The memory is organized into 1 KiB blocks arranged in lanes, and each new block depends on earlier ones chosen by a defined indexing rule. The compression function is built from the round function of the BLAKE2b hash.

The defensive idea is memory hardness. Attackers gain speed by running thousands of guesses in parallel on GPUs or ASICs, but each guess now needs its own large memory area. Memory is far more expensive to replicate than arithmetic units, so the cost per guess rises sharply and the attacker’s hardware advantage shrinks.

Argon2 accepts several inputs and parameters, which the table below summarizes with their effects.

ParameterMeaningEffect of increasing it
Memory cost (m)Memory used, in KiBStronger resistance to parallel hardware
Time cost (t)Number of passes over memoryLonger computation per hash
Parallelism (p)Number of independent lanesUses more CPU cores at once
SaltRandom per-password value, 16 bytes typicalPrevents precomputed tables and duplicates
Tag lengthOutput size, often 32 bytesLonger derived key or hash
Secret and associated dataOptional key (pepper) and contextBinds hashes to a server secret
Argon2 parameters and their effects

Argon2d, Argon2i and Argon2id variants

Argon2 comes in three variants that differ in how they choose which memory blocks to read. The choice determines the balance between resistance to side-channel attacks and resistance to time-memory trade-off attacks.

VariantMemory access patternBest suited for
Argon2dData-dependentCryptocurrency proof of work, no side-channel exposure
Argon2iData-independentEnvironments with strong side-channel concerns
Argon2idIndependent first half pass, then dependentPassword hashing and general use
Comparison of the Argon2 variants

Data-dependent access in Argon2d gives the best resistance to GPU cracking, but the access pattern can leak information through cache timing. Argon2i avoids that leak at the price of weaker trade-off resistance. Argon2id combines both approaches and is the variant RFC 9106 marks as mandatory to implement and recommended by default.

Argon2 compared with other password hashing functions

Argon2 belongs to the family of slow, salted password hashing functions alongside bcrypt, scrypt and PBKDF2. All of them add deliberate work factors, but they differ in whether they also demand memory and in how easily the cost can be tuned.

FunctionMemory-hardNotable characteristics
Argon2idYes, tunableModern default, separate memory, time and lane settings
scryptYesMemory-hard, but parameters are coupled and less flexible
bcryptSmall fixed memoryMature and widely deployed, input limited to 72 bytes
PBKDF2NoRequired by some FIPS 140 contexts, weak against GPUs
SHA-256 aloneNoToo fast, unsuitable for storing passwords
Argon2 and alternative password hashing schemes

A plain hash function should never be used directly for password storage. Its speed, often billions of hashes per second on a single GPU, is exactly what an attacker wants. Argon2 is one concrete implementation of the broader practice of password hashing, and it always depends on a unique salt per password.

Choosing Argon2 parameters in practice

Parameter selection is a trade-off between security and server capacity. Every login consumes the configured memory and CPU time, so the right values depend on expected traffic, available hardware and acceptable latency. A common target is roughly 0.5 to 1 second for interactive logins, or less on busy services.

The settings below are widely cited starting points; each deployment should still benchmark on its own hardware.

ScenarioSuggested parametersRationale
RFC 9106 first choicem = 2 GiB, t = 1, p = 4Maximum hardness where memory is plentiful
RFC 9106 second choicem = 64 MiB, t = 3, p = 4Practical for memory-constrained servers
OWASP minimum baselinem = 19 MiB, t = 2, p = 1Floor for high-volume web logins
Disk or vault encryption keym of 1 GiB or more, t of 3 or moreRare derivation, high attacker incentive
Typical Argon2id configurations

Implementations store results in a self-describing string such as $argon2id$v=19$m=65536,t=3,p=4$salt$hash. Because the parameters travel with each hash, a system can raise its settings later and rehash passwords transparently at the next successful login.

Limitations and implementation mistakes

Argon2 protects stored hashes, but it cannot rescue weak passwords or replace other controls. A password such as a common dictionary word will still fall quickly, because the attacker tries it among the first guesses.

  • Choosing memory too low: a few megabytes largely cancels the memory-hardness advantage.
  • Reusing or omitting the salt: identical passwords then produce identical hashes.
  • Writing a custom implementation: well-reviewed libraries such as libsodium are safer.
  • Ignoring denial-of-service risk: expensive hashing needs login rate limiting.
  • Comparing hashes with ordinary string equality: use constant-time verification functions.

High memory settings can also exhaust server resources under heavy load, so capacity planning and queueing should accompany any increase. Adding a pepper stored outside the database provides extra protection if only the database leaks.

Understanding it simply

When a website stores passwords, it should not keep the passwords themselves. It keeps a scrambled fingerprint instead. Argon2 is a way of making that fingerprint on purpose slow and memory hungry to produce.

For one person logging in, the delay is a fraction of a second. For a thief trying billions of guesses, every guess needs its own large slice of memory, which makes the attack enormously expensive. It is like a lock that takes a moment to turn with the right key but requires a warehouse of equipment to pick at scale.

Applied in practice

An online learning platform with two million user accounts stored passwords as unsalted SHA-256 hashes. A security review showed that a single modern GPU could test billions of candidates per second against such hashes, so a database leak would expose most passwords within days.

The engineering team migrated to Argon2id with 64 MiB of memory, three passes and four lanes, tuned to about 300 milliseconds on their login servers. Existing users were upgraded transparently: at each successful login, the old hash was verified and replaced with a new Argon2id string. Within four months, more than 85 percent of active accounts used the new format, and the remaining dormant accounts were forced to reset. A later red team exercise against a copy of the database recovered only a handful of extremely weak passwords, reducing exposure from most accounts to a tiny fraction.