#include "../lib/lib.h" #include "../lib/lib2.h" #include "../lib/lib3.h" #include "../lib/lib4.h" #include "../lib/lib5.h" int main() { int i; struct rsa_key_bignum private[3]; struct rsa_key_bignum public[3]; BIGNUM *res = BN_new(); BIGNUM *encrypted[3]; BIGNUM *decrypted = BN_new(); BIGNUM *ab[3]; BIGNUM *nb[3]; BIGNUM *solution_no_mod = BN_new(); out = BIO_new(BIO_s_file()); BIO_set_fp(out, stdout, BIO_NOCLOSE); ctx = BN_CTX_new(); printf("encrypt the following message with three different keys:\n"); unsigned char *mess = "All you need is love! Love is all you need"; printf("%s\n", mess); for(i=0;i<2;i++) { rsa_generate_key_bignum(&public[i], &private[i]); do { rsa_generate_key_bignum(&public[i+1], &private[i+1]); } while (!BN_cmp(private[i].exponent, private[i+1].exponent)); } printf("private keys:\n"); for(i=0;i<3;i++) { BN_print(out, private[i].exponent); printf("\n"); } BIGNUM *message = BN_bin2bn(mess, strlen(mess), NULL); printf("message as BN:\n"); BN_print(out, message); printf("\nencrypted rsa messages:\n"); for(i=0;i<3;i++) { encrypted[i] = BN_new(); if(!rsa_encrypt_bignum(message, encrypted[i], &public[i])) die("could not rsa encrypt message"); BN_print(out, encrypted[i]); printf("\n"); } for(i=0;i<3;i++) { ab[i] = BN_new(); nb[i] = BN_new(); BN_copy(ab[i], encrypted[i]); BN_copy(nb[i], public[i].modulo); } BIGNUM *n_3 = BN_new(); BN_set_word(n_3, 3); rsa_broadcast_cube(res, ab, nb); printf("\nrsa broadcast cube is\n"); BN_print(out, res); printf("\noriginal message is:\n"); BN_print(out, message); unsigned char *__dec = malloc(1000); BN_bn2bin(res, __dec); printf("\ndecrypted text with rsa broadcast attack: %s\n", __dec); }