The implementation of RSA algorithm was divided into the following parts:
- Key generation
- Encryption
- Decryption
Parameter | Value |
---|---|
Plaintext block size | 8 bits |
Key length (size of n) | 16 bits |
Ciphertext block size | 16 bits |
The implementation has the following programs:
- rsa_key_gen - Generates the values of the public-private key components i.e. the values of e, d and n.
- rsa_enc - Encrypts the given plaintext message using the values of e and n provided in the command line.
- rsa_dec - Decrypts the given ciphertext message using the values of d and n provided in the command line.
The following programs are implemented:
- The rsa_key_gen.h and rsa_key_gen.c files provides the functions for generating the keys.
- The algorithm is as follows:
- Generates two random 8 bit prime numbers whose product is greater than 256. Say p and q.
- Finds the value of n using p and q i.e. n = p x q.
- Finds the value of totient(n) = totient(p x q) = (p - 1) x (q - 1).
- Finds a random integer e, such that 1 < e < totient(n) and e and totient(n) are coprime.
- Finds a integer d, such that d is multiplicative inverse of e under modulo totient(n), using the extended euclidean algorithm.
- The rsa_key_gen_drv.c is a driver program to use the above discussed function and print the values on the standard output for further use.
- The rsa_enc_dec.h and rsa_enc_dec.c files provide the functions to encrypt and decrypt entire blocks of messages to their corresponding counterparts.
- The encryption function takes in an array of 8 bit blocks and encrypts them to an array of 16 bit blocks. Similarly the decryption function takes in an array of 16 bits blocks and decrypts them to an array of 8 bit plaintext blocks respectively.
- For encryption-decryption the modular exponentiation function has been implemented for efficient calculation.
- The files rsa_enc_drv.c and rsa_dec_drv.c are the driver programs for allowing the user to use the above implemented functions.
The file provides the various data types used throughout the implementation.
- First the users (end-points) have to create their own pair of public and private key components. For this they must run the key generation program.
-
Then the sender will use the public components to encrypt the message and then send the ciphertext to the end user.
-
The receiver will now use the private components of the key to decrypt the message in order to get the plaintext.
-
To show the correctness of the encryption and decryption algorithms, we can pipe the output of the encryption program to the decryption program and check if the decrypted plaintext is same as the entered plaintext, if yes then the program is correct.