Table of Contents

Class AsconHash256

Namespace
CryptoHives.Foundation.Security.Cryptography.Hash
Assembly
CryptoHives.Foundation.Security.Cryptography.dll

Computes the Ascon-Hash256 for the input data.

public sealed class AsconHash256 : AsconHashAlgorithm, ICryptoTransform, IDisposable, IResettable
Inheritance
AsconHash256
Implements
Inherited Members

Remarks

This is a fully managed implementation of Ascon-Hash256 that does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.

Ascon-Hash256 is defined in NIST SP 800-232. It is based on the Ascon permutation with 12 rounds and produces a 256-bit hash.

Ascon was the winner of the NIST Lightweight Cryptography competition (2023).

References:

Constructors

AsconHash256()

Initializes a new instance of the AsconHash256 class.

public AsconHash256()

Fields

HashSizeBits

The hash size in bits.

public const int HashSizeBits = 256

Field Value

int

HashSizeBytes

The hash size in bytes.

public const int HashSizeBytes = 32

Field Value

int

Properties

AlgorithmName

Gets the name of the hash algorithm.

public override string AlgorithmName { get; }

Property Value

string

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

(ulong IV0, ulong IV1, ulong IV2, ulong IV3, ulong IV4)

OutputSizeBytes

Gets the output size in bytes for this variant.

protected override int OutputSizeBytes { get; }

Property Value

int

Methods

Create()

Creates a new instance of the AsconHash256 class.

public static AsconHash256 Create()

Returns

AsconHash256

A new Ascon-Hash256 algorithm instance.

HashData(in ReadOnlySequence<byte>)

Computes the Ascon-Hash256 of source and returns it as a new byte array.

public static byte[] HashData(in ReadOnlySequence<byte> source)

Parameters

source ReadOnlySequence<byte>

The (possibly multi-segment) input sequence to hash.

Returns

byte[]

A new byte array containing the Ascon-Hash256 hash.

HashData(ReadOnlySpan<byte>)

Computes the Ascon-Hash256 of source and returns it as a new byte array.

public static byte[] HashData(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The input data to hash.

Returns

byte[]

A new byte array containing the Ascon-Hash256 hash.

SqueezeOutput(Span<byte>)

Squeezes the output from the internal state.

protected override void SqueezeOutput(Span<byte> destination)

Parameters

destination Span<byte>

The destination span for the output.

TryHashData(in ReadOnlySequence<byte>, Span<byte>, out int)

Computes the Ascon-Hash256 of source and writes it into destination.

public static bool TryHashData(in ReadOnlySequence<byte> source, Span<byte> destination, out int bytesWritten)

Parameters

source ReadOnlySequence<byte>

The (possibly multi-segment) input sequence to hash.

destination Span<byte>

The buffer to receive the hash value. Must be at least HashSizeBytes bytes.

bytesWritten int

When this method returns, the number of bytes written into destination.

Returns

bool

true if destination was large enough; otherwise, false.

TryHashData(ReadOnlySpan<byte>, Span<byte>, out int)

Computes the Ascon-Hash256 of source and writes it into destination.

public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)

Parameters

source ReadOnlySpan<byte>

The input data to hash.

destination Span<byte>

The buffer to receive the hash value. Must be at least HashSizeBytes bytes.

bytesWritten int

When this method returns, the number of bytes written into destination.

Returns

bool

true if destination was large enough; otherwise, false.