Argon2d Class
Definition
- Namespace
- Bodu.Security.Cryptography
- Assembly
- Bodu.Security.Cryptography.dll
- Package
- Bodu.Security.Cryptography 1.2.0
- Source
- Argon2d.cs
Computes the Argon2d password-hashing and key-derivation function (RFC 9106) - the variant that uses data-dependent memory addressing, maximizing time-memory trade-off resistance at the cost of exposing memory access patterns to side-channel observation. This class cannot be inherited.
public sealed class Argon2d : Argon2
- Inheritance
-
Argon2d
- Inherited Members
- Extension Methods
Remarks
Argon2d is appropriate where side-channel timing attacks are not a concern - for example cryptocurrency and proof-of-work workloads. For password hashing on shared hardware, prefer Argon2id.
Constructors
Argon2d(Argon2Parameters)
Initializes a new instance of the Argon2d class with the specified cost parameters.
public Argon2d(Argon2Parameters parameters)
Parameters
parametersArgon2ParametersThe cost and auxiliary parameters governing the derivation.
Remarks
Each derivation may use up to Parallelism threads, bounded by the processor count, when its lanes are large enough to be worth dividing; see MaxDegreeOfParallelism.
Exceptions
- ArgumentNullException
parametersis null.- ArgumentOutOfRangeException
A cost parameter in
parametersfalls outside the range permitted by RFC 9106.- ArgumentException
The version code in
parametersis neither 0x10 nor 0x13.
Argon2d(Argon2Parameters, int)
Initializes a new instance of the Argon2d class with the specified cost parameters and bound on the threads each derivation may use.
public Argon2d(Argon2Parameters parameters, int maxDegreeOfParallelism)
Parameters
parametersArgon2ParametersThe cost and auxiliary parameters governing the derivation.
maxDegreeOfParallelismintThe greatest number of threads one derivation may use, the calling thread included;
-1lets the library choose.
Remarks
1 confines every derivation to the calling thread, which suits a service that already runs many
derivations at once; a larger value caps the threads. The tag never depends on the bound.
Exceptions
- ArgumentNullException
parametersis null.- ArgumentOutOfRangeException
A cost parameter in
parametersfalls outside the range permitted by RFC 9106, ormaxDegreeOfParallelismis zero or less than-1.- ArgumentException
The version code in
parametersis neither 0x10 nor 0x13.
Methods
DeriveKey(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Argon2Parameters)
Derives a tag from a password and salt using the supplied parameters in a single call.
public static byte[] DeriveKey(ReadOnlySpan<byte> password, ReadOnlySpan<byte> salt, Argon2Parameters parameters)
Parameters
passwordReadOnlySpan<byte>The password / message to derive from.
saltReadOnlySpan<byte>The salt; must be at least 8 bytes.
parametersArgon2ParametersThe cost and auxiliary parameters.
Returns
- byte[]
The derived tag.
Hash(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Argon2Parameters)
Derives a password hash and returns it as a PHC encoded-hash string in a single call.
public static string Hash(ReadOnlySpan<byte> password, ReadOnlySpan<byte> salt, Argon2Parameters parameters)
Parameters
passwordReadOnlySpan<byte>The password to hash.
saltReadOnlySpan<byte>The salt to embed; must be at least 8 bytes.
parametersArgon2ParametersThe cost and auxiliary parameters.
Returns
- string
The PHC encoded-hash string.
Verify(string, ReadOnlySpan<byte>)
Verifies a password against an Argon2d PHC encoded-hash string.
public static bool Verify(string encoded, ReadOnlySpan<byte> password)
Parameters
encodedstringThe PHC encoded-hash string; must name the
argon2dvariant.passwordReadOnlySpan<byte>The password to verify.
Returns
Verify(string, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Verifies a password against an Argon2d PHC encoded-hash string using the supplied secret key.
public static bool Verify(string encoded, ReadOnlySpan<byte> password, ReadOnlySpan<byte> secret)
Parameters
encodedstringThe PHC encoded-hash string; must name the
argon2dvariant.passwordReadOnlySpan<byte>The password to verify.
secretReadOnlySpan<byte>The secret key used when the hash was produced.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |