Class AsconXof128
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Hash
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Computes the Ascon-XOF128 (Extendable Output Function) for the input data.
public sealed class AsconXof128 : AsconHashAlgorithm, ICryptoTransform, IDisposable, IResettable, IExtendableOutput
- Inheritance
-
AsconXof128
- Implements
- Inherited Members
Remarks
This is a fully managed implementation of Ascon-XOF128 that does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.
Ascon-XOF128 is defined in NIST SP 800-232. It is based on the Ascon permutation with 12 rounds and produces variable-length output.
Ascon was the winner of the NIST Lightweight Cryptography competition (2023).
References:
Constructors
AsconXof128()
Initializes a new instance of the AsconXof128 class with default output size.
public AsconXof128()
AsconXof128(int)
Initializes a new instance of the AsconXof128 class with the specified output size.
public AsconXof128(int outputSizeBytes)
Parameters
outputSizeBytesintThe desired output size in bytes.
Exceptions
- ArgumentOutOfRangeException
Thrown when outputSizeBytes is less than 1.
Fields
DefaultOutputSizeBits
The default output size in bits.
public const int DefaultOutputSizeBits = 256
Field Value
DefaultOutputSizeBytes
The default output size in bytes.
public const int DefaultOutputSizeBytes = 32
Field Value
Properties
AlgorithmName
Gets the name of the hash algorithm.
public override string AlgorithmName { get; }
Property Value
InitializationVector
Gets the initialization vector values for this variant.
protected override (ulong IV0, ulong IV1, ulong IV2, ulong IV3, ulong IV4) InitializationVector { get; }
Property Value
OutputSizeBytes
Gets the output size in bytes for this variant.
protected override int OutputSizeBytes { get; }
Property Value
Methods
Absorb(ReadOnlySpan<byte>)
Absorbs input data into the XOF state.
public void Absorb(ReadOnlySpan<byte> input)
Parameters
inputReadOnlySpan<byte>The input data to absorb.
Exceptions
- InvalidOperationException
Thrown when data is added after output has been squeezed.
Create()
Creates a new instance of the AsconXof128 class with default output size.
public static AsconXof128 Create()
Returns
- AsconXof128
A new Ascon-XOF128 algorithm instance.
Create(int)
Creates a new instance of the AsconXof128 class with the specified output size.
public static AsconXof128 Create(int outputSizeBytes)
Parameters
outputSizeBytesintThe desired output size in bytes.
Returns
- AsconXof128
A new Ascon-XOF128 algorithm instance.
HashData(ReadOnlySpan<byte>)
Computes the Ascon-XOF128 hash of source using the default output size
and returns it as a new byte array.
public static byte[] HashData(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<byte>The input data to hash.
Returns
- byte[]
A new byte array containing the Ascon-XOF128 hash.
Reset()
Resets the XOF state so the instance can be reused for a new computation.
public void Reset()
Remarks
After calling this method, the instance is in the same state as a newly constructed one. All previously absorbed data and squeezed output are discarded.
Squeeze(Span<byte>)
Squeezes output bytes from the Ascon-XOF128 state.
public void Squeeze(Span<byte> output)
Parameters
Remarks
After the first call, the hash is finalized and no more data can be absorbed. May be called multiple times for streaming output.
SqueezeOutput(Span<byte>)
Squeezes the output from the internal state.
protected override void SqueezeOutput(Span<byte> destination)
Parameters
TryHashData(ReadOnlySpan<byte>, Span<byte>, out int)
Computes the Ascon-XOF128 hash of source using the default output size
and writes it into destination.
public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
Parameters
sourceReadOnlySpan<byte>The input data to hash.
destinationSpan<byte>The buffer to receive the hash value. Must be at least
32bytes.bytesWrittenintWhen this method returns, the number of bytes written into
destination.