Logo
RSS Feed

Block Ciphers

Created: 06.10.2020

This is the next generation. 128-bit blocks, 128,192, 256 keys. It takes too much time to brute force. However, there are some situations when this could be cracked. And not only ECB but CBC as well.

One block of plaintext results in a 2-block cypher (random string + cypher text) for some modes. That’s why different modes exist.

  • Stream
    • synchronised
    • unsynchronised
  • Block
    • CTR

Encryption steps:

  • Choose some random string of length N (call it a 🐊)
  • Do something with the string to get a key 🗝 from 🐊
  • XOR your message 🍆 with a key 🗝
  • Cypher text 🫐 = 🐊, 🍆 XOR 🗝

Decryption steps:

  • c2 XOR Fk(c1)

CBC

Let’s start with an example. Let’s say we want to encrypt the message: explore. If it’s ASCII, it’s 7 bytes long. Let’s translate this into char: 65 78 70 6C 6F 72 65. Since the message needs to be padded to become 8 bytes long and we only have one character to add, we add 01 (see PKCS#5 padding).

65 78 70 6C 6F 72 65 01

Now, we pick an array of random numbers of the same length to make an IV (initialisation vector):

89 03 42 12 01 00 98 54

We first XOR IV with the message to get the following result:

EC 7B 32 7E 6E 72 FD 55

Then we encrypt this newly acquired array with AES (a series of shifting, meddling and xoring).

In the end, we have the following output:

89 03 42 12 01 00 98 54 EC 7B 32 7E 6E 72 FD 55

The first 8 bytes are the IV, and the last 8 are the encrypted message. How do we find out what the plaintext has access to the IV and be able to modify it and observe the server response?

ECB

Why is ECB considered insecure? To answer that we could go back to one-time pad and answer the question “why is one-time pad insecure when the same key is used more than once?” We already know why it’s not good. If you need to refresh it, go to the article about one-time pad to find more information.

Here is a picture I found online that shows how ECB works.

Let’s keep things simple. If the encryption algorithm 🔏 is basically adding number three 3 to each block, then the resulting blocks would retain the same difference as they had in the plaintext. All of the blocks become +3.

img

CBC

img

CTR

Encryption steps:

some_function(ctr):
	...
	return ctr

key_length = 10
number_of_blocks = 4
ctr = random(length=key_length)
message = [number_of_blocks]
cypher_text = ctr

for i in range(0,number_of_blocks):
	cypher_text += message[i] ^ ctr
	some_function(ctr += 1)

Decryption steps:

Cracking