Table of Contents

Class KeccakKMacCore

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

Base class for KMAC (Keccak Message Authentication Code) variants.

public abstract class KeccakKMacCore : KeccakCore, ICryptoTransform, IDisposable, IResettable, IExtendableOutput
Inheritance
KeccakKMacCore
Implements
Derived
Inherited Members

Remarks

This is a fully managed implementation of KMAC based on the Keccak sponge construction. It does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.

KMAC is a MAC function based on Keccak (cSHAKE) defined in NIST SP 800-185. It supports variable-length output and can be used as both a traditional MAC (fixed output length) or as a pseudorandom function (XOF mode with arbitrary output length).

Methods

Absorb(ReadOnlySpan<byte>)

Absorbs input data into the XOF state.

public void Absorb(ReadOnlySpan<byte> input)

Parameters

input ReadOnlySpan<byte>

The input data to absorb.

Exceptions

InvalidOperationException

Thrown when data is added after output has been squeezed.

Dispose(bool)

Releases the unmanaged resources used by the HashAlgorithm and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

HashCore(ReadOnlySpan<byte>)

When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.

protected override void HashCore(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The input to compute the hash code for.

Exceptions

ObjectDisposedException

Thrown when the instance has been disposed.

Initialize()

Initializes an implementation of the HashAlgorithm class.

public override void Initialize()

Exceptions

ObjectDisposedException

Thrown when the instance has been disposed.

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>)

Finalizes the MAC computation and squeezes output bytes.

public void Squeeze(Span<byte> output)

Parameters

output Span<byte>

The buffer to receive the output.

Exceptions

ObjectDisposedException

Thrown when the instance has been disposed.

TryHashFinal(Span<byte>, out int)

When overridden in a derived class, finalizes the hash computation and writes the result into the provided buffer.

protected override bool TryHashFinal(Span<byte> destination, out int bytesWritten)

Parameters

destination Span<byte>

The target buffer to write the hash to.

bytesWritten int

The number of bytes written into the buffer.

Returns

bool

true if the destination buffer was large enough; otherwise false.