Table of Contents

Class TurboShake256

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

Computes a variable-length output using TurboSHAKE256 (XOF) per RFC 9861.

public sealed class TurboShake256 : KeccakXofCore, ICryptoTransform, IDisposable, IResettable, IExtendableOutput
Inheritance
TurboShake256
Implements
Inherited Members

Remarks

This is a fully managed implementation of TurboSHAKE256 based on the reduced-round Keccak permutation. It does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms and runtimes.

TurboSHAKE256 is an extendable-output function (XOF) based on a reduced-round Keccak-p[1600, n_r=12] permutation with 12 rounds instead of 24 used in SHAKE. It provides 256-bit security strength and is approximately twice as fast as SHAKE256.

TurboSHAKE256 uses a rate of 136 bytes (1088 bits) and a capacity of 64 bytes (512 bits).

The domain separation byte D must be in the range [0x01, 0x7F]. The default value is 0x1F.

Constructors

TurboShake256()

Initializes a new instance of the TurboShake256 class with default output size.

public TurboShake256()

TurboShake256(int)

Initializes a new instance of the TurboShake256 class with specified output size.

public TurboShake256(int outputBytes)

Parameters

outputBytes int

The desired output size in bytes.

TurboShake256(int, byte)

Initializes a new instance of the TurboShake256 class with specified output size and domain separator.

public TurboShake256(int outputBytes, byte domainSeparator)

Parameters

outputBytes int

The desired output size in bytes.

domainSeparator byte

The domain separation byte (must be in range [0x01, 0x7F]).

Fields

CapacityBytes

The capacity in bytes (512 bits for TurboShake256).

public const int CapacityBytes = 64

Field Value

int

DefaultOutputBits

The default output size in bits.

public const int DefaultOutputBits = 512

Field Value

int

DomainSeparator

The TurboShake domain separation byte.

public const byte DomainSeparator = 31

Field Value

byte

RateBytes

The rate in bytes (1088 bits for TurboShake256).

public const int RateBytes = 136

Field Value

int

StartRound

The start round for the sponge construction.

public const int StartRound = 12

Field Value

int

Properties

AlgorithmName

Gets the name of the hash algorithm.

public override string AlgorithmName { get; }

Property Value

string

BlockSize

Gets the block size in bytes used by the hash algorithm.

public override int BlockSize { get; }

Property Value

int

Methods

Create()

Creates a new instance of the TurboShake256 class with default output size.

public static TurboShake256 Create()

Returns

TurboShake256

A new TurboShake256 instance.

Create(int)

Creates a new instance of the TurboShake256 class with specified output size.

public static TurboShake256 Create(int outputBytes)

Parameters

outputBytes int

The desired output size in bytes.

Returns

TurboShake256

A new TurboShake256 instance.

Create(int, byte)

Creates a new instance of the TurboShake256 class with specified output size and domain separator.

public static TurboShake256 Create(int outputBytes, byte domainSeparator)

Parameters

outputBytes int

The desired output size in bytes.

domainSeparator byte

The domain separation byte.

Returns

TurboShake256

A new TurboShake256 instance.

HashData(in ReadOnlySequence<byte>)

Computes the TurboSHAKE256 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

source ReadOnlySequence<byte>

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

Returns

byte[]

A new byte array containing the TurboSHAKE256 hash.

HashData(ReadOnlySpan<byte>)

Computes the TurboSHAKE256 hash of source using the default output size 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 TurboSHAKE256 hash.

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

Computes the TurboSHAKE256 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

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 64 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 TurboSHAKE256 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

source ReadOnlySpan<byte>

The input data to hash.

destination Span<byte>

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

bytesWritten int

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

Returns

bool

true if destination was large enough; otherwise, false.