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

How to Use LLMs for Log File Analysis: Examples, Workflows, and Best Practices
Learn
7 Minute Read

How to Use LLMs for Log File Analysis: Examples, Workflows, and Best Practices

Learn how to use LLMs for log file analysis, from parsing unstructured logs to detecting anomalies, summarizing incidents, and accelerating root cause analysis.
Beyond Deepfakes: Why Digital Provenance is Critical Now
Learn
5 Minute Read

Beyond Deepfakes: Why Digital Provenance is Critical Now

Combat AI misinformation with digital provenance. Learn how this essential concept tracks digital asset lifecycles, ensuring content authenticity.
The Best IT/Tech Conferences & Events of 2026
Learn
5 Minute Read

The Best IT/Tech Conferences & Events of 2026

Discover the top IT and tech conferences of 2026! Network, learn about the latest trends, and connect with industry leaders at must-attend events worldwide.
The Best Artificial Intelligence Conferences & Events of 2026
Learn
4 Minute Read

The Best Artificial Intelligence Conferences & Events of 2026

Discover the top AI and machine learning conferences of 2026, featuring global events, expert speakers, and networking opportunities to advance your AI knowledge and career.
The Best Blockchain & Crypto Conferences in 2026
Learn
5 Minute Read

The Best Blockchain & Crypto Conferences in 2026

Explore the top blockchain and crypto conferences of 2026 for insights, networking, and the latest trends in Web3, DeFi, NFTs, and digital assets worldwide.
Log Analytics: How To Turn Log Data into Actionable Insights
Learn
11 Minute Read

Log Analytics: How To Turn Log Data into Actionable Insights

Breaking news: Log data can provide a ton of value, if you know how to do it right. Read on to get everything you need to know to maximize value from logs.
The Best Security Conferences & Events 2026
Learn
6 Minute Read

The Best Security Conferences & Events 2026

Discover the top security conferences and events for 2026 to network, learn the latest trends, and stay ahead in cybersecurity — virtual and in-person options included.
Top Ransomware Attack Types in 2026 and How to Defend
Learn
9 Minute Read

Top Ransomware Attack Types in 2026 and How to Defend

Learn about ransomware and its various attack types. Take a look at ransomware examples and statistics and learn how you can stop attacks.
How to Build an AI First Organization: Strategy, Culture, and Governance
Learn
6 Minute Read

How to Build an AI First Organization: Strategy, Culture, and Governance

Adopting an AI First approach transforms organizations by embedding intelligence into strategy, operations, and culture for lasting innovation and agility.