Class Argon2
Argon2 Hashing of passwords.
Implements
Inherited Members
Namespace: Isopoh.Cryptography.Argon2
Assembly: Isopoh.Cryptography.Argon2.dll
Syntax
public sealed class Argon2 : IDisposable
Constructors
| Edit this page View SourceArgon2(Argon2Config)
Initializes a new instance of the Argon2 class.
Declaration
public Argon2(Argon2Config config)
Parameters
| Type | Name | Description |
|---|---|---|
| Argon2Config | config | The configuration to use. |
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 SourceBlockSize
The Argon2 block size in bytes.
Declaration
public const int BlockSize = 1024
Field Value
| Type | Description |
|---|---|
| int |
PrehashDigestLength
The number of bytes hashed in initializing Argon2.
Declaration
public const int PrehashDigestLength = 64
Field Value
| Type | Description |
|---|---|
| int |
PrehashSeedLength
Bytes required in the buffer passed into the internal FillFirstBlocks method.
Declaration
public const int PrehashSeedLength = 72
Field Value
| Type | Description |
|---|---|
| int |
QwordsInBlock
The number of 8-byte words in an Argon2 block.
Declaration
public const int QwordsInBlock = 128
Field Value
| Type | Description |
|---|---|
| int |
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 SourceLaneBlockCount
Gets the number of memory blocks per lane. SegmentBlockCount * SyncPointCount.
Declaration
public int LaneBlockCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Memory
Gets the MemoryBlockCount blocks.
Declaration
public Blocks Memory { get; }
Property Value
| Type | Description |
|---|---|
| Blocks |
MemoryBlockCount
Gets the number of memory blocks, (Lanes*LaneBlockCount).
Declaration
public int MemoryBlockCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
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 SourceDispose()
Zero sensitive memories and dispose of resources.
Declaration
public void Dispose()
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.
Hash()
Perform the hash.
Declaration
public Span<byte> Hash()
Returns
| Type | Description |
|---|---|
| Span<byte> | The hash bytes. |
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. |
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. |
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. |
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. |
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
|
| 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. |
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 |
Returns
| Type | Description |
|---|---|
| bool | True on success; false otherwise. |
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. |
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. |
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. |
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 |
| 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. |
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 |
| 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. |
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. |
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 |
| 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. |
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 |
| 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. |
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 |
| int | threads | The number of threads to use. Setting this to a higher number than
the "p=" parameter in the |
| 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. |