Table of Contents

ThreefishBlockCipher Class

Definition

Namespace
Bodu.Security.Cryptography
Assembly
Bodu.Security.Cryptography.dll
Package
Bodu.Security.Cryptography 1.2.0
Source
ThreefishBlockCipher.cs

Serves as the abstract base class for managed Threefish block cipher engines, providing shared key and tweak scheduling, resource disposal, and the core MIX/UNMIX primitives used by the Threefish-256, Threefish-512, and Threefish-1024 variants.

public abstract class ThreefishBlockCipher : IBlockCipher, IDisposable
Inheritance
ThreefishBlockCipher
Implements
Derived
Inherited Members
Extension Methods

Remarks

Derived classes - Threefish256Cipher, Threefish512Cipher, and Threefish1024Cipher - supply the block size, word count, rotation schedule, and round count for a specific Threefish variant, along with their own Encrypt(ReadOnlySpan<byte>, Span<byte>) and Decrypt(ReadOnlySpan<byte>, Span<byte>) implementations.

External callers cannot derive new variants: the constructor and protected members are scoped private protected, limiting derivation to the three variants that ship with this library. Use Threefish256Cipher, Threefish512Cipher, or Threefish1024Cipher for the raw block primitive, or one of the higher-level Threefish256, Threefish512, or Threefish1024 wrappers for the standard SymmetricAlgorithm contract.

Properties

BlockSize

Gets the block size, in bits, of the cipher (for example, 128 bits / 16 bytes for AES).

public abstract int BlockSize { get; }

Property Value

int

The block size, in bits.

Remarks

The block size is expressed in bits to align with the BCL convention used by BlockSize. Byte-array operations (encrypt, decrypt, slice) convert to bytes at the call site as BlockSize / 8.

BlockWords

Gets the number of 64-bit words in a single block.

protected abstract int BlockWords { get; }

Property Value

int

RotationSchedule

Gets the rotation constants used for MIX/UNMIX operations in this cipher variant.

protected abstract int[] RotationSchedule { get; }

Property Value

int[]

Rounds

Gets the total number of cipher rounds.

protected abstract int Rounds { get; }

Property Value

int

Methods

Decrypt(ReadOnlySpan<byte>, Span<byte>)

Decrypts a full ciphertext block and writes the plaintext to the output span.

public abstract void Decrypt(ReadOnlySpan<byte> input, Span<byte> output)

Parameters

input ReadOnlySpan<byte>

The ciphertext input block.

output Span<byte>

The output span to receive the decrypted data.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases all internal buffers and sensitive material. Securely clears the key and tweak schedules.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Whether the method was called from Dispose().

Encrypt(ReadOnlySpan<byte>, Span<byte>)

Encrypts a full input block and writes the ciphertext to the output span.

public abstract void Encrypt(ReadOnlySpan<byte> input, Span<byte> output)

Parameters

input ReadOnlySpan<byte>

The plaintext input block.

output Span<byte>

The output span to receive the encrypted data.

~ThreefishBlockCipher()

Finalizes an instance of the ThreefishBlockCipher class.

protected ~ThreefishBlockCipher()

Mix(ref ulong, ref ulong, int)

Performs a Threefish mixing operation by rotating and XORing the input values.

protected static void Mix(ref ulong a, ref ulong b, int rotation)

Parameters

a ulong

The first value (accumulator), modified in-place.

b ulong

The second value, rotated and XORed with a.

rotation int

The rotation amount (in bits).

ThrowIfDisposed()

Throws an ObjectDisposedException if the algorithm instance has been disposed.

protected void ThrowIfDisposed()

Exceptions

ObjectDisposedException

Thrown when any public method or property is accessed after the instance has been disposed.

Unmix(ref ulong, ref ulong, int)

Reverses the Threefish mixing operation performed by Mix(ref ulong, ref ulong, int).

protected static void Unmix(ref ulong a, ref ulong b, int rotation)

Parameters

a ulong

The accumulator used in the forward pass.

b ulong

The rotated/XORed value to unmix.

rotation int

The rotation amount (in bits) used during encryption.

Applies to

ProductVersions
.NET8, 10

See Also