Serpent512 Class
Definition
- Namespace
- Bodu.Security.Cryptography
- Assembly
- Bodu.Security.Cryptography.dll
- Package
- Bodu.Security.Cryptography 1.2.0
- Source
- Serpent.512.cs
Provides a managed implementation of the non-standard wide-block tweakable Serpent-512 symmetric block
cipher, which operates on 512-bit (64-byte) blocks using a 512-bit key and a 128-bit tweak. This class cannot be
inherited.
public sealed class Serpent512 : Serpent, IDisposable
- Inheritance
-
Serpent512
- Implements
- Inherited Members
- Extension Methods
Examples
using System.Security.Cryptography;
using Bodu.Security.Cryptography;
using Bodu.Security.Cryptography.Extensions;
using var serpent = Serpent512.Create();
serpent.Key = RandomNumberGenerator.GetBytes(64); // 512-bit key
serpent.IV = RandomNumberGenerator.GetBytes(64); // matches the 512-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 a sixteen-word state for 64 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 Serpent256 and Serpent1024.
Parameters at a glance.
- Block size: 512 bits (64 bytes).
- Key size: 512 bits (64 bytes).
- Tweak size: 128 bits (16 bytes).
- 64 rounds; tweak subkey injected every 4 rounds.
- Default mode: CBC; default padding: PKCS7.
When to choose Serpent-512. Pick the wide-block Serpent variants only for experimental work where a tweakable wide-block cipher with Serpent's round function is wanted. Threefish512 is a better-studied alternative for the same role. Use Serpent128 for any production scenario that requires interoperable Serpent.
important
Serpent-512 (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
Serpent512()
Initializes a new instance of the Serpent512 class using a 512-bit block size, 512-bit key, and 128-bit tweak.
public Serpent512()
Methods
Create()
Creates a new Serpent512 instance with default parameters.
public static Serpent512 Create()
Returns
- Serpent512
A new Serpent512 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 |