← Cryptography guide

K005 / Symmetric ciphers (block and stream)

Twofish

Twofish cipher · Survey date 2026-12-05

Twofish is a symmetric block cipher with 128-bit blocks and variable key lengths up to 256 bits.

CRYPTOGRAPHY LAB / K005

Cryptography Lab · Twofish

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Standard operation

Twofish (16 rounds)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Open lab →

Definition and overview
Twofish is a symmetric block cipher with 128-bit blocks and variable key lengths up to 256 bits. Source document ↗
Classification and reversibility
A symmetric block cipher that encrypts and decrypts with the same key. Source document ↗
Key or secret requirements
Requires a secret symmetric key; one key is used for encryption and decryption. Source document ↗
Operating principle and structure
Consists of a 16-round Feistel network and key-dependent 8×8 S-boxes. Source document ↗
Key size, block size and parameters
128-bit blocks, 128/192/256-bit keys and a 16-round Feistel structure. Source document ↗
Security strength and recommendation
Not currently recommended by NIST/BSI; only AES is recommended. Source document ↗
Known attacks and vulnerabilities
No attack on all 16 rounds is known; only reduced-round attacks have been disclosed. Source document ↗
Standards and certification
Defined for OpenPGP in RFC 9580 and supported by various tools. Source document ↗
Typical uses
Used or supported in OpenPGP, VeraCrypt, KeePassXC, GnuPG and the Linux kernel crypto API. Source document ↗
Implementations, libraries and tools
Libraries include Python bindings for a RustCrypto-based implementation. Source document ↗
Decryption or decoding
Call the Decrypt API using the same key; handle mode, IV and padding separately. Source document ↗
Advantages
Runs quickly on 32-bit and 8-bit CPUs and in hardware. Source document ↗
Limitations and cautions
Classified as a legacy cipher that should not be used in new applications. Source document ↗
Distinguishing encryption, encoding and hashing
Key-based encryption, distinct from encoding and hashing; a key is required for decryption. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Example using 128-bit plaintext blocks: choose a 128/192/256-bit key and operating mode/IV, generate Twofish ciphertext and decrypt using the same key and parameters. Actual key and IV values are not shown and must be securely managed.

Procedure

Encryption: prepare plaintext, choose padding/mode/IV, derive the Twofish key schedule, encrypt blocks, store IV and metadata. Decryption: confirm ciphertext and key/mode/IV, decrypt blocks, remove padding, verify plaintext. Encryption/decryption is secret-key reversible transformation; encoding/decoding changes representation and hashing is irreversible summarization.

Scenario

Use when reading existing OpenPGP/KeePassXC/VeraCrypt-compatible data or maintaining legacy systems. Replacing it with AES-based AEAD is safer for new designs.

Pitfalls and alternatives

Twofish is not a mainstream NIST/BSI recommendation and is classified as legacy; use AEAD such as AES-GCM for new designs. Avoid ECB, IV reuse, padding oracles and hardcoded keys. Do not mistake Base64 or hashing for encryption.

References