Serpent256 Class
Definition
- Namespace
- Bodu.Security.Cryptography
- Assembly
- Bodu.Security.Cryptography.dll
- Package
- Bodu.Security.Cryptography 1.2.0
- Source
- Serpent.256.cs
Provides a managed implementation of the non-standard wide-block tweakable Serpent-256 symmetric block
cipher, 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 Serpent256 : Serpent, IDisposable
- Inheritance
-
Serpent256
- Implements
- Inherited Members
- Extension Methods
Examples
using System.Security.Cryptography;
using Bodu.Security.Cryptography;
using Bodu.Security.Cryptography.Extensions;
using var serpent = Serpent256.Create();
serpent.Key = RandomNumberGenerator.GetBytes(32); // 256-bit key
serpent.IV = RandomNumberGenerator.GetBytes(32); // matches the 256-bit block
serpent.Tweak = RandomNumberGenerator.GetBytes(16); // 128-bit tweak
byte[] ciphertext = serpent.Encrypt(plaintext);
byte[] roundTrip = serpent.Decrypt(ciphertext);
Remarks
This variant runs the Serpent round function over an eight-word state for 48 rounds, injecting a tweak subkey every four rounds in the style of Threefish. It supports the extended block cipher modes exposed by CipherModeKind via the BlockMode property.
For other block sizes, see Serpent512 and Serpent1024.
Parameters at a glance.
- Block size: 256 bits (32 bytes).
- Key size: 256 bits (32 bytes).
- Tweak size: 128 bits (16 bytes).
- 48 rounds; tweak subkey injected every 4 rounds.
- Default mode: CBC; default padding: PKCS7.
When to choose Serpent-256. Pick the wide-block Serpent variants only for experimental work where a tweakable wide-block cipher with Serpent's round function is wanted. Threefish256 is a better-studied alternative for the same role. Use Serpent128 for any production scenario that requires interoperable Serpent.
important
Serpent-256 (this type) is a non-standard Serpent-derived construction and is not interoperable with any reference Serpent implementation. For standard, externally vetted Serpent, use Serpent128.
Constructors
Serpent256()
Initializes a new instance of the Serpent256 class using a 256-bit block size, 256-bit key, and 128-bit tweak.
public Serpent256()
Methods
Create()
Creates a new Serpent256 instance with default parameters.
public static Serpent256 Create()
Returns
- Serpent256
A new Serpent256 instance.
Remarks
CreateCipher(byte[], byte[])
Instantiates the concrete Serpent block cipher with the specified key and tweak.
protected override IBlockCipher CreateCipher(byte[] key, byte[] tweak)
Parameters
Returns
- IBlockCipher
A configured IBlockCipher instance for encryption or decryption.
Exceptions
- ArgumentNullException
Thrown when
keyis null.- CryptographicException
Thrown when the underlying cryptographic algorithm fails.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |