本文整理匯總了C++中ECDSA_verify函數的典型用法代碼示例。如果您正苦於以下問題:C++ ECDSA_verify函數的具體用法?C++ ECDSA_verify怎麽用?C++ ECDSA_verify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ECDSA_verify函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: test_ecdsa_openssl
void test_ecdsa_openssl() {
const secp256k1_ge_consts_t *c = secp256k1_ge_consts;
secp256k1_num_t key, msg;
secp256k1_num_init(&msg);
unsigned char message[32];
secp256k1_rand256_test(message);
secp256k1_num_set_bin(&msg, message, 32);
secp256k1_num_init(&key);
random_num_order_test(&key);
secp256k1_gej_t qj;
secp256k1_ecmult_gen(&qj, &key);
secp256k1_ge_t q;
secp256k1_ge_set_gej(&q, &qj);
EC_KEY *ec_key = get_openssl_key(&key);
assert(ec_key);
unsigned char signature[80];
int sigsize = 80;
assert(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key));
secp256k1_ecdsa_sig_t sig;
secp256k1_ecdsa_sig_init(&sig);
assert(secp256k1_ecdsa_sig_parse(&sig, signature, sigsize));
assert(secp256k1_ecdsa_sig_verify(&sig, &q, &msg));
secp256k1_num_inc(&sig.r);
assert(!secp256k1_ecdsa_sig_verify(&sig, &q, &msg));
random_sign(&sig, &key, &msg, NULL);
sigsize = 80;
assert(secp256k1_ecdsa_sig_serialize(signature, &sigsize, &sig));
assert(ECDSA_verify(0, message, sizeof(message), signature, sigsize, ec_key) == 1);
secp256k1_ecdsa_sig_free(&sig);
EC_KEY_free(ec_key);
secp256k1_num_free(&key);
secp256k1_num_free(&msg);
}
示例2: test_ecdsa_openssl
void test_ecdsa_openssl(void) {
secp256k1_scalar_t key, msg;
unsigned char message[32];
secp256k1_rand256_test(message);
secp256k1_scalar_set_b32(&msg, message, NULL);
random_scalar_order_test(&key);
secp256k1_gej_t qj;
secp256k1_ecmult_gen(&qj, &key);
secp256k1_ge_t q;
secp256k1_ge_set_gej(&q, &qj);
EC_KEY *ec_key = get_openssl_key(&key);
CHECK(ec_key);
unsigned char signature[80];
unsigned int sigsize = 80;
CHECK(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key));
secp256k1_ecdsa_sig_t sig;
CHECK(secp256k1_ecdsa_sig_parse(&sig, signature, sigsize));
CHECK(secp256k1_ecdsa_sig_verify(&sig, &q, &msg));
secp256k1_scalar_t one;
secp256k1_scalar_set_int(&one, 1);
secp256k1_scalar_t msg2;
secp256k1_scalar_add(&msg2, &msg, &one);
CHECK(!secp256k1_ecdsa_sig_verify(&sig, &q, &msg2));
random_sign(&sig, &key, &msg, NULL);
int secp_sigsize = 80;
CHECK(secp256k1_ecdsa_sig_serialize(signature, &secp_sigsize, &sig));
CHECK(ECDSA_verify(0, message, sizeof(message), signature, secp_sigsize, ec_key) == 1);
EC_KEY_free(ec_key);
}
示例3: ECDSA_do_sign
bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
{
vchSig.clear();
ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey);
if (sig==NULL)
return false;
const EC_GROUP *group = EC_KEY_get0_group(pkey);
CBigNum order, halforder;
EC_GROUP_get_order(group, &order, NULL);
BN_rshift1(&halforder, &order);
// enforce low S values, by negating the value (modulo the order) if above order/2.
if (BN_cmp(sig->s, &halforder) > 0) {
BN_sub(sig->s, &order, sig->s);
}
unsigned int nSize = ECDSA_size(pkey);
vchSig.resize(nSize); // Make sure it is big enough
unsigned char *pos = &vchSig[0];
nSize = i2d_ECDSA_SIG(sig, &pos);
ECDSA_SIG_free(sig);
vchSig.resize(nSize); // Shrink to fit actual size
// Testing our new signature
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1) {
vchSig.clear();
return false;
}
return true;
}
示例4: libecdsaauth_verify
/*
* Verify a signature.
*/
bool libecdsaauth_verify(libecdsaauth_key_t *key, unsigned char *blob, size_t len, unsigned char *sig, size_t siglen)
{
if (1 != ECDSA_verify(0, blob, len, sig, siglen, key->eckey))
return false;
return true;
}
示例5: d2i_EC_PUBKEY
bool
PolicyManager::verifySha256WithEcdsaSignature
(const Blob& signature, const SignedBlob& signedBlob, const Blob& publicKeyDer)
{
// Set signedPortionDigest to the digest of the signed portion of the signedBlob.
uint8_t signedPortionDigest[SHA256_DIGEST_LENGTH];
ndn_digestSha256
(signedBlob.signedBuf(), signedBlob.signedSize(), signedPortionDigest);
// Verify the signedPortionDigest.
// Use a temporary pointer since d2i updates it.
const uint8_t *derPointer = publicKeyDer.buf();
EC_KEY *ecPublicKey = d2i_EC_PUBKEY(NULL, &derPointer, publicKeyDer.size());
if (!ecPublicKey)
throw UnrecognizedKeyFormatException
("Error decoding public key in d2i_EC_PUBKEY");
int success = ECDSA_verify
(NID_sha256, signedPortionDigest, sizeof(signedPortionDigest),
(uint8_t *)signature.buf(),signature.size(), ecPublicKey);
// Free the public key before checking for success.
EC_KEY_free(ecPublicKey);
// ECDSA_verify returns 1 for a valid signature.
return (success == 1);
}
示例6: CBEcdsaVerify
bool CBEcdsaVerify(uint8_t * signature, uint8_t sigLen, uint8_t * hash, uint8_t * pubKey, uint8_t keyLen){
EC_KEY * key = EC_KEY_new_by_curve_name(NID_secp256k1);
o2i_ECPublicKey(&key, (const unsigned char **)&pubKey, keyLen);
int res = ECDSA_verify(0, hash, 32, signature, sigLen, key);
EC_KEY_free(key);
return res == 1;
}
示例7: benchmark_verify_openssl
static void benchmark_verify_openssl(void* arg) {
int i;
benchmark_verify_t* data = (benchmark_verify_t*)arg;
for (i = 0; i < 20000; i++) {
data->sig[data->siglen - 1] ^= (i & 0xFF);
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
{
EC_KEY *pkey = EC_KEY_new();
const unsigned char *pubkey = &data->pubkey[0];
int result;
CHECK(pkey != NULL);
result = EC_KEY_set_group(pkey, data->ec_group);
CHECK(result);
result = (o2i_ECPublicKey(&pkey, &pubkey, data->pubkeylen)) != NULL;
CHECK(result);
result = ECDSA_verify(0, &data->msg[0], sizeof(data->msg), &data->sig[0], data->siglen, pkey) == (i == 0);
CHECK(result);
EC_KEY_free(pkey);
}
data->sig[data->siglen - 1] ^= (i & 0xFF);
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
}
}
示例8: verify_u2f_user
int
verify_u2f_user(Key *key, u_char *dgst, size_t dgstlen, u_char *sig, size_t siglen)
{
int ret;
EC_KEY *ec;
unsigned char *pk;
// TODO: validate that the given key is in the key files.
// We are privileged in this function so it should be easy.
// TODO: replace a lot of stuff here with constants
pk = malloc(sizeof(unsigned char) * (u2f_pubkey_len+26));
memcpy(pk, pubkeyprefix, 26);
memcpy(pk+26, key->u2f_pubkey, u2f_pubkey_len);
if ((ec = d2i_EC_PUBKEY(NULL, &pk, u2f_pubkey_len+26)) == NULL)
fatal("d2i_EC_PUBKEY() failed");
debug("pubkey loaded, yay");
if ((ret = ECDSA_verify(0, dgst, dgstlen, sig, siglen, ec)) == -1)
fatal("ECDSA_verify failed");
debug("ret = %d", ret);
if (ret == 1)
debug("sig verified!");
EC_KEY_free(ec);
return ret == 1;
}
示例9: ECDSA_SIG_new
bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
{
if (vchSig.empty())
return false;
// New versions of OpenSSL will reject non-canonical DER signatures. de/re-serialize first.
unsigned char *norm_der = NULL;
ECDSA_SIG *norm_sig = ECDSA_SIG_new();
const unsigned char* sigptr = &vchSig[0];
assert(norm_sig);
if (d2i_ECDSA_SIG(&norm_sig, &sigptr, vchSig.size()) == NULL)
{
/* As of OpenSSL 1.0.0p d2i_ECDSA_SIG frees and nulls the pointer on
* error. But OpenSSL's own use of this function redundantly frees the
* result. As ECDSA_SIG_free(NULL) is a no-op, and in the absence of a
* clear contract for the function behaving the same way is more
* conservative.
*/
ECDSA_SIG_free(norm_sig);
return false;
}
int derlen = i2d_ECDSA_SIG(norm_sig, &norm_der);
ECDSA_SIG_free(norm_sig);
if (derlen <= 0)
return false;
// -1 = error, 0 = bad sig, 1 = good
bool ret = ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), norm_der, derlen, pkey) == 1;
OPENSSL_free(norm_der);
return ret;
}
示例10: key_verify
bool key_verify(struct key *k, const void *data, size_t datalen,
const void *sig, size_t siglen) {
int res;
res = ECDSA_verify(0, data, datalen, sig, siglen, k->key);
return res == 1;
}
示例11: Verify
bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSig)
{
// -1 = error, 0 = bad sig, 1 = good
if (ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey) != 1)
return false;
return true;
}
示例12: ECDSA_verify
bool CKey::Verify(uint1024 hash, const std::vector<unsigned char>& vchSig, int nBits)
{
bool fSuccess = false;
if(nBits == 256)
{
uint256 hash256 = hash.getuint256();
fSuccess = ECDSA_verify(0, (unsigned char*)&hash256, sizeof(hash256), &vchSig[0], vchSig.size(), pkey);
}
else if(nBits == 512)
{
uint512 hash512 = hash.getuint512();
fSuccess = ECDSA_verify(0, (unsigned char*)&hash512, sizeof(hash512), &vchSig[0], vchSig.size(), pkey);
}
else
fSuccess = ECDSA_verify(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], vchSig.size(), pkey);
return fSuccess;
}
示例13: mech_step_response
static int mech_step_response(sasl_session_t *p, char *message, size_t len, char **out, size_t *out_len)
{
ecdsa_session_t *s = p->mechdata;
if (!ECDSA_verify(0, s->challenge, CHALLENGE_LENGTH, (const unsigned char *)message, len, s->pubkey))
return ASASL_FAIL;
return ASASL_DONE;
}
示例14: BITCOIN_ASSERT
bool elliptic_curve_key::verify(hash_digest hash, const data_chunk& signature)
{
BITCOIN_ASSERT(key_ != nullptr);
// SSL likes a reversed hash
std::reverse(hash.begin(), hash.end());
// -1 = error, 0 = bad sig, 1 = good
if (ECDSA_verify(0, hash.data(), hash.size(),
signature.data(), signature.size(), key_) == 1)
return true;
return false;
}
示例15: openssl_ec_crypt
void openssl_ec_crypt()
{
BIO *berr;
EC_KEY *key1, *key2;
unsigned int sig_len;
int clen, len1, len2;
EC_builtin_curve *curves;
EC_GROUP *group1, *group2;
const EC_KEY *key3, *key4;
const EC_GROUP *group3, *group4;
const EC_POINT *pubkey1, *pubkey2;
unsigned char shareKey1[COMM_LEN], shareKey2[COMM_LEN];
unsigned char *signature, cont[COMM_LEN] = "123456";
key1 = EC_KEY_new();
key2 = EC_KEY_new();
clen = EC_get_builtin_curves(NULL, 0);
curves = (EC_builtin_curve *) malloc(sizeof(EC_builtin_curve) * clen);
EC_get_builtin_curves(curves, clen);
group1 = EC_GROUP_new_by_curve_name(curves[25].nid);
group2 = EC_GROUP_new_by_curve_name(curves[25].nid);
group3 = group1;
group4 = group2;
EC_KEY_set_group(key1, group3);
EC_KEY_set_group(key2, group4);
EC_KEY_generate_key(key1);
EC_KEY_generate_key(key2);
EC_KEY_check_key(key1);
key3 = key1;
key4 = key2;
printf("\nECDSA_size: %d\n", ECDSA_size(key3));
signature = (unsigned char *)malloc(ECDSA_size(key3));
ERR_load_crypto_strings();
berr = BIO_new(BIO_s_file());
BIO_set_fp(berr, stdout, BIO_NOCLOSE);
ECDSA_sign(0, cont, 8, signature, &sig_len, key1);
ECDSA_verify(0, cont, 8, signature, sig_len, key1);
pubkey1 = EC_KEY_get0_public_key(key1);
pubkey2 = EC_KEY_get0_public_key(key2);
len1 = ECDH_compute_key(shareKey1, COMM_LEN, pubkey2, key1, NULL);
len2 = ECDH_compute_key(shareKey2, COMM_LEN, pubkey1, key1, NULL);
if (len1 != len2 || memcmp(shareKey1, shareKey2, len1) != 0) {
printf("ECDH_compute_key err!\n");
return;
}
BIO_free(berr);
EC_KEY_free(key1);
EC_KEY_free(key2);
free(signature);
free(curves);
}