静脉模拟终止调用openssl ECDSA_SIG_get0函数

时间:2019-03-27 21:20:27

标签: c++ openssl omnet++ veins ecdsa

我在VirtualBox上将虚拟机Omnet++-5.3Sumo-0.32.0openssl一起使用。

我已经安装了库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); 时,仿真突然终止,并出现以下错误

enter image description here

这是生成错误的代码片段:

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,但错误不断发生。

我在做什么错了?

谢谢

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);