# Cryptography series: twofish symmetric key grouping algorithm

# Introduction

In the previous article, we talked about the blowfish algorithm because the encrypted block each time is relatively small and only has 64 bits, so it is not recommended to use blowfish to encrypt files over 4G. At the same time, because the encryption block is small, it can also cause birthday attacks. That's why there is twofish, the successor of blowfish.

Today we will reveal the twofish encryption algorithm together.

# The origin of twofish

Twofish, like blowfish, is also a symmetric encryption algorithm. The difference is that the block size of twofish is 128 bits, while its key length is 256 bits.

I believe everyone is familiar with AES. The full name of AES is The Advanced Encryption Standard, which is a standard symmetric block cipher technology approved by the National Institute of Standards and Technology (NIST).

AES was publicly selected from 1997 to 2000. It was created mainly to replace DES. Because DES has only 56-bit keys, it is vulnerable to brute force attacks.

NIST announced on January 2, 1997 that they wanted to choose the successor to DES, namely AES. Like DES, it should also be "an undisclosed, public encryption algorithm that can well protect sensitive government information before the 20th century." However, NIST did not simply issue a successor, but For an open selection, candidates need to provide relevant information to prove that they are better than DES. This kind of open solicitation immediately aroused people's keen interest.

In the following months, NIST received 15 proposals from multiple countries. They are CAST-256, CRYPTON, DEAL, DFC, E2, FROG, HPC, LOKI97, MAGENTA, MARS, RC6, Rijndael, SAFER+, Serpent and Twofish.

In the subsequent evaluation, cryptographers evaluated these candidate algorithms including security, performance and limited environment operation and other factors, and finally announced 5 finalists in August 1999: MARS, RC6, Rijndael, Serpent and Twofish.

Finally, on October 2, 2000, NIST announced the selection of Rijndael as the final AES algorithm. It became the official AES standard on November 26, 2001.

Although twofish is not the final AES standard, it is also very powerful to be among the top 5.

# performance of twofish

In 2000, for most platforms, the performance of twofish on 128-bit keys was slower than Rijndael, which is why Rijndael was elected as the AES standard. But the performance of 256-bit keys is better than Rijndael.

However, with Rijndael as the AES standard, more and more hardware is optimized based on AES, which finally leads to a growing gap between twofish and Rijndael.

Twofish is free like Blowfish.

# The principle of twofish

Twofish is evolved from blowfish. Let's first look at the working diagram of twofish:

Twofish, like DES, also uses Feistel structure.

First divide the plaintext of 128bits into 4 parts, and then _{ them with K 160e40680a90bd 0 } , K _{ 1 } , K _{ 2 } , K _{ 3 } , we XOR them as A1, A2, we call them A1, A2, we call them A3 , A4.

The part enclosed by the dashed line is the F function.

A1, A2 are XORed with A3 as the result of input of F, then shifted to the right by one bit, and XORed with the result of A4 shifted to the left by one bit, and then exchange the positions of the left and right parts.

The output of the last round is directly XORed with the four extended keys without being exchanged to obtain the ciphertext C.

Let's look at the F function again.

F is a permutation function related to the key on 64-bit data. It has three parameters, R1 and R2 as two inputs, and the number of rounds of the sub-item represented by r.

R1 and R2 first pass through the S-box transformation, then multiply by the MDS matrix, then perform the PHT transformation, and finally perform the XOR operation with the subkey.

This article has been included in http://www.flydean.com/twofish/

The most popular interpretation, the most profound dry goods, the most concise tutorial, and many tips you don't know are waiting for you to discover!

0 条评论