Lab 2b-RSA Public-Key Encryption and Signature Lab
Lab 2b-RSA Public-Key Encryption and Signature Lab
Table of Contents
Overview................................................................................................................ 2
Task 1: A Complete Example of BIGNUM............................................................................2
Task 2: Deriving the Private Key...........................................................................................3
Task 3: Encrypting a Message...............................................................................................5
Task 4: Decrypting a Message..............................................................................................6
Task 5: Signing a Message.....................................................................................................6
Task 6: Verifying a Signature..................................................................................8
Task 7: Manually Verifying an X.509 Certificate...............................................................9
Submission .............................................................................................................................10
1
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
Overview
Lab Tasks
Task 1: A Complete Example of BIGNUM
The program below shows a complete example of BIGNUM. This program uses three
BIGNUM variables, a, b, and n; and then compute a ∗ b and (a b mod n).
2
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
Commands
Execute the following command to compile the above program
$gcc -o task1 task1.c -lcrypto
$./task1
Give your observation with screen shot along with full plaintext.
3
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
Commands:
$gcc -o task2 task2_derivepk.c -lcrypto
$./task2
4
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
Commands
$gcc -o task3 task3.c -lcrypto
$./task3
5
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
The objective of this task is to decrypt a given ciphertext. given are the hexadecimal values of n, e, d
from the above task
Commands
$gcc -o task4 task4.c -lcrypto
$./task4
Give your observation with screen shot.
6
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
step2: Execute the following program to generate signature of the given message. Using the
signing algorithm M^d mod n
Commands:
$gcc -o task5 task5.c -lcrypto
$./task5
7
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
Commands
$gcc -o task6 task6.c -lcrypto
$./task6
$python -c ‘print(“//output of task6”.decode(“hex”))’
The objective of this task is to verify the signature of a public key certificate from a server
and show that the signature matches.
To verify that a certificate was signed by a specific certificate authority we need the
following details
1. public key of the certificate authority (issuer).
2. signature and algorithm used to generate signature from the server’s certificate.
8
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
Copy server certificate to c0.pem file and root certificate of the issuer to c1.pem
Give your observation with screen shot.
Step 2: Extract the public key (e, n) from the issuer’s certificate. Openssl provides commands
to extract certain attributes from the x509 certificates. We can extract the value of n using -
modulus. There is no specific command to extract e, but we can print out all the fields and
can easily find the value of e.
Commands
For modulus (n):
$ openssl x509 -in c1.pem -noout -modulus
Print out all the fields, find the exponent (e):
$ openssl x509 -in c1.pem -text -noout |grep "Exponent"
Give your observation with screen shot.
Step 3: Extract the signature from the server’s certificate. There is no specific
opensslcommand to extract the signature field. However, we can print out all the fields and
then copy and paste the signature block into a file (note: if the signature algorithm used in
the certificate is not based on RSA, you can find another certificate).
Commands
$openssl x509 -in c0.pem -text -noout
//extract only the signature part and paste it in signature file
$ cat signature | tr -d ’[:space:]:’
Commands:
$ openssl asn1parse -i -in c0.pem -strparse 4 -out c0_body.bin -noout
$ sha256sum c0_body.bin
9
PES University Department of CSE
CS 314: Applied Cryptography
Lab 2: Secret Key Encryption Lab
step 5: Verify the signature. Now we have all the information, including the CA’s public key,
the CA’s signature, and the body of the server’s certificate. We can run our own program to
verify whether the signature is valid or not. Openssl does provide a command to verify the
certificate for us, but students are required to use their own programs to do so, otherwise,
they get zero credit for this task.
You need to submit a detailed lab report to describe what you have done and what you have
observed, including screenshots and code snippets. You also need to provide explanation to the
observations that are interesting or surprising. You are encouraged to pursue further investigation,
beyond what is required by the lab description. Please submit in word or PDF format only.
10
PES University Department of CSE