本文整理汇总了C++中HMAC_CTX_cleanup函数的典型用法代码示例。如果您正苦于以下问题:C++ HMAC_CTX_cleanup函数的具体用法?C++ HMAC_CTX_cleanup怎么用?C++ HMAC_CTX_cleanup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HMAC_CTX_cleanup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hmac_sha1
void hmac_sha1( uint8_t* key, int32_t key_length,
const uint8_t* data_chunks[],
uint32_t data_chunck_length[],
uint8_t* mac, int32_t* mac_length ) {
HMAC_CTX ctx;
HMAC_CTX_init( &ctx );
HMAC_Init_ex( &ctx, key, key_length, EVP_sha1(), NULL );
while ( *data_chunks ) {
HMAC_Update( &ctx, *data_chunks, *data_chunck_length );
data_chunks ++;
data_chunck_length ++;
}
HMAC_Final( &ctx, mac, reinterpret_cast<uint32_t*>(mac_length) );
HMAC_CTX_cleanup( &ctx );
}
示例2: EVP_MD_size
bool OSSLEVPMacAlgorithm::verifyFinal(ByteString& signature)
{
if (!MacAlgorithm::verifyFinal(signature))
{
return false;
}
ByteString macResult;
unsigned int outLen = EVP_MD_size(getEVPHash());
macResult.resize(outLen);
if (!HMAC_Final(&curCTX, &macResult[0], &outLen))
{
ERROR_MSG("HMAC_Final failed");
HMAC_CTX_cleanup(&curCTX);
return false;
}
HMAC_CTX_cleanup(&curCTX);
return macResult == signature;
}
示例3: xmlSecOpenSSLHmacFinalize
static void
xmlSecOpenSSLHmacFinalize(xmlSecTransformPtr transform) {
xmlSecOpenSSLHmacCtxPtr ctx;
xmlSecAssert(xmlSecOpenSSLHmacCheckId(transform));
xmlSecAssert(xmlSecTransformCheckSize(transform, xmlSecOpenSSLHmacSize));
ctx = xmlSecOpenSSLHmacGetCtx(transform);
xmlSecAssert(ctx != NULL);
#ifndef XMLSEC_OPENSSL_096
HMAC_CTX_cleanup(&(ctx->hmacCtx));
#endif /* XMLSEC_OPENSSL_096 */
memset(ctx, 0, sizeof(xmlSecOpenSSLHmacCtx));
}
示例4: encrypt_esp_packet
int encrypt_esp_packet(struct openconnect_info *vpninfo, struct pkt *pkt)
{
int i, padlen;
const int blksize = 16;
unsigned int hmac_len = 20;
int crypt_len;
HMAC_CTX hmac_ctx;
/* This gets much more fun if the IV is variable-length */
pkt->esp.spi = vpninfo->esp_out.spi;
pkt->esp.seq = htonl(vpninfo->esp_out.seq++);
if (!RAND_bytes((void *)&pkt->esp.iv, sizeof(pkt->esp.iv))) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to generate random IV for ESP packet:\n"));
openconnect_report_ssl_errors(vpninfo);
return -EIO;
}
padlen = blksize - 1 - ((pkt->len + 1) % blksize);
for (i=0; i<padlen; i++)
pkt->data[pkt->len + i] = i + 1;
pkt->data[pkt->len + padlen] = padlen;
pkt->data[pkt->len + padlen + 1] = 0x04; /* Legacy IP */
if (!EVP_EncryptInit_ex(&vpninfo->esp_out.cipher, NULL, NULL, NULL,
pkt->esp.iv)) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to set up encryption context for ESP packet:\n"));
openconnect_report_ssl_errors(vpninfo);
return -EINVAL;
}
crypt_len = pkt->len + padlen + 2;
if (!EVP_EncryptUpdate(&vpninfo->esp_out.cipher, pkt->data, &crypt_len,
pkt->data, crypt_len)) {
vpn_progress(vpninfo, PRG_ERR,
_("Failed to encrypt ESP packet:\n"));
openconnect_report_ssl_errors(vpninfo);
return -EINVAL;
}
HMAC_CTX_copy(&hmac_ctx, &vpninfo->esp_out.hmac);
HMAC_Update(&hmac_ctx, (void *)&pkt->esp, sizeof(pkt->esp) + crypt_len);
HMAC_Final(&hmac_ctx, pkt->data + crypt_len, &hmac_len);
HMAC_CTX_cleanup(&hmac_ctx);
return sizeof(pkt->esp) + crypt_len + 12;
}
示例5: 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 err = 1;
if (buf)
{ /* finalize the digest or signature computation */
switch (data->alg & (SOAP_SMD_PASSTHRU-1))
{ case SOAP_SMD_DGST_MD5:
case SOAP_SMD_DGST_SHA1:
case SOAP_SMD_DGST_SHA256:
EVP_DigestFinal((EVP_MD_CTX*)data->ctx, (unsigned char*)buf, &n);
break;
case SOAP_SMD_HMAC_SHA1:
HMAC_Final((HMAC_CTX*)data->ctx, (unsigned char*)buf, &n);
break;
case SOAP_SMD_SIGN_DSA_SHA1:
case SOAP_SMD_SIGN_RSA_SHA1:
case SOAP_SMD_SIGN_RSA_SHA256:
err = EVP_SignFinal((EVP_MD_CTX*)data->ctx, (unsigned char*)buf, &n, (EVP_PKEY*)data->key);
break;
case SOAP_SMD_VRFY_DSA_SHA1:
case SOAP_SMD_VRFY_RSA_SHA1:
if (len)
{ n = (unsigned int)*len;
err = EVP_VerifyFinal((EVP_MD_CTX*)data->ctx, (unsigned char*)buf, n, (EVP_PKEY*)data->key);
}
else
err = 0;
break;
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "-- SMD Final alg=%d (%p) %d bytes--\n", data->alg, data->ctx, n));
DBGHEX(TEST, buf, n);
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n--"));
/* return length of digest or signature produced */
if (len)
*len = (int)n;
}
/* cleanup and free the HMAC or EVP_MD context */
if ((data->alg & (SOAP_SMD_PASSTHRU-1)) == SOAP_SMD_HMAC_SHA1)
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, err, "soap_smd_final() failed");
}
示例6: getHMACSHA256
int getHMACSHA256(char *msg, unsigned char* md_value, int len, unsigned char key[], int keylen)
{
HMAC_CTX mdctx;
int md_len;
const EVP_MD *md;
OpenSSL_add_all_digests();
md = EVP_get_digestbyname("sha256");
HMAC_CTX_init(&mdctx);
HMAC_Init_ex(&mdctx,key,keylen,md,NULL);
HMAC_Update(&mdctx, msg, len);
HMAC_Final(&mdctx, md_value, &md_len);
HMAC_CTX_cleanup(&mdctx);
return md_len;
}
示例7: aes_sha_combo
void aes_sha_combo(void* ctx, void* plaintext, void* ciphertext, int size, void* tag)
{
uint8_t iv[16];
AES_KEY* key = ctx;
HMAC_CTX hctx;
unsigned int rlen = 20;
HMAC_CTX_init(&hctx);
HMAC_Init_ex(&hctx, iv, 16, EVP_sha1(), NULL);
HMAC_Update(&hctx, plaintext, size);
HMAC_Final(&hctx, tag, &rlen);
HMAC_CTX_cleanup(&hctx);
AES_cbc_encrypt(plaintext, ciphertext, size, key, iv, 1);
}
示例8: ntlm_compute_message_integrity_check
void ntlm_compute_message_integrity_check(NTLM_CONTEXT* context)
{
HMAC_CTX hmac_ctx;
/*
* Compute the HMAC-MD5 hash of ConcatenationOf(NEGOTIATE_MESSAGE,
* CHALLENGE_MESSAGE, AUTHENTICATE_MESSAGE) using the ExportedSessionKey
*/
HMAC_CTX_init(&hmac_ctx);
HMAC_Init_ex(&hmac_ctx, context->ExportedSessionKey, 16, EVP_md5(), NULL);
HMAC_Update(&hmac_ctx, context->NegotiateMessage.pvBuffer, context->NegotiateMessage.cbBuffer);
HMAC_Update(&hmac_ctx, context->ChallengeMessage.pvBuffer, context->ChallengeMessage.cbBuffer);
HMAC_Update(&hmac_ctx, context->AuthenticateMessage.pvBuffer, context->AuthenticateMessage.cbBuffer);
HMAC_Final(&hmac_ctx, context->MessageIntegrityCheck, NULL);
HMAC_CTX_cleanup(&hmac_ctx);
}
示例9: hmac_sha1_rtp
/* rfc 3711, sections 4.2 and 4.2.1 */
static int hmac_sha1_rtp(struct crypto_context *c, char *out, str *in, u_int64_t index) {
unsigned char hmac[20];
HMAC_CTX hc;
u_int32_t roc;
HMAC_Init(&hc, c->session_auth_key, c->crypto_suite->srtp_auth_key_len, EVP_sha1());
HMAC_Update(&hc, (unsigned char *) in->s, in->len);
roc = htonl((index & 0xffffffff0000ULL) >> 16);
HMAC_Update(&hc, (unsigned char *) &roc, sizeof(roc));
HMAC_Final(&hc, hmac, NULL);
HMAC_CTX_cleanup(&hc);
assert(sizeof(hmac) >= c->crypto_suite->srtp_auth_tag);
memcpy(out, hmac, c->crypto_suite->srtp_auth_tag);
return 0;
}
示例10: pkey_hmac_cleanup
static void pkey_hmac_cleanup(EVP_PKEY_CTX *ctx) {
HMAC_PKEY_CTX *hctx = ctx->data;
if (hctx == NULL) {
return;
}
HMAC_CTX_cleanup(&hctx->ctx);
if (hctx->ktmp.data) {
if (hctx->ktmp.length) {
OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length);
}
OPENSSL_free(hctx->ktmp.data);
hctx->ktmp.data = NULL;
}
OPENSSL_free(hctx);
}
示例11: openssl_HMACsha256
/**
* sha256 digest algorithm.
* @param key the sha256 key, NULL to use EVP_Digest, for instance,
* hashlib.sha256(data).digest().
*/
int openssl_HMACsha256(const void* key, int key_size, const void* data, int data_size, void* digest)
{
int ret = ERROR_SUCCESS;
unsigned int digest_size = 0;
unsigned char* __key = (unsigned char*)key;
unsigned char* __digest = (unsigned char*)digest;
if (key == NULL) {
// use data to digest.
// @see ./crypto/sha/sha256t.c
// @see ./crypto/evp/digest.c
if (EVP_Digest(data, data_size, __digest, &digest_size, EVP_sha256(), NULL) < 0)
{
ret = ERROR_OpenSslSha256EvpDigest;
return ret;
}
} else {
// use key-data to digest.
HMAC_CTX ctx;
// @remark, if no key, use EVP_Digest to digest,
// for instance, in python, hashlib.sha256(data).digest().
HMAC_CTX_init(&ctx);
if (HMAC_Init_ex(&ctx, __key, key_size, EVP_sha256(), NULL) < 0) {
ret = ERROR_OpenSslSha256Init;
return ret;
}
ret = __openssl_HMACsha256(&ctx, data, data_size, __digest, &digest_size);
HMAC_CTX_cleanup(&ctx);
if (ret != ERROR_SUCCESS) {
return ret;
}
}
if (digest_size != 32) {
ret = ERROR_OpenSslSha256DigestSize;
return ret;
}
return ret;
}
示例12: compute_file_hmac
static int compute_file_hmac(const char *path, void **buf, size_t *hmaclen)
{
FILE *f = NULL;
int rv = -1;
unsigned char rbuf[READ_BUFFER_LENGTH];
size_t len;
unsigned int hlen;
HMAC_CTX c;
HMAC_CTX_init(&c);
f = fopen(path, "r");
if (f == NULL) {
goto end;
}
HMAC_Init(&c, hmackey, sizeof(hmackey) - 1, EVP_sha256());
while ((len = fread(rbuf, 1, sizeof(rbuf), f)) != 0) {
HMAC_Update(&c, rbuf, len);
}
len = sizeof(rbuf);
/* reuse rbuf for hmac */
HMAC_Final(&c, rbuf, &hlen);
*buf = malloc(hlen);
if (*buf == NULL) {
goto end;
}
*hmaclen = hlen;
memcpy(*buf, rbuf, hlen);
rv = 0;
end:
HMAC_CTX_cleanup(&c);
if (f)
fclose(f);
return rv;
}
示例13: hmac_sha512
//------------------------------------------------------------------------------
// helper function to hash with HMAC algorithm:
static std::vector<unsigned char>
hmac_sha512(const std::vector<unsigned char>& data,
const std::vector<unsigned char>& key)
{
unsigned int len = EVP_MAX_MD_SIZE;
std::vector<unsigned char> digest(len);
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key.data(), key.size(), EVP_sha512(), NULL);
HMAC_Update(&ctx, data.data(), data.size());
HMAC_Final(&ctx, digest.data(), &len);
HMAC_CTX_cleanup(&ctx);
return digest;
}
示例14: HmacSha256Hash
/*----------------------------------------------------------------------
* Name : HmacSha256Hash
* Purpose :
* Input : none
* Output : none
*---------------------------------------------------------------------*/
int HmacSha256Hash(uint8_t *data, uint32_t len, uint8_t *hash, uint8_t *key)
{
HMAC_CTX hctx;
HMAC_CTX_init(&hctx);
HMAC_Init_ex(&hctx, key, 32, EVP_sha256(), NULL);
/*
* FIXME: why we need this? NULL means to use whatever there is?
* if removed, result is different
*/
HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
HMAC_Update(&hctx, data, len);
HMAC_Final(&hctx, hash, NULL);
HMAC_CTX_cleanup(&hctx);
return 0;
}
示例15: winpr_HMAC_Final
int winpr_HMAC_Final(WINPR_HMAC_CTX* ctx, BYTE* output)
{
#if defined(WITH_OPENSSL)
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
HMAC_Final((HMAC_CTX*) ctx, output, NULL);
#else
if (HMAC_Final((HMAC_CTX*) ctx, output, NULL) != 1)
return -1;
#endif
HMAC_CTX_cleanup((HMAC_CTX*) ctx);
#elif defined(WITH_MBEDTLS)
if (mbedtls_md_hmac_finish((mbedtls_md_context_t*) ctx, output) != 0)
return -1;
mbedtls_md_free((mbedtls_md_context_t*) ctx);
#endif
return 0;
}