我在VirtualBox上将虚拟机Omnet++-5.3
与Sumo-0.32.0
和openssl
一起使用。
我已经安装了库ECDSA_SIG
1.1.0版。当我尝试使用功能ECDSA_SIG_get0
访问存储签名的结构ECDSA_SIG * signed_hash;
s->generateSignature(message, messageLength, signed_hash);
const BIGNUM **pr;
const BIGNUM **ps;
ECDSA_SIG_get0(signed_hash, pr, ps);
时,仿真突然终止,并出现以下错误
这是生成错误的代码片段:
generateSignature
void SignatureOpenSSL::generateSignature(const unsigned char* message, int messageLength, ECDSA_SIG * signed_hash)
{
unsigned char *md;
unsigned char *hash;
hash = SHA256(message, messageLength, md);
// Computes the ECDSA signature of the given message using the supplied private key and returns the created signature
signed_hash = ECDSA_do_sign(hash, 32, eckey);
if (signed_hash == NULL){
std::cout <<" ko signature " << std::endl;
}else{
std::cout <<" ok signature" << std::endl;
}
}
功能代码为:
openssl
我已将{{1}}库升级到版本1.1.1,但错误不断发生。
我在做什么错了?
谢谢
答案 0 :(得分:2)
您的问题与openssl无关,但与您的“ C”代码和指针的滥用有关。
您的问题所在行是:
signed_hash = ECDSA_do_sign(hash, 32, eckey);
您的代码假定它正在更改调用函数中的指针,但事实并非如此。它只是更改指针的“副本”。您想要返回指针或将指针传递给指针并以这种方式进行设置。
例如
ECDSA_SIG *SignatureOpenSSL::generateSignature(const unsigned char* message, int messageLength)
{
...
ECDSA_SIG * signed_hash = ECDSA_do_sign(hash, 32, eckey);
...
return signed_hash;
}
ECDSA_SIG * signed_hash = s->generateSignature(message, messageLength);
或
void SignatureOpenSSL::generateSignature(const unsigned char* message, int messageLength, ECDSA_SIG ** signed_hash)
{
...
*signed_hash = ECDSA_do_sign(hash, 32, eckey);
if (*signed_hash == NULL){
std::cout <<" ko signature " << std::endl;
}else{
std::cout <<" ok signature" << std::endl;
}
}
ECDSA_SIG * signed_hash;
s->generateSignature(message, messageLength, &signed_hash);