Computer Networks 159.334 Assignment 3 due 4/Nov/2016
Cryptography: the RSA algorithm with Cipher Block Chaining
Introduction
In this assignment your task is to implement a hybrid algorithm called RSA with Cipher Block Chaining in a client/server application using TCP sockets. In the TCP client/server example, as you might remember, a client types a message, and then sends it to a server. In turn, the server echoes back the message. In this assignment, you have to modify the client so that it encrypts all communications sent to the server. In addition, you will also have to modify the server, so that it decrypts the encrypted message locally.
The first time a connection is established, the server will have to inform the client about its public key for the current session. In turn, the client informs the server of the random number (nonce) that will be used for the initial encryption and decryption operations. Successive messages coming from the client will then be encrypted accordingly, and the server will echo back to the client the decrypted messages.
In subsequent sessions (after the client disconnects and connects again), the keys should not be the same (see notes 2).
The client/server should be able to generate the following form of reporting on screen, as seen in the example below:
– The client types:
hello
– The server prints locally:
The received encrypted message was: 10898 15630 8308 321 13772 22674 22040
After decryption, the message found is: hello
Implementation details
There are many details in the implementation of a real RSA with Cipher Block Chaining that might have to be left out in order to keep it under the scope of an assignment. You have to ask the following questions regarding some decisions about the implementation:
a) What are the sizes of the keys? (aim for a big number(in the thousands) for the variable n in RSA)
b) Should the encryption be done character by character, or by block of characters?
c) Should padding be used?
d) Do you need an arbitrary precision library, or the keys are small enough to use a simple exponential code?
e) How are the keys sent to the client (your protocol design should specify: format, message order, etc).
The answers to these questions will establish how your own “encryption protocol” works.
Follow the following instructions:
1) The details of the core algorithm that should be implemented can be found in “Lecture-14- Network Security_Implementing RSA_CBC_2016.pptx” You are allowed to use relatively small prime number pairs, but do not use pairs that will make the same keys for encryption and decryption.
2) The keys should be different for subsequent connections. You can use a limited set of keys defined statically, or compute a new key when the client asks for the establishment of the connection. In this case, the server has to run the Extended Euclidean Algorithm, or try to find e and d by brute force.
3) Use the given start-up codes: Simple TCP Server.cpp and Simple TCP Client.cpp, found in our 159334 Stream website. Modify these source codes for your implementation of the encryption protocol.
Testing the assignment:
For quickly testing the assignment, use the batch file, run.bat provided.
The assignment is going to be marked based on functionality and design. The marks are distributed as follows:
– 1 mark: for the successful sending of the RSA public key to the server.
– 2 marks: for protocol implementations that use different keys for every session (cycle through the list of keys available, every time a new user connects).
– 2 marks: for correctly sending the encrypted random number (encrypted(nonce)) to the server. That also includes the server decrypting and extracting the nonce correctly.
– 3 marks: minimum implementation, able to send a set of alphanumeric characters (letters of the alphabet, both in lower-case and upper-case, digits 0-9, space and punctuation marks). For that to work, you need to make sure that the selected keys and nonce will not have any problem representing all of the aforementioned characters.
– 5 marks: for the correct implementation of RSA with Cipher Block Chaining: encryption/decryption results are always correct for any of the keys used.
– 2 marks: Documentation (MS Word). Write a pseudocode of your system (i.e. specify the message format, encoding, decoding scheme, how keys are sent, generation of keys, etc.). Provide a snapshot of one complete client/server interaction. For testing, use the message “the quick brown fox jumps over the lazy dog.” Also, indicate if you have implemented the Extended Euclidean Algorithm, to get some bonus marks.
*2 Bonus marks will be given to those who can implement correctly the Extended Euclidean Algorithm (make a note in your assignment submission if you did this). Include a simple test function that shows that your implementation is correct.
Notes:
1 – Submit your files electronically via Stream, in zip format. Submit everything, including the folders and the batch file.
2 – This assignment is worth 15 marks (+ bonus, if your submission qualifies).
3 – Marks will be subtracted for obvious copying and/or for delays without justification.