Block ciphers

Twofish

Schneier and colleagues' AES finalist with key-dependent S-boxes

standard Safe API

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–2001
  1. NIST calls for a successor to DES

    AES selection process
  2. Twofish published

  3. 15 candidates accepted

    AES selection process
  4. Five finalists: MARS, RC6, Rijndael, Serpent and Twofish

    AES selection process
  5. Rijndael selected

    AES selection process
  6. AES 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

Disk encryption and cascadesReplacing Blowfish in older designs

Sizes

FieldBytesMeaning
key16 – 32Secret key
block16Block

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]

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Similar names

Looking for something else?

Frequently 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.