ECE 8473 - Assignment #7 - Due: 10 November 2022


Upload source files - individual files or archive (e.g. zip, tar) - to your osp/a7 upload area.

C programs must compile with no warnings or errors using: gcc -std=c11 -pedantic -Wall

Each source file must start with a comment containing your name and a description.


a7/p1.c - big integer using openssl library

Write a C program, similar to a6/p2.c, but using the openssl BIGNUM datatype and associated routines.

As in a6/p2.c, the main program will start by reading three lines of hex representing RSA modulus, prime1, and prime2 values. For each input use BN_hex2bn() to create a BIGNUM. Then use BN_add() and BN_mul() to create the sum and product, and use BN_print_fp() to print to stdout the primes, the sum of the primes, and the product of the primes. Use BN_cmp() to compare the modulus with the product of the primes and display an error message if they are not equal.

Test your program with input redirected from p1.in which contains five lines of hex data: the first three lines are identical to p1.out from assignment #6; the fourth line contains the privateExponent value, and the fifth line contains an encrypted value (c).

Extend your program to read the two extra lines from p1.in, and use BN_mod_exp() to decrypt and obtain the plaintext (m):

  m = cprivateExponent mod modulus
Display m in hex, it should be a recognizable word.
Notes

The input file p1.in is available here and also in the VECR a7/ directory.

Programs using the openssl library must be linked using: -lcrypt

If openssl/bn.h is not found, install the openssl development environment, e.g. in Ubuntu: sudo apt install libssl-dev

Example: p1.c, Makefile

openssl man pages:

summary - routines used in the assignment

BN_new - BN_new()

BN_CTX_new - BN_CTX_new()

BN_hex2bn - BN_hex2bn(), BN_print_fp()

BN_add - BN_add(), BN_mul(), BN_mod_exp()

BN_cmp - BN_cmp()