当前位置: 首页>>代码示例>>C++>>正文


C++ EVP_VerifyFinal函数代码示例

本文整理汇总了C++中EVP_VerifyFinal函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_VerifyFinal函数的具体用法?C++ EVP_VerifyFinal怎么用?C++ EVP_VerifyFinal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了EVP_VerifyFinal函数的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);
}
开发者ID:jonstewart,项目名称:afflib,代码行数:53,代码来源:aftest.cpp

示例2: 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);
}
开发者ID:Aakanksha,项目名称:c-twitter,代码行数:33,代码来源:hash.c

示例3: ERROR_MSG

bool OSSLGOST::verifyFinal(const ByteString& signature)
{
	// Save necessary state before calling super class verifyFinal
	OSSLGOSTPublicKey* pk = (OSSLGOSTPublicKey*) currentPublicKey;

	if (!AsymmetricAlgorithm::verifyFinal(signature))
	{
		return false;
	}

	// Perform the verify operation
	EVP_PKEY *pkey = pk->getOSSLKey();
	int ret;

	if (pkey == NULL)
	{
		ERROR_MSG("Could not get the OpenSSL public key");

		EVP_MD_CTX_cleanup(&curCTX);

		return false;
	}

	ret = EVP_VerifyFinal(&curCTX, signature.const_byte_str(), signature.size(), pkey);
	EVP_MD_CTX_cleanup(&curCTX);
	if (ret != 1)
	{
		if (ret < 0)
			ERROR_MSG("GOST verify failed (0x%08X)", ERR_get_error());

		return false;
	}
	return true;
}
开发者ID:GarysExperiments2014,项目名称:SoftHSMv2,代码行数:34,代码来源:OSSLGOST.cpp

示例4: 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;
}
开发者ID:marianoheller,项目名称:itni_crypto,代码行数:30,代码来源:verificador.cpp

示例5: 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);
}
开发者ID:beike2020,项目名称:source,代码行数:34,代码来源:openssl_base.c

示例6: dsa_verify_final

ssize_t
dsa_verify_final(struct iked_dsa *dsa, void *buf, size_t len)
{
	uint8_t		 sig[EVP_MAX_MD_SIZE];
	unsigned int	 siglen = sizeof(sig);
	uint8_t		*ptr = buf;
	size_t		 off = 0;

	if (dsa->dsa_hmac) {
		if (!HMAC_Final(dsa->dsa_ctx, sig, &siglen))
			return (-1);
		if (siglen != len || memcmp(buf, sig, siglen) != 0)
			return (-1);
	} else {
		if ((off = _dsa_verify_offset(dsa, ptr)) >= len)
			return (-1);
		if (EVP_VerifyFinal(dsa->dsa_ctx, ptr + off, len - off,
		    dsa->dsa_key) != 1) {
			ca_sslerror(__func__);
			return (-1);
		}
	}

	return (0);
}
开发者ID:jymigeon,项目名称:openiked,代码行数:25,代码来源:crypto.c

示例7: 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;
}
开发者ID:MangoCats,项目名称:winglib,代码行数:26,代码来源:sq_ossl_key.cpp

示例8: 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;
}
开发者ID:grawity,项目名称:gale,代码行数:41,代码来源:crypto_sign_raw.c

示例9: 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;
  }
}
开发者ID:dtiedy,项目名称:luaplus51-all,代码行数:30,代码来源:lcrypto.c

示例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;
}
开发者ID:Ana06,项目名称:openssl,代码行数:59,代码来源:a_verify.c

示例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);
}
开发者ID:Adallom,项目名称:openssl,代码行数:58,代码来源:a_verify.c

示例12: LUA_FUNCTION

static LUA_FUNCTION(openssl_verifyFinal)
{
    EVP_MD_CTX *ctx = CHECK_OBJECT(1, EVP_MD_CTX, "openssl.evp_digest_ctx");
    size_t signature_len;
    const char* signature = luaL_checklstring(L, 2, &signature_len);
    EVP_PKEY *pkey = CHECK_OBJECT(3, EVP_PKEY, "openssl.evp_pkey");
    int ret = EVP_VerifyFinal(ctx, (const unsigned char*)signature, signature_len, pkey);
    EVP_MD_CTX_cleanup(ctx);
    return openssl_pushresult(L, ret);
}
开发者ID:witchu,项目名称:lua-openssl,代码行数:10,代码来源:digest.c

示例13: sync

	int RSASHA256Stream::getVerification(const std::string& their_sign)
	{
		// check if data was feed into the stream and the sign needs to be
		// recalculated
		if (!_sign_valid)
		{
			sync();
			_return_code = EVP_VerifyFinal(&_ctx, reinterpret_cast<const unsigned char *>(their_sign.c_str()), their_sign.size(), _pkey);
			_sign_valid = true;
		}
		return _return_code;
	}
开发者ID:Stefan-Schmidt,项目名称:ibrcommon,代码行数:12,代码来源:RSASHA256Stream.cpp

示例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;
}
开发者ID:nextgis,项目名称:nextgis_datastore,代码行数:53,代码来源:account.cpp

示例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);
	}
开发者ID:cdaffara,项目名称:symbiandump-os2,代码行数:52,代码来源:a_verify.c


注:本文中的EVP_VerifyFinal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。