Class Shake128
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Hash
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Computes a variable-length output using SHAKE128 (XOF).
public sealed class Shake128 : KeccakXofCore, ICryptoTransform, IDisposable, IResettable, IExtendableOutput
- Inheritance
-
Shake128
- Implements
- Inherited Members
Remarks
This is a fully managed implementation of SHAKE128 based on the Keccak sponge construction. It does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.
SHAKE128 is an extendable-output function (XOF) based on the Keccak sponge construction. Unlike traditional hash functions, XOFs can produce output of arbitrary length.
SHAKE128 provides 128-bit security strength against all attacks.
Constructors
Shake128()
Initializes a new instance of the Shake128 class with default output size.
public Shake128()
Shake128(int)
Initializes a new instance of the Shake128 class with specified output size.
public Shake128(int outputBytes)
Parameters
outputBytesintThe desired output size in bytes.
Fields
CapacityBytes
The capacity in bytes (256 bits for SHAKE128).
public const int CapacityBytes = 32
Field Value
DefaultOutputBits
The default output size in bits.
public const int DefaultOutputBits = 256
Field Value
RateBytes
The rate in bytes (1344 bits for SHAKE128).
public const int RateBytes = 168
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
Create()
Creates a new instance of the Shake128 class with default output size.
public static Shake128 Create()
Returns
- Shake128
A new SHAKE128 instance.
Create(int)
Creates a new instance of the Shake128 class with specified output size.
public static Shake128 Create(int outputBytes)
Parameters
outputBytesintThe desired output size in bytes.
Returns
- Shake128
A new SHAKE128 instance.
HashData(in ReadOnlySequence<byte>)
Computes the SHAKE128 hash of source using the default output size
and returns it as a new byte array.
public static byte[] HashData(in ReadOnlySequence<byte> source)
Parameters
sourceReadOnlySequence<byte>The (possibly multi-segment) input sequence to hash.
Returns
- byte[]
A new byte array containing the SHAKE128 hash.
HashData(ReadOnlySpan<byte>)
Computes the SHAKE128 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 SHAKE128 hash.
TryHashData(in ReadOnlySequence<byte>, Span<byte>, out int)
Computes the SHAKE128 hash of source using the default output size
and writes it into destination.
public static bool TryHashData(in ReadOnlySequence<byte> source, Span<byte> destination, out int bytesWritten)
Parameters
sourceReadOnlySequence<byte>The (possibly multi-segment) input sequence 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.
Returns
TryHashData(ReadOnlySpan<byte>, Span<byte>, out int)
Computes the SHAKE128 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.