0
$\begingroup$

I am trying to learn some basic cryptography and I am reading some conflicting statements about block cipher.

My current understanding is that we start with an XOR to obfuscate our data. We can then generate a one-time pad to encrypt our message. The only limitation is that the message length must be less than the length of our single-use pad (making one-time padding impractical for large files).

So we introduce block ciphers which encrypt blocks of plaintext at a time. We generate a key which is essentially a mapping of input to output. An example of a block cipher is AES.

I read that AES would blow up if we tried to encrypt a jpeg file - or any message that is larger than our key size (thus introducing stream cipher). I've also read that block cipher is best used on any known-length message (i.e. any file). The latter makes more sense since we're breaking down messages of any length down into blocks anyway.

Which is true? Am I misunderstanding something?

$\endgroup$
4
$\begingroup$

A block cipher like AES itself cannot be used to encrypt large files. One needs to use some mode of operation to chain a sequence of blocks. The length of this whole "chain", which essentially is the product of the block size and number of blocks, is the length that you can encrypt files with. The key size of the block cipher basically tells you what security level you can get from a "chain" of block ciphers (or a single block cipher of course).

$\endgroup$
  • $\begingroup$ ... which essentially is the product of the block size and number of blocks plus or minus a padding block, depending on the mode that is used $\endgroup$ – Ella Rose Mar 1 at 18:36
  • 2
    $\begingroup$ @EllaRose Yes, that's why I said "essentially" :) $\endgroup$ – Shan Chen Mar 1 at 18:41
1
$\begingroup$

If you want to encrypt messages that are larger/shorter than the key length, then just a block cipher is not enough.

In order to be able to encrypt these kind of messages you will need to design an algorithm that decides how to call and use the block cipher and how to apply padding in such a way that you will not affect privacy (and authenticity if you want it too).

These kinds of algorithms are called mode of operation. There are few mode operations, the most basic 3 of them are:

Electronic code book-ECB:

In this mode of operation you will have one block cipher with one key-K. Assuming your message length is L, your message will be divide to L/K blocks when each block will be encrypted separately. In a case that L is not divisible by K, some padding will need to be added to L.

The main disadvantage of this mode of operation is the lack of diffusion as it encrypts identical plaintext to identical cipher text.

Cipher block chaining-CBC

This mode of operation requires a block cipher with a key-k and some random publicly know string -IV. Assuming your message length is L, your message will be divide to L/K blocks. The first block will be xored with IV and then encrypted. Each another block will be xored with the encryption result of the previous block. The main disadvantage is that it can not be parallelizable as each block needs the result of the previous block for encryption.

Counter mode

This mode of operation turns a block cipher to a stream cipher. In this mode of operation you will have one block cipher with one key-K and a random message -nonce and a counter. Each block cipher input will be the nonce and the current value of the counter. The output of the block cipher will be xored with the plain text. This case does not require padding as you can just throw the out out of the last block cipher in a case that your plain text length is shorter.

$\endgroup$
  • $\begingroup$ Please don't highlight ‘ECB mode’ as a concept! It is not merely that ECB has a ‘lack of diffusion’ which sounds like some obscure technical criterion; ECB is a completely bonkers broken idea that should never have existed or been named in the first place. The whole concept of block cipher modes of operation was a mistake of cryptographic engineering ontology from the last century, and should be left in the dustbin of history; what matters for users is authenticated ciphers like AES-GCM or crypto_secretbox_xsalsa20poly1305. $\endgroup$ – Squeamish Ossifrage Apr 27 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.