Error: "Invalid use of incomplete type" RSA {aka struct rsa_st} in OpenSSL 1.1.0

I have old code that was written to reference the old version of openssl. Part of this code loads the key from the PEM file and tries to figure out if this key is a private or public key using the following code:

if( (prv->p==0 || prv->q==0) ) {
    // This is not a private key!
    throw error("No private key for decryption");
}

With the latest version of openssl, this (justifiably) does not compile:

crypto.cpp: In functionkey* decrypt_header(file_t, RSA*)’:
crypto.cpp:158:13: error: invalid use of incomplete typeRSA {aka struct rsa_st}’
     if( (prv->p==0 || prv->q==0) ) {
             ^~

I understand that direct access to private members of the structure has been replaced by a function, but I find it difficult to determine which function is.

+4
source share
2 answers
crypto.cpp:158:13: error: invalid use of incomplete type ‘RSA {aka struct rsa_st}’
     if( (prv->p==0 || prv->q==0) ) {
             ^~

, OpenSSL 1.1.0 . . getter setter.

RSA_get0_factors. get0 , . BN_free .

void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);

OpenSSL, , RSA_get0_factors OpenSSL 1.1.0 . , - . . OPENSSL_VERSION_NUMBER .

#include <openssl/opensslv.h>

#if OPENSSL_VERSION_NUMBER < 0x10100000L

    /* OpenSSL 1.0.2 and below (old code) */

#else

    /* OpenSSL 1.1.0 and above (new code) */

#endif
+6
#if OPENSSL_VERSION_NUMBER < 0x10100005L
static void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d, const BIGNUM **p, const BIGNUM **q)
{
    if(n != NULL)
        *n = r->n;

    if(e != NULL)
        *e = r->e;

    if(d != NULL)
        *d = r->d;

    if(p != NULL)
        *p = r->p;

    if(q != NULL)
        *q = r->q;
}
#endif

const BIGNUM *bn_p;
const BIGNUM *bn_q;

RSA_get0_key(key, NULL, NULL, NULL, &bn_p, &bn_q);
/*   if( (prv->p==0 || prv->q==0) ) { */
if( (prv_p==0 || prv_q==0) ) {
0

Source: https://habr.com/ru/post/1660507/


All Articles