本文整理汇总了C++中RSA_verify函数的典型用法代码示例。如果您正苦于以下问题:C++ RSA_verify函数的具体用法?C++ RSA_verify怎么用?C++ RSA_verify使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RSA_verify函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throw_error_if_not
void rsa_key::verify(const void* _sign, size_t sign_len, const void* buf, size_t buf_len, int type) const
{
#if OPENSSL_VERSION_NUMBER >= 0x01000000
throw_error_if_not(RSA_verify(type, static_cast<const unsigned char*>(buf), static_cast<unsigned int>(buf_len), static_cast<const unsigned char*>(_sign), static_cast<unsigned int>(sign_len), ptr().get()) != 0);
#else
throw_error_if_not(RSA_verify(type, static_cast<unsigned char*>(const_cast<void*>(buf)), static_cast<unsigned int>(buf_len), static_cast<unsigned char*>(const_cast<void*>(_sign)), static_cast<unsigned int>(sign_len), ptr().get()) != 0);
#endif
}
示例2: key_verify
int
key_verify(struct key *k, u_char *msg, int mlen, u_char *sig, int slen)
{
switch (k->type) {
case KEY_RSA:
if (RSA_verify(NID_sha1, msg, mlen,
sig, slen, (RSA *)k->data) <= 0) {
fprintf(stderr, "RSA verification failed\n");
return (-1);
}
break;
case KEY_DSA:
if (DSA_verify(NID_sha1, msg, mlen,
sig, slen, (DSA *)k->data) <= 0) {
fprintf(stderr, "DSA verification failed\n");
return (-1);
}
break;
default:
fprintf(stderr, "Unknown key type: %d\n", k->type);
return (-1);
}
return (slen);
}
示例3: SHA1_Init
bool UpdateManager::verifyVersionData(const string& data, const ByteVector& signature) {
int res = -1;
// Make SHA hash
SHA_CTX sha_ctx = { 0 };
uint8_t digest[SHA_DIGEST_LENGTH];
res = SHA1_Init(&sha_ctx);
if(res != 1)
return false;
res = SHA1_Update(&sha_ctx, data.c_str(), data.size());
if(res != 1)
return false;
res = SHA1_Final(digest, &sha_ctx);
if(res != 1)
return false;
// Extract Key
const uint8_t* key = UpdateManager::publicKey;
RSA* rsa = d2i_RSAPublicKey(NULL, &key, sizeof(UpdateManager::publicKey));
if(rsa) {
res = RSA_verify(NID_sha1, digest, sizeof(digest), &signature[0], signature.size(), rsa);
RSA_free(rsa);
rsa = NULL;
} else return false;
return (res == 1);
}
示例4: HAGGLE_ERR
bool SecurityHelper::verifyDataObject(DataObjectRef& dObj, CertificateRef& cert) const
{
RSA *key;
// Cannot verify without signature
if (!dObj->getSignature()) {
HAGGLE_ERR("No signature in data object, cannot verify\n");
return false;
}
writeErrors("(not this): ");
key = cert->getPubKey();
if (RSA_verify(NID_sha1, dObj->getId(), sizeof(DataObjectId_t),
const_cast<unsigned char *>(dObj->getSignature()), dObj->getSignatureLength(), key) != 1) {
char *raw;
size_t len;
writeErrors("");
dObj->getRawMetadataAlloc((unsigned char **)&raw, &len);
if (raw) {
HAGGLE_DBG("Signature is invalid:\n%s\n", raw);
free(raw);
}
dObj->setSignatureStatus(DataObject::SIGNATURE_INVALID);
return false;
}
HAGGLE_DBG("Signature is valid\n");
dObj->setSignatureStatus(DataObject::SIGNATURE_VALID);
return true;
}
示例5: verify_data
bool verify_data( const char* key, uint32_t key_size, uint32_t pe, const sha1& digest, const char* sig )
{
RSA* pub = get_pub( key,key_size,pe);
auto v = RSA_verify( NID_sha1, (const uint8_t*)digest.data(), 20, (uint8_t*)sig, key_size, pub );
RSA_free(pub);
return 0 != v;
}
示例6: RSA_verify_signature
/*
* Perform the verification step [RFC3447 sec 8.2.2].
*/
static int RSA_verify_signature(const struct public_key *key,
const struct public_key_signature *sig)
{
size_t tsize;
int ret;
/* Variables as per RFC3447 sec 8.2.2 */
const u8 *H = sig->digest;
u8 *EM = NULL;
MPI m = NULL;
size_t k;
kenter("");
if (!RSA_ASN1_templates[sig->pkey_hash_algo].data)
return -ENOTSUPP;
/* (1) Check the signature size against the public key modulus size */
k = mpi_get_nbits(key->rsa.n);
tsize = mpi_get_nbits(sig->rsa.s);
/* According to RFC 4880 sec 3.2, length of MPI is computed starting
* from most significant bit. So the RFC 3447 sec 8.2.2 size check
* must be relaxed to conform with shorter signatures - so we fail here
* only if signature length is longer than modulus size.
*/
pr_devel("step 1: k=%zu size(S)=%zu\n", k, tsize);
if (k < tsize) {
ret = -EBADMSG;
goto error;
}
/* Round up and convert to octets */
k = (k + 7) / 8;
/* (2b) Apply the RSAVP1 verification primitive to the public key */
ret = RSAVP1(key, sig->rsa.s, &m);
if (ret < 0)
goto error;
/* (2c) Convert the message representative (m) to an encoded message
* (EM) of length k octets.
*
* NOTE! The leading zero byte is suppressed by MPI, so we pass a
* pointer to the _preceding_ byte to RSA_verify()!
*/
ret = RSA_I2OSP(m, k, &EM);
if (ret < 0)
goto error;
ret = RSA_verify(H, EM - 1, k, sig->digest_size,
RSA_ASN1_templates[sig->pkey_hash_algo].data,
RSA_ASN1_templates[sig->pkey_hash_algo].size);
error:
kfree(EM);
mpi_free(m);
kleave(" = %d", ret);
return ret;
}
示例7: ccnet_rpc_verify_message
int
ccnet_rpc_verify_message (const char *message,
const char *sig_base64,
const char *peer_id,
GError **error)
{
unsigned char *sig;
gsize sig_len;
CcnetPeer *peer;
sig = g_base64_decode (sig_base64, &sig_len);
peer = ccnet_peer_manager_get_peer (session->peer_mgr, peer_id);
if (!peer) {
g_warning ("Cannot find peer %s.\n", peer_id);
return -1;
}
if (!RSA_verify (NID_sha1, (const unsigned char *)message, strlen(message),
sig, (guint)sig_len, peer->pubkey)) {
g_object_unref (peer);
return -1;
}
g_object_unref (peer);
return 0;
}
示例8: rsa_verify_cb
static int
rsa_verify_cb(int fd, void *ud)
{
struct rsa_verify_cbdata *cbdata = ud;
char *sha256;
char errbuf[1024];
RSA *rsa = NULL;
int ret;
sha256 = pkg_checksum_fd(fd, PKG_HASH_TYPE_SHA256_HEX);
if (sha256 == NULL)
return (EPKG_FATAL);
rsa = _load_rsa_public_key_buf(cbdata->key, cbdata->keylen);
if (rsa == NULL) {
free(sha256);
return(EPKG_FATAL);
}
ret = RSA_verify(NID_sha1, sha256,
pkg_checksum_type_size(PKG_HASH_TYPE_SHA256_HEX), cbdata->sig,
cbdata->siglen, rsa);
free(sha256);
if (ret == 0) {
pkg_emit_error("%s: %s", cbdata->key,
ERR_error_string(ERR_get_error(), errbuf));
RSA_free(rsa);
return (EPKG_FATAL);
}
RSA_free(rsa);
return (EPKG_OK);
}
示例9: lua_rsa_verify_memory
/**
* Check memory using specified rsa key and signature
*
* arguments:
* (rsa_pubkey, rsa_signature, string)
*
* returns:
* true - if string match rsa signature
* false - otherwise
*/
static gint
lua_rsa_verify_memory (lua_State *L)
{
RSA *rsa;
rspamd_fstring_t *signature;
const gchar *data;
gchar *data_sig;
gint ret;
rsa = lua_check_rsa_pubkey (L, 1);
signature = lua_check_rsa_sign (L, 2);
data = luaL_checkstring (L, 3);
if (rsa != NULL && signature != NULL && data != NULL) {
data_sig = g_compute_checksum_for_string (G_CHECKSUM_SHA256, data, -1);
ret = RSA_verify (NID_sha1, data_sig, strlen (data_sig),
signature->str, signature->len, rsa);
if (ret == 0) {
msg_info ("cannot check rsa signature for data: %s",
ERR_error_string (ERR_get_error (), NULL));
lua_pushboolean (L, FALSE);
}
else {
lua_pushboolean (L, TRUE);
}
g_free (data_sig);
}
else {
lua_pushnil (L);
}
return 1;
}
示例10: pkg_repo_verify
int
pkg_repo_verify(const char *path, unsigned char *sig, unsigned int sig_len)
{
char sha256[SHA256_DIGEST_LENGTH *2 +1];
char errbuf[1024];
RSA *rsa = NULL;
sha256_file(path, sha256);
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
OpenSSL_add_all_ciphers();
rsa = load_rsa_public_key(pkg_config("PUBKEY"));
if (rsa == NULL)
return(EPKG_FATAL);
if (RSA_verify(NID_sha1, sha256, sizeof(sha256), sig, sig_len, rsa) == 0) {
pkg_emit_error("%s: %s", pkg_config("PUBKEY"),
ERR_error_string(ERR_get_error(), errbuf));
return (EPKG_FATAL);
}
RSA_free(rsa);
ERR_free_strings();
return (EPKG_OK);
}
示例11: PyErr_Format
static PyObject *verify(RSAObject *self, PyObject *args)
{
Py_buffer digest, signature;
int result = 0;
PyObject *result_obj = NULL;
#if PY_MAJOR_VERSION >= 3
if (!PyArg_ParseTuple(args, "y*y*:verify", &digest, &signature))
return NULL;
#else
if (!PyArg_ParseTuple(args, "s*s*:verify", &digest, &signature))
return NULL;
#endif
if (digest.len != SHA_DIGEST_LENGTH)
{
PyErr_Format(PyExc_ValueError, "digest should be %i bytes",
SHA_DIGEST_LENGTH);
goto cleanup;
}
result = RSA_verify(NID_sha1, digest.buf, digest.len,
signature.buf, signature.len, self->rsa);
result_obj = PyBool_FromLong(result);
cleanup:
PyBuffer_Release(&digest);
PyBuffer_Release(&signature);
return result_obj;
}
示例12: RSAVerifyBinary_f
int RSAVerifyBinary_f(const uint8_t* key_blob,
const RSAPublicKey* key,
const uint8_t* buf,
int len,
const uint8_t* sig,
int algorithm) {
RSAPublicKey* verification_key = NULL;
uint8_t* digest = NULL;
int key_size;
int sig_size;
int success;
if (algorithm >= kNumAlgorithms)
return 0; /* Invalid algorithm. */
key_size = RSAProcessedKeySize(algorithm);
sig_size = siglen_map[algorithm] * sizeof(uint32_t);
if (key_blob && !key)
verification_key = RSAPublicKeyFromBuf(key_blob, key_size);
else if (!key_blob && key)
verification_key = (RSAPublicKey*) key; /* Supress const warning. */
else
return 0; /* Both can't be NULL or non-NULL. */
digest = DigestBuf(buf, len, algorithm);
success = RSA_verify(verification_key, sig, sig_size, algorithm, digest);
Free(digest);
if (!key)
RSAPublicKeyFree(verification_key); /* Only free if we allocated it. */
return success;
}
示例13: __ast_check_signature_bin
static int __ast_check_signature_bin(struct ast_key *key, const char *msg, int msglen, const unsigned char *dsig)
{
unsigned char digest[20];
int res;
if (key->ktype != AST_KEY_PUBLIC) {
/* Okay, so of course you really *can* but for our purposes
we're going to say you can't */
ast_log(LOG_WARNING, "Cannot check message signature with a private key\n");
return -1;
}
/* Calculate digest of message */
SHA1((unsigned char *)msg, msglen, digest);
/* Verify signature */
res = RSA_verify(NID_sha1, digest, sizeof(digest), (unsigned char *)dsig, 128, key->rsa);
if (!res) {
ast_log(LOG_DEBUG, "Key failed verification: %s\n", key->name);
return -1;
}
/* Pass */
return 0;
}
示例14: rsa_verifydigest
static bool
rsa_verifydigest(dnssec_key* key, u8* digest, u32 digest_len, u8* signature, u32 signature_len)
{
zassert(signature_len <= DNSSEC_MAXIMUM_KEY_SIZE_BYTES);
int err = RSA_verify(key->nid, digest, digest_len, signature, signature_len, key->key.rsa);
if(err == 0)
{
unsigned long ssl_err;
while((ssl_err = ERR_get_error()) != 0)
{
char buffer[128];
ERR_error_string_n(ssl_err, buffer, sizeof (buffer));
log_debug("digest verification returned an ssl error %08x %s", ssl_err, buffer);
}
ERR_clear_error();
return FALSE;
}
return TRUE;
}
示例15: d2i_RSA_PUBKEY
/**
* Verify the RSA signature on the SignedBlob using the given public key.
* TODO: Move this general verification code to a more central location.
* @param signature The Sha256WithRsaSignature.
* @param signedBlob the SignedBlob with the signed portion to verify.
* @param publicKeyDer The DER-encoded public key used to verify the signature.
* @return true if the signature verifies, false if not.
*/
static bool
verifySha256WithRsaSignature
(const Sha256WithRsaSignature* signature, const SignedBlob& signedBlob,
const Blob& publicKeyDer)
{
// Set signedPortionDigest to the digest of the signed portion of the wire encoding.
uint8_t signedPortionDigest[SHA256_DIGEST_LENGTH];
// wireEncode returns the cached encoding if available.
ndn_digestSha256
(signedBlob.signedBuf(), signedBlob.signedSize(), signedPortionDigest);
// Verify the signedPortionDigest.
// Use a temporary pointer since d2i updates it.
const uint8_t *derPointer = publicKeyDer.buf();
RSA *rsaPublicKey = d2i_RSA_PUBKEY(NULL, &derPointer, publicKeyDer.size());
if (!rsaPublicKey)
throw UnrecognizedKeyFormatException("Error decoding public key in d2i_RSAPublicKey");
int success = RSA_verify
(NID_sha256, signedPortionDigest, sizeof(signedPortionDigest), (uint8_t *)signature->getSignature().buf(),
signature->getSignature().size(), rsaPublicKey);
// Free the public key before checking for success.
RSA_free(rsaPublicKey);
// RSA_verify returns 1 for a valid signature.
return (success == 1);
}