错误:“无效使用不完整类型'RSA {aka struct rsa_st}"在OpenSSL 1.1.0中 [英] Error: "invalid use of incomplete type ‘RSA {aka struct rsa_st}" in OpenSSL 1.1.0

查看:1533
本文介绍了错误:“无效使用不完整类型'RSA {aka struct rsa_st}"在OpenSSL 1.1.0中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些旧代码被编写来链接到旧版本的openssl.此代码的一部分从PEM文件中加载密钥,并尝试使用以下代码来了解此密钥是私钥还是公钥:

I have old code that was written to link against an old version of openssl. Part of this code loads a key from a PEM file, and tries to understand whether this key is a private or public key, by using the following code:

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

使用最新版本的openssl,该文件(合理地)不会编译:

With the latest version of openssl, this (justifiably) doesn't compile:

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

我知道直接访问该结构的私有成员已替换为一个函数,但是我很难确定是哪个函数.

I understand that direct access to the struct's private members was replaced with a function, but I am having a hard time figuring out which function that is.

推荐答案

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函数.

As you are aware, OpenSSL 1.1.0 changed the visibility of a lot of struct members. You can no longer access the members directly. Instead, you have to use getter and setter functions.

尝试 RSA_get0_factors . get0表示引用计数 递增. BN_free.

Try RSA_get0_factors. The get0 means the reference counts are not incremented. Do not BN_free them.

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


如果代码支持多个版本的OpenSSL,则您将需要保护,因为RSA_get0_factors用于OpenSSL 1.1.0及更高版本.也许像下面这样.另请参见 OPENSSL_VERSION_NUMBER手册页.


If the code supports multiple versions of OpenSSL, then you will need a guard because RSA_get0_factors is for OpenSSL 1.1.0 and above. Maybe something like the following. Also see OPENSSL_VERSION_NUMBER man page.

#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

这篇关于错误:“无效使用不完整类型'RSA {aka struct rsa_st}"在OpenSSL 1.1.0中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆