本文整理汇总了C++中HMAC_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ HMAC_Init函数的具体用法?C++ HMAC_Init怎么用?C++ HMAC_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HMAC_Init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: hmac_init
HMACCTX hmac_init(const void *key, int len, int type) {
HMACCTX ctx = NULL;
ctx = malloc(sizeof(*ctx));
if (ctx == NULL) {
return NULL;
}
#ifndef OLD_CRYPTO
HMAC_CTX_init(ctx); // openssl 0.9.7 requires it.
#endif
switch(type) {
case HMAC_SHA1:
HMAC_Init(ctx, key, len, EVP_sha1());
break;
case HMAC_MD5:
HMAC_Init(ctx, key, len, EVP_md5());
break;
default:
SAFE_FREE(ctx);
ctx = NULL;
}
return ctx;
}
开发者ID:BackupTheBerlios,项目名称:libssh-svn,代码行数:26,代码来源:wrapper.c
示例2: sftp_mac_set_read_key
int sftp_mac_set_read_key(pool *p, const EVP_MD *hash, const BIGNUM *k,
const char *h, uint32_t hlen) {
const unsigned char *id = NULL;
char *buf, *ptr;
uint32_t buflen, bufsz, id_len;
char letter;
size_t blocksz;
struct sftp_mac *mac;
HMAC_CTX *mac_ctx;
switch_read_mac();
mac = &(read_macs[read_mac_idx]);
mac_ctx = &(read_ctxs[read_mac_idx]);
bufsz = buflen = 1024;
ptr = buf = sftp_msg_getbuf(p, bufsz);
/* Need to use SSH2-style format of K for the key. */
sftp_msg_write_mpint(&buf, &buflen, k);
id_len = sftp_session_get_id(&id);
/* HASH(K || H || "E" || session_id) */
letter = 'E';
set_mac_key(mac, hash, ptr, (bufsz - buflen), h, hlen, &letter, id, id_len);
#if OPENSSL_VERSION_NUMBER > 0x000907000L
HMAC_CTX_init(mac_ctx);
# if OPENSSL_VERSION_NUMBER >= 0x10000001L
if (HMAC_Init_ex(mac_ctx, mac->key, mac->key_len, mac->digest, NULL) != 1) {
pr_log_writefile(sftp_logfd, MOD_SFTP_VERSION,
"error initializing HMAC: %s", sftp_crypto_get_errors());
errno = EPERM;
return -1;
}
# else
HMAC_Init_ex(mac_ctx, mac->key, mac->key_len, mac->digest, NULL);
# endif /* OpenSSL-1.0.0 and later */
#else
/* Reset the HMAC context. */
HMAC_Init(mac_ctx, NULL, 0, NULL);
HMAC_Init(mac_ctx, mac->key, mac->key_len, mac->digest);
#endif
if (mac->mac_len == 0) {
blocksz = EVP_MD_size(mac->digest);
} else {
blocksz = mac->mac_len;
}
pr_memscrub(ptr, bufsz);
sftp_mac_set_block_size(blocksz);
return 0;
}
开发者ID:Distrotech,项目名称:proftpd,代码行数:59,代码来源:mac.c
示例3: isc_hmacmd5_init
void
isc_hmacmd5_init(isc_hmacmd5_t *ctx, const unsigned char *key,
unsigned int len)
{
#ifdef HMAC_RETURN_INT
RUNTIME_CHECK(HMAC_Init(ctx, (const void *) key,
(int) len, EVP_md5()) == 1);
#else
HMAC_Init(ctx, (const void *) key, (int) len, EVP_md5());
#endif
}
开发者ID:execunix,项目名称:vinos,代码行数:11,代码来源:hmacmd5.c
示例4: HDW_generate_master_node
int HDW_generate_master_node(uint8_t *seed,
size_t seed_len,
HDW_XKEY_NET net,
HDW_xkey_t *key) {
int res;
HMAC_CTX hmac_ctx;
res = HMAC_Init(&hmac_ctx, BIP32_SPEC_DEFAULT_KEY, (int) strlen(BIP32_SPEC_DEFAULT_KEY), EVP_sha512());
if (!res) {
fprintf(stderr, "Could not HMAC_Init\n");
return res;
}
res = HMAC_Update(&hmac_ctx, seed, seed_len);
if (!res) {
fprintf(stderr, "Could not HMAC_Update\n");
goto cleanup_hmac_context;
}
uint8_t master_digest[SHA512_DIGEST_LENGTH];
uint32_t digest_len;
res = HMAC_Final(&hmac_ctx, master_digest, &digest_len);
if (digest_len != SHA512_DIGEST_LENGTH) {
// Oh ho, we might have smashed the stack :( . Abort everything!
// This should not happen at all.
fprintf(stderr, "Big problem at %s%d\n", __FILE__, __LINE__);
exit(-1);
}
if (!res) {
fprintf(stderr, "Could not HMAC_Final\n");
goto cleanup_hmac_context;
}
size_t half_hash_len = SHA512_DIGEST_LENGTH / 2;
memcpy(key->version, KEY_VERSIONS_VALUES[net | HDW_XKEY_TYPE_PRIVATE], sizeof(key->version));
// Copy the L and R part into the key.
key->key_data[0] = 0;
memcpy(key->key_data + 1, master_digest, half_hash_len);
memcpy(key->chain_code, master_digest + half_hash_len, half_hash_len);
// Set the rest of the data as master key.
key->depth = (uint8_t) 0;
memset(key->parent_fingerprint, 0, sizeof(key->parent_fingerprint));
memset(key->child_number, 0, sizeof(key->child_number));
cleanup_hmac_context:
HMAC_CTX_cleanup(&hmac_ctx);
return res;
}
开发者ID:marctrem,项目名称:BIP32c,代码行数:60,代码来源:hdwallet.c
示例5: mz_crypt_hmac_init
int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length)
{
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
int32_t result = 0;
const EVP_MD *evp_md = NULL;
if (hmac == NULL || key == NULL)
return MZ_PARAM_ERROR;
mz_crypt_hmac_reset(handle);
hmac->ctx = HMAC_CTX_new();
if (hmac->algorithm == MZ_HASH_SHA1)
evp_md = EVP_sha1();
else
evp_md = EVP_sha256();
result = HMAC_Init(hmac->ctx, key, key_length, evp_md);
if (!result)
{
hmac->error = ERR_get_error();
return MZ_HASH_ERROR;
}
return MZ_OK;
}
开发者ID:mschmieder,项目名称:minizip,代码行数:26,代码来源:mz_crypt_openssl.c
示例6: insert_message_authenticator
static void
insert_message_authenticator(struct rad_handle *h, int resp)
{
#ifdef WITH_SSL
u_char md[EVP_MAX_MD_SIZE];
u_int md_len;
const struct rad_server *srvp;
HMAC_CTX ctx;
srvp = &h->servers[h->srv];
if (h->authentic_pos != 0) {
HMAC_CTX_init(&ctx);
HMAC_Init(&ctx, srvp->secret, strlen(srvp->secret), EVP_md5());
HMAC_Update(&ctx, &h->out[POS_CODE], POS_AUTH - POS_CODE);
if (resp)
HMAC_Update(&ctx, &h->in[POS_AUTH], LEN_AUTH);
else
HMAC_Update(&ctx, &h->out[POS_AUTH], LEN_AUTH);
HMAC_Update(&ctx, &h->out[POS_ATTRS],
h->out_len - POS_ATTRS);
HMAC_Final(&ctx, md, &md_len);
HMAC_CTX_cleanup(&ctx);
HMAC_cleanup(&ctx);
memcpy(&h->out[h->authentic_pos + 2], md, md_len);
}
#endif
}
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:27,代码来源:radlib.c
示例7: __hmac_sha1_init
static int
__hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
{
HMAC_CTX_init(ctx);
HMAC_Init(ctx, key, key_len, EVP_sha1());
return 0;
}
开发者ID:DimitryAndric,项目名称:libarchive,代码行数:7,代码来源:archive_hmac.c
示例8: HMAC_CTX_init
// Signing functions
bool OSSLEVPMacAlgorithm::signInit(const SymmetricKey* key)
{
// Call the superclass initialiser
if (!MacAlgorithm::signInit(key))
{
return false;
}
// Initialize the context
HMAC_CTX_init(&curCTX);
// Initialize EVP signing
if (!HMAC_Init(&curCTX, key->getKeyBits().const_byte_str(), key->getKeyBits().size(), getEVPHash()))
{
ERROR_MSG("HMAC_Init failed");
HMAC_CTX_cleanup(&curCTX);
ByteString dummy;
MacAlgorithm::signFinal(dummy);
return false;
}
return true;
}
开发者ID:GarysRefererence2014,项目名称:SoftHSMv2,代码行数:27,代码来源:OSSLEVPMacAlgorithm.cpp
示例9: H_Init
/* The random function H(x) = HMAC-SHA256(0^32, x) */
void H_Init(HMAC_CTX *ctx)
{
u8 allzero[SHA256_DIGEST_LENGTH];
os_memset(allzero, 0, SHA256_DIGEST_LENGTH);
HMAC_Init(ctx, allzero, SHA256_DIGEST_LENGTH, EVP_sha256());
}
开发者ID:avchinch,项目名称:hostap-1,代码行数:8,代码来源:eap_pwd_common.c
示例10: openssl_hmac_md5
void openssl_hmac_md5()
{
int fd, size;
unsigned int len;
HMAC_CTX hmac_ctx;
char file_name[COMM_LEN], inputs[COMM_LEN];
unsigned char tmps[LINE_LEN], outputs[EVP_MAX_MD_SIZE];
memset(tmps, 0, sizeof(tmps));
memset(inputs, 0, sizeof(inputs));
memset(outputs, 0, sizeof(outputs));
printf("\nPlease input a file name: ");
scanf("%s", file_name);
fd = open(file_name, O_RDONLY);
if (fd < 0)
return;
OpenSSL_add_all_digests();
strcpy(inputs, "hmac_md5");
HMAC_Init(&hmac_ctx, inputs, sizeof(inputs), EVP_get_digestbyname("md5"));
while ((size = read(fd, tmps, LINE_LEN)) > 0)
HMAC_Update(&hmac_ctx, tmps, size);
HMAC_Final(&hmac_ctx, outputs, &len);
HMAC_cleanup(&hmac_ctx);
close(fd);
printf("HMAC_MD5(%s, %s) = ", file_name, inputs);
for (size = 0; size < len; size++)
printf("%02x", outputs[size]);
printf("\n");
}
开发者ID:beike2020,项目名称:source,代码行数:31,代码来源:openssl_base.c
示例11: mac_compute
int
mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen,
u_char *digest, size_t dlen)
{
static u_char m[MAC_DIGEST_LEN_MAX];
u_char b[4], nonce[8];
if (mac->mac_len > sizeof(m))
return SSH_ERR_INTERNAL_ERROR;
switch (mac->type) {
case SSH_EVP:
POKE_U32(b, seqno);
/* reset HMAC context */
if (HMAC_Init(&mac->evp_ctx, NULL, 0, NULL) != 1 ||
HMAC_Update(&mac->evp_ctx, b, sizeof(b)) != 1 ||
HMAC_Update(&mac->evp_ctx, data, datalen) != 1 ||
HMAC_Final(&mac->evp_ctx, m, NULL) != 1)
return SSH_ERR_LIBCRYPTO_ERROR;
break;
case SSH_UMAC:
POKE_U64(nonce, seqno);
umac_update(mac->umac_ctx, data, datalen);
umac_final(mac->umac_ctx, m, nonce);
break;
default:
return SSH_ERR_INVALID_ARGUMENT;
}
if (digest != NULL) {
if (dlen > mac->mac_len)
dlen = mac->mac_len;
memcpy(digest, m, dlen);
}
return 0;
}
开发者ID:mpitzl,项目名称:libopenssh,代码行数:35,代码来源:mac.c
示例12: mac_compute
u_char *
mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen)
{
static u_char m[EVP_MAX_MD_SIZE];
u_char b[4];
if (mac->mac_len > sizeof(m))
fatal("mac_compute: mac too long %u %lu",
mac->mac_len, (u_long)sizeof(m));
switch (mac->type) {
case SSH_EVP:
put_u32(b, seqno);
/* reset HMAC context */
HMAC_Init(&mac->evp_ctx, NULL, 0, NULL);
HMAC_Update(&mac->evp_ctx, b, sizeof(b));
HMAC_Update(&mac->evp_ctx, data, datalen);
HMAC_Final(&mac->evp_ctx, m, NULL);
break;
default:
fatal("mac_compute: unknown MAC type");
}
return (m);
}
开发者ID:AlfredArouna,项目名称:illumos-gate,代码行数:25,代码来源:mac.c
示例13: mac_init
int
mac_init(struct sshmac *mac)
{
if (mac->key == NULL)
return SSH_ERR_INVALID_ARGUMENT;
switch (mac->type) {
case SSH_EVP:
if (mac->evp_md == NULL)
return SSH_ERR_INVALID_ARGUMENT;
HMAC_CTX_init(&mac->evp_ctx);
if (HMAC_Init(&mac->evp_ctx, mac->key, mac->key_len,
mac->evp_md) != 1) {
HMAC_CTX_cleanup(&mac->evp_ctx);
return SSH_ERR_LIBCRYPTO_ERROR;
}
return 0;
case SSH_UMAC:
if ((mac->umac_ctx = umac_new(mac->key)) == NULL)
return SSH_ERR_ALLOC_FAIL;
return 0;
case SSH_UMAC128:
mac->umac_ctx = umac128_new(mac->key);
return 0;
default:
return SSH_ERR_INVALID_ARGUMENT;
}
}
开发者ID:hshoexer,项目名称:libopenssh,代码行数:27,代码来源:mac.c
示例14: soap_smd_init
/**
@fn int soap_smd_init(struct soap *soap, struct soap_smd_data *data, int alg, const void *key, int keylen)
@brief Initiates a (signed) digest computation.
@param soap context
@param[in,out] data smdevp engine context
@param[in] alg is algorithm to use
@param[in] key is key to use or NULL for digests
@param[in] keylen is length of HMAC key (when provided)
@return SOAP_OK or SOAP_SSL_ERROR
*/
int
soap_smd_init(struct soap *soap, struct soap_smd_data *data, int alg, const void *key, int keylen)
{ static int done = 0;
int err = 1;
#ifdef WITH_OPENSSL
/* OpenSSL: make sure we have the digest algorithms, need to call just once */
if (!done)
{ done = 1;
OpenSSL_add_all_digests();
OpenSSL_add_all_algorithms();
}
#endif
/* the algorithm to use */
data->alg = alg;
/* the key to use */
data->key = key;
/* allocate and init the OpenSSL HMAC or EVP_MD context */
if ((alg & (SOAP_SMD_PASSTHRU-1)) == SOAP_SMD_HMAC_SHA1)
{ data->ctx = (void*)SOAP_MALLOC(soap, sizeof(HMAC_CTX));
HMAC_CTX_init((HMAC_CTX*)data->ctx);
}
else
{ data->ctx = (void*)SOAP_MALLOC(soap, sizeof(EVP_MD_CTX));
EVP_MD_CTX_init((EVP_MD_CTX*)data->ctx);
}
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "-- SMD Init alg=%d (%p) --\n", alg, data->ctx));
/* init the digest or signature computations */
switch (alg & (SOAP_SMD_PASSTHRU-1))
{ case SOAP_SMD_DGST_MD5:
EVP_DigestInit((EVP_MD_CTX*)data->ctx, EVP_md5());
break;
case SOAP_SMD_DGST_SHA1:
EVP_DigestInit((EVP_MD_CTX*)data->ctx, EVP_sha1());
break;
case SOAP_SMD_DGST_SHA256:
EVP_DigestInit((EVP_MD_CTX*)data->ctx, EVP_sha256());
break;
case SOAP_SMD_HMAC_SHA1:
HMAC_Init((HMAC_CTX*)data->ctx, key, keylen, EVP_sha1());
break;
case SOAP_SMD_SIGN_DSA_SHA1:
err = EVP_SignInit((EVP_MD_CTX*)data->ctx, EVP_dss1());
break;
case SOAP_SMD_SIGN_RSA_SHA1:
err = EVP_SignInit((EVP_MD_CTX*)data->ctx, EVP_sha1());
break;
case SOAP_SMD_SIGN_RSA_SHA256:
err = EVP_SignInit((EVP_MD_CTX*)data->ctx, EVP_sha256());
break;
case SOAP_SMD_VRFY_DSA_SHA1:
err = EVP_VerifyInit((EVP_MD_CTX*)data->ctx, EVP_dss1());
break;
case SOAP_SMD_VRFY_RSA_SHA1:
err = EVP_VerifyInit((EVP_MD_CTX*)data->ctx, EVP_sha1());
break;
}
/* check and return */
return soap_smd_check(soap, data, err, "soap_smd_init() failed");
}
开发者ID:abidinz,项目名称:Stormee,代码行数:69,代码来源:smdevp.c
示例15: hmac
QByteArray SSH2MAC::mac(const QByteArray & data)
{
QByteArray hmac(m_macLen, 0);
HMAC_Init(m_ctx, (const uint8_t*) m_key.data(), m_keyLen, m_evptype);
HMAC_Update(m_ctx, (const uint8_t *) data.data(), data.size());
HMAC_Final(m_ctx, (uint8_t *) hmac.data(), NULL);
return hmac;
}
开发者ID:adaptee,项目名称:qterm-hack,代码行数:8,代码来源:transport.cpp
示例16: H_Init
/* The random function H(x) = HMAC-SHA256(0^32, x) */
static void
H_Init(HMAC_CTX *ctx)
{
uint8_t allzero[SHA256_DIGEST_LENGTH];
memset(allzero, 0, SHA256_DIGEST_LENGTH);
HMAC_Init(ctx, allzero, SHA256_DIGEST_LENGTH, EVP_sha256());
}
开发者ID:p11235,项目名称:freeradius-server,代码行数:9,代码来源:eap_pwd.c
示例17: auth_cram_md5
/*
* Authenticate to the server with the Challenge-Response Authentication
* Mechanism (CRAM). The authentication type associated with CRAM is
* "CRAM-MD5".
*/
int
auth_cram_md5(session *ssn, const char *user, const char *pass)
{
int t;
size_t n;
unsigned int i;
unsigned char *chal, *resp, *out, *buf;
unsigned char md[EVP_MAX_MD_SIZE], mdhex[EVP_MAX_MD_SIZE * 2 + 1];
unsigned int mdlen;
HMAC_CTX hmac;
if ((t = imap_authenticate(ssn, "CRAM-MD5")) == -1)
return -1;
if (response_authenticate(ssn, t, &chal) ==
STATUS_RESPONSE_CONTINUE) {
n = strlen((char *)(chal)) * 3 / 4 + 1;
resp = (unsigned char *)xmalloc(n * sizeof(char));
memset(resp, 0, n);
EVP_DecodeBlock(resp, chal, strlen((char *)(chal)));
HMAC_Init(&hmac, (const unsigned char *)pass, strlen(pass),
EVP_md5());
HMAC_Update(&hmac, resp, strlen((char *)(resp)));
HMAC_Final(&hmac, md, &mdlen);
xfree(chal);
xfree(resp);
for (i = 0; i < mdlen; i++)
snprintf((char *)(mdhex) + i * 2, mdlen * 2 - i * 2 + 1,
"%02x", md[i]);
mdhex[mdlen * 2] = '\0';
n = strlen(user) + 1 + strlen((char *)(mdhex)) + 1;
buf = (unsigned char *)xmalloc(n * sizeof(unsigned char));
memset(buf, 0, n);
snprintf((char *)(buf), n, "%s %s", user, mdhex);
n = (strlen((char *)(buf)) + 3) * 4 / 3 + 1;
out = (unsigned char *)xmalloc(n * sizeof(unsigned char));
memset(out, 0, n);
EVP_EncodeBlock(out, buf, strlen((char *)(buf)));
imap_continuation(ssn, (char *)(out), strlen((char *)(out)));
xfree(buf);
xfree(out);
} else
return -1;
return response_authenticate(ssn, t, NULL);
}
开发者ID:laszlo,项目名称:imapfilter,代码行数:61,代码来源:auth.c
示例18: _sol_message_digest_hmac_init
static int
_sol_message_digest_hmac_init(struct sol_message_digest *handle, const EVP_MD *md, const struct sol_str_slice key)
{
HMAC_CTX *ctx = sol_message_digest_common_get_context(handle);
if (HMAC_Init(ctx, key.data, key.len, md))
return 0;
return -EINVAL;
}
开发者ID:thiagomacieira,项目名称:soletta,代码行数:10,代码来源:sol-message-digest-impl-openssl.c
示例19: tls1_P_hash
static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec,
int sec_len, unsigned char *seed, int seed_len,
unsigned char *out, int olen)
{
int chunk,n;
unsigned int j;
HMAC_CTX ctx;
HMAC_CTX ctx_tmp;
unsigned char A1[HMAC_MAX_MD_CBLOCK];
unsigned int A1_len;
chunk=EVP_MD_size(md);
HMAC_Init(&ctx,sec,sec_len,md);
HMAC_Update(&ctx,seed,seed_len);
HMAC_Final(&ctx,A1,&A1_len);
n=0;
for (;;)
{
HMAC_Init(&ctx,NULL,0,NULL); /* re-init */
HMAC_Update(&ctx,A1,A1_len);
memcpy(&ctx_tmp,&ctx,sizeof(ctx)); /* Copy for A2 */ /* not needed for last one */
HMAC_Update(&ctx,seed,seed_len);
if (olen > chunk)
{
HMAC_Final(&ctx,out,&j);
out+=j;
olen-=j;
HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */
}
else /* last one */
{
HMAC_Final(&ctx,A1,&A1_len);
memcpy(out,A1,olen);
break;
}
}
HMAC_cleanup(&ctx);
HMAC_cleanup(&ctx_tmp);
memset(A1,0,sizeof(A1));
}
开发者ID:jhbsz,项目名称:actiontec_opensource_mi424wr-rev-acd-56-0-10-14-4,代码行数:43,代码来源:t1_enc.c
示例20: tls_hash
static int
tls_hash(StringInfo* secret, StringInfo* seed, const EVP_MD *md, StringInfo* out)
{
uint8_t *ptr;
unsigned int left;
int tocpy;
uint8_t *A;
uint8_t _A[48],tmp[48];
unsigned int A_l,tmp_l;
HMAC_CTX ctx;
ptr = out->data;
left = out->data_len;
ssl_print_string("tls_hash: hash secret", secret);
ssl_print_string("tls_hash: hash seed", seed);
A=seed->data;
A_l=seed->data_len;
while(left){
HMAC_CTX_init(&ctx);
HMAC_Init(&ctx, secret->data, secret->data_len, md);
HMAC_Update(&ctx,A,A_l);
HMAC_Final(&ctx,_A,&A_l);
HMAC_cleanup(&ctx);
A=_A;
HMAC_CTX_init(&ctx);
HMAC_Init(&ctx,secret->data,secret->data_len,md);
HMAC_Update(&ctx,A,A_l);
HMAC_Update(&ctx,seed->data,seed->data_len);
HMAC_Final(&ctx,tmp,&tmp_l);
HMAC_cleanup(&ctx);
tocpy=std::min(left,tmp_l);
memcpy(ptr,tmp,tocpy);
ptr+=tocpy;
left-=tocpy;
}
ssl_print_string("hash out", out);
return (0);
}
开发者ID:3a9LL,项目名称:panda,代码行数:42,代码来源:tls_prf.cpp
注:本文中的HMAC_Init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论