Argon2 Class

Computes the Argon2 memory-hard function (RFC 9106): Argon2d, Argon2i and Argon2id.

public static class Argon2

Remarks

Argon2 derives a key from a password, or hashes a password to store it. RFC 9106 recommends Argon2id. The cost is set by the memory size, the number of passes and the degree of parallelism; RFC 9106 section 4 gives recommended values, such as 2 GiB of memory with 1 pass, or 64 MiB of memory with 3 passes, both with 4 lanes.

The lanes are computed sequentially: the degree of parallelism changes the result, not the number of threads.

Methods

NameDescription
DeriveBytes(Argon2Type, ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, int, int, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Argon2Version)Computes the Argon2 tag T (RFC 9106 section 3.2).
DeriveBytes(Argon2Type, ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, int, Span<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Argon2Version)Computes the Argon2 tag T (RFC 9106 section 3.2) into a buffer.

DeriveBytes overloads

DeriveBytes(Argon2Type, ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, int, int, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Argon2Version)

Argon2.cs

Computes the Argon2 tag T (RFC 9106 section 3.2).

public static byte[] DeriveBytes(Argon2Type type, ReadOnlySpan<byte> password, ReadOnlySpan<byte> salt, int parallelism, int memorySizeInKiB, int passes, int outputLength, ReadOnlySpan<byte> secret = default, ReadOnlySpan<byte> associatedData = default, Argon2Version version = Argon2Version.Version13)
Parameters
type Argon2Type
The variant y: Argon2Type.Argon2id unless you have a reason to use another one.
password ReadOnlySpan<byte>
The message P: the password.
salt ReadOnlySpan<byte>
The nonce S: a salt, 16 bytes of random data are recommended.
parallelism int
The degree of parallelism p, the number of lanes: 1 to Argon2.MaxParallelism.
memorySizeInKiB int
The memory size m, in kibibytes: at least 8 times parallelism.
passes int
The number of passes t over the memory: at least 1.
outputLength int
The length of the tag T, in bytes: at least Argon2.MinOutputLength.
secret ReadOnlySpan<byte>
The secret value K (a pepper), usually empty.
associatedData ReadOnlySpan<byte>
The associated data X, usually empty.
version Argon2Version
The version v.
Returns

byte[] The tag, of outputLength bytes.

Exceptions
ArgumentOutOfRangeException
A parameter is out of the range allowed by RFC 9106.
OutOfMemoryException
The memory cannot be allocated.

DeriveBytes(Argon2Type, ReadOnlySpan<byte>, ReadOnlySpan<byte>, int, int, int, Span<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Argon2Version)

Argon2.cs

Computes the Argon2 tag T (RFC 9106 section 3.2) into a buffer.

public static void DeriveBytes(Argon2Type type, ReadOnlySpan<byte> password, ReadOnlySpan<byte> salt, int parallelism, int memorySizeInKiB, int passes, Span<byte> destination, ReadOnlySpan<byte> secret = default, ReadOnlySpan<byte> associatedData = default, Argon2Version version = Argon2Version.Version13)
Parameters
type Argon2Type
The variant y: Argon2Type.Argon2id unless you have a reason to use another one.
password ReadOnlySpan<byte>
The message P: the password.
salt ReadOnlySpan<byte>
The nonce S: a salt, 16 bytes of random data are recommended.
parallelism int
The degree of parallelism p, the number of lanes: 1 to Argon2.MaxParallelism.
memorySizeInKiB int
The memory size m, in kibibytes: at least 8 times parallelism.
passes int
The number of passes t over the memory: at least 1.
destination Span<byte>
The buffer that receives the tag: its length, at least Argon2.MinOutputLength bytes, is the length of the tag.
secret ReadOnlySpan<byte>
The secret value K (a pepper), usually empty.
associatedData ReadOnlySpan<byte>
The associated data X, usually empty.
version Argon2Version
The version v.
Exceptions
ArgumentOutOfRangeException
A parameter is out of the range allowed by RFC 9106.
OutOfMemoryException
The memory cannot be allocated.

Constants

NameDescription
MaxParallelismThe maximum degree of parallelism p (RFC 9106 section 3.1: 2^24 - 1).
MinOutputLengthThe minimum length of the tag T, in bytes (RFC 9106 section 3.1).

MaxParallelism

The maximum degree of parallelism p (RFC 9106 section 3.1: 2^24 - 1).

public const int MaxParallelism = 16777215

MinOutputLength

The minimum length of the tag T, in bytes (RFC 9106 section 3.1).

public const int MinOutputLength = 4