Twofish
Schneier and colleagues' AES finalist with key-dependent S-boxes
About Twofish
Twofish is a block cipher. It uses a 16–32-byte key and a 16-byte (128-bit) block. Its registry entry cites AES finalist (Twofish). NextSSL lists it in the standard tier and exposes it through the safe API.
Overview
Twofish is a 128-bit block cipher designed by Bruce Schneier, John Kelsey, Doug Whiting, David Wagner, Chris Hall and Niels Ferguson. It was one of the five AES finalists and is the successor to Blowfish.
Twofish is a 16-round Feistel network. Its round function g applies four key-dependent 8-bit S-boxes and an MDS matrix, and two g outputs are combined with a pseudo-Hadamard transform and round subkeys. Additional one-bit rotations and input and output whitening with key material complete the round. Key-dependent S-boxes make the cipher's internal tables unknown to an attacker, at the cost of a more complex key schedule.
NextSSL includes Twofish with 128-, 192- and 256-bit keys. It is available in GnuPG, VeraCrypt and many cryptographic libraries. Its key schedule can be precomputed for speed or computed on the fly to save memory, and the designers documented many implementation trade-offs. Twofish was released unpatented and free for any use.
History
1997–2001NIST calls for a successor to DES
AES selection processTwofish published
15 candidates accepted
AES selection processFive finalists: MARS, RC6, Rijndael, Serpent and Twofish
AES selection processRijndael selected
AES selection processAES published as FIPS 197
AES selection process
Security notes
No practical attacks on full Twofish are known; published results break reduced rounds only. It is slower than AES on hardware with AES instructions and is mostly used where cipher diversity is desired.
Typical uses
Sizes
| Field | Bytes | Meaning |
|---|---|---|
| key | 16 – 32 | Secret key |
| block | 16 | Block |
Use it
from nextssl_demo import NextSSL
ns = NextSSL() # safe API: safe and standard tiers
block = ns.call("blockcipher_encrypt", "twofish", None, key, plaintext_block)[0]
nextssl_blockcipher_encrypt("twofish", NULL, key, block, out); /* exactly one block */
use nextssl_core::Params;
use nextssl_registry::{self as reg, Policy};
let alg = reg::new_blockcipher_in(reg::all(), Policy::Safe, "twofish", &Params::new())?;
let out = alg.encrypt_block(&key, &block)?;
Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.
Similar names
Looking for something else?More block ciphers
All 84Frequently asked questions
What is Twofish?
Twofish is a block cipher in the Twofish family. Twofish is a 128-bit block cipher designed by Bruce Schneier, John Kelsey, Doug Whiting, David Wagner, Chris Hall and Niels Ferguson.
What are the Twofish sizes?
In NextSSL, Twofish uses: key 16 to 32 bytes, block 16 bytes.
Who designed Twofish and when?
Twofish belongs to the Twofish family, first published in 1998 by Bruce Schneier, John Kelsey, Doug Whiting, David Wagner, Chris Hall, Niels Ferguson. Its origin: AES finalist.
Which standards define Twofish?
Twofish is referenced by AES finalist (Twofish).
Is Twofish safe to use?
Twofish is in the standard tier. Standardised and sound. Reachable from the safe API. It can be called from the safe API.