Show / Hide Table of Contents

Class Argon2

Argon2 Hashing of passwords.

Inheritance
object
Argon2
Implements
IDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Isopoh.Cryptography.Argon2
Assembly: Isopoh.Cryptography.Argon2.dll
Syntax
public sealed class Argon2 : IDisposable

Constructors

| Edit this page View Source

Argon2(Argon2Config)

Initializes a new instance of the Argon2 class.

Declaration
public Argon2(Argon2Config config)
Parameters
Type Name Description
Argon2Config config

The configuration to use.

| Edit this page View Source

Argon2(Argon2Memory)

Initializes a new instance of the Argon2 class.

Declaration
public Argon2(Argon2Memory memory)
Parameters
Type Name Description
Argon2Memory memory

The memory (and Argon2Config) to use for the hash.

Fields

| Edit this page View Source

BlockSize

The Argon2 block size in bytes.

Declaration
public const int BlockSize = 1024
Field Value
Type Description
int
| Edit this page View Source

PrehashDigestLength

The number of bytes hashed in initializing Argon2.

Declaration
public const int PrehashDigestLength = 64
Field Value
Type Description
int
| Edit this page View Source

PrehashSeedLength

Bytes required in the buffer passed into the internal FillFirstBlocks method.

Declaration
public const int PrehashSeedLength = 72
Field Value
Type Description
int
| Edit this page View Source

QwordsInBlock

The number of 8-byte words in an Argon2 block.

Declaration
public const int QwordsInBlock = 128
Field Value
Type Description
int
| Edit this page View Source

SyncPointCount

Number of synchronization points between lanes per pass.

Declaration
public const int SyncPointCount = 4
Field Value
Type Description
int

Properties

| Edit this page View Source

LaneBlockCount

Gets the number of memory blocks per lane. SegmentBlockCount * SyncPointCount.

Declaration
public int LaneBlockCount { get; }
Property Value
Type Description
int
| Edit this page View Source

Memory

Gets the MemoryBlockCount blocks.

Declaration
public Blocks Memory { get; }
Property Value
Type Description
Blocks
| Edit this page View Source

MemoryBlockCount

Gets the number of memory blocks, (Lanes*LaneBlockCount).

Declaration
public int MemoryBlockCount { get; }
Property Value
Type Description
int
| Edit this page View Source

SegmentBlockCount

Gets the number of memory blocks per segment. This value gets derived from the memory cost. The memory cost value is a request for that number of blocks. If that request is less than (2 * SyncPointCount) times the number of lanes requested, it is first bumped up to that amount. Then, it may be reduced to fit on a SyncPointCount times the number of lanes requested boundary.

Declaration
public int SegmentBlockCount { get; }
Property Value
Type Description
int

Methods

| Edit this page View Source

Dispose()

Zero sensitive memories and dispose of resources.

Declaration
public void Dispose()
| Edit this page View Source

FixedTimeEquals(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Compare two SecureArrays without leaking timing information.

Declaration
public static bool FixedTimeEquals(ReadOnlySpan<byte> left, ReadOnlySpan<byte> right)
Parameters
Type Name Description
ReadOnlySpan<byte> left

The first SecureArray to compare.

ReadOnlySpan<byte> right

The second SecureArray to compare.

Returns
Type Description
bool

true if left and right have the same values for Length and the same contents; otherwise, false.

Remarks

Uses System.Security.Cryptography.CryptographicOperations.FixedTimeEquals() when available; otherwise implements a similar algorithm.

| Edit this page View Source

Hash()

Perform the hash.

Declaration
public Span<byte> Hash()
Returns
Type Description
Span<byte>

The hash bytes.

| Edit this page View Source

Hash(Argon2Config)

Hash the given password to an Argon2 hash string.

Declaration
public static string Hash(Argon2Config configToHash)
Parameters
Type Name Description
Argon2Config configToHash

Contains all the information used to create the hash returned.

Returns
Type Description
string

The Argon2 hash of the given password.

| Edit this page View Source

Hash(Argon2Memory)

Hash the given password to an Argon2 hash string.

Declaration
public static string Hash(Argon2Memory memory)
Parameters
Type Name Description
Argon2Memory memory

The memory, including the Argon2Config containing the password, to use to create the hash.

Returns
Type Description
string

The Argon2 hash of the given password.

| Edit this page View Source

Hash(byte[], byte[]?, int, int, int, Argon2Type, int, SecureArrayCall?)

Hash the given password to an Argon2 hash string.

Declaration
public static string Hash(byte[] password, byte[]? secret, int timeCost = 3, int memoryCost = 65536, int parallelism = 1, Argon2Type type = Argon2Type.HybridAddressing, int hashLength = 32, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
byte[] password

The password to hash. Gets UTF-8 encoded before hashing.

byte[] secret

The secret to use in creating the hash.

int timeCost

The time cost to use. Defaults to 3.

int memoryCost

The target memory cost to use. Defaults to 65536 (65536 * 1024 = 64MB). MemoryCost for detail on calculating the actual memory used from this value.

int parallelism

The parallelism to use. Default to 1 (single threaded).

Argon2Type type

Data-dependent, data-independent, or hybrid. Defaults to hybrid (as recommended for password hashing).

int hashLength

The length of the hash in bytes. Note, the string returned base-64 encodes this with other parameters so the resulting string is significantly longer.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
string

The Argon2 hash of the given password.

| Edit this page View Source

Hash(string, int, int, int, Argon2Type, int, SecureArrayCall?)

Hash the given password to an Argon2 hash string.

Declaration
public static string Hash(string password, int timeCost = 3, int memoryCost = 65536, int parallelism = 1, Argon2Type type = Argon2Type.HybridAddressing, int hashLength = 32, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string password

The password to hash. Gets UTF-8 encoded before hashing.

int timeCost

The time cost to use. Defaults to 3.

int memoryCost

The target memory cost to use. Defaults to 65536 (65536 * 1024 = 64MB). MemoryCost for detail on calculating the actual memory used from this value.

int parallelism

The parallelism to use. Defaults to 1 (single threaded).

Argon2Type type

Data-dependent, data-independent, or hybrid. Defaults to hybrid (as recommended for password hashing).

int hashLength

The length of the hash in bytes. Note, the string returned base-64 encodes this with other parameters so the resulting string is significantly longer.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
string

The Argon2 hash of the given password.

| Edit this page View Source

Hash(string, string?, int, int, int, Argon2Type, int, SecureArrayCall?)

Hash the given password to an Argon2 hash string.

Declaration
public static string Hash(string password, string? secret, int timeCost = 3, int memoryCost = 65536, int parallelism = 1, Argon2Type type = Argon2Type.HybridAddressing, int hashLength = 32, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string password

The password to hash. Gets UTF-8 encoded before hashing.

string secret

The secret to use in creating the hash. UTF-8 encoded before hashing. May be null. A string.Empty is treated the same as null.

int timeCost

The time cost to use. Defaults to 3.

int memoryCost

The target memory cost to use. Defaults to 65536 (65536 * 1024 = 64MB). MemoryCost for detail on calculating the actual memory used from this value.

int parallelism

The parallelism to use. Default to 1 (single threaded).

Argon2Type type

Data-dependent, data-independent, or hybrid. Defaults to hybrid (as recommended for password hashing).

int hashLength

The length of the hash in bytes. Note, the string returned base-64 encodes this with other parameters so the resulting string is significantly longer.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
string

The Argon2 hash of the given password.

| Edit this page View Source

Verify(string, Argon2Config)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, Argon2Config configToVerify)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

Argon2Config configToVerify

The configuration that contains the values used to created encoded.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, Argon2Memory)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, Argon2Memory memoryToVerify)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

Argon2Memory memoryToVerify

The memory that will be used to limit allocations.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, byte[], SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, byte[] password, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

byte[] password

The password to verify.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, byte[], byte[]?, SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, byte[] password, byte[]? secret, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

byte[] password

The password to verify.

byte[] secret

The secret hashed into the password.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, byte[], byte[]?, int, SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, byte[] password, byte[]? secret, int threads, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

byte[] password

The password to verify.

byte[] secret

The secret hashed into the password.

int threads

The number of threads to use. Setting this to a higher number than the "p=" parameter in the encoded string doesn't cause even more parallelism.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, byte[], int, SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, byte[] password, int threads, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

byte[] password

The password to verify.

int threads

The number of threads to use. Setting this to a higher number than the "p=" parameter in the encoded string doesn't cause even more parallelism.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, string, SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, string password, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

string password

The password to verify. This gets UTF-8 encoded.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, string, int, SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, string password, int threads, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

string password

The password to verify. This gets UTF-8 encoded.

int threads

The number of threads to use. Setting this to a higher number than the "p=" parameter in the encoded string doesn't cause even more parallelism.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, string, string?, SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, string password, string? secret, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

string password

The password to verify. This gets UTF-8 encoded.

string secret

The secret used in the creation of encoded. UTF-8 encoded to create the byte-buffer actually used in the verification. May be null for no secret. string.Empty is treated as null.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

| Edit this page View Source

Verify(string, string, string?, int, SecureArrayCall?)

Verify the given Argon2 hash as being that of the given password.

Declaration
public static bool Verify(string encoded, string password, string? secret, int threads, SecureArrayCall? secureArrayCall = null)
Parameters
Type Name Description
string encoded

The Argon2 hash string. This has the actual hash along with other parameters used in the hash.

string password

The password to verify. This gets UTF-8 encoded.

string secret

The secret used in the creation of encoded. UTF-8 encoded to create the byte-buffer actually used in the verification. May be null for no secret. string.Empty is treated as null.

int threads

The number of threads to use. Setting this to a higher number than the "p=" parameter in the encoded string doesn't cause even more parallelism.

SecureArrayCall secureArrayCall

The methods that get called to secure arrays. A null value defaults to SecureArray.DefaultCall.

Returns
Type Description
bool

True on success; false otherwise.

Implements

IDisposable
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX