Professional Documents
Culture Documents
Week 3 Lab Sheet
Week 3 Lab Sheet
Form groups of 2 and attempt the exercises. The exercises are not designed to be completed in tutorial
sessions but rather to give you some tasks and a starting point to continue and complete on your own. No
solutions will be released for these exercises.
Lab Exercises
1. Use man utility for genrsa, rsa, and rsautl to learn about the command line options of openssl
utility for generating RSA keys. Then:
(a) Generate a key pair of size 2048 bits (genrsa generates the private key which contains the
public exponent, you can use the rsa utility to get the public key out).
(b) Create a text file and encrypt the file and then decrypt it.
(c) Sign the file and then verify it. Which mode of RSA is used? with or without message recovery?.
Note: You can use bless hex editor or vim -b to modify the binary files.
2. Use man dgst to learn about hash functions detached signatures (e.g. RSA without message
recovery).
3. Use man utility for dsaparam, dsa, and pkeyutl to learn about the command line options of openssl
utility for generating DSA keys and signing and verification operations. The pkeyutl is used for all
public key method supported by openssl (RSA, DSA, and EC). Then:
4. Use man utility for ecparam, ec, and pkeyutl to learn about the command line options of openssl
utility for generating EC keys and sign and verify operations.
5. We are going to use Gnu Multi-precision library for this exercise. The gmpy2 is a wrapper python
library for C version of gmp. As in RSA and DH algorithms we only work with integers then only
multi-precision integers are needed. You can find a list of available methods and brief description at
https://gmpy2.readthedocs.io/en/latest/mpz.html. Write python code to:
1
FIT5037 Asymmetric Key Encryption Week 3 Lab Sheet
def rand_n ( n ) :
’’’ return a n - bit random integer ’’’
def rsa_keygen ( N ) :
’’’ To generate RSA key pair ’’’
pass
def main () :
status , n , e , d = rsa_keygen (2048)
if __name__ == ’ __main__ ’:
main ()
Notes:
• The status variable stores the returned Success (True) or Failure (False) status of the key
generation.
• In practice it is not recommended to use your own implementation of security primitives but in
this exercise we are interested in understanding of the primitives.
• We need the following functions from library:
next_prime()
gcd()
invert()
powmod()
6. Test the following scenario using python (and gmpy2 library) to see if it is possible: Your tutor is
sending a report about your engagement in tutorial to the lecturer and you are keen to know what
2
FIT5037 Asymmetric Key Encryption Week 3 Lab Sheet
the report says about you. You manage to intercept the communication between your tutor and
lecturer however the communication is encrypted using RSA (public key of lecturer) c = me mod n.
You think you can recover the message by performing a chosen ciphertext attack (or more accurately
an adaptive ciphertext attack). You choose a random number r and multiply re mod n to ciphertext:
t = re · c mod n and send this to the lecturer. You ask the lecturer to sign t as a test vector to verify
that you have the correct public key. The lecturer sends you back td mod n. Can you recover the
report?
Note: Generate a key pair and play all three roles yourself.