Class CShake256
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Hash
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Computes a customizable SHAKE256 (cSHAKE256) output.
public sealed class CShake256 : KeccakCore, ICryptoTransform, IDisposable, IResettable, IExtendableOutput
- Inheritance
-
CShake256
- Implements
- Inherited Members
Remarks
This is a fully managed implementation of cSHAKE256 based on the Keccak sponge construction. It does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.
cSHAKE256 is a customizable variant of SHAKE256 defined in NIST SP 800-185. It supports function name (N) and customization string (S) parameters for domain separation.
When both N and S are empty, cSHAKE256 is equivalent to SHAKE256.
Constructors
CShake256(int, byte[]?, byte[]?)
Initializes a new instance of the CShake256 class with byte array parameters.
public CShake256(int outputBytes, byte[]? functionName, byte[]? customization)
Parameters
outputBytesintThe desired output size in bytes.
functionNamebyte[]The function name bytes N.
customizationbyte[]The customization bytes S.
CShake256(int, string?, string?)
Initializes a new instance of the CShake256 class.
public CShake256(int outputBytes = 64, string? functionName = null, string? customization = null)
Parameters
outputBytesintThe desired output size in bytes.
functionNamestringThe function name string N (for NIST-defined functions).
customizationstringThe customization string S.
Fields
CapacityBytes
The capacity in bytes (512 bits for cSHAKE256).
public const int CapacityBytes = 64
Field Value
DefaultOutputBits
The default output size in bits.
public const int DefaultOutputBits = 512
Field Value
RateBytes
The rate in bytes (1088 bits for cSHAKE256).
public const int RateBytes = 136
Field Value
Properties
AlgorithmName
Gets the name of the hash algorithm.
public override string AlgorithmName { get; }
Property Value
BlockSize
Gets the block size in bytes used by the hash algorithm.
public override int BlockSize { 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 CShake256 class with default parameters.
public static CShake256 Create()
Returns
Create(int, byte[]?, byte[]?)
Creates a new instance of the CShake256 hash function with the specified output length, function name, and customization string.
public static CShake256 Create(int outputBytes, byte[]? functionName = null, byte[]? customization = null)
Parameters
outputBytesintThe desired length, in bytes, of the hash output. Must be a positive integer.
functionNamebyte[]An optional function name as a byte array, used to domain-separate the hash function. Can be null if no function name is required.
customizationbyte[]An optional customization string as a byte array, used to further parameterize the hash function. Can be null if no customization is required.
Returns
- CShake256
A new CShake256 instance configured with the specified output length, function name, and customization string.
Create(int, string, string?)
Creates a new instance of the CShake256 class with specified parameters.
public static CShake256 Create(int outputBytes, string functionName, string? customization = null)
Parameters
outputBytesintThe desired output size in bytes.
functionNamestringThe function name N (for NIST-defined functions).
customizationstringThe customization string S (user-defined).
Returns
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
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 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>)
Squeezes output bytes from the XOF state.
public void Squeeze(Span<byte> output)
Parameters
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
destinationSpan<byte>The target buffer to write the hash to.
bytesWrittenintThe number of bytes written into the buffer.