将OpenSSL 1.0.2迁移到1.1.1时出错
我正在迁移代码以与OpenSSL 1.0.2和OpenSSL 1.1.1兼容,具体取决于编译代码的系统,但我收到以下错误:将OpenSSL 1.0.2迁移到1.1.1时出错,openssl,cryptocurrency,Openssl,Cryptocurrency,我正在迁移代码以与OpenSSL 1.0.2和OpenSSL 1.1.1兼容,具体取决于编译代码的系统,但我收到以下错误: src\key.cpp: In member function 'bool CKey::Sign(uint256, std::vector<unsigned char>&)': src\key.cpp:325:22: error: invalid use of incomplete type 'ECDSA_SIG {aka struct ECDSA_SI
src\key.cpp: In member function 'bool CKey::Sign(uint256, std::vector<unsigned char>&)': src\key.cpp:325:22: error: invalid use of incomplete type 'ECDSA_SIG {aka struct ECDSA_SIG_st}'
if (BN_is_odd(sig->s)) {
^ In file included from ..\deps_x64\openssl-1.1.1g\include/openssl/ecdsa.h:10:0,
from src\key.cpp:8: ..\deps_x64\openssl-1.1.1g\include/openssl/ec.h:1125:16: error: forward declaration of 'ECDSA_SIG {aka struct ECDSA_SIG_st}' typedef struct ECDSA_SIG_st ECDSA_SIG;
^ src\key.cpp:328:47: error: cannot convert 'CBigNum*' to 'BIGNUM* {aka bignum_st*}' for argument '2' to 'int EC_GROUP_get_order(const EC_GROUP*, BIGNUM*, BN_CTX*)'
EC_GROUP_get_order(group, &order, NULL);
^ src\key.cpp:329:19: error: invalid use of incomplete type 'ECDSA_SIG {aka struct ECDSA_SIG_st}'
BN_sub(sig->s, &order, sig->s);
^ In file included from ..\deps_x64\openssl-1.1.1g\include/openssl/ecdsa.h:10:0,
from src\key.cpp:8: ..\deps_x64\openssl-1.1.1g\include/openssl/ec.h:1125:16: error: forward declaration of 'ECDSA_SIG {aka struct ECDSA_SIG_st}' typedef struct ECDSA_SIG_st ECDSA_SIG;
^ src\key.cpp:329:35: error: invalid use of incomplete type 'ECDSA_SIG {aka struct ECDSA_SIG_st}'
BN_sub(sig->s, &order, sig->s);
^ In file included from ..\deps_x64\openssl-1.1.1g\include/openssl/ecdsa.h:10:0,
from src\key.cpp:8: ..\deps_x64\openssl-1.1.1g\include/openssl/ec.h:1125:16: error: forward declaration of 'ECDSA_SIG {aka struct ECDSA_SIG_st}' typedef struct ECDSA_SIG_st ECDSA_SIG;
^ Makefile.Release:47538: recipe for target 'build/key.o' failed mingw32-make: *** [build/key.o] Error 1 mingw32-make: *** Waiting for unfinished jobs....
src\key.cpp:In成员函数'bool CKey::Sign(uint256,std::vector&'):src\key.cpp:325:22:错误:无效使用不完整类型'ECDSA_SIG{aka struct ECDSA_SIG_st}
如果(BN_为奇数(sig->s)){
^在..\deps_x64\openssl-1.1.1g\include/openssl/ecdsa.h:10:0中包含的文件中,
来自src\key.cpp:8:…\deps_x64\openssl-1.1.1g\include/openssl/ec.h:1125:16:错误:前向声明“ECDSA_SIG{aka struct ECDSA_SIG st}”typedef struct ECDSA_st ECDSA_SIG;
^src\key.cpp:328:47:错误:无法将参数“2”的“CBigNum*”转换为“BIGNUM*{aka BIGNUM\u st*}”,以获得“int-EC\u-GROUP\u-get\u-order(const-EC\u-GROUP*,BIGNUM*,BN\u-CTX*)”
EC_GROUP_get_order(组和订单,空);
^src\key.cpp:329:19:错误:不完整类型“ECDSA_SIG{aka struct ECDSA_SIG_st}的使用无效
BN_sub(sig->s,&order,sig->s);
^在..\deps_x64\openssl-1.1.1g\include/openssl/ecdsa.h:10:0中包含的文件中,
来自src\key.cpp:8:…\deps_x64\openssl-1.1.1g\include/openssl/ec.h:1125:16:错误:前向声明“ECDSA_SIG{aka struct ECDSA_SIG st}”typedef struct ECDSA_st ECDSA_SIG;
^src\key.cpp:329:35:错误:不完整类型“ECDSA_SIG{aka struct ECDSA_SIG_st}的使用无效
BN_sub(sig->s,&order,sig->s);
^在..\deps_x64\openssl-1.1.1g\include/openssl/ecdsa.h:10:0中包含的文件中,
来自src\key.cpp:8:…\deps_x64\openssl-1.1.1g\include/openssl/ec.h:1125:16:错误:前向声明“ECDSA_SIG{aka struct ECDSA_SIG st}”typedef struct ECDSA_st ECDSA_SIG;
^Makefile.Release:47538:目标'build/key.o'的配方失败mingw32 make:**[build/key.o]错误1 mingw32 make:**正在等待未完成的作业。。。。
错误代码为:
bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
{
vchSig.clear();
ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey);
if (sig==NULL)
return false;
// Force even S value in order to prevent signature modification issues.
if (BN_is_odd(sig->s)) {
const EC_GROUP *group = EC_KEY_get0_group(pkey);
CBigNum order;
EC_GROUP_get_order(group, &order, NULL);
BN_sub(sig->s, &order, sig->s);
}
unsigned int nSize = ECDSA_size(pkey);
vchSig.resize(nSize); // Make sure it is big enough
unsigned char *pos = &vchSig[0];
nSize = i2d_ECDSA_SIG(sig, &pos);
ECDSA_SIG_free(sig);
vchSig.resize(nSize); // Shrink to fit actual size
// Testing our new signature
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1) {
vchSig.clear();
return false;
}
return true;
}
boolckey::Sign(uint256散列、std::vector和vchSig)
{
vchSig.clear();
ECDSA_SIG*SIG=ECDSA_do_sign((unsigned char*)和hash,sizeof(hash),pkey);
if(sig==NULL)
返回false;
//强制偶数S值,以防止签名修改问题。
如果(BN_为奇数(sig->s)){
const EC_GROUP*GROUP=EC_KEY_get0_GROUP(pkey);
CBigNum顺序;
EC_GROUP_get_order(组和订单,空);
BN_sub(sig->s,&order,sig->s);
}
无符号整数nSize=ECDSA_大小(pkey);
vchSig.resize(nSize);//确保它足够大
无符号字符*pos=&vchSig[0];
nSize=i2d_ECDSA_SIG(SIG和pos);
无信号ECDSA(SIG);
vchSig.resize(nSize);//收缩以适合实际大小
//测试我们的新签名
如果(ECDSA_verify(0,(unsigned char*)和hash,sizeof(hash),&vchSig[0],vchSig.size(),pkey)!=1){
vchSig.clear();
返回false;
}
返回true;
}
这将是我目前正在使用的OpenSSL 1.0.2的代码。
在这种情况下,编译会完美地进行,只有版本1.1.1会生成上述错误
编辑:
我做了以下修改,没有更多的错误。。。
我不完全确定这到底是应该做的
bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
{
#if OPENSSL_VERSION_NUMBER < 0x10100000
vchSig.clear();
ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey);
if (sig==NULL)
return false;
// Force even S value in order to prevent signature modification issues.
if (BN_is_odd(sig->s)) {
const EC_GROUP *group = EC_KEY_get0_group(pkey);
CBigNum order;
EC_GROUP_get_order(group, &order, NULL);
BN_sub(sig->s, &order, sig->s);
}
#endif
unsigned int nSize = ECDSA_size(pkey);
vchSig.resize(nSize); // Make sure it is big enough
#if OPENSSL_VERSION_NUMBER < 0x10100000
unsigned char *pos = &vchSig[0];
nSize = i2d_ECDSA_SIG(sig, &pos);
ECDSA_SIG_free(sig);
#else
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1) {
vchSig.clear();
return false;
}
#endif
vchSig.resize(nSize); // Shrink to fit actual size
return true;
}
boolckey::Sign(uint256散列、std::vector和vchSig)
{
#如果OPENSSL\u版本号<0x10100000
vchSig.clear();
ECDSA_SIG*SIG=ECDSA_do_sign((unsigned char*)和hash,sizeof(hash),pkey);
if(sig==NULL)
返回false;
//强制偶数S值,以防止签名修改问题。
如果(BN_为奇数(sig->s)){
const EC_GROUP*GROUP=EC_KEY_get0_GROUP(pkey);
CBigNum顺序;
EC_GROUP_get_order(组和订单,空);
BN_sub(sig->s,&order,sig->s);
}
#恩迪夫
无符号整数nSize=ECDSA_大小(pkey);
vchSig.resize(nSize);//确保它足够大
#如果OPENSSL\u版本号<0x10100000
无符号字符*pos=&vchSig[0];
nSize=i2d_ECDSA_SIG(SIG和pos);
无信号ECDSA(SIG);
#否则
如果(ECDSA_verify(0,(unsigned char*)和hash,sizeof(hash),&vchSig[0],vchSig.size(),pkey)!=1){
vchSig.clear();
返回false;
}
#恩迪夫
vchSig.resize(nSize);//收缩以适合实际大小
返回true;
}
OpenSSL 1.1.0及以上版本更改了几个以前允许使用getter和setter直接访问不透明的结构,包括这一个。请使用中的函数。注意,您的指针必须是[const]BIGNUM*
而不是CBigNum*
,除非CBigNum
是BIGNUM
(或编译器认为不支持的基础类型struct bignum\u st
)。如果仍要支持1.0.x,请在OPENSSL\u VERSION\u NUMBER>=0x10100000L
或类似版本上对该代码进行条件化。