CounterMode CTR for Block Cipher Encryption and Decryption

preview_player
Показать описание
Intro
1. At the start, the plain text is broken down into every 16 bytes which has the block size of 128bits.
2. Instead of sending the plain text blocks into Advanced Encryption Standard (AES), we hold the plain text for now.
3. For counter mode, we will require a counter and the key that will be used for AES. The key is used as the input and the counter is used as the input message.
4. Using a counter alone is not very secure, so a nonce is appended to the counter before running it through AES. A nonce is a one-time use, random value.
5. After getting the output from AES, the plaintext block will be XOR with the output to create the ciphertext. The counter will increase for each plaintext block while the nonce and the key remains unchanged for the entire encryption process.
6. Once all the plaintext block is processed, it will be combined to generate the ciphertext block.
7. For this example, we have simplified the encryption operation to 4 bits.
8. We have an 8bit plaintext which is split into 4 bit blocks, and for the nonce and counter we have 2 bits for each of them and a 4 bit key.
9. And as an example, the output generated is 0110, which is then XOR with the first block 1010 to produce a ciphertext block with the value of 1100.
10. And when we move on to the second block, the counter increments by one while the nonce and key remains the same. The output 1101 is then XOR with the second plaintext block 1100 to produce ciphertext block 2 0001.
11. After this, the ciphertext blocks are combined to generated the 8 bit ciphertext.

12. And now for the decryption of countermode
The process is similar to the encryption. We receive the ciphertext block and break it down to 16bytes block size. We will use the same key and nonce with the counter to generate the output. The ciphertext is then XOR with the output to produce the plaintext blocks which is combined to generate the original plaintext.

13. This example will be similar to the example for encryption. Here we have a simplified decryption example with 4 bit operation. We will be using the ciphertext block generated from the earlier encryption example.
14. Similarly we will use the same key and nonce with the counter to generate the output 0110 which will be XOR with the ciphertext block 1100 to get the plaintext value of 1010. And proceeding to the second ciphertext block, the counter is incremented and the process is repeated again to generate an output of 1100. The output blocks are then combined to generate the plaintext.
Рекомендации по теме
welcome to shbcf.ru