我有旧的代码,用于链接旧版本的openssl.此代码的一部分从PEM文件加载密钥,并尝试通过使用以下代码来了解此密钥是私钥还是公钥:
if( (prv->p==0 || prv->q==0) ) {
// This is not a private key!
throw error("No private key for decryption");
}
Run Code Online (Sandbox Code Playgroud)
使用最新版本的openssl,这(有理由)不编译:
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) ) {
^~
Run Code Online (Sandbox Code Playgroud)
我理解直接访问struct的私有成员被替换为一个函数,但我很难搞清楚哪个函数是什么.
crypto.cpp:158:13: error: invalid use of incomplete type ‘RSA {aka struct rsa_st}’
if( (prv->p==0 || prv->q==0) ) {
^~
Run Code Online (Sandbox Code Playgroud)
如您所知,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);
Run Code Online (Sandbox Code Playgroud)
如果代码支持多个版本的OpenSSL,那么您将需要一个防护,因为RSA_get0_factors它适用于OpenSSL 1.1.0及更高版本.也许类似以下内容.另见OPENSSL_VERSION_NUMBERman 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
Run Code Online (Sandbox Code Playgroud)
1.1.1之后OpenSSL支持像这样返回每个参数的getter。
const BIGNUM *RSA_get0_n(const RSA *d);
const BIGNUM *RSA_get0_e(const RSA *d);
const BIGNUM *RSA_get0_d(const RSA *d);
const BIGNUM *RSA_get0_p(const RSA *d);
const BIGNUM *RSA_get0_q(const RSA *d);
const BIGNUM *RSA_get0_dmp1(const RSA *r);
const BIGNUM *RSA_get0_dmq1(const RSA *r);
const BIGNUM *RSA_get0_iqmp(const RSA *r);
Run Code Online (Sandbox Code Playgroud)
因此,如果您不需要考虑低于 1.1.1 的 OpenSSL 版本,这些代码将成为简单的代码。其他结构也支持这种吸气剂。您可以找到有关此功能的更多信息。https://www.openssl.org/docs/man1.1.1/man3/
| 归档时间: |
|
| 查看次数: |
6673 次 |
| 最近记录: |