【发布时间】:2017-02-21 00:46:50
【问题描述】:
我是椭圆曲线密码学、openSSL 和 wolfSSL 的新手。我的上下文是我使用 openssl 从命令行生成 KeyPair 并将私钥导入我的代码。然后我使用 wolfSSL 生成签名并输出。
我将输出保存为DER格式并尝试使用openSSL进行验证,验证失败。
如果我在我的代码中使用 wolfSSL 签名和验证,它会成功验证,如果我在命令行中使用 openSSL 签名和验证,它也会成功。
是否存在我不确定的编码问题?
更新代码
// ECC public key
const uint8_t pubKey[] ={Hex Format key};
// ECC Signature from wolfSSL
char* sigString = {Signature from wolfSSL returned as char};
/* TYPE CONVERTIONS*/
const uint8_t *der_bytes_copy;
const uint8_t *pub_bytes_copy;
der_bytes_copy = (const unsigned char*)sigString;
pub_bytes_copy = pubKey;
EC_KEY *ECpubkey;
size_t keySize = sizeof(pubKey);
int eccgrp;
eccgrp = OBJ_txt2nid("secp256r1");
ECpubkey = EC_KEY_new_by_curve_name(eccgrp);
o2i_ECPublicKey(&ECpubkey, &pub_bytes_copy, keySize);
ECDSA_SIG *signature;
signature = d2i_ECDSA_SIG(NULL, &der_bytes_copy, signedSize);
uint8_t digest[36];
int verified;
const char message[] = "Test for Authenticate Kernel with ECC";
SHA256_CTX ctx;
SHA256_Init(&ctx);
SHA256_Update(&ctx, (const uint8_t*)message,sizeof(message));
SHA256_Final(digest, &ctx);
verified = ECDSA_do_verify(digest, sizeof(digest), signature, ECpubkey);
用 wolfSSL 使用私钥对消息进行签名,然后使用 openssl 使用公钥进行验证,但这会突然停止。
【问题讨论】:
-
“我将输出保存为 DER 格式并尝试使用 openSSL 进行验证,验证失败...” - 请出示您的代码。另请参阅 OpenSSL wiki 上的 EVP Signing and Verifying。
-
嘿jww,如果可能,请检查。谢谢
标签: c cryptography elliptic-curve challenge-response wolfssl