The Twofish Encryption Algorithm

Key Takeaways

  • Twofish is a symmetric block cipher that operates on 128-bit blocks and supports key sizes up to 256 bits.
  • The algorithm employs a 16-round Feistel network, key-dependent S-boxes, pre- and post-whitening, and a maximum distance separable (MDS) matrix, providing strong security and resistance to cryptanalysis.
  • Twofish is unpatented, open-source, and remains efficient for both software and hardware implementations, making it a versatile choice for disk encryption and secure communications.

Twofish is an Advanced Encryption Standard (AES) blockcypher algorithm. Twofish is not vulnerable to a simple brute force attack and is not inherently insecure against side-channel attacks.

Let’s explore Twofish here.

History of Twofish

In 1997, Twofish was entered into a NIST competition to replace the DES algorithm. Among the most successful cryptographic algorithms, DES was widely criticized due to its closed-door design process.

So, the goal of the NIST competition was to develop a block cipher algorithm that can flexibly handle a variety of properties:

Specifically, the NIST design criteria called for algorithms with 128-bit symmetric block ciphers that can handle 128- to 256-bit key lengths, with no weak keys, a simple design for analysis and processing in low-power devices, and implementable on a variety of platforms and applications.

Developers of the Twofish algorithm aimed to achieve these goals with a block cipher algorithm that is not vulnerable to a chosen plaintext attack with an arbitrarily large key length. Specifically, the authors aimed to develop a 16-round Twofish algorithm with no attack for 2^80 chosen plaintexts and a 12-round Twofish with no key-attack for less than 2^64 chosen plaintexts.

(Related reading: how encryption works & data encryption methods to use.)

Capabilities & cryptographic structure of Twofish

The proposed Twofish algorithm achieved this goal by using the following capabilities and cryptographic structure:

Feistel Network

A transformation function that takes the input data, divides it in equal blocks, each processed through a series of encryption rounds depending on the encryption keys derived from either blocks.

Substitution Operation with S-Box

A non-linear substitution between block ciphers based on a predefined substitution table. The idea is to introduce small changes in the form of substitutions, which can result in significant changes on the output. This process obscures the relationship between the input and output data and can have an avalanche effect: changing a single data bit can cause a significant proportion of the corresponding block output to change.

MDS Matrix

The Maximum Distance Separable (MDS) refers to the linear distance between two field elements. This process applies a restriction on two distinct data vectors, such that the minimum distance between two elements is as large as possible.

Pseudo-Hadamard Transforms

A mathematical operation that retains the desired properties of the data transformation using fewer mathematical computations.

Whitening

The process of introducing randomness with each encryption round. The mathematical operation of XOR is applied to the data before the first round and at the end of the final encryption round. Two fish uses a 128-bit text block and applies the XOR operation to four key words.

Key Schedule

A process to ensure that subkeys used in every encryption round are different and not easily predictable.

Twofish structure: how it works

The structure of the Twofish algorithm is as follows:

This algorithm structure is illustrated in the image below:

(Image source)

Twofish was designed to perform well on small devices that contain low-power processing capabilities. The performance advantage emerges from the key schedule, where twofish makes key-dependent S-box and round-subkeys with several variations depending on the application:

The encryption and decryption process can take either variation, depending on the performance capabilities of the underlying hardware and performance requirements for the applications.

Rijndael AES vs. Twofish

At the NIST competition, the Rijndael algorithm was chosen as the winner over the Twofish algorithm due to two important factors.

Nevertheless, both the AES and Twofish algorithms have yet to be cracked. While some would argue that a longer key-length Twofish implementation may be more secure than a standard AES implementation, the choice comes down to ease of implementation, memory consumption and computational performance.

Other cryptographic algorithms

Check out our key management explainer and explore our three-part series on quantum computing: what it means for your encryptions.

Related Articles

Cybersecurity Attacks Explained: How They Work & What’s Coming Next in 2026
Learn
4 Minute Read

Cybersecurity Attacks Explained: How They Work & What’s Coming Next in 2026

Today’s cyberattacks are more targeted, AI-driven, and harder to detect. Learn how modern attacks work, key attack types, and what security teams should expect in 2026.
Exploit Prediction Scoring System (EPSS): How It Works and Why It Matters
Learn
5 Minute Read

Exploit Prediction Scoring System (EPSS): How It Works and Why It Matters

Discover how the Exploit Prediction Scoring System (EPSS) predicts the likelihood of vulnerability exploitation, improves prioritization, and differs from CVSS.
What Are Servers? A Practical Guide for Modern IT & AI
Learn
4 Minute Read

What Are Servers? A Practical Guide for Modern IT & AI

Learn what a computer server is, how servers work, common server types, key components, and how to choose the right server for your organization.