• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ EVP_MD_CTX_free函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了EVP_MD_CTX_free函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ERROR_MSG

bool OSSLEVPHashAlgorithm::hashFinal(ByteString& hashedData)
{
	if (!HashAlgorithm::hashFinal(hashedData))
	{
		return false;
	}

	hashedData.resize(EVP_MD_size(getEVPHash()));
	unsigned int outLen = hashedData.size();

	if (!EVP_DigestFinal_ex(curCTX, &hashedData[0], &outLen))
	{
		ERROR_MSG("EVP_DigestFinal failed");

		EVP_MD_CTX_free(curCTX);
		curCTX = NULL;

		return false;
	}

	hashedData.resize(outLen);

	EVP_MD_CTX_free(curCTX);
	curCTX = NULL;

	return true;
}
开发者ID:bellgrim,项目名称:SoftHSMv2,代码行数:27,代码来源:OSSLEVPHashAlgorithm.cpp


示例2: _libssh2_sha1

int
_libssh2_sha1(const unsigned char *message, unsigned long len,
              unsigned char *out)
{
#ifdef HAVE_OPAQUE_STRUCTS
    EVP_MD_CTX * ctx = EVP_MD_CTX_new();

    if(ctx == NULL)
        return 1; /* error */

    if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"))) {
        EVP_DigestUpdate(ctx, message, len);
        EVP_DigestFinal(ctx, out, NULL);
        EVP_MD_CTX_free(ctx);
        return 0; /* success */
    }
    EVP_MD_CTX_free(ctx);
#else
    EVP_MD_CTX ctx;

    EVP_MD_CTX_init(&ctx);
    if(EVP_DigestInit(&ctx, EVP_get_digestbyname("sha1"))) {
        EVP_DigestUpdate(&ctx, message, len);
        EVP_DigestFinal(&ctx, out, NULL);
        return 0; /* success */
    }
#endif
    return 1; /* error */
}
开发者ID:stinb,项目名称:libssh2,代码行数:29,代码来源:openssl.c


示例3: ssl3_generate_key_block

static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
{
    EVP_MD_CTX *m5;
    EVP_MD_CTX *s1;
    unsigned char buf[16], smd[SHA_DIGEST_LENGTH];
    unsigned char c = 'A';
    unsigned int i, j, k;
    int ret = 0;

#ifdef CHARSET_EBCDIC
    c = os_toascii[c];          /* 'A' in ASCII */
#endif
    k = 0;
    m5 = EVP_MD_CTX_new();
    s1 = EVP_MD_CTX_new();
    if (m5 == NULL || s1 == NULL) {
        SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    EVP_MD_CTX_set_flags(m5, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
    for (i = 0; (int)i < num; i += MD5_DIGEST_LENGTH) {
        k++;
        if (k > sizeof buf) {
            /* bug: 'buf' is too small for this ciphersuite */
            SSLerr(SSL_F_SSL3_GENERATE_KEY_BLOCK, ERR_R_INTERNAL_ERROR);
            return 0;
        }

        for (j = 0; j < k; j++)
            buf[j] = c;
        c++;
        EVP_DigestInit_ex(s1, EVP_sha1(), NULL);
        EVP_DigestUpdate(s1, buf, k);
        EVP_DigestUpdate(s1, s->session->master_key,
                         s->session->master_key_length);
        EVP_DigestUpdate(s1, s->s3->server_random, SSL3_RANDOM_SIZE);
        EVP_DigestUpdate(s1, s->s3->client_random, SSL3_RANDOM_SIZE);
        EVP_DigestFinal_ex(s1, smd, NULL);

        EVP_DigestInit_ex(m5, EVP_md5(), NULL);
        EVP_DigestUpdate(m5, s->session->master_key,
                         s->session->master_key_length);
        EVP_DigestUpdate(m5, smd, SHA_DIGEST_LENGTH);
        if ((int)(i + MD5_DIGEST_LENGTH) > num) {
            EVP_DigestFinal_ex(m5, smd, NULL);
            memcpy(km, smd, (num - i));
        } else
            EVP_DigestFinal_ex(m5, km, NULL);

        km += MD5_DIGEST_LENGTH;
    }
    OPENSSL_cleanse(smd, sizeof(smd));
    ret = 1;
 err:
    EVP_MD_CTX_free(m5);
    EVP_MD_CTX_free(s1);
    return ret;
}
开发者ID:DeqiangSun,项目名称:openssl,代码行数:58,代码来源:s3_enc.c


示例4: HSM_OPENSSL_sign

PKI_MEM * HSM_OPENSSL_sign(PKI_MEM *der, PKI_DIGEST_ALG *digest, PKI_X509_KEYPAIR *key)
{

	EVP_MD_CTX *ctx = NULL;
	size_t out_size = 0;
	size_t ossl_ret = 0;

	PKI_MEM *out_mem = NULL;
	EVP_PKEY *pkey = NULL;

	if (!der || !der->data || !key || !key->value)
	{
		PKI_ERROR( PKI_ERR_PARAM_NULL, NULL);
		return NULL;
	}

	// Private Key
	pkey = key->value;

	// Get the Maximum size of a signature
	ossl_ret = out_size = (size_t) EVP_PKEY_size(pkey);

	// Initialize the return structure
	out_mem = PKI_MEM_new ((size_t)out_size);
	ctx = EVP_MD_CTX_new();

	if (!out_mem || !ctx) {
		if (ctx) EVP_MD_CTX_free(ctx);
		if (out_mem) PKI_MEM_free(out_mem);
		PKI_ERROR( PKI_ERR_MEMORY_ALLOC, NULL);
		return NULL;
	}

	EVP_MD_CTX_init(ctx);
	EVP_SignInit_ex(ctx, digest, NULL);
	EVP_SignUpdate (ctx, der->data, der->size);

	// Finalize the signature
	if (!EVP_SignFinal(ctx, out_mem->data, (unsigned int *) &ossl_ret, pkey))
	{
		PKI_log_err("ERROR while finalizing signature (%s)", 
			HSM_OPENSSL_get_errdesc(HSM_OPENSSL_get_errno(), NULL, 0));

		PKI_MEM_free(out_mem);
		out_mem = NULL;
	}
	else out_mem->size = (size_t) ossl_ret;

	// Cleanup the context
#if OPENSSL_VERSION_NUMBER <= 0x1010000f
	EVP_MD_CTX_cleanup(ctx);
#else
	EVP_MD_CTX_reset(ctx);
#endif
	EVP_MD_CTX_free(ctx);

	return out_mem;
}
开发者ID:openca,项目名称:libpki,代码行数:58,代码来源:openssl_hsm.c


示例5: HMAC_CTX_free

void HMAC_CTX_free(HMAC_CTX *ctx)
{
    if (ctx != NULL) {
        hmac_ctx_cleanup(ctx);
        EVP_MD_CTX_free(ctx->i_ctx);
        EVP_MD_CTX_free(ctx->o_ctx);
        EVP_MD_CTX_free(ctx->md_ctx);
        OPENSSL_free(ctx);
    }
}
开发者ID:skaligotla,项目名称:openssl,代码行数:10,代码来源:hmac.c


示例6: test_EVP_DigestSignInit

static int test_EVP_DigestSignInit(void)
{
    int ret = 0;
    EVP_PKEY *pkey = NULL;
    unsigned char *sig = NULL;
    size_t sig_len = 0;
    EVP_MD_CTX *md_ctx, *md_ctx_verify;

    md_ctx = EVP_MD_CTX_new();
    md_ctx_verify = EVP_MD_CTX_new();
    if (md_ctx == NULL || md_ctx_verify == NULL)
        goto out;

    pkey = load_example_rsa_key();
    if (pkey == NULL ||
        !EVP_DigestSignInit(md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
        !EVP_DigestSignUpdate(md_ctx, kMsg, sizeof(kMsg))) {
        goto out;
    }
    /* Determine the size of the signature. */
    if (!EVP_DigestSignFinal(md_ctx, NULL, &sig_len)) {
        goto out;
    }
    /* Sanity check for testing. */
    if (sig_len != (size_t)EVP_PKEY_size(pkey)) {
        fprintf(stderr, "sig_len mismatch\n");
        goto out;
    }

    sig = OPENSSL_malloc(sig_len);
    if (sig == NULL || !EVP_DigestSignFinal(md_ctx, sig, &sig_len)) {
        goto out;
    }

    /* Ensure that the signature round-trips. */
    if (!EVP_DigestVerifyInit(md_ctx_verify, NULL, EVP_sha256(), NULL, pkey)
        || !EVP_DigestVerifyUpdate(md_ctx_verify, kMsg, sizeof(kMsg))
        || !EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len)) {
        goto out;
    }

    ret = 1;

 out:
    if (!ret) {
        ERR_print_errors_fp(stderr);
    }

    EVP_MD_CTX_free(md_ctx);
    EVP_MD_CTX_free(md_ctx_verify);
    EVP_PKEY_free(pkey);
    OPENSSL_free(sig);

    return ret;
}
开发者ID:erbridge,项目名称:openssl,代码行数:55,代码来源:evp_extra_test.c


示例7: EVP_MD_CTX_new

BIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass)
{
    unsigned char dig[SHA_DIGEST_LENGTH];
    EVP_MD_CTX *ctxt;
    unsigned char *cs;
    BIGNUM *res = NULL;

    if ((s == NULL) || (user == NULL) || (pass == NULL))
        return NULL;

    ctxt = EVP_MD_CTX_new();
    if (ctxt == NULL)
        return NULL;
    if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL)
        goto err;

    EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
    EVP_DigestUpdate(ctxt, user, strlen(user));
    EVP_DigestUpdate(ctxt, ":", 1);
    EVP_DigestUpdate(ctxt, pass, strlen(pass));
    EVP_DigestFinal_ex(ctxt, dig, NULL);

    EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
    BN_bn2bin(s, cs);
    EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s));
    OPENSSL_free(cs);
    EVP_DigestUpdate(ctxt, dig, sizeof(dig));
    EVP_DigestFinal_ex(ctxt, dig, NULL);

    res = BN_bin2bn(dig, sizeof(dig), NULL);
 err:
    EVP_MD_CTX_free(ctxt);
    return res;
}
开发者ID:AndreV84,项目名称:openssl,代码行数:34,代码来源:srp_lib.c


示例8: EVP_DigestVerifyFinal

int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig,
                          size_t siglen)
{
    unsigned char md[EVP_MAX_MD_SIZE];
    int r = 0;
    unsigned int mdlen = 0;
    int vctx = 0;

    if (ctx->pctx->pmeth->verifyctx)
        vctx = 1;
    else
        vctx = 0;
    if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
        if (vctx) {
            r = ctx->pctx->pmeth->verifyctx(ctx->pctx, sig, siglen, ctx);
        } else
            r = EVP_DigestFinal_ex(ctx, md, &mdlen);
    } else {
        EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
        if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
            return -1;
        if (vctx) {
            r = tmp_ctx->pctx->pmeth->verifyctx(tmp_ctx->pctx,
                                                sig, siglen, tmp_ctx);
        } else
            r = EVP_DigestFinal_ex(tmp_ctx, md, &mdlen);
        EVP_MD_CTX_free(tmp_ctx);
    }
    if (vctx || !r)
        return r;
    return EVP_PKEY_verify(ctx->pctx, sig, siglen, md, mdlen);
}
开发者ID:AndreV84,项目名称:openssl,代码行数:32,代码来源:m_sigver.c


示例9: _md_cleanup

static int
_md_cleanup (md_ctx *x)
{
    int rv = 0;

    assert (x != NULL);
    assert (x->ctx != NULL);

#if HAVE_EVP_MD_CTX_FREE
    /*  OpenSSL >= 1.1.0  */
    EVP_MD_CTX_free (x->ctx);
#elif HAVE_EVP_MD_CTX_DESTROY
    /*  OpenSSL >= 0.9.7, < 1.1.0  */
    EVP_MD_CTX_destroy (x->ctx);
#else  /* !HAVE_EVP_MD_CTX_DESTROY */
#if HAVE_EVP_MD_CTX_CLEANUP
    /*  OpenSSL >= 0.9.7, < 1.1.0  */
    if (EVP_MD_CTX_cleanup (x->ctx) != 1) {
        rv = -1;
    }
#endif /* HAVE_EVP_MD_CTX_CLEANUP */
    OPENSSL_free (x->ctx);
#endif /* !HAVE_EVP_MD_CTX_DESTROY */

    x->ctx = NULL;
    return (rv);
}
开发者ID:dun,项目名称:munge,代码行数:27,代码来源:md.c


示例10: tls13_final_finish_mac

/*
 * Generates the mac for the Finished message. Returns the length of the MAC or
 * 0 on error.
 */
size_t tls13_final_finish_mac(SSL *s, const char *str, size_t slen,
                             unsigned char *out)
{
    const EVP_MD *md = ssl_handshake_md(s);
    unsigned char hash[EVP_MAX_MD_SIZE];
    size_t hashlen, ret = 0;
    EVP_PKEY *key = NULL;
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();

    if (!ssl_handshake_hash(s, hash, sizeof(hash), &hashlen))
        goto err;

    if (str == s->method->ssl3_enc->server_finished_label)
        key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
                                   s->server_finished_secret, hashlen);
    else
        key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
                                   s->client_finished_secret, hashlen);

    if (key == NULL
            || ctx == NULL
            || EVP_DigestSignInit(ctx, NULL, md, NULL, key) <= 0
            || EVP_DigestSignUpdate(ctx, hash, hashlen) <= 0
            || EVP_DigestSignFinal(ctx, out, &hashlen) <= 0)
        goto err;

    ret = hashlen;
 err:
    EVP_PKEY_free(key);
    EVP_MD_CTX_free(ctx);
    return ret;
}
开发者ID:G-P-S,项目名称:openssl,代码行数:36,代码来源:tls13_enc.c


示例11: test_mdc2

static int test_mdc2(void)
{
    int testresult = 0;
    unsigned char md[MDC2_DIGEST_LENGTH];
    EVP_MD_CTX *c;
    static char text[] = "Now is the time for all ";
    size_t tlen = strlen(text);

# ifdef CHARSET_EBCDIC
    ebcdic2ascii(text, text, tlen);
# endif

    c = EVP_MD_CTX_new();
    if (!TEST_ptr(c)
        || !TEST_true(EVP_DigestInit_ex(c, EVP_mdc2(), NULL))
        || !TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
        || !TEST_true(EVP_DigestFinal_ex(c, &(md[0]), NULL))
        || !TEST_mem_eq(md, MDC2_DIGEST_LENGTH, pad1, MDC2_DIGEST_LENGTH)
        || !TEST_true(EVP_DigestInit_ex(c, EVP_mdc2(), NULL)))
        goto end;

    /* FIXME: use a ctl function? */
    ((MDC2_CTX *)EVP_MD_CTX_md_data(c))->pad_type = 2;
    if (!TEST_true(EVP_DigestUpdate(c, (unsigned char *)text, tlen))
        || !TEST_true(EVP_DigestFinal_ex(c, &(md[0]), NULL))
        || !TEST_mem_eq(md, MDC2_DIGEST_LENGTH, pad2, MDC2_DIGEST_LENGTH))
        goto end;

    testresult = 1;
 end:
    EVP_MD_CTX_free(c);
    return testresult;
}
开发者ID:Vonage,项目名称:openssl,代码行数:33,代码来源:mdc2test.c


示例12: X509_issuer_and_serial_hash

unsigned long X509_issuer_and_serial_hash(X509 *a)
{
    unsigned long ret = 0;
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    unsigned char md[16];
    char *f;

    if (ctx == NULL)
        goto err;
    f = X509_NAME_oneline(a->cert_info.issuer, NULL, 0);
    if (!EVP_DigestInit_ex(ctx, EVP_md5(), NULL))
        goto err;
    if (!EVP_DigestUpdate(ctx, (unsigned char *)f, strlen(f)))
        goto err;
    OPENSSL_free(f);
    if (!EVP_DigestUpdate
        (ctx, (unsigned char *)a->cert_info.serialNumber.data,
         (unsigned long)a->cert_info.serialNumber.length))
        goto err;
    if (!EVP_DigestFinal_ex(ctx, &(md[0]), NULL))
        goto err;
    ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |
           ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)
        ) & 0xffffffffL;
 err:
    EVP_MD_CTX_free(ctx);
    return (ret);
}
开发者ID:1234-,项目名称:openssl,代码行数:28,代码来源:x509_cmp.c


示例13: EVP_MD_CTX_new

// Hashing functions
bool OSSLEVPHashAlgorithm::hashInit()
{
	if (!HashAlgorithm::hashInit())
	{
		return false;
	}

	// Initialize the context
	curCTX = EVP_MD_CTX_new();
	if (curCTX == NULL)
	{
		ERROR_MSG("Failed to allocate space for EVP_MD_CTX");

		return false;
	}

	// Initialize EVP digesting
	if (!EVP_DigestInit_ex(curCTX, getEVPHash(), NULL))
	{
		ERROR_MSG("EVP_DigestInit failed");

		EVP_MD_CTX_free(curCTX);
		curCTX = NULL;

		ByteString dummy;
		HashAlgorithm::hashFinal(dummy);

		return false;
	}

	return true;
}
开发者ID:bellgrim,项目名称:SoftHSMv2,代码行数:33,代码来源:OSSLEVPHashAlgorithm.cpp


示例14: EVP_hexdigest

static PyObject *
EVP_hexdigest(EVPobject *self, PyObject *unused)
{
    unsigned char digest[EVP_MAX_MD_SIZE];
    EVP_MD_CTX *temp_ctx;
    unsigned int digest_size;

    temp_ctx = EVP_MD_CTX_new();
    if (temp_ctx == NULL) {
        PyErr_NoMemory();
        return NULL;
    }

    /* Get the raw (binary) digest value */
    if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
        return _setException(PyExc_ValueError);
    }
    digest_size = EVP_MD_CTX_size(temp_ctx);
    if (!EVP_DigestFinal(temp_ctx, digest, NULL)) {
        _setException(PyExc_ValueError);
        return NULL;
    }

    EVP_MD_CTX_free(temp_ctx);

    return _Py_strhex((const char *)digest, digest_size);
}
开发者ID:M31MOTH,项目名称:cpython,代码行数:27,代码来源:_hashopenssl.c


示例15: crypto_sign

/* NOTE: Caller must xfree the signature returned by sig_pp */
extern int
crypto_sign(void * key, char *buffer, int buf_size, char **sig_pp,
		unsigned int *sig_size_p)
{
	EVP_MD_CTX    *ectx;
	int           rc    = SLURM_SUCCESS;
	int           ksize = EVP_PKEY_size((EVP_PKEY *) key);

	/*
	 * Allocate memory for signature: at most EVP_PKEY_size() bytes
	 */
	*sig_pp = xmalloc(ksize * sizeof(unsigned char));

	ectx = EVP_MD_CTX_new();

	EVP_SignInit(ectx, EVP_sha1());
	EVP_SignUpdate(ectx, buffer, buf_size);

	if (!(EVP_SignFinal(ectx, (unsigned char *)*sig_pp, sig_size_p,
			(EVP_PKEY *) key))) {
		rc = SLURM_ERROR;
	}

	EVP_MD_CTX_free(ectx);

	return rc;
}
开发者ID:HPCNow,项目名称:slurm,代码行数:28,代码来源:crypto_openssl.c


示例16: EVP_digest

static PyObject *
EVP_digest(EVPobject *self, PyObject *unused)
{
    unsigned char digest[EVP_MAX_MD_SIZE];
    EVP_MD_CTX *temp_ctx;
    PyObject *retval;
    unsigned int digest_size;

    temp_ctx = EVP_MD_CTX_new();
    if (temp_ctx == NULL) {
        PyErr_NoMemory();
        return NULL;
    }

    if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
        return _setException(PyExc_ValueError);
    }
    digest_size = EVP_MD_CTX_size(temp_ctx);
    if (!EVP_DigestFinal(temp_ctx, digest, NULL)) {
        _setException(PyExc_ValueError);
        return NULL;
    }

    retval = PyBytes_FromStringAndSize((const char *)digest, digest_size);
    EVP_MD_CTX_free(temp_ctx);
    return retval;
}
开发者ID:M31MOTH,项目名称:cpython,代码行数:27,代码来源:_hashopenssl.c


示例17: ssl3_free_digest_list

void ssl3_free_digest_list(SSL *s)
{
    BIO_free(s->s3->handshake_buffer);
    s->s3->handshake_buffer = NULL;
    EVP_MD_CTX_free(s->s3->handshake_dgst);
    s->s3->handshake_dgst = NULL;
}
开发者ID:2007750219,项目名称:openssl,代码行数:7,代码来源:s3_enc.c


示例18: winpr_Digest_Free

void winpr_Digest_Free(WINPR_DIGEST_CTX* ctx)
{
#if defined(WITH_OPENSSL)
	EVP_MD_CTX* mdctx = (EVP_MD_CTX*) ctx;

	if (mdctx)
	{
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
		EVP_MD_CTX_destroy(mdctx);
#else
		EVP_MD_CTX_free(mdctx);
#endif
	}

#elif defined(WITH_MBEDTLS)
	mbedtls_md_context_t* mdctx = (mbedtls_md_context_t*) ctx;

	if (mdctx)
	{
		mbedtls_md_free(mdctx);
		free(mdctx);
	}

#endif
}
开发者ID:99455125,项目名称:FreeRDP,代码行数:25,代码来源:hash.c


示例19: test_EVP_DigestVerifyInit

static int test_EVP_DigestVerifyInit(void)
{
    int ret = 0;
    EVP_PKEY *pkey = NULL;
    EVP_MD_CTX *md_ctx;

    md_ctx = EVP_MD_CTX_new();

    pkey = load_example_rsa_key();
    if (pkey == NULL ||
        !EVP_DigestVerifyInit(md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
        !EVP_DigestVerifyUpdate(md_ctx, kMsg, sizeof(kMsg)) ||
        !EVP_DigestVerifyFinal(md_ctx, kSignature, sizeof(kSignature))) {
        goto out;
    }
    ret = 1;

 out:
    if (!ret) {
        ERR_print_errors_fp(stderr);
    }

    EVP_MD_CTX_free(md_ctx);
    EVP_PKEY_free(pkey);

    return ret;
}
开发者ID:erbridge,项目名称:openssl,代码行数:27,代码来源:evp_extra_test.c


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ EVP_MD_CTX_init函数代码示例发布时间:2022-05-30
下一篇:
C++ EVP_MD_CTX_destroy函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap