繁体   English   中英

CryptoPP::ed25519::Verifier 显示与 libsignal 不同的结果

[英]CryptoPP::ed25519::Verifier shows different result from libsignal

我正在尝试使用 CryptoPP 实现curve25519 验证 我首先尝试了libsignal库,女巫显示了正确的结果。 然后我用 CryptoPP 尝试了相同的数据,但显示错误的结果。

这是使用libsignal验证签名的代码:

string pub = str2hex("0504f05568cc7a16fa9b4bc1c9d9294a80b7727e349365f855031a180bf0f80910");
ec_public_key* pub_key;
curve_decode_point(&pub_key, (uint8_t*)pub.data(), pub.size(), 0);

string message = str2hex("05f1fd491d63f1860bdaf3f9b0eb46c2494b7f184a32d9e6c859a421ad284f4307");
string signature = str2hex("5e525df3360ea62281efe8fb9e183521105bb3d9ba8ad43be9fac9d87dd216a6ea9e64099f6f05fbcd6e5a39ab239aad8c1e03d27a1378e4bcbf8937eac4300a");

int ret = curve_verify_signature(
    pub_key, 
    (uint8_t*)message.data(), message.size(), 
    (uint8_t*)signature.data(), signature.size()
    );

cout << "ret: " << ret << endl; // shows 1 (correct)

结果为 1,表示正确。 请注意libsignal要求pub_key以字节 0x05(密钥类型)开头,此处不适用于CryptoPP

使用CryptoPP的代码:

string pub = str2hex("04f05568cc7a16fa9b4bc1c9d9294a80b7727e349365f855031a180bf0f80910");

string message = str2hex("05f1fd491d63f1860bdaf3f9b0eb46c2494b7f184a32d9e6c859a421ad284f4307");
string signature = str2hex("5e525df3360ea62281efe8fb9e183521105bb3d9ba8ad43be9fac9d87dd216a6ea9e64099f6f05fbcd6e5a39ab239aad8c1e03d27a1378e4bcbf8937eac4300a");

ed25519::Verifier verifier((uint8_t*)pub.data());
bool ret = verifier.VerifyMessage(
    (uint8_t*)message.data(), message.size(), 
    (uint8_t*)signature.data(), signature.size()
    );
cout << "ret: " << ret << endl; // shows 0 (wrong)

它显示0,代码有什么问题?

libsignal 在curve25519_verification 上有一个定制的实现:

  • curve25519 公钥转换为 ed25519 公钥(见这里
  • 验证是使用 ed25519 签名验证算法完成的(见这里

如果您尝试使用转换后的 ed25519 公钥和 CryptoPP 验证签名,验证将失败。 那是因为在 libsignal 中对signedd25519_verify操作也做了轻微的调整。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM