~aritra1911/openssl_madness

d82553e02b6c5e87301acc41e8bbe615a93d12e7 — Aritra Sarkar 2 years ago 48d61be
Add a bunch of CPP to get it compiling with OpenSSL 1.1.1

But not fully working yet
1 files changed, 42 insertions(+), 8 deletions(-)

M madness.c
M madness.c => madness.c +42 -8
@@ 151,14 151,27 @@ int main(int argc, char* argv[]) {
        }

        if (verbose) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
            printf("INFO : Key size = %i bits (%i bytes)\n",
                    /* `EVP_PKEY_get0_description()`
                     * was added in OpenSSL 3.0. */
                    EVP_PKEY_bits(public_key),
                    EVP_PKEY_size(public_key));
#else
            printf("INFO : %s\n"
                   "     : Key size = %i bits (%i bytes)\n",
                   EVP_PKEY_get0_description(public_key),
                   EVP_PKEY_get_bits(public_key),
                   EVP_PKEY_get_size(public_key));
                    EVP_PKEY_get0_description(public_key),
                    EVP_PKEY_get_bits(public_key),
                    EVP_PKEY_get_size(public_key));
#endif
        }

        if ( EVP_PKEY_get_id(public_key) != EVP_PKEY_RSA ) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
        if ( EVP_PKEY_id(public_key) != EVP_PKEY_RSA )
#else
        if ( EVP_PKEY_get_id(public_key) != EVP_PKEY_RSA )
#endif
        {
            fprintf(stderr, "Not a valid RSA public key!!!\n");
            fclose(fp);
            return EXIT_FAILURE;


@@ 178,14 191,27 @@ int main(int argc, char* argv[]) {
        }

        if (verbose) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
            printf("INFO : Key size = %i bits (%i bytes)\n",
                    /* `EVP_PKEY_get0_description()`
                     * was added in OpenSSL 3.0. */
                    EVP_PKEY_bits(private_key),
                    EVP_PKEY_size(private_key));
#else
            printf("INFO : %s\n"
                   "     : Key size = %i bits (%i bytes)\n",
                   EVP_PKEY_get0_description(private_key),
                   EVP_PKEY_get_bits(private_key),
                   EVP_PKEY_get_size(private_key));
                    EVP_PKEY_get0_description(private_key),
                    EVP_PKEY_get_bits(private_key),
                    EVP_PKEY_get_size(private_key));
#endif
        }

        if ( EVP_PKEY_get_id(private_key) != EVP_PKEY_RSA ) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
        if ( EVP_PKEY_id(private_key) != EVP_PKEY_RSA )
#else
        if ( EVP_PKEY_get_id(private_key) != EVP_PKEY_RSA )
#endif
        {
            fprintf(stderr, "Not a valid RSA private key!!!\n");
            fclose(fp);
            return EXIT_FAILURE;


@@ 237,7 263,11 @@ int main(int argc, char* argv[]) {
}

int rsa_encrypt(EVP_PKEY* public_key, FILE* infile, FILE* outfile, const int verbose) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
    int key_size = EVP_PKEY_size(public_key);
#else
    int key_size = EVP_PKEY_get_size(public_key);
#endif
    size_t flen, len;
    unsigned char *buf, *encbuf;
    EVP_PKEY_CTX* ctx;


@@ 317,7 347,11 @@ int rsa_encrypt(EVP_PKEY* public_key, FILE* infile, FILE* outfile, const int ver
}

int rsa_decrypt(EVP_PKEY* private_key, FILE* infile, FILE* outfile, const int verbose) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
    int key_size = EVP_PKEY_size(private_key);
#else
    int key_size = EVP_PKEY_get_size(private_key);
#endif
    size_t flen, len, declen;
    unsigned char *buf, *decbuf;
    EVP_PKEY_CTX* ctx;