ArticleslgStudy

science

Blowfish (cipher)

Blowfish (cipher) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Blowfish (cipher) rather than just read about it. In short: Blowfish is a symmetric-key block cipher, designed in 1993 by Bruce Schneier and included in many cipher suites and encryption products. Blowfish provides a good encryption rate in software, and no effective cryptanalysis of it has been found to date for smaller files.

Blowfish (cipher) — main illustration
Blowfish (cipher) — illustration

Key takeaways

  • Blowfish (cipher) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Blowfish (cipher) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Blowfish (cipher) from memory before moving on to harder problems.

Reference excerpt

Blowfish is a symmetric-key block cipher, designed in 1993 by Bruce Schneier and included in many cipher suites and encryption products. Blowfish provides a good encryption rate in software, and no effective cryptanalysis of it has been found to date for smaller files. It is recommended Blowfish should not be used to encrypt files larger than 4GB in size, in which case Twofish should be used instead. Blowfish has a 64-bit block size and therefore it could be vulnerable to Sweet32 birthday attacks. Schneier designed Blowfish as a general-purpose algorithm, intended as an alternative to the aging DES and free of the problems and constraints associated with other algorithms. At the time Blowfish was released, many other designs were proprietary, encumbered by patents, or were commercial or government secrets. Schneier has stated that "Blowfish is unpatented, and will remain so in all countries. The algorithm is hereby placed in the public domain, and can be freely used by anyone." Notable features of the design include key-dependent S-boxes and a highly complex key schedule.

The algorithm Blowfish has a 64-bit block size and a variable key length from 32 bits up to 448 bits. It is a 16-round Feistel cipher and uses large key-dependent S-boxes. In structure it resembles CAST-128, which uses fixed S-boxes.

The adjacent diagram shows Blowfish's encryption routine. Each line represents 32 bits. There are five subkey-arrays: one 18-entry P-array (denoted as K in the diagram, to avoid confusion with the Plaintext) and four 256-entry S-boxes (S0, S1, S2 and S3). Every round r consists of 4 actions:

The F-function splits the 32-bit input into four 8-bit quarters and uses the quarters as input to the S-boxes. The S-boxes accept 8-bit input and produce 32-bit output. The outputs are added modulo 232 and XORed to produce the final 32-bit output (see image in the upper right corner). After the 16th round, undo the last swap, and XOR L with K18 and R with K17 (output whitening). Decryption is exactly the same as encryption, except that P1, P2, ..., P18 are used in the reverse order. This is not so obvious because xor is commutative and associative. A common misconception is to use inverse order of encryption as decryption algorithm (i.e. first XORing P17 and P18 to the ciphertext block, then using the P-entries in reverse order). Blowfish's key schedule starts by initializing the P-array and S-boxes with values derived from the hexadecimal digits of pi, which contain no obvious pattern (see nothing up my sleeve number). The secret key is then, byte by byte, cycling the key if necessary, XORed with all the P-entries in order. A 64-bit all-zero block is then encrypted with the algorithm as it stands. The resultant ciphertext replaces P1 and P2. The same ciphertext is then encrypted again with the new subkeys, and the new ciphertext replaces P3 and P4. This continues, replacing the entire P-array and all the S-box entries. In all, the Blowfish encryption algorithm will run 521 times to generate all the subkeys – about 4 KB of data is processed. Because the P-array is 576 bits long, and the key bytes are XORed through all these 576 bits during the initialization, many implementations support key sizes up to 576 bits. The reason for that is a discrepancy between the original Blowfish description, which uses 448-bit keys, and its reference implementation, which uses 576-bit keys. The test vectors for verifying third-party implementations were also produced with 576-bit keys. When asked which Blowfish version is the correct one, Bruce Schneier answered: "The test vectors should be used to determine the one true Blowfish". Another opinion is that the 448 bits limit is present to ensure that every bit of every subkey depends on every bit of the key, as the last four values of the P-array don't affect every bit of the ciphertext. This point should be taken in consideration for implementations with a different number of rounds, as even though it increases security against an exhaustive attack, it weakens the security guaranteed by the algorithm. And given the slow initialization of the cipher with each change of key, it is granted a natural protection against brute-force attacks, which doesn't really justify key sizes longer than 448 bits.

Blowfish in pseudocode P[18] // P-array of 18 elements S[4][256] // S-boxes: 4 arrays of 256 elements

function f(x): // Calculates a function f on a 32-bit input x, using S-boxes and bit manipulation high_byte := (x shifted right by 24 bits) second_byte := (x shifted right by 16 bits) AND 0xff third_byte := (x shifted right by 8 bits) AND 0xff low_byte := x AND 0xff

h := S[0][high_byte] + S[1][second_byte] return (h XOR S[2][third_byte]) + S[3][low_byte]

procedure blowfish_encrypt(L, R): // Encrypts two 32-bit halves L and R using the P-array and function f over 16 rounds for round := 0 to 15: L := L XOR P[round] R := f(L) XOR R swap values of L and R swap values of L and R R := R XOR P[16] L := L XOR P[17]

procedure blowfish_decrypt(L, R): // Decrypts two 32-bit halves L and R using the P-array and function f over 16 rounds in reverse for round := 17 down to 2: L := L XOR P[round] R := f(L) XOR R swap values of L and R swap values of L and R R := R XOR P[1] L := L XOR P[0] // Initializes the P-array and S-boxes using the provided key, followed by key expansion // Initialize P-array with the key values key_position := 0 for i := 0 to 17: k := 0 for j := 0 to 3: k := (k shifted left by 8 bits) OR key[key_position] key_position := (key_position + 1) mod key_length P[i] := P[i] XOR k

// Blowfish key expansion (521 iterations) L := 0, R := 0 for i := 0 to 17 by 2: blowfish_encrypt(L, R) P[i] := L P[i + 1] := R

// Fill S-boxes by encrypting L and R for i := 0 to 3: for j := 0 to 255 by 2: blowfish_encrypt(L, R) S[i][j] := L S[i][j + 1] := R

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Blowfish (cipher)

Start with the simplest possible case. Write down what Blowfish (cipher) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Blowfish (cipher) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Blowfish (cipher) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Blowfish (cipher)

In research
Blowfish (cipher) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Blowfish (cipher) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Blowfish (cipher) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Block ciphers, Feistel ciphers, Free ciphers, so understanding it makes those chapters shorter.
In everyday life
Look for Blowfish (cipher) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Blowfish (cipher)” →

How to study Blowfish (cipher) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Blowfish (cipher) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Blowfish (cipher) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Blowfish (cipher) in simple terms?

Blowfish is a symmetric-key block cipher, designed in 1993 by Bruce Schneier and included in many cipher suites and encryption products. Blowfish provides a good encryption rate in software, and no effective cryptanalysis of it has been found to date for smaller files.

Why does Blowfish (cipher) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Blowfish (cipher)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Blowfish (cipher).

Tags

  • Block ciphers
  • Feistel ciphers
  • Free ciphers

Keep exploring