From a82d7c30cffe935bdd4caf109d12786b23465213 Mon Sep 17 00:00:00 2001 From: Aritra Sarkar Date: Sat, 19 Jun 2021 00:36:45 +0530 Subject: [PATCH] Replace RSA specific structures with EVP_PKEY --- madness.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/madness.c b/madness.c index 58d4595..ca49455 100644 --- a/madness.c +++ b/madness.c @@ -4,11 +4,12 @@ #include #include #include +#include #include #include -int rsa_encrypt(RSA*, FILE*, FILE*, const int); -int rsa_decrypt(RSA*, FILE*, FILE*, const int); +int rsa_encrypt(EVP_PKEY*, FILE*, FILE*, const int); +int rsa_decrypt(EVP_PKEY*, FILE*, FILE*, const int); void print_usage(const char*); void print_usage(const char* bin) { @@ -35,7 +36,7 @@ void print_usage(const char* bin) { } int main(int argc, char* argv[]) { - RSA *private_key = NULL, *public_key = NULL; + EVP_PKEY *private_key = NULL, *public_key = NULL; FILE *fp, *fpin, *fpout; char *input_filename = NULL, *key_filename = NULL, *output_filename = NULL; int decrypt = -1, verbose = 0; @@ -136,7 +137,7 @@ int main(int argc, char* argv[]) { // Fetch key from PEM formattted key in key file if (!decrypt) { - if (!PEM_read_RSA_PUBKEY(fp, &public_key, NULL, NULL)) { + if (!PEM_read_PUBKEY(fp, &public_key, NULL, NULL)) { fprintf(stderr, "Not a valid public key!!!\n"); putchar('\n'); print_usage(argv[0]); @@ -144,10 +145,10 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } - if (verbose) printf("RSA %d\n", RSA_bits(public_key)); + if (verbose) printf("RSA %d\n", EVP_PKEY_get_bits(public_key)); } else { - if (!PEM_read_RSAPrivateKey(fp, &private_key, NULL, NULL)) { + if (!PEM_read_PrivateKey(fp, &private_key, NULL, NULL)) { fprintf(stderr, "Not a valid private key!!!\n"); putchar('\n'); print_usage(argv[0]); @@ -155,7 +156,7 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } - if (verbose) printf("RSA %d\n", RSA_bits(private_key)); + if (verbose) printf("RSA %d\n", EVP_PKEY_get_bits(private_key)); } fclose(fp); // Close key file @@ -202,8 +203,8 @@ int main(int argc, char* argv[]) { return (ret_status == -1) ? EXIT_FAILURE : EXIT_SUCCESS; } -int rsa_encrypt(RSA* public_key, FILE* infile, FILE* outfile, const int verbose) { - int len, key_size = RSA_size(public_key); +int rsa_encrypt(EVP_PKEY* public_key, FILE* infile, FILE* outfile, const int verbose) { + int len, key_size = EVP_PKEY_get_size(public_key); char *buf, *encbuf; size_t flen; @@ -244,8 +245,8 @@ int rsa_encrypt(RSA* public_key, FILE* infile, FILE* outfile, const int verbose) return 0; } -int rsa_decrypt(RSA* private_key, FILE* infile, FILE* outfile, const int verbose) { - int len, key_size = RSA_size(private_key); +int rsa_decrypt(EVP_PKEY* private_key, FILE* infile, FILE* outfile, const int verbose) { + int len, key_size = EVP_PKEY_get_size(private_key); char *buf, *decbuf; size_t flen; -- 2.45.2