07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5 ■ Stream Ciphers and Block Ciphers 165

■■

Encryption is decryption (just pass in the IV)

■■

We don’t have to pad the message, just use the bits we need (saves bandwidth

on small messages)

■■

CTR can be efficiently parallelized both for encryption and decryption

Weaknesses:

■■

OFB might have short permutation cycles (more in a minute on that)

■■

Using the same IV twice is deadly (not great in CBC but worse here)

■■

Tampering with the ciphertext can lead to tampered plaintext (and not

just noise)

DIY Block Cipher Using Feistel Networks

In this next section, I want to show you a slick method to use one-way function,

like hashes, to create block ciphers using the Feistel network. A Feistel cipher/

Feistel network implements a series of iterative ciphers on a block of data and

is generally designed for block ciphers that encrypt large quantities of data.

A Feistel network works by splitting the data block into two equal pieces and

applying encryption in multiple rounds.

The input block is split in the middle to create equal-sized sub-blocks. Examine

Figure 5.15; let’s call the initial left-hand side sub-block L 0 , and the initial

right-hand side sub-block R 0 . Let the function F ki be the round function that

uses the i th round key, k i . These round keys are generated by the key schedule,

which is unspecified. If we have r rounds, then for 1 ≤ i < r.

L i = R i−1

R i = L i−1 ⊕ F ki (R i−1 )

and for i = r

L r = R r−1 ⊕ F kr (L r−1 )

R r = L r−1

The idea is to split your message into two halves, with one half to make

something that looks like noise. Then XOR the other half with the noise. Finally,

pass the XOR’d result and the unmodified half. This gives you everything you

need to know to go backward, which is the same exact process. In Figure 5.16

you will see an illustration of how the Feistel network decryption works.

Next, convince yourself that reversing one step of the Feistel network is doable

by hashing the part that passed in the clear, XORing with the other half, and

reversing their spots. Now we want to have our output have the same bit length

as our input, which was not true for a hash function.

Use the super-hash as the one-way function in a Feistel network. Our output

is a 256-bit hexadecimal number. The input should be 512 bits. Eight bits is

enough to encode one ASCII character. The secrets should be 64 characters long.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!