Threefish512 Class
Definition
- Namespace
- Bodu.Security.Cryptography
- Assembly
- Bodu.Security.Cryptography.dll
- Package
- Bodu.Security.Cryptography 1.2.0
- Source
- Threefish.512.cs
Provides a managed implementation of the Threefish-512 tweakable 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 Threefish512 : Threefish, IDisposable
- Inheritance
-
Threefish512
- Implements
- Inherited Members
- Extension Methods
Examples
using System.Security.Cryptography;
using Bodu.Security.Cryptography;
using Bodu.Security.Cryptography.Extensions;
using var tf = Threefish512.Create();
tf.Key = RandomNumberGenerator.GetBytes(64); // 512-bit key
tf.IV = RandomNumberGenerator.GetBytes(64); // matches the 512-bit block
tf.Tweak = RandomNumberGenerator.GetBytes(16); // 128-bit tweak
byte[] ciphertext = tf.Encrypt(plaintext);
byte[] roundTrip = tf.Decrypt(ciphertext);
Remarks
Threefish is the tweakable block cipher underlying the Skein hash function. This variant supports a variety of cipher block modes (CBC, CFB, OFB, CTR) via the BlockMode property, and is suitable for scenarios such as disk encryption or format-preserving encryption where a tweak is useful.
For other block sizes, see Threefish256 and Threefish1024.
Parameters at a glance.
- Block size: 512 bits (64 bytes).
- Key size: 512 bits (64 bytes).
- Tweak size: 128 bits (16 bytes).
- Default mode: CBC; default padding: PKCS7.
When to choose Threefish-512. The most common Threefish width - the wider 512-bit block lifts the
birthday bound to ~2256 blocks, removing the SWEET32-style concerns that 64-bit and 128-bit block
ciphers run into when re-used heavily under one key. A natural fit when building Skein-style constructions
(Skein-512 wraps this engine under the UBI mode). Use Threefish256 when the smaller block matches the
surrounding scheme; use Threefish1024 when even more block width is required.
Constructors
Threefish512()
Initializes a new instance of the Threefish512 class using a 512-bit block size, 512-bit key, and 128-bit tweak.
public Threefish512()
Methods
Create()
Creates a new Threefish512 instance with default parameters.
public static Threefish512 Create()
Returns
- Threefish512
A new Threefish512 instance.
Remarks
CreateCipher(byte[], byte[])
Instantiates the concrete Threefish block cipher with the specified key and tweak.
protected override ThreefishBlockCipher CreateCipher(byte[] key, byte[] tweak)
Parameters
Returns
- ThreefishBlockCipher
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 |