Skip to content

OnixLabs.Security.Cryptography.Sha3Shake128

matthew edited this page May 27, 2026 · 1 revision

Sha3Shake128 Class

Represents the FIPS 202 SHAKE128 extendable-output function (XOF).

Namespace OnixLabs.Security.Cryptography
Assembly OnixLabs.Security.Cryptography.dll (NuGet)
Inheritance object → HashAlgorithm → Sha3 → Sha3Shake128

Definition

public sealed class Sha3Shake128 : Sha3

Remarks

Sha3Shake128 implements the SHAKE128 extendable-output function (XOF) defined in FIPS 202. Unlike the fixed-length SHA-3 hash variants, SHAKE128 does not have a predetermined output size. Instead, the caller specifies the desired number of output bytes at construction time via the length parameter, and the sponge squeezes exactly that many bytes from the state.

Key parameters:

  • Sponge rate: 168 bytes
  • Domain-separation delimiter: 0x1f (ShakeDelimiter)
  • Output length: caller-supplied, in bytes (length * 8 bits stored internally)

Any positive length value is accepted. This makes SHAKE128 well-suited for use cases that require output of arbitrary size, such as key derivation, mask generation functions, or streaming PRF output. The security strength is min(capacity/2, output-bits), capped at 128 bits for SHAKE128 regardless of how many output bytes are requested.

The preferred instantiation path is the static factory method Sha3.CreateSha3Shake128(int). Constructing directly with new Sha3Shake128(length) is equivalent.

Because Sha3Shake128 extends HashAlgorithm, it integrates with all BCL hashing idioms: ComputeHash, TransformBlock / TransformFinalBlock, the using-disposable pattern, and Hash.Compute all work without modification.

Examples

Producing 32 bytes of SHAKE128 output

using OnixLabs.Security.Cryptography;

byte[] input = System.Text.Encoding.UTF8.GetBytes("Hello, World!");

using Sha3Shake128 shake = Sha3.CreateSha3Shake128(length: 32);
byte[] hash = shake.ComputeHash(input);

Console.WriteLine(Convert.ToHexString(hash)); // 64 hex characters (32 bytes)

Producing 64 bytes of SHAKE128 output via the Hash wrapper

using System.Security.Cryptography;
using OnixLabs.Security.Cryptography;

byte[] input = System.Text.Encoding.UTF8.GetBytes("Hello, World!");

using HashAlgorithm shake = new Sha3Shake128(length: 64);
Hash hash = Hash.Compute(shake, input);

Console.WriteLine(hash.Length); // 64

Constructors

Constructor Description
Sha3Shake128(int) Initializes a new instance of the Sha3Shake128 class with the specified output length.

Sha3Shake128(int)

public Sha3Shake128(int length)

Initializes a new instance of the Sha3Shake128 class, configuring the Keccak sponge with a rate of 168 bytes and an output length of length * 8 bits. The sponge state is reset immediately via Initialize.

Parameter Type Description
length int The desired hash output length in bytes.

See Also

ONIXLabs .NET Library


Clone this wiki locally