We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Feistel Network

Many block ciphers, including DES which we'll be talking about soon, use a Feistel network (or "Feistel Cipher") as a key component of their encryption algorithms.

Feistel structures have the useful property that encryption and decryption operations are very similar and sometimes identical. Decryption only requires a reversal of the key schedule. This keeps the implementation of the algorithms simple and concise.

  • n = The number of ciphering rounds
  • L0 = Left (first) half of the plaintext bytes
  • R0 = Right (second) half of the plaintext bytes
  • K0 - Kn = The round keys (from a key schedule)
  • F = The round function (specific to the ciphering algorithm, like DES for example)

One of the most interesting things about Feistel networks is that the round function does NOT have to be reversible.

A Feistel cipher is not a fully-fledged encryption algorithm but is rather a framework that more complete cipher implementations (like DES) utilize.

Assignment

For marketing purposes, Passly has decided to create its own Feistel network. It will use the Go standard library's SHA-256 hash function as the round function.

Here's some pseudocode:

func feistel(msg []byte, roundKeys [][]byte) []byte
  • Split the message into equal left and right-hand sides of equal length.
  • For each round:
    • nextRHS = xor(lhs, hash(rhs+key))
    • nextLHS = oldRHS
  • When you're done with all the rounds, return the concatenation of the right and left-hand sides (right first, then left)

The hash() and xor() functions are provided for you.

Click to play video