Crypto Lab - Symmetric Key Ciphers: 3.1 Task 1: Encryption Using Different Ciphers and Modes
Crypto Lab - Symmetric Key Ciphers: 3.1 Task 1: Encryption Using Different Ciphers and Modes
Crypto Lab - Symmetric Key Ciphers: 3.1 Task 1: Encryption Using Different Ciphers and Modes
This document has been slightly modified by Mirela Damian, Villanova University. The original document
can be found at http://www.cis.syr.edu/˜wedu/seed/.
1 Overview
The learning objective of this lab is for students to get familiar with the concepts in the secret-key encryption.
After finishing the lab, students should be able to gain a first-hand experience on encryption algorithms,
encryption modes, paddings, and initial vector (IV). Moreover, students will be able to use tools and write
programs to encrypt/decrypt messages.
2 Lab Environment
Cryptography library OpenSSL. In this lab, we will use openssl commands and libraries. Make sure
you have openssl installed in your VM. It should be noted that if you want to use openssl libraries in
your programs, you also need to install libssl-dev, the development version of ssl, using the following
command:
Binary editor GHex. In this lab, we need to be able to view and modify files of binary format. Make sure
you have GHex installed in your VM. GHex is a hex editor for GNOME that allows the user to load data
from any file, view and edit it in either hex or ascii.
3 Lab Tasks
3.1 Task 1: Encryption using different ciphers and modes
In this task, we will play with various encryption algorithms and modes. You can use the following
openssl enc command to encrypt/decrypt a file. To see the manuals, you can type man openssl
and man enc.
Please replace the ciphertype with a specific cipher type, such as -aes-128-cbc, -aes-128-cfb,
-des-cbc, etc. In this task, you should try at least 3 different ciphers and three different modes. You can
SEED Labs 2
find the meaning of the command-line options and all the supported cipher types by typing "man enc".
We include some common options for the openssl enc command in the following:
1. Let us treat the encrypted picture as a picture, and use a picture viewing software to display it. How-
ever, the first 54 bytes of a .bmp file contain the header information about the picture. We have to
set these bytes correctly, so that the encrypted file can be treated as a legitimate .bmp file. We will
replace the header of the encrypted picture with that of the original picture. You can use the ghex
tool to directly modify binary files.
2. Display the encrypted picture using any picture viewing software. Can you derive any useful infor-
mation about the original picture from the encrypted picture? Please explain your observations.
3. Unfortunately, a single bit of the 30th byte in the encrypted file got corrupted. You can achieve this
corruption using ghex.
4. Decrypt the corrupted file (encrypted) using the correct key and IV.
Please answer the following questions: (1) How much information can you recover by decrypting the
corrupted file, if the encryption mode is ECB, CBC, CFB, or OFB, respectively? Please answer this question
before you conduct this task, and then find out whether your answer is correct or wrong after you finish this
task. (2) Explain why. (3) What are the implication of these differences?
1. The openssl manual (try man enc) says that openssl uses PKCS5 (Public Key Cryptography
Standard) for its padding. In this standard the value of each byte is the number of bytes that are added
– for example, if padding is required for 4 bytes, the hexadecimal padding string 04 04 04 04 is
used. If the input data is a multiple of the block size, then an extra block of bytes with the block size
value is added – for example, if the input data is 80 bytes and the block size is 16 bytes, an extra
padding block of 16 bytes, with each byte 10 in hexadecimal, is added.
Design an experiment to verify the padding scheme. In particular, use your experiment to figure out
the paddings in the AES encryption when the length of the plaintext is 20 bytes and 32 bytes.
2. Use ECB, CBC, CFB, and OFB modes to encrypt a file (you can pick any cipher). Report which
modes have paddings and which ones do not. For those that do not need paddings, explain why.
Note 1: If you choose to store the plaintex message in a file, and feed the file to your program, you need
to check whether the file length is 21. Some editors may add a special character to the end of the file. If that
happens, you can use the ghex tool to remove the special character.
Note 2: In this task, you are supposed to write your own program to invoke the crypto library. No credit
will be given if you simply use the openssl commands to do this task.
Note 3: To compile your code, you may need to include the header files in openssl, and link to
openssl libraries. To do that, you need to tell your compiler where those files are. In your Makefile,
you may want to specify the following:
SEED Labs 4
IDIR=/usr/include/
LDIR=/usr/lib/x86_64-linux-gnu
all:
gcc -I$(IDIR) -L$(LDIR) -o file file.c -lcrypto -ldl
4 Submission
You need to submit a detailed lab report to describe what you have done and what you have observed; you
also need to provide explanation to the observations that are interesting or surprising. In your report, you
need to answer all the questions listed in this lab.