[英]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 上有一個定制的實現:
如果您嘗試使用轉換后的 ed25519 公鑰和 CryptoPP 驗證簽名,驗證將失敗。 那是因為在 libsignal 中對sign和edd25519_verify操作也做了輕微的調整。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.