Argon2 Class
Computes the Argon2 memory-hard function (RFC 9106): Argon2d, Argon2i and Argon2id.
public static class Argon2Remarks
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
| Name | Description |
|---|---|
| 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.csComputes 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
typeArgon2Type- The variant y:
Argon2Type.Argon2idunless you have a reason to use another one. passwordReadOnlySpan<byte>- The message P: the password.
saltReadOnlySpan<byte>- The nonce S: a salt, 16 bytes of random data are recommended.
parallelismint- The degree of parallelism p, the number of lanes: 1 to
Argon2.MaxParallelism. memorySizeInKiBint- The memory size m, in kibibytes: at least 8 times
parallelism. passesint- The number of passes t over the memory: at least 1.
outputLengthint- The length of the tag T, in bytes: at least
Argon2.MinOutputLength. secretReadOnlySpan<byte>- The secret value K (a pepper), usually empty.
associatedDataReadOnlySpan<byte>- The associated data X, usually empty.
versionArgon2Version- 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.csComputes 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
typeArgon2Type- The variant y:
Argon2Type.Argon2idunless you have a reason to use another one. passwordReadOnlySpan<byte>- The message P: the password.
saltReadOnlySpan<byte>- The nonce S: a salt, 16 bytes of random data are recommended.
parallelismint- The degree of parallelism p, the number of lanes: 1 to
Argon2.MaxParallelism. memorySizeInKiBint- The memory size m, in kibibytes: at least 8 times
parallelism. passesint- The number of passes t over the memory: at least 1.
destinationSpan<byte>- The buffer that receives the tag: its length, at least
Argon2.MinOutputLengthbytes, is the length of the tag. secretReadOnlySpan<byte>- The secret value K (a pepper), usually empty.
associatedDataReadOnlySpan<byte>- The associated data X, usually empty.
versionArgon2Version- The version v.
Exceptions
ArgumentOutOfRangeException- A parameter is out of the range allowed by RFC 9106.
OutOfMemoryException- The memory cannot be allocated.
Constants
| Name | Description |
|---|---|
| MaxParallelism | The maximum degree of parallelism p (RFC 9106 section 3.1: 2^24 - 1). |
| MinOutputLength | The 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 = 16777215MinOutputLength
The minimum length of the tag T, in bytes (RFC 9106 section 3.1).
public const int MinOutputLength = 4