Table of Contents

Serpent256Cipher Class

Definition

Namespace
Bodu.Security.Cryptography
Assembly
Bodu.Security.Cryptography.dll
Package
Bodu.Security.Cryptography 1.2.0
Source
SerpentBlockCipher.256.cs

Implements the wide-block tweakable Serpent-256 block cipher variant, which operates on 256-bit (32-byte) blocks using a 256-bit key and a 128-bit tweak. This class cannot be inherited.

public sealed class Serpent256Cipher : SerpentBlockCipher, IBlockCipher, IDisposable
Inheritance
Serpent256Cipher
Implements
Inherited Members
Extension Methods

Examples

// Direct single-block use. For most workloads prefer the Serpent256 SymmetricAlgorithm wrapper.
byte[] key   = new byte[32];   // 256-bit key
byte[] tweak = new byte[16];   // 128-bit tweak
RandomNumberGenerator.Fill(key);
RandomNumberGenerator.Fill(tweak);

using var cipher = new Serpent256Cipher(key, tweak);

byte[] plaintext  = new byte[32];
byte[] ciphertext = new byte[32];
cipher.Encrypt(plaintext, ciphertext);

byte[] roundtrip = new byte[32];
cipher.Decrypt(ciphertext, roundtrip);
// roundtrip equals plaintext

Remarks

The cipher runs 48 rounds over an eight-word (256-bit) state, alternating the canonical Serpent S-boxes with the bitsliced linear transform applied to each four-word lane. A cross-lane rotation between rounds provides diffusion across lanes, and a Threefish-style tweak subkey is XOR-injected every four rounds.

Most callers should prefer the higher-level Serpent256 class, which exposes the standard SymmetricAlgorithm contract. Use Serpent256Cipher directly only when composing the raw block primitive with an IBlockCipherModeTransform or IPaddingStrategy.

important

This type is a **non-standard Serpent-derived construction** and is not interoperable with any reference Serpent implementation. Its cryptographic properties have not been externally analyzed. For standard, externally vetted Serpent, use Serpent128Cipher.

Constructors

Serpent256Cipher(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Initializes a new instance of the Serpent256Cipher class using the specified key and tweak.

public Serpent256Cipher(ReadOnlySpan<byte> key, ReadOnlySpan<byte> tweak)

Parameters

key ReadOnlySpan<byte>

The 256-bit (32-byte) key used for encryption and decryption.

tweak ReadOnlySpan<byte>

The 128-bit (16-byte) tweak value used to modify the block cipher behavior.

Fields

KeySize

Length of the Serpent-256 key is 256 bits (32 bytes).

public const int KeySize = 256

Field Value

int

Properties

BlockSize

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

public override 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.

Applies to

ProductVersions
.NET8, 10

See Also