【问题标题】:Veins simulation terminates calling openssl ECDSA_SIG_get0 function静脉模拟终止调用 openssl ECDSA_SIG_get0 函数
【发布时间】:2019-03-27 21:20:26
【问题描述】:

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

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

这是产生错误的代码的 sn-p:

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,但错误不断出现。

我做错了什么?

谢谢

【问题讨论】:

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


    【解决方案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);
    

    【讨论】:

    • 谢谢。我使用了第二种解决方案。在这种情况下,调用函数ECDSA_SIG_get0 的正确方法是ECDSA_SIG_get0(signed_hash, &amp;pr, &amp;ps);。对吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多