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

C++ HMAC_CTX_cleanup函数代码示例

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

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



在下文中一共展示了HMAC_CTX_cleanup函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 );
}
开发者ID:jkorkean,项目名称:greencontrol,代码行数:15,代码来源:hmac.cpp


示例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;
}
开发者ID:GarysRefererence2014,项目名称:SoftHSMv2,代码行数:24,代码来源:OSSLEVPMacAlgorithm.cpp


示例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));
}
开发者ID:Arcenciel,项目名称:DDReader,代码行数:15,代码来源:hmac.c


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


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


示例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;

}
开发者ID:zhuzhu9910,项目名称:AcademicProjects,代码行数:17,代码来源:utilities.c


示例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);
}
开发者ID:kazt81,项目名称:cryptodev-linux,代码行数:17,代码来源:threshold.c


示例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);
}
开发者ID:AlessioLeo,项目名称:FreeRDP,代码行数:17,代码来源:ntlm_compute.c


示例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;
}
开发者ID:SibghatullahSheikh,项目名称:mediaproxy-ng,代码行数:18,代码来源:crypto.c


示例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);
}
开发者ID:gotomypc,项目名称:tiny-webrtc-gw,代码行数:17,代码来源:p_hmac.c


示例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;
 }
开发者ID:WilliamRen,项目名称:simple-rtmp-server,代码行数:51,代码来源:srs_protocol_handshake.cpp


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


示例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;
}
开发者ID:CrazyCaptian,项目名称:Test,代码行数:20,代码来源:kclient.cpp


示例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;
}
开发者ID:bitpick,项目名称:coreboot,代码行数:24,代码来源:crypto.c


示例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;
}
开发者ID:colemickens,项目名称:FreeRDP,代码行数:18,代码来源:hash.c


示例16: throw

void Hmac::init(ByteArray &key, MessageDigest::Algorithm algorithm, Engine &engine) throw (HmacException) {
	if (this->state != Hmac::NO_INIT)
	{
		HMAC_CTX_cleanup( &this->ctx );
	}
	HMAC_CTX_init( &this->ctx );

	this->algorithm = algorithm;
	const EVP_MD *md = MessageDigest::getMessageDigest( this->algorithm );
	int rc = HMAC_Init_ex( &this->ctx, (void*)key.getDataPointer(), key.size(), md, engine.getEngine() );
	if (!rc)
	{
		this->state = Hmac::NO_INIT;
		throw HmacException(HmacException::CTX_INIT, "Hmac::init");
	}

	this->state = Hmac::INIT;
}
开发者ID:GNakayama,项目名称:libcryptosec,代码行数:18,代码来源:Hmac.cpp


示例17: hmac_sha256

void hmac_sha256(uint8_t* key, uint32_t key_length,
                 uint8_t* data_chunks[],
                 uint32_t data_chunck_length[],
                 uint8_t* mac, uint32_t* mac_length )
{
    unsigned int tmp;
    HMAC_CTX ctx;
    HMAC_CTX_init( &ctx );
    HMAC_Init_ex( &ctx, key, key_length, EVP_sha256(), NULL );
    while( *data_chunks ){
      HMAC_Update( &ctx, *data_chunks, *data_chunck_length );
      data_chunks ++;
      data_chunck_length ++;
    }
    HMAC_Final( &ctx, mac, &tmp);
    *mac_length = tmp;
    HMAC_CTX_cleanup( &ctx );
}
开发者ID:AGProjects,项目名称:python-sipsimple,代码行数:18,代码来源:hmac256.cpp


示例18: decrypt_esp_packet

/* pkt->len shall be the *payload* length. Omitting the header and the 12-byte HMAC */
int decrypt_esp_packet(struct openconnect_info *vpninfo, struct esp *esp, struct pkt *pkt)
{
	unsigned char hmac_buf[20];
	unsigned int hmac_len = sizeof(hmac_buf);
	int crypt_len = pkt->len;
	HMAC_CTX hmac_ctx;

	HMAC_CTX_copy(&hmac_ctx, &esp->hmac);
	HMAC_Update(&hmac_ctx, (void *)&pkt->esp, sizeof(pkt->esp) + pkt->len);
	HMAC_Final(&hmac_ctx, hmac_buf, &hmac_len);
	HMAC_CTX_cleanup(&hmac_ctx);

	if (memcmp(hmac_buf, pkt->data + pkt->len, 12)) {
		vpn_progress(vpninfo, PRG_DEBUG,
			     _("Received ESP packet with invalid HMAC\n"));
		return -EINVAL;
	}

	/* Why in $DEITY's name would you ever *not* set this? Perhaps we
	 * should do th check anyway, but only warn instead of discarding
	 * the packet? */
	if (vpninfo->esp_replay_protect &&
	    verify_packet_seqno(vpninfo, esp, ntohl(pkt->esp.seq)))
		return -EINVAL;


	if (!EVP_DecryptInit_ex(&esp->cipher, NULL, NULL, NULL,
				pkt->esp.iv)) {
		vpn_progress(vpninfo, PRG_ERR,
			     _("Failed to set up decryption context for ESP packet:\n"));
		openconnect_report_ssl_errors(vpninfo);
		return -EINVAL;
	}

	if (!EVP_DecryptUpdate(&esp->cipher, pkt->data, &crypt_len,
			       pkt->data, pkt->len)) {
		vpn_progress(vpninfo, PRG_ERR,
			     _("Failed to decrypt ESP packet:\n"));
		openconnect_report_ssl_errors(vpninfo);
		return -EINVAL;
	}

	return 0;
}
开发者ID:atyndall,项目名称:openconnect,代码行数:45,代码来源:openssl-esp.c


示例19: 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");
}
开发者ID:allenway,项目名称:onvif,代码行数:55,代码来源:smdevp.c


示例20: build_packet

static int build_packet(char *buffer, const char *metric)
{
	HMAC_CTX ctx;
	struct timespec now;
	uint64_t timestamp;
	uint32_t nonce;
	unsigned int hmac_len;
	int metric_len = strlen(metric);

	RAND_pseudo_bytes((void *)&nonce, sizeof(nonce));
	clock_gettime(CLOCK_REALTIME, &now);
	timestamp = (uint64_t)now.tv_sec - 2; /* fake delay */

	HMAC_CTX_init(&ctx);
	HMAC_Init_ex(&ctx, HMAC_KEY, strlen(HMAC_KEY), EVP_sha256(), NULL);

	HMAC_Update(&ctx, (void *)&timestamp, sizeof(timestamp));
	HMAC_Update(&ctx, (void *)&nonce, sizeof(nonce));
	HMAC_Update(&ctx, (void *)metric, metric_len);

	HMAC_Final(&ctx, buffer, &hmac_len);

	HMAC_CTX_cleanup(&ctx);

	memcpy(buffer + SHA_SIZE, &timestamp, sizeof(timestamp));
	memcpy(buffer + SHA_SIZE + 8, &nonce, sizeof(nonce));
	memcpy(buffer + SHA_SIZE + 12, metric, metric_len);

#ifdef DEBUG
	{
		int i;

		fprintf(stderr, "HMAC: ");
		for (i = 0; i < SHA_SIZE; ++i)
			fprintf(stderr, "%02x", (unsigned char)buffer[i]);

		fprintf(stderr, "\nTIMESTAMP: %llu\nNONCE: %08x\nMETRIC: %s\n",
			(long long unsigned int)timestamp, nonce, metric);
	}
#endif

	return SHA_SIZE + 12 + metric_len;
}
开发者ID:IonicaBizauKitchen,项目名称:brubeck,代码行数:43,代码来源:statsd-secure-send.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ HMAC_CTX_init函数代码示例发布时间:2022-05-30
下一篇:
C++ HMAC函数代码示例发布时间: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