CS333 Exercise02

pdf

School

University of Oregon *

*We aren’t endorsed by this school

Course

333

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

5

Uploaded by PrivatePowerYak34

Report
Ethan Reinhart 02/02/2024 CS333 Lab on Symmetric Key Cipher The purpose of this lab was to enhance understanding of the AES-RSA Hybrid Encryption Scheme. This scheme utilizes the strengths of both types, the speed of AES and the security of RSA. This allows for fast and secure encryption. This works by using AES to encrypt the original message with a randomly generated key. This key is then encrypted using the public RSA key. Both cipher texts are sent to the receiver. The receiver can first decrypt the second cipher text with their private key and then decrypt the first cipher text to get the message with the decrypted AES key. For the purpose of this lab, the “sender” and the “receiver” will be two different folders, but in real life, they would be distinct individuals. Additionally, it is required that OpenSSL is already installed and working. If this is not the case for your machine, please return to the previous lab. Folder Creation: Let us first navigate to our home directory in terminal or whatever directory is desired to run this lab. To create the two folders, type: mkdir Receiver, mkdir Sender This creates two folders, one title “Receiver” and the other title “Sender” in the directory you are currently in. We would like to first be in the “Sender” folder to create our file so run the following command: cd Sender File Creation: As a preface, my program was run on a Mac, meaning all parts of this project are intended to run on Mac, if the reader decides to follow along. The first part of this assignment requires the generation of a large text file to encrypt. The content of this file is irrelevant as the purpose of this project is solely to measure runtime variancies. The files is of the following sizes: 500MB. This file can be generated with the following command line input: mkfile -n 500m big.pdf This command will generate a file with random characters of size 500MB. We would next like to enter the “Receiver” folder. Run the following command: cd ../Receiver RSA Key Generation: This lab necessitates the creation of three distinct RSA keys of different sizes: 1024 bits, 2048 bits, and 4096 bits. These RSA keys are used to encrypt the generated AES key used to encrypt the message. The private key can be created by running the following command:
Ethan Reinhart 02/02/2024 CS333 openssl genrsa -out privateKey.pem {key_size} The key_size parameter should be filled in with 1024, 2048, or 4096. I used 1024 for the first iteration to keep track of all AES–key runtimes using a 1024-bit RSA key size. This key will then be used for three sequential AES Encryption Schemes with different AES-key sizes. Next, it is helpful to view the key to ensure it was created properly. Run the following command to do such: openssl rsa -in privateKey.pem -text The public key can be created from the private key with the following command: openssl rsa -in privateKey.pem -pubout -out publicKey.pem The public key should then be sent to the “Sender” folder as well as this would be public information. This can be done with the following command: cp publicKey.pem ../Sender AES Key Generation: We should first move to the “Sender” folder. This can be done with the following command: cd ../Sender The AES key can be generated with the following command: openssl enc -nosalt -aes-{size}-cbc -k secret -P > key.dat This generates the AES key with the specified size. This size must either be 128, 192, or 256 bits. You should alternate between the three, using one each for each RSA key generated. I elected to go in sequential order. Encryption: We should now run encryption. The first set of encryption will be AES. This can be completed by running the following command: time openssl enc -aes-{size}-cbc -in big.pdf -out big.pdf.enc -pass file:key.dat This commands parameter size should be identical to the AES key size used in the last command. This will run the command and print the time taken to standard output. Next is the step of RSA Encryption. This can be done with the following command: time openssl rsautl -encrypt -inkey publicKey.pem -pubin -in key.dat -out key.dat.enc This will encrypt the generated AES key. We shall then copy the file big.pdf.enc and key.data.enc, which are our ciphertexts. Again, this will print the time taken to decrypt. This can be done by executing the following command: cp big.pdf.enc ../Receiver/big.pdf.enc; cp key.dat.enc ../Receiver/key.dat.enc We should the change our directory to the “Receiver” directory by running the following command: cd ../Receiver Decryption:
Ethan Reinhart 02/02/2024 CS333 We should now decrypt the provided cipher text. We are now in the receiver folder and can decrypt the encrypted messages using our private key. The first step is to decrypt the encrypted AES key with our previously generated private key, using RSA decryption. This can be done with the following command: openssl rsautl -decrypt -inkey privateKey.pem -in key.dat.enc -out key.dat This will decrypt the key and store the output in the file key.dat. We can then decrypt the message using AES decryption with the following command: openssl enc -d -aes-{key}-cbc -in big.pdf.enc -out big-dec.pdf -pass file:key.dat This will decrypt the message and store it in the file big-dec.pdf. The key parameter should be the same AES key size used throughout this entire process. We should now ensure the correctness of our decryption. We can do such with the following command: diff big-dec.pdf ../Sender/big.pdf If the commands run with no printed output, this means our files are the same. Repeating the process: If not all AES key sizes have been tested for a specific RSA key size, return to the AES Key Generation header and continue from there. If all AES key sizes have been tried, return to the RSA Key Generation and continue with the next RSA key size. Once all AES key sizes have been attempted, you have successfully tried all combinations! Results: The runtimes of the commands were measured as specified above and the results are given below.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Ethan Reinhart 02/02/2024 CS333 Originally, I was surprised by the significant difference between RSA and AES encryption runtime. AES should be significantly quicker at encrypting data as it doesn’t requisite large modulus multiplication. I looked back over the structure of Hybrid Encryption and then realized the RSA Encryption/Decryption was only encrypting/decrypting the small session key generated be AES encryption. This made sense to me why RSA was so much quicker here as AES needed to encrypt 500MB of data. I was also surprised by the nonlinear trend from smaller key size runtimes to larger. I anticipated that smaller key sizes would lead to lower runtimes than larger key sizes would. This would be because encryption would be quicker and RSA would require less time to encrypt the smaller session key. Graph results are displayed below to illustrate this. As you can see, the runtimes did not follow their anticipated trajectories. I think there is a variety of reasons for this. I think one potential reason is variance of CPU allotment per process. Some processes may have received more CPU time as there were some background applications open. I was also unsure that this was working properly so after every encryption/decryption, I would ascertain the decrypted and the original file were the same. Below is the complete list of commands used:
Ethan Reinhart 02/02/2024 CS333 Conclusion: In conclusion, I would argue that this algorithm is better than either of the two individually. I think that it is very beneficial that the RSA encryption is responsible for encrypting the key for the first encryption. This allows computational security and a computationally infeasible algorithm to break. This assignment gave me a much better understanding of how to the Hybrid Encryption/Decryption Scheme works in practice. I additionally feel much more confident in the use of OpenSSL. I feel certain that I could now use this in practice to encrypt/decrypt real information.