Class KeccakXofCore
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Hash
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Base class for Keccak-based extendable-output functions (XOF) with variable-length output.
public abstract class KeccakXofCore : KeccakCore, ICryptoTransform, IDisposable, IResettable, IExtendableOutput
- Inheritance
-
KeccakXofCore
- Implements
- Derived
- Inherited Members
Remarks
This base class provides common sponge construction logic for all Keccak XOF variants, eliminating code duplication across SHAKE128, SHAKE256, TurboShake128, TurboShake256, cSHAKE128, and cSHAKE256.
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.
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 sealed void HashCore(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<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 sealed 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.
ResetWithDomainSeparator(byte)
Resets the XOF state and changes the domain separator byte.
public void ResetWithDomainSeparator(byte domainSeparator)
Parameters
domainSeparatorbyteThe new domain separation byte for the next hash operation.
Remarks
This allows reusing an existing XOF instance with a different domain separator without allocating a new object. The Keccak state is fully cleared.
Squeeze(Span<byte>)
Squeezes output bytes from the XOF state.
public void Squeeze(Span<byte> output)
Parameters
Exceptions
- ObjectDisposedException
Thrown when the instance has been disposed.
TransformBlock(ReadOnlySpan<byte>)
Absorbs input data into the sponge state (convenience method for XOF usage).
public void TransformBlock(ReadOnlySpan<byte> input)
Parameters
inputReadOnlySpan<byte>The input data to absorb.
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 sealed bool TryHashFinal(Span<byte> destination, out int bytesWritten)
Parameters
destinationSpan<byte>The target buffer to write the hash to.
bytesWrittenintThe number of bytes written into the buffer.