本文整理汇总了C++中EVP_DigestFinal_ex函数的典型用法代码示例。如果您正苦于以下问题:C++ EVP_DigestFinal_ex函数的具体用法?C++ EVP_DigestFinal_ex怎么用?C++ EVP_DigestFinal_ex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EVP_DigestFinal_ex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: soap_smd_final
/**
@fn int soap_smd_final(struct soap *soap, struct soap_smd_data *data, char *buf, int *len)
@brief Finalizes (signed) digest computation and returns digest or signature.
@param soap context
@param[in,out] data smdevp engine context
@param[in] buf contains signature for verification (SOAP_SMD_VRFY algorithms)
@param[out] buf is populated with the digest or signature
@param[in] len points to length of signature to verify (SOAP_SMD_VRFY algorithms)
@param[out] len points to length of stored digest or signature (pass NULL if you are not interested in this value)
@return SOAP_OK or SOAP_SSL_ERROR
*/
int
soap_smd_final(struct soap *soap, struct soap_smd_data *data, char *buf, int *len)
{ unsigned int n = 0;
int ok = 1;
if (!data->ctx)
return soap_set_receiver_error(soap, "soap_smd_final() failed", "No context", SOAP_SSL_ERROR);
if (buf)
{ /* finalize the digest or signature computation */
switch (data->alg & SOAP_SMD_ALGO)
{ case SOAP_SMD_HMAC:
HMAC_Final((HMAC_CTX*)data->ctx, (unsigned char*)buf, &n);
break;
case SOAP_SMD_DGST:
EVP_DigestFinal_ex((EVP_MD_CTX*)data->ctx, (unsigned char*)buf, &n);
break;
case SOAP_SMD_SIGN:
ok = EVP_SignFinal((EVP_MD_CTX*)data->ctx, (unsigned char*)buf, &n, (EVP_PKEY*)data->key);
break;
case SOAP_SMD_VRFY:
if (len)
{ n = (unsigned int)*len;
ok = EVP_VerifyFinal((EVP_MD_CTX*)data->ctx, (unsigned char*)buf, n, (EVP_PKEY*)data->key);
}
else
ok = 0;
break;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "-- SMD Final alg=%x (%p) %d bytes--\n", data->alg, data->ctx, n));
DBGHEX(TEST, buf, n);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n--"));
/* pass back length of digest or signature produced */
if (len)
*len = (int)n;
}
/* cleanup */
if ((data->alg & SOAP_SMD_ALGO) == SOAP_SMD_HMAC)
HMAC_CTX_cleanup((HMAC_CTX*)data->ctx);
else
EVP_MD_CTX_cleanup((EVP_MD_CTX*)data->ctx);
SOAP_FREE(soap, data->ctx);
data->ctx = NULL;
/* check and return */
return soap_smd_check(soap, data, ok, "soap_smd_final() failed");
}
示例2: block_in
static int block_in(BIO *b)
{
BIO_OK_CTX *ctx;
EVP_MD_CTX *md;
unsigned long tl = 0;
unsigned char tmp[EVP_MAX_MD_SIZE];
int md_size;
ctx = BIO_get_data(b);
md = ctx->md;
md_size = EVP_MD_size(EVP_MD_CTX_md(md));
assert(sizeof(tl) >= OK_BLOCK_BLOCK); /* always true */
tl = ctx->buf[0];
tl <<= 8;
tl |= ctx->buf[1];
tl <<= 8;
tl |= ctx->buf[2];
tl <<= 8;
tl |= ctx->buf[3];
if (ctx->buf_len < tl + OK_BLOCK_BLOCK + md_size)
return 1;
if (!EVP_DigestUpdate(md,
(unsigned char *)&(ctx->buf[OK_BLOCK_BLOCK]), tl))
goto berr;
if (!EVP_DigestFinal_ex(md, tmp, NULL))
goto berr;
if (memcmp(&(ctx->buf[tl + OK_BLOCK_BLOCK]), tmp, md_size) == 0) {
/* there might be parts from next block lurking around ! */
ctx->buf_off_save = tl + OK_BLOCK_BLOCK + md_size;
ctx->buf_len_save = ctx->buf_len;
ctx->buf_off = OK_BLOCK_BLOCK;
ctx->buf_len = tl + OK_BLOCK_BLOCK;
ctx->blockout = 1;
} else {
ctx->cont = 0;
}
return 1;
berr:
BIO_clear_retry_flags(b);
return 0;
}
示例3: ssl3_final_finish_mac
size_t ssl3_final_finish_mac(SSL *s, const char *sender, size_t len,
unsigned char *p)
{
int ret;
EVP_MD_CTX *ctx = NULL;
if (!ssl3_digest_cached_records(s, 0))
return 0;
if (EVP_MD_CTX_type(s->s3->handshake_dgst) != NID_md5_sha1) {
SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, SSL_R_NO_REQUIRED_DIGEST);
return 0;
}
ctx = EVP_MD_CTX_new();
if (ctx == NULL) {
SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!EVP_MD_CTX_copy_ex(ctx, s->s3->handshake_dgst)) {
SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, ERR_R_INTERNAL_ERROR);
return 0;
}
ret = EVP_MD_CTX_size(ctx);
if (ret < 0) {
EVP_MD_CTX_reset(ctx);
return 0;
}
if ((sender != NULL && EVP_DigestUpdate(ctx, sender, len) <= 0)
|| EVP_MD_CTX_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET,
(int)s->session->master_key_length,
s->session->master_key) <= 0
|| EVP_DigestFinal_ex(ctx, p, NULL) <= 0) {
SSLerr(SSL_F_SSL3_FINAL_FINISH_MAC, ERR_R_INTERNAL_ERROR);
ret = 0;
}
EVP_MD_CTX_free(ctx);
return ret;
}
示例4: hash_string
/**
* Return the SHA-512 based hash.
*/
char * hash_string(char *inbytes, size_t inLen, size_t *wroteBytes) {
unsigned char md_value[EVP_MAX_MD_SIZE];
unsigned int md_len;
mdctx = EVP_MD_CTX_create();
EVP_DigestInit_ex(mdctx, md,NULL);
EVP_DigestUpdate(mdctx,inbytes,inLen);
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
char *outputBuffer = (char *)malloc(sizeof(char) * 64);
for(int i=0; i<SHA512_DIGEST_LENGTH; i++) {
outputBuffer[i] = md_value[i];
}
if (wroteBytes != NULL) {
*wroteBytes = 512;
}
EVP_MD_CTX_destroy(mdctx);
return outputBuffer;
}
示例5: tc_sha1_digest_one
int
tc_sha1_digest_one(unsigned char *dest, unsigned int dest_len,
const unsigned char *seed, unsigned int seed_len)
{
unsigned int sha1_value_len;
unsigned char sha1_value[EVP_MAX_MD_SIZE];
if (!sha1_init) {
return 0;
}
EVP_DigestInit_ex(&sha1_ctx, md, NULL);
EVP_DigestUpdate(&sha1_ctx, seed, seed_len);
EVP_DigestFinal_ex(&sha1_ctx, sha1_value, &sha1_value_len);
tc_tailor(dest, dest_len, sha1_value, sha1_value_len);
return 1;
}
示例6: block_out
static void block_out(BIO* b)
{
BIO_OK_CTX *ctx;
EVP_MD_CTX *md;
unsigned long tl;
ctx=(BIO_OK_CTX *)b->ptr;
md=&ctx->md;
tl= ctx->buf_len- OK_BLOCK_BLOCK;
ctx->buf[0]=(unsigned char)(tl>>24);
ctx->buf[1]=(unsigned char)(tl>>16);
ctx->buf[2]=(unsigned char)(tl>>8);
ctx->buf[3]=(unsigned char)(tl);
EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL);
ctx->buf_len+= md->digest->md_size;
ctx->blockout= 1;
}
示例7: BN_num_bytes
BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N)
{
/* k = SHA1(PAD(A) || PAD(B) ) -- tls-srp draft 8 */
BIGNUM *u = NULL;
unsigned char cu[SHA_DIGEST_LENGTH];
unsigned char *cAB = NULL;
EVP_MD_CTX *ctxt = NULL;
int longN;
if ((A == NULL) || (B == NULL) || (N == NULL))
return NULL;
if (BN_ucmp(A, N) >= 0 || BN_ucmp(B, N) >= 0)
return NULL;
longN = BN_num_bytes(N);
ctxt = EVP_MD_CTX_new();
if (ctxt == NULL)
return NULL;
if ((cAB = OPENSSL_malloc(2 * longN)) == NULL)
goto err;
memset(cAB, 0, longN);
EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(A, cAB + longN), longN);
EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(B, cAB + longN), longN);
OPENSSL_free(cAB);
EVP_DigestFinal_ex(ctxt, cu, NULL);
if ((u = BN_bin2bn(cu, sizeof(cu), NULL)) == NULL)
goto err;
if (BN_is_zero(u)) {
BN_free(u);
u = NULL;
}
err:
EVP_MD_CTX_free(ctxt);
return u;
}
示例8: digest_fdigest
static int digest_fdigest(lua_State *L)
{
const char *type_name = luaL_checkstring(L, 2);
const EVP_MD *type = EVP_get_digestbyname(type_name);
const char *s = luaL_checkstring(L, 3);
unsigned char digest[EVP_MAX_MD_SIZE];
unsigned int written = 0;
EVP_MD_CTX *c;
if (type == NULL) {
luaL_argerror(L, 1, "invalid digest type");
return 0;
}
c = EVP_MD_CTX_create();
if (!EVP_DigestInit_ex(c, type, NULL)) {
EVP_MD_CTX_destroy(c);
return crypto_error(L);
}
if (!EVP_DigestUpdate(c, s, lua_strlen(L, 3))) {
EVP_MD_CTX_destroy(c);
return crypto_error(L);
}
if (!EVP_DigestFinal_ex(c, digest, &written)) {
EVP_MD_CTX_destroy(c);
return crypto_error(L);
}
EVP_MD_CTX_destroy(c);
if (lua_toboolean(L, 4))
lua_pushlstring(L, (char *)digest, written);
else {
char *hex = (char*)calloc(sizeof(char), written*2 + 1);
unsigned int i;
for (i = 0; i < written; i++)
sprintf(hex + 2*i, "%02x", digest[i]);
lua_pushlstring(L, hex, written*2);
free(hex);
}
return 1;
}
示例9: EVP_DigestSignFinal
int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
{
int sctx, r = 0;
if (ctx->pctx->pmeth->signctx)
sctx = 1;
else
sctx = 0;
if (sigret)
{
EVP_MD_CTX tmp_ctx;
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen;
EVP_MD_CTX_init(&tmp_ctx);
if (!EVP_MD_CTX_copy_ex(&tmp_ctx,ctx))
return 0;
if (sctx)
r = tmp_ctx.pctx->pmeth->signctx(tmp_ctx.pctx,
sigret, siglen, &tmp_ctx);
else
r = EVP_DigestFinal_ex(&tmp_ctx,md,&mdlen);
EVP_MD_CTX_cleanup(&tmp_ctx);
if (sctx || !r)
return r;
if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0)
return 0;
}
else
{
if (sctx)
{
if (ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx) <= 0)
return 0;
}
else
{
int s = EVP_MD_size(ctx->digest);
if (s < 0 || EVP_PKEY_sign(ctx->pctx, sigret, siglen, NULL, s) <= 0)
return 0;
}
}
return 1;
}
示例10: cms_DigestedData_do_final
int
cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify)
{
EVP_MD_CTX mctx;
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen;
int r = 0;
CMS_DigestedData *dd;
EVP_MD_CTX_init(&mctx);
dd = cms->d.digestedData;
if (!cms_DigestAlgorithm_find_ctx(&mctx, chain, dd->digestAlgorithm))
goto err;
if (EVP_DigestFinal_ex(&mctx, md, &mdlen) <= 0)
goto err;
if (verify) {
if (mdlen != (unsigned int)dd->digest->length) {
CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
CMS_R_MESSAGEDIGEST_WRONG_LENGTH);
goto err;
}
if (memcmp(md, dd->digest->data, mdlen))
CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
CMS_R_VERIFICATION_FAILURE);
else
r = 1;
} else {
if (!ASN1_STRING_set(dd->digest, md, mdlen))
goto err;
r = 1;
}
err:
EVP_MD_CTX_cleanup(&mctx);
return r;
}
示例11: openssl_evp_digest
void openssl_evp_digest()
{
EVP_MD_CTX mdctx;
unsigned int md_len, i;
char author[] = "beike";
char msg[] = "openssl digest";
unsigned char md_value[EVP_MAX_MD_SIZE];
OpenSSL_add_all_algorithms();
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, EVP_md5(), NULL);
EVP_DigestUpdate(&mdctx, msg, strlen(msg));
EVP_DigestUpdate(&mdctx, author, strlen(author));
EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
printf("\nEVP_Digest(%s, %s) = ", msg, author);
for (i = 0; i < md_len; i++)
printf("0x%02x ", md_value[i]);
printf("\n");
EVP_MD_CTX_cleanup(&mdctx);
}
示例12: digest_MD5_util
int
digest_MD5_util(char * input, char * output_t) {
EVP_MD_CTX mdctx;
const EVP_MD *md;
int output_len;
unsigned char output[EVP_MAX_MD_SIZE];
OpenSSL_add_all_digests();
md = EVP_get_digestbyname("MD5");
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md, NULL);
EVP_DigestUpdate(&mdctx, input, strlen(input));
EVP_DigestFinal_ex(&mdctx, output, &output_len);
EVP_MD_CTX_cleanup(&mdctx);
strncpy(output_t, output, output_len);
output_t[output_len + 1] = 0;
return output_len;
}
示例13: Crypto_Digest_Hash
char * Crypto_Digest_Hash (int count, char * algoName, char * data) {
count = count;
EVP_MD_CTX mdctx;
const EVP_MD *md;
unsigned char md_value [EVP_MAX_MD_SIZE];
unsigned int md_len;
OpenSSL_add_all_digests ();
md = EVP_get_digestbyname (algoName);
if (!md) return "";
EVP_MD_CTX_init (&mdctx);
EVP_DigestInit_ex (&mdctx, md, NULL);
EVP_DigestUpdate (&mdctx, data, strlen (data));
EVP_DigestFinal_ex (&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup (&mdctx);
return Crypto_Digest_MakeHexDigest (md_value, md_len);
}
示例14: EVP_DigestSignFinal
int EVP_DigestSignFinal(EVP_MD_CTX *ctx, uint8_t *out_sig,
size_t *out_sig_len) {
if (out_sig) {
EVP_MD_CTX tmp_ctx;
int ret;
uint8_t md[EVP_MAX_MD_SIZE];
unsigned int mdlen;
EVP_MD_CTX_init(&tmp_ctx);
ret = EVP_MD_CTX_copy_ex(&tmp_ctx, ctx) &&
EVP_DigestFinal_ex(&tmp_ctx, md, &mdlen) &&
EVP_PKEY_sign(ctx->pctx, out_sig, out_sig_len, md, mdlen);
EVP_MD_CTX_cleanup(&tmp_ctx);
return ret;
} else {
size_t s = EVP_MD_size(ctx->digest);
return EVP_PKEY_sign(ctx->pctx, out_sig, out_sig_len, NULL, s);
}
}
示例15: getHash
/*****************get the Hash value with sha256****************************/
void getHash(char *msg, int len, char *hash) {
EVP_MD_CTX *mdctx;
const EVP_MD *md;
size_t md_len, i;
unsigned char md_value[EVP_MAX_MD_SIZE];
char hashname[] = "sha256";
OpenSSL_add_all_digests();
md = EVP_get_digestbyname(hashname);
if(!md) {
printf("Unknown message digest %s\n", hashname);
exit(1);
}
mdctx = EVP_MD_CTX_create();
EVP_DigestInit_ex(mdctx, md, NULL);
EVP_DigestUpdate(mdctx, msg, len);
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
EVP_MD_CTX_destroy(mdctx);
memcpy(hash, md_value, HASHLEN);
}