07.07.2023 Views

Implementing-cryptography-using-python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

162 Chapter 5 ■ Stream Ciphers and Block Ciphers

CFB offers two advantages over CBC mode with the stream cipher modes

OFB and CTR: first, the block cipher is only used in the encryption process,

and second, the message does not need to be padded to a multiple of the cipher

block size.

OFB Mode

The OFB mode, formally named Output Feedback, makes a block cipher into

a synchronous stream cipher. OFB mode generates keystream blocks that are

XOR’d with plaintext blocks to get the ciphertext. See Figure 5.11 for a visual

representation. As with other stream ciphers, modifying a bit in the ciphertext

will result in a flipped bit in the produced plaintext at the same location. This

characteristic allows many error-correcting codes to function normally. The

encryption and decryption methods are the same.

Initialization Vector (IV)

Key

block cipher

encryption

Key

block cipher

encryption

Key

block cipher

encryption

Plaintext

Plaintext

Plaintext

Ciphertext Ciphertext Ciphertext

Figure 5.11: Output Feedback (OFB) mode encryption

As with the CBC mode, the OFB cipher operation depends on the previous

blocks and therefore cannot be performed in parallel. One notable difference

is that because the ciphertext and plaintext are only used for the final XOR,

the block cipher operations may be performed in advance. This property will

allow the final step to be performed in parallel once the cipher or plaintext is

available. See Figure 5.12 for a review of OFB mode decryption.

One thing to note is that you can obtain an OFB mode keystream by using

CBC mode with a constant string of zeros as input. This property can be useful

as it allows the usage of fast hardware implementations of CBC mode for OFB

mode encryption.

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

Saved successfully!

Ooh no, something went wrong!