]>
The memory-hard Argon2 password hash function
University of LuxembourgUniversity of LuxembourgUniversity of LuxembourgSJD ABsimon@josefsson.orghttp://josefsson.org/This document describes the Argon2 memory-hard function for
password hashing and other applications. We provide a
implementer oriented description together with sample code and
test vectors. The purpose is to simplify adoption of Argon2 for
Internet protocols.This document describes the Argon2 memory-hard function for
password hashing and other applications. We provide a
implementer oriented description together with sample code and
test vectors. The purpose is to simplify adoption of Argon2 for
Internet protocols.Argon2 summarizes the state of the art in the design of
memory-hard functions. It is a streamlined and simple design.
It aims at the highest memory filling rate and effective use of
multiple computing units, while still providing defense against
tradeoff attacks. Argon2 is optimized for the x86 architecture
and exploits the cache and memory organization of the recent
Intel and AMD processors. Argon2 has two variants: Argon2d and
Argon2i. Argon2d is faster and uses data-depending memory
access, which makes it suitable for cryptocurrencies and
applications with no threats from side-channel timing attacks.
Argon2i uses data-independent memory access, which is preferred
for password hashing and password-based key derivation. Argon2i
is slower as it makes more passes over the memory to protect
from tradeoff attacks.For further background and discussion, see the Argon2 paper.x^y --- x multiplied by itself y timesa*b --- multiplication of a and bc-d --- substraction of c with dE_f --- variable E with subscript index fg / h --- g divided by hI(j) --- function I evaluated on parameters jK || L --- string K concatenated with string LArgon2 have the following input parameters:
Message string P, typically a password. May have any
length from 0 to 2^32 - 1 bytes.Nonce S, typically a random salt. May have any length
from 8 to 2^32 - 1 bytes. 16 bytes is recommended for
password hashing. See for
discussion about randomness.Degree of parallelism p determines how many independent
(but synchronizing) computational chains can be run. It may
take any integer value from 1 to 255.Tag length T may be any integer number of bytes from 4 to
2^32-1.Memory size m can be any integer number of kilobytes from
8*p to 2^32-1. The actual number of blocks is m', which is
m rounded down to the nearest multiple of 4*p.Number of iterations t (used to tune the running time
independently of the memory size) can be any integer number
from 1 to 2^32-1.Version number v is one byte 0x10.Secret value K (serves as key if necessary, but we do not
assume any key use by default) may have any length from 0 to
32 bytes.Associated data X may have any length from 0 to 2^32-1
bytes.Type y of Argon2: 0 for Argon2d, 1 for Argon2i.The Argon2 output is a T-length string.Argon2 uses an internal compression function G with two
1024-byte inputs and a 1024-byte output, and an internal hash
function H. Here H is the Blake2b hash function, and
the compression function G is based on its internal
permutation. A variable-length hash function H' built upon H
is also used. G and H' are described in later section.The Argon2 operation is as follows.
Establish H_0 as the 64-bit value as shown in the figure
below. H is BLAKE2b and the non-strings p, T, m, t, v, y,
length(P), length(S), length(K), and length(X) are treated
as a 32-bit little-endian encoding of the integer.
Allocate the memory as m' 1024-byte blocks where m' is
derived as:
For tunable parallelism with p threads, the memory is
organized in a matrix B[i][j] of blocks with p rows (lanes)
and q = m' / p columns.Compute B[i][0] for all i ranging from (and including) 0
to (not including) p.
Here 4byteencode is a function which takes an integer and
little-endian encode and padds it to 4 bytes.Compute B[i][1] for all i ranging from (and including) 0
to (not including) p.
Compute B[i][j] for all i ranging from (and including) 0
to (not including) p, and for all j ranging from (and
including) 2) to (not including) q. The block indices i'
and j' are determined differently for Argon2d and Argon2i.
If the number of iterations t is larger than 1, we repeat
the steps however replacing the computations with with the
following expression:
After t steps have been iterated, we compute the final
block C as the XOR of the last column:
The output tag is computed as H'(C).Let H_x be a hash function with x-byte output (in our case
H_x is Blake2b, which supports x between 1 and 64 inclusive).
Let V_i be a 64-byte block, and A_i be its first 32 bytes, and
T < 2^32 be the tag length in bytes. Then we define
FIXME: improve this description.
FIXME2: V_{r+1} is not properly described, is it a 64-byte
block or a {T mod 64} block?TBDCompression function G is built upon the Blake2b round
function P. P operates on the 128-byte input, which can be
viewed as 8 16-byte registers:
Compression function G(X, Y) operates on two 1024-byte
blocks X and Y. It first computes R = X XOR Y. Then R is
viewed as a 8x8-matrix of 16-byte registers R_0, R_1, ... ,
R_63. Then P is first applied rowwise, and then columnwise to
get Z:
Finally, G outputs Z XOR R:
FIXME: improve this description.TBDArgon2d is optimized for settings where the adversary does
not get regular access to system memory or CPU, i.e. he can not
run side-channel attacks based on the timing information, nor he
can recover the password much faster using garbage
collection. These settings are more typical for backend servers
and cryptocurrency minings. For practice we suggest the
following settings:
Cryptocurrency mining, that takes 0.1 seconds on a 2 Ghz
CPU using 1 core — Argon2d with 2 lanes and 250 MB of RAM.Backend server authentication, that takes 0.5 seconds on a
2 GHz CPU using 4 cores — Argon2d with 8 lanes and 4 GB of
RAM.Argon2i is optimized for more realistic settings, where the
adversary possibly can access the same machine, use its CPU or
mount cold-boot attacks. We use three passes to get rid entirely
of the password in the memory. We suggest the following
settings:
Key derivation for hard-drive encryption, that takes 3
seconds on a 2 GHz CPU using 2 cores - Argon2i with 4 lanes
and 6 GB of RAMFrontend server authentication, that takes 0.5 seconds on a
2 GHz CPU using 2 cores - Argon2i with 4 lanes and 1 GB of
RAM.We recommend the following procedure to select the type and
the parameters for practical use of Argon2.
Select the type y. If you do not know the difference
between them or you consider side-channel attacks as viable
threat, choose Argon2i.Figure out the maximum number h of threads that can be
initiated by each call to Argon2.Figure out the maximum amount m of memory that each call
can afford.Figure out the maximum amount x of time (in seconds) that
each call can afford.Select the salt length. 128 bits is sufficient for all
applications, but can be reduced to 64 bits in the case of
space constraints.Select the tag length. 128 bits is sufficient for most
applications, including key derivation. If longer keys are
needed, select longer tags.If side-channel attacks is a viable threat, enable the
memory wiping option in the library call.Run the scheme of type y, memory m and h lanes and threads,
using different number of passes t. Figure out the maximum t
such that the running time does not exceed x. If it exceeds x
even for t = 1, reduce m accordingly.Hash all the passwords with the just determined values m,
h, and t.TBD -- is there a python implementation?This section contains test vectors for Argon2.TBANone.TBA
&BLAKE2;
&RFC4086;
Argon2: the memory-hard function for password hashing
and other applications