本文整理汇总了C++中EVP_VerifyUpdate函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_VerifyUpdate函数的具体用法?C++ EVP_VerifyUpdate怎么用?C++ EVP_VerifyUpdate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVP_VerifyUpdate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rsatest
void rsatest()
{
const EVP_MD *sha256 = EVP_get_digestbyname("sha256");
if(!sha256){
fprintf(stderr,"SHA256 not available\n");
return;
}
printf("Now try signing with X.509 certificates and EVP\n");
char ptext[16];
memset(ptext,0,sizeof(ptext));
strcpy(ptext,"Simson");
unsigned char sig[1024];
uint32_t siglen = sizeof(sig);
BIO *bp = BIO_new_file("signing_key.pem","r");
EVP_MD_CTX md;
EVP_PKEY *pkey = PEM_read_bio_PrivateKey(bp,0,0,0);
EVP_SignInit(&md,sha256);
EVP_SignUpdate(&md,ptext,sizeof(ptext));
EVP_SignFinal(&md,sig,&siglen,pkey);
/* let's try to verify it */
bp = BIO_new_file("signing_cert.pem","r");
X509 *x = 0;
PEM_read_bio_X509(bp,&x,0,0);
EVP_PKEY *pubkey = X509_get_pubkey(x);
printf("pubkey=%p\n",pubkey);
EVP_VerifyInit(&md,sha256);
EVP_VerifyUpdate(&md,ptext,sizeof(ptext));
int r = EVP_VerifyFinal(&md,sig,siglen,pubkey);
printf("r=%d\n",r);
printf("do it again...\n");
EVP_VerifyInit(&md,sha256);
EVP_VerifyUpdate(&md,ptext,sizeof(ptext));
r = EVP_VerifyFinal(&md,sig,siglen,pubkey);
printf("r=%d\n",r);
printf("make a tiny change...\n");
ptext[0]='f';
EVP_VerifyInit(&md,sha256);
EVP_VerifyUpdate(&md,ptext,sizeof(ptext));
r = EVP_VerifyFinal(&md,sig,siglen,pubkey);
printf("r=%d\n",r);
}
示例2: soap_smd_update
/**
@fn int soap_smd_update(struct soap *soap, struct soap_smd_data *data, const char *buf, size_t len)
@brief Updates (signed) digest computation with message part.
@param soap context
@param[in,out] data smdevp engine context
@param[in] buf contains message part
@param[in] len of message part
@return SOAP_OK or SOAP_SSL_ERROR
*/
int
soap_smd_update(struct soap *soap, struct soap_smd_data *data, const char *buf, size_t len)
{ int ok = 1;
if (!data->ctx)
return soap_set_receiver_error(soap, "soap_smd_update() failed", "No context", SOAP_SSL_ERROR);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "-- SMD Update alg=%x n=%lu (%p) --\n", data->alg, (unsigned long)len, data->ctx));
switch (data->alg & SOAP_SMD_ALGO)
{ case SOAP_SMD_HMAC:
HMAC_Update((HMAC_CTX*)data->ctx, (const unsigned char*)buf, len);
break;
case SOAP_SMD_DGST:
EVP_DigestUpdate((EVP_MD_CTX*)data->ctx, (const void*)buf, (unsigned int)len);
break;
case SOAP_SMD_SIGN:
ok = EVP_SignUpdate((EVP_MD_CTX*)data->ctx, (const void*)buf, (unsigned int)len);
break;
case SOAP_SMD_VRFY:
ok = EVP_VerifyUpdate((EVP_MD_CTX*)data->ctx, (const void*)buf, (unsigned int)len);
break;
}
DBGMSG(TEST, buf, len);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n--"));
/* check and return */
return soap_smd_check(soap, data, ok, "soap_smd_update() failed");
}
示例3: gale_crypto_verify_raw
/** Low-level signature verification.
* \param key_count Number of keys in the \a keys array
* and number fo signatures in the \a sigs array.
* \param keys Array of keys. The keys must include public key data.
* \param sigs Array of signatures, as returned from gale_crypto_sign_raw().
* \param data Data to verify against signatures.
* \return Nonzero iff the all signatures are valid. */
int gale_crypto_verify_raw(int key_count,
const struct gale_group *keys,
const struct gale_data *sigs,
struct gale_data data)
{
int i,is_valid = 1;
EVP_MD_CTX *context = EVP_MD_CTX_new();
RSA *rsa;
EVP_VerifyInit(context,EVP_md5());
EVP_VerifyUpdate(context,data.p,data.l);
for (i = 0; is_valid && i < key_count; ++i) {
EVP_PKEY *key = EVP_PKEY_new();
EVP_PKEY_assign_RSA(key,RSA_new());
rsa = EVP_PKEY_get0_RSA(key);
crypto_i_rsa(keys[i],rsa);
if (!crypto_i_public_valid(rsa)) {
gale_alert(GALE_WARNING,G_("invalid public key"),0);
is_valid = 0;
goto cleanup;
}
if (!EVP_VerifyFinal(context,sigs[i].p,sigs[i].l,key)) {
crypto_i_error();
is_valid = 0;
goto cleanup;
}
cleanup:
EVP_PKEY_free(key);
}
return is_valid;
}
示例4: oauth_verify_rsa_sha1
int oauth_verify_rsa_sha1 (const char *m, const char *c, const char *s) {
EVP_MD_CTX md_ctx;
EVP_PKEY *pkey;
BIO *in;
X509 *cert = NULL;
unsigned char *b64d;
int slen, err;
in = BIO_new_mem_buf((unsigned char*)c, strlen(c));
cert = PEM_read_bio_X509(in, NULL, 0, NULL);
if (cert) {
pkey = (EVP_PKEY *) X509_get_pubkey(cert);
X509_free(cert);
} else {
pkey = PEM_read_bio_PUBKEY(in, NULL, 0, NULL);
}
BIO_free(in);
if (pkey == NULL) {
//fprintf(stderr, "could not read cert/pubkey.\n");
return -2;
}
b64d= (unsigned char*) xmalloc(sizeof(char)*strlen(s));
slen = oauth_decode_base64(b64d, s);
EVP_VerifyInit(&md_ctx, EVP_sha1());
EVP_VerifyUpdate(&md_ctx, m, strlen(m));
err = EVP_VerifyFinal(&md_ctx, b64d, slen, pkey);
EVP_MD_CTX_cleanup(&md_ctx);
EVP_PKEY_free(pkey);
free(b64d);
return (err);
}
示例5: verify_fverify
static int verify_fverify(lua_State *L)
{
/* parameter 1 is the 'crypto.verify' table */
const char *type_name = luaL_checkstring(L, 2);
const EVP_MD *type = EVP_get_digestbyname(type_name);
if (type == NULL) {
luaL_argerror(L, 1, "invalid digest type");
return 0;
} else {
EVP_MD_CTX c;
size_t input_len = 0;
const unsigned char *input = (unsigned char *) luaL_checklstring(L, 3, &input_len);
size_t sig_len = 0;
const unsigned char *sig = (unsigned char *) luaL_checklstring(L, 4, &sig_len);
EVP_PKEY **pkey = (EVP_PKEY **)luaL_checkudata(L, 5, LUACRYPTO_PKEYNAME);
int ret;
EVP_MD_CTX_init(&c);
EVP_VerifyInit_ex(&c, type, NULL);
EVP_VerifyUpdate(&c, input, input_len);
ret = EVP_VerifyFinal(&c, sig, sig_len, *pkey);
EVP_MD_CTX_cleanup(&c);
if (ret == -1)
return crypto_error(L);
lua_pushboolean(L, ret);
return 1;
}
}
示例6: EVP_PKEY_new
bool Verificador::verificarFirma(ParDeClaves& parDeClaves,const std::string& firma,std::istream& mensaje){
RSA* rsa = parDeClaves;
EVP_PKEY* pk = EVP_PKEY_new();
EVP_MD_CTX ctx;
EVP_PKEY_set1_RSA(pk,parDeClaves);
EVP_MD_CTX_init(&ctx);
M_EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_PAD_PKCS1/*EVP_MD_CTX_FLAG_PAD_X931*/);
EVP_VerifyInit_ex(&ctx, EVP_get_digestbynid(NID_sha1), NULL);
while(!mensaje.eof()){
unsigned char buffer[tamanio_de_buffer_default];
mensaje.read((char*)buffer,tamanio_de_buffer_default);
EVP_VerifyUpdate(&ctx, buffer, mensaje.gcount());
mensaje.peek();
}
int ok = EVP_VerifyFinal(&ctx, (unsigned char*)firma.c_str(), firma.size(), pk);
EVP_MD_CTX_cleanup(&ctx);
// El free esta en el constructor de ParDeClaves no puede
// liberarse aca
//FIPS_rsa_free(pk.pkey.rsa);
EVP_PKEY_free(pk);
return ok==1;
}
示例7: soap_smd_update
/**
@fn int soap_smd_update(struct soap *soap, struct soap_smd_data *data, const char *buf, size_t len)
@brief Updates (signed) digest computation with message part.
@param soap context
@param[in,out] data smdevp engine context
@param[in] buf contains message part
@param[in] len of message part
@return SOAP_OK or SOAP_SSL_ERROR
*/
int
soap_smd_update(struct soap *soap, struct soap_smd_data *data, const char *buf, size_t len)
{ int err = 1;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "-- SMD Update alg=%d n=%lu (%p) --\n", data->alg, (unsigned long)len, data->ctx));
switch (data->alg & (SOAP_SMD_PASSTHRU-1))
{ case SOAP_SMD_DGST_MD5:
case SOAP_SMD_DGST_SHA1:
EVP_DigestUpdate((EVP_MD_CTX*)data->ctx, (const void*)buf, (unsigned int)len);
break;
case SOAP_SMD_HMAC_SHA1:
HMAC_Update((HMAC_CTX*)data->ctx, (const unsigned char*)buf, len);
break;
case SOAP_SMD_SIGN_DSA_SHA1:
case SOAP_SMD_SIGN_RSA_SHA1:
err = EVP_SignUpdate((EVP_MD_CTX*)data->ctx, (const void*)buf, (unsigned int)len);
break;
case SOAP_SMD_VRFY_DSA_SHA1:
case SOAP_SMD_VRFY_RSA_SHA1:
err = EVP_VerifyUpdate((EVP_MD_CTX*)data->ctx, (const void*)buf, (unsigned int)len);
break;
}
DBGMSG(TEST, buf, len);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n--"));
/* check and return */
return soap_smd_check(soap, data, err, "soap_smd_update() failed");
}
示例8: oexERROR
int COsslKey::VerifyBin( sqbind::CSqBinary *pData, sqbind::CSqBinary *sig )
{_STT();
if ( !pData || !sig || !getPublicKeyPtr() )
return 0;
EVP_MD_CTX md_ctx;
if ( !EVP_VerifyInit( &md_ctx, EVP_sha1() ) )
{ oexERROR( 0, oexT( "EVP_VerifyInit() failed" ) );
return 0;
} // end if
if ( !EVP_VerifyUpdate( &md_ctx, pData->Ptr(), pData->getUsed() ) )
{ oexERROR( 0, oexT( "EVP_VerifyUpdate() failed" ) );
return 0;
} // end if
int err = EVP_VerifyFinal( &md_ctx, (unsigned char*)sig->Ptr(), sig->getUsed(), getPublicKeyPtr() );
if ( err != 1 )
{ oexERROR( err, oexT( "EVP_VerifyFinal() failed" ) );
return 0;
} // end if
return 1;
}
示例9: openssl_evp_comsign
void openssl_evp_comsign()
{
RSA *rsa;
EVP_PKEY *evpKey;
EVP_MD_CTX mdctx;
unsigned int i, len;
char ins[MAX1_LEN] = "openssl signature";
unsigned char outs[MAX1_LEN];
OpenSSL_add_all_algorithms();
rsa = RSA_generate_key(MAX1_LEN, RSA_F4, NULL, NULL);
evpKey = EVP_PKEY_new();
EVP_PKEY_set1_RSA(evpKey, rsa);
EVP_MD_CTX_init(&mdctx);
EVP_SignInit_ex(&mdctx, EVP_md5(), NULL);
EVP_SignUpdate(&mdctx, ins, strlen(ins));
EVP_SignFinal(&mdctx, outs, &len, evpKey);
printf("\nEVP_COMSignature(%s) = ", ins);
for (i = 0; i < len; i++)
printf("0x%02x ", outs[i]);
printf("\n");
EVP_MD_CTX_cleanup(&mdctx);
EVP_MD_CTX_init(&mdctx);
EVP_VerifyInit_ex(&mdctx, EVP_md5(), NULL);
EVP_VerifyUpdate(&mdctx, ins, strlen(ins));
if (EVP_VerifyFinal(&mdctx, outs, len, evpKey) == 1)
printf("EVP_COMVerify OK!\n");
EVP_MD_CTX_cleanup(&mdctx);
EVP_PKEY_free(evpKey);
RSA_free(rsa);
}
示例10: ASN1_verify
int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
char *data, EVP_PKEY *pkey)
{
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
const EVP_MD *type;
unsigned char *p, *buf_in = NULL;
int ret = -1, i, inl;
if (ctx == NULL) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_MALLOC_FAILURE);
goto err;
}
i = OBJ_obj2nid(a->algorithm);
type = EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL) {
ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7) {
ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
goto err;
}
inl = i2d(data, NULL);
if (inl <= 0) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_INTERNAL_ERROR);
goto err;
}
buf_in = OPENSSL_malloc((unsigned int)inl);
if (buf_in == NULL) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_MALLOC_FAILURE);
goto err;
}
p = buf_in;
i2d(data, &p);
ret = EVP_VerifyInit_ex(ctx, type, NULL)
&& EVP_VerifyUpdate(ctx, (unsigned char *)buf_in, inl);
OPENSSL_clear_free(buf_in, (unsigned int)inl);
if (!ret) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);
goto err;
}
ret = -1;
if (EVP_VerifyFinal(ctx, (unsigned char *)signature->data,
(unsigned int)signature->length, pkey) <= 0) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);
ret = 0;
goto err;
}
ret = 1;
err:
EVP_MD_CTX_free(ctx);
return ret;
}
示例11: ASN1_verify
int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
char *data, EVP_PKEY *pkey)
{
EVP_MD_CTX ctx;
const EVP_MD *type;
unsigned char *p, *buf_in = NULL;
int ret = -1, i, inl;
EVP_MD_CTX_init(&ctx);
i = OBJ_obj2nid(a->algorithm);
type = EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL) {
ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7) {
ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
goto err;
}
inl = i2d(data, NULL);
buf_in = OPENSSL_malloc((unsigned int)inl);
if (buf_in == NULL) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_MALLOC_FAILURE);
goto err;
}
p = buf_in;
i2d(data, &p);
ret = EVP_VerifyInit_ex(&ctx, type, NULL)
&& EVP_VerifyUpdate(&ctx, (unsigned char *)buf_in, inl);
OPENSSL_cleanse(buf_in, (unsigned int)inl);
OPENSSL_free(buf_in);
if (!ret) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);
goto err;
}
ret = -1;
if (EVP_VerifyFinal(&ctx, (unsigned char *)signature->data,
(unsigned int)signature->length, pkey) <= 0) {
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_EVP_LIB);
ret = 0;
goto err;
}
/*
* we don't need to zero the 'ctx' because we just checked public
* information
*/
/* memset(&ctx,0,sizeof(ctx)); */
ret = 1;
err:
EVP_MD_CTX_cleanup(&ctx);
return (ret);
}
示例12: verify_update
static int verify_update(lua_State *L)
{
EVP_MD_CTX *c = (EVP_MD_CTX*)luaL_checkudata(L, 1, LUACRYPTO_VERIFYNAME);
size_t input_len = 0;
const unsigned char *input = (unsigned char *) luaL_checklstring(L, 2, &input_len);
EVP_VerifyUpdate(c, input, input_len);
return 0;
}
示例13: LUA_FUNCTION
static LUA_FUNCTION(openssl_verifyUpdate)
{
size_t l;
int ret;
EVP_MD_CTX *ctx = CHECK_OBJECT(1, EVP_MD_CTX, "openssl.evp_digest_ctx");
const char* data = luaL_checklstring(L, 2, &l);
ret = EVP_VerifyUpdate(ctx, data, l);
return openssl_pushresult(L, ret);
}
示例14: verifyRSASignature
static bool verifyRSASignature(const unsigned char *originalMessage,
unsigned int messageLength,
const unsigned char *signature,
unsigned int sigLength)
{
if(nullptr == originalMessage) {
return errorMessage(_("Message is empty"));
}
if(nullptr == signature) {
return errorMessage(_("Signature is empty"));
}
const char *settingsPath = CPLGetConfigOption("NGS_SETTINGS_PATH", nullptr);
std::string keyFilePath = File::formFileName(settingsPath, KEY_FILE, "");
FILE *file = VSIFOpen( keyFilePath.c_str(), "r" );
if( file == nullptr ) {
return errorMessage(_("Failed open file %s"), keyFilePath.c_str());
}
EVP_PKEY *evp_pubkey = PEM_read_PUBKEY(file, nullptr, nullptr, nullptr);
VSIFClose( file );
if (!evp_pubkey) {
return errorMessage(_("Failed PEM_read_PUBKEY"));
}
EVP_MD_CTX *ctx = EVP_MD_CTX_create();
if (!ctx) {
EVP_PKEY_free(evp_pubkey);
return errorMessage(_("Failed PEM_read_PUBKEY"));
}
if(!EVP_VerifyInit(ctx, EVP_sha256())) {
EVP_MD_CTX_destroy(ctx);
EVP_PKEY_free(evp_pubkey);
return errorMessage(_("Failed EVP_VerifyInit"));
}
if(!EVP_VerifyUpdate(ctx, originalMessage, messageLength)) {
EVP_MD_CTX_destroy(ctx);
EVP_PKEY_free(evp_pubkey);
return errorMessage(_("Failed EVP_VerifyUpdate"));
}
int result = EVP_VerifyFinal(ctx, signature, sigLength, evp_pubkey);
EVP_MD_CTX_destroy(ctx);
EVP_PKEY_free(evp_pubkey);
outMessage(result == 1 ? COD_SUCCESS : COD_UNEXPECTED_ERROR,
"Signature is %s", result == 1 ? "valid" : "invalid");
return result == 1;
}
示例15: ASN1_item_verify
EXPORT_C int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signature,
void *asn, EVP_PKEY *pkey)
{
EVP_MD_CTX ctx;
const EVP_MD *type;
unsigned char *buf_in=NULL;
int ret= -1,i,inl;
EVP_MD_CTX_init(&ctx);
i=OBJ_obj2nid(a->algorithm);
type=EVP_get_digestbyname(OBJ_nid2sn(i));
if (type == NULL)
{
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
goto err;
}
if (!EVP_VerifyInit_ex(&ctx,type, NULL))
{
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
inl = ASN1_item_i2d(asn, &buf_in, it);
if (buf_in == NULL)
{
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE);
goto err;
}
EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl);
OPENSSL_cleanse(buf_in,(unsigned int)inl);
OPENSSL_free(buf_in);
if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
(unsigned int)signature->length,pkey) <= 0)
{
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB);
ret=0;
goto err;
}
/* we don't need to zero the 'ctx' because we just checked
* public information */
/* memset(&ctx,0,sizeof(ctx)); */
ret=1;
err:
EVP_MD_CTX_cleanup(&ctx);
return(ret);
}