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

标签 c++ openssl omnet++ veins ecdsa

我在 VirtualBox 上使用虚拟机 instant-veins-4-7-1-i1Omnet++-5.3Sumo-0.32.0.

我已经安装了库 openssl 版本 1.1.0。当我尝试使用函数 ECDSA_SIG_get0 访问存储签名的结构 ECDSA_SIG 时,模拟突然终止并出现以下错误

enter image description here

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

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 版本,但错误仍然存​​在。

我做错了什么?

谢谢

最佳答案

您的问题与 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);

关于c++ - 静脉模拟终止调用 openssl ECDSA_SIG_get0 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55386633/

相关文章:

c++ - 用于 std::list 指针排序算法的 STL 谓词

linux - 在 GNU/Linux 中使用 OpenSSL 部署应用程序

java - gRPC : Generate certificateChainFile and privateKeyFile to make TLS/SSL work

c++ - 模块不在节点内(节点必须由 ned 模块中的@node 属性标记)

c++ - 有没有办法可以同时运行 3 个 CreateWindow 函数?

c++ - 像 GTA IV 这样的游戏如何不碎片化堆?

c++ - 如何使用 Visual Studio 自动记录断言?

OpenSSL 1.0 : Remove Elliptic Curves Extension

linux - 发出 "make"命令时发生错误

module - 使用 INET 3.0(无 MiXiM)在 OMNeT++ 中进行 Zigbee 仿真