本文整理汇总了C++中HMAC_Update函数的典型用法代码示例。如果您正苦于以下问题:C++ HMAC_Update函数的具体用法?C++ HMAC_Update怎么用?C++ HMAC_Update使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HMAC_Update函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HMAC_CTX_init
uint8_t *HMAC(const EVP_MD *evp_md, const void *key, size_t key_len,
const uint8_t *data, size_t data_len, uint8_t *out,
unsigned int *out_len) {
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
if (!HMAC_Init_ex(&ctx, key, key_len, evp_md, NULL) ||
!HMAC_Update(&ctx, data, data_len) ||
!HMAC_Final(&ctx, out, out_len)) {
out = NULL;
}
HMAC_CTX_cleanup(&ctx);
return out;
}
示例2: hmac_fdigest
static int hmac_fdigest(lua_State *L)
{
HANDLER_HMAC c;
size_t written = 0;
const char *t = luaL_checkstring(L, 1);
size_t s_len;
const char *s = luaL_checklstring(L, 2, &s_len);
size_t k_len;
const char *k = luaL_checklstring(L, 3, &k_len);
DIGEST_TYPE type = DIGEST_BY_NAME(t);
#if CRYPTO_OPENSSL
unsigned char digest[EVP_MAX_MD_SIZE];
#elif CRYPTO_GCRYPT
unsigned char *digest;
#endif
if (IS_DIGEST_INVALID(type)) {
luaL_argerror(L, 1, "invalid digest type");
return 0;
}
#if CRYPTO_OPENSSL
HMAC_CTX_init(&c);
HMAC_Init_ex(&c, k, k_len, type, NULL);
HMAC_Update(&c, (unsigned char *)s, s_len);
HMAC_Final(&c, digest, &written);
#elif CRYPTO_GCRYPT
gcry_md_open(&c, type, GCRY_MD_FLAG_HMAC);
gcry_md_setkey(c, k, k_len);
gcry_md_write(c, s, s_len);
gcry_md_final(c);
digest = gcry_md_read(c,type);
written = gcry_md_get_algo_dlen(type);
#endif
if (lua_toboolean(L, 4))
lua_pushlstring(L, (char *)digest, written);
else
{
char *hex = bin2hex(digest,written);
lua_pushlstring(L, hex, written*2);
free(hex);
}
#if CRYPTO_GCRYPT
gcry_md_close(c);
#endif
return 1;
}
示例3: PKI_HMAC_update
int PKI_HMAC_update(PKI_HMAC *hmac, unsigned char *data, size_t data_size)
{
#if OPENSSL_VERSION_NUMBER > 0x0090900fL
int rv = 0;
#endif
if (!hmac || !hmac->initialized)
{
return PKI_ERROR(PKI_ERR_GENERAL, "PKI_HMAC is not initialized");
}
#if OPENSSL_VERSION_NUMBER > 0x0090900fL
rv = HMAC_Update(&hmac->ctx, (const unsigned char *) data, (unsigned int) data_size);
if (rv == 0)
{
return PKI_ERROR(PKI_ERR_GENERAL, "Error while updating the HMAC value");
}
#else
HMAC_Update(&hmac->ctx, (const unsigned char *) data, (unsigned int) data_size);
#endif
return PKI_OK;
}
示例4: dsa_update
int
dsa_update(struct iked_dsa *dsa, const void *buf, size_t len)
{
int ret = 1;
if (dsa->dsa_hmac)
ret = HMAC_Update(dsa->dsa_ctx, buf, len);
else if (dsa->dsa_sign)
ret = EVP_SignUpdate(dsa->dsa_ctx, buf, len);
else
ret = EVP_VerifyUpdate(dsa->dsa_ctx, buf, len);
return (ret ? 0 : -1);
}
示例5: P_hash
int
P_hash(const char *digest, unsigned char *dest, int dlen, unsigned char *secret, int sslen,
unsigned char *seed, int slen)
{
unsigned char hmac[20];
uint32_t hlen;
HMAC_CTX hm;
const EVP_MD *md = EVP_get_digestbyname(digest);
uint32_t tmpslen;
unsigned char tmpseed[slen];
unsigned char *out = dest;
int pending = dlen;
// Copy initial seed
memcpy(tmpseed, seed, slen);
tmpslen = slen;
// Calculate enough data to fill destination
while (pending > 0) {
HMAC_Init(&hm, secret, sslen, md);
HMAC_Update(&hm, tmpseed, tmpslen);
HMAC_Final(&hm, tmpseed, &tmpslen);
HMAC_Init(&hm, secret, sslen, md);
HMAC_Update(&hm, tmpseed, tmpslen);
HMAC_Update(&hm, seed, slen);
HMAC_Final(&hm, hmac, &hlen);
hlen = (hlen > pending) ? pending : hlen;
memcpy(out, hmac, hlen);
out += hlen;
pending -= hlen;
}
HMAC_cleanup(&hm);
return hlen;
}
示例6: sqlcipher_openssl_hmac
static int sqlcipher_openssl_hmac(void *ctx, int algorithm, unsigned char *hmac_key, int key_sz, unsigned char *in, int in_sz, unsigned char *in2, int in2_sz, unsigned char *out) {
unsigned int outlen;
int rc = SQLITE_OK;
HMAC_CTX* hctx = NULL;
if(in == NULL) goto error;
hctx = HMAC_CTX_new();
if(hctx == NULL) goto error;
switch(algorithm) {
case SQLCIPHER_HMAC_SHA1:
if(!HMAC_Init_ex(hctx, hmac_key, key_sz, EVP_sha1(), NULL)) goto error;
break;
case SQLCIPHER_HMAC_SHA256:
if(!HMAC_Init_ex(hctx, hmac_key, key_sz, EVP_sha256(), NULL)) goto error;
break;
case SQLCIPHER_HMAC_SHA512:
if(!HMAC_Init_ex(hctx, hmac_key, key_sz, EVP_sha512(), NULL)) goto error;
break;
default:
goto error;
}
if(!HMAC_Update(hctx, in, in_sz)) goto error;
if(in2 != NULL) {
if(!HMAC_Update(hctx, in2, in2_sz)) goto error;
}
if(!HMAC_Final(hctx, out, &outlen)) goto error;
goto cleanup;
error:
rc = SQLITE_ERROR;
cleanup:
if(hctx) HMAC_CTX_free(hctx);
return rc;
}
示例7: mac_compute
u_char *
mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen)
{
static union {
u_char m[EVP_MAX_MD_SIZE];
u_int64_t for_align;
} u;
u_char b[4], nonce[8];
if (mac->mac_len > sizeof(u))
fatal("mac_compute: mac too long %u %lu",
mac->mac_len, (u_long)sizeof(u));
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, u.m, NULL);
break;
case SSH_UMAC:
put_u64(nonce, seqno);
umac_update(mac->umac_ctx, data, datalen);
umac_final(mac->umac_ctx, u.m, nonce);
break;
case SSH_UMAC128:
put_u64(nonce, seqno);
umac128_update(mac->umac_ctx, data, datalen);
umac128_final(mac->umac_ctx, u.m, nonce);
break;
default:
fatal("mac_compute: unknown MAC type");
}
return (u.m);
}
示例8: eap_pwd_kdf
/* a counter-based KDF based on NIST SP800-108 */
static void eap_pwd_kdf(uint8_t *key, int keylen, char const *label, int labellen, uint8_t *result, int resultbitlen)
{
HMAC_CTX hctx;
uint8_t digest[SHA256_DIGEST_LENGTH];
uint16_t i, ctr, L;
int resultbytelen, len = 0;
unsigned int mdlen = SHA256_DIGEST_LENGTH;
uint8_t mask = 0xff;
resultbytelen = (resultbitlen + 7)/8;
ctr = 0;
L = htons(resultbitlen);
while (len < resultbytelen) {
ctr++; i = htons(ctr);
HMAC_Init(&hctx, key, keylen, EVP_sha256());
if (ctr > 1) {
HMAC_Update(&hctx, digest, mdlen);
}
HMAC_Update(&hctx, (uint8_t *) &i, sizeof(uint16_t));
HMAC_Update(&hctx, (uint8_t const *)label, labellen);
HMAC_Update(&hctx, (uint8_t *) &L, sizeof(uint16_t));
HMAC_Final(&hctx, digest, &mdlen);
if ((len + (int) mdlen) > resultbytelen) {
memcpy(result + len, digest, resultbytelen - len);
} else {
memcpy(result + len, digest, mdlen);
}
len += mdlen;
HMAC_CTX_cleanup(&hctx);
}
/* since we're expanding to a bit length, mask off the excess */
if (resultbitlen % 8) {
mask <<= (8 - (resultbitlen % 8));
result[resultbytelen - 1] &= mask;
}
}
示例9: _checksum_64
static uint64_t _checksum_64(encfs_common_custom_salt *cur_salt, unsigned char *key, const unsigned char *data, int dataLen, uint64_t *chainedIV)
{
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdLen = EVP_MAX_MD_SIZE;
int i;
unsigned char h[8] = {0,0,0,0,0,0,0,0};
uint64_t value;
HMAC_CTX mac_ctx;
HMAC_CTX_init(&mac_ctx);
HMAC_Init_ex( &mac_ctx, key, cur_salt->keySize, EVP_sha1(), 0 );
HMAC_Init_ex( &mac_ctx, 0, 0, 0, 0 );
HMAC_Update( &mac_ctx, data, dataLen );
if(chainedIV)
{
// toss in the chained IV as well
uint64_t tmp = *chainedIV;
unsigned char h[8];
for(i=0; i<8; ++i) {
h[i] = tmp & 0xff;
tmp >>= 8;
}
HMAC_Update( &mac_ctx, h, 8 );
}
HMAC_Final( &mac_ctx, md, &mdLen );
HMAC_CTX_cleanup(&mac_ctx);
// chop this down to a 64bit value..
for(i=0; i < (mdLen - 1); ++i)
h[i%8] ^= (unsigned char)(md[i]);
value = (uint64_t)h[0];
for(i=1; i<8; ++i)
value = (value << 8) | (uint64_t)h[i];
return value;
}
示例10: 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 );
}
示例11: rfc6287_ocra
int
rfc6287_ocra(const ocra_suite * ocra, const char *suite_string,
const uint8_t *key, size_t key_l, uint64_t C, const char *Q,
const uint8_t *P, size_t P_l, const uint8_t *S, size_t S_l,
uint64_t T, char **resp)
{
int ret;
uint8_t qbuf[128];
uint8_t CBE[8];
uint8_t TBE[8];
uint8_t *md = NULL;
unsigned int md_l = 20;
int suite_l = strlen(suite_string) + 1;
int flags = ocra->flags;
HMAC_CTX *ctx;
if ((0 != (ret = check_di_params(ocra, key_l, Q, P_l, S_l, T))) ||
(0 != (ret = format_questions(ocra, qbuf, Q))))
return ret;
if (flags & FL_C)
st64be(CBE, C);
if (flags & FL_T)
st64be(TBE, T);
if (0 != (ret = hmac_new(&ctx)))
return ret;
if (NULL == (md = (uint8_t *)malloc(mdlen(ocra->hotp_alg))))
return RFC6287_ERR_POSIX;
if ((1 != HMAC_Init_ex(ctx, key, key_l, evp_md(ocra->hotp_alg), NULL)) ||
(1 !=
HMAC_Update(ctx, (const uint8_t *)suite_string, suite_l)) ||
((flags & FL_C) && (1 != HMAC_Update(ctx, CBE, 8))) ||
(1 != HMAC_Update(ctx, qbuf, 128)) ||
((flags & FL_P) && (1 != HMAC_Update(ctx, P, P_l))) ||
((flags & FL_S) && (1 != HMAC_Update(ctx, S, S_l))) ||
((flags & FL_T) && (1 != HMAC_Update(ctx, TBE, 8))) ||
(NULL == (md = (uint8_t *)malloc(mdlen(ocra->hotp_alg)))) ||
(1 != HMAC_Final(ctx, md, &md_l)) ||
(md_l != mdlen(ocra->hotp_alg))) {
hmac_destroy(ctx);
free(md);
return RFC6287_ERR_OPENSSL;
}
hmac_destroy(ctx);
if (ocra->hotp_trunc) {
ret = truncate_md(md, md_l, ocra->hotp_trunc, resp);
free(md);
} else {
*resp = (char *)md;
ret = 0;
}
return ret;
}
示例12: Java_com_facebook_crypto_mac_NativeMac_nativeUpdate__B
JNIEXPORT int JNICALL Java_com_facebook_crypto_mac_NativeMac_nativeUpdate__B(
JNIEnv* env,
jobject obj,
jbyte data) {
HMAC_CTX* ctx = Get_HMAC_CTX(env, obj);
if (!ctx) {
return CRYPTO_FAILURE;
}
if (!HMAC_Update(ctx, (unsigned char*)&data, sizeof(jbyte))) {
return CRYPTO_FAILURE;
}
return CRYPTO_SUCCESS;
}
示例13: HMAC_Init
unsigned char *HMAC2(//fixed to SHA256: EVP_MD *evp_md,
unsigned char *key, int key_len,
unsigned char *d, int n,
unsigned char *md)
//always 64, unsigned int *md_len)
{
HMAC_CTX c;
//static unsigned char m[EVP_MAX_MD_SIZE];
static unsigned char m[2*SHA256_DIGEST_LENGTH];
if (md == NULL) md=m;
//first round
HMAC_Init(&c, key, key_len);
HMAC_Update(&c,d,n);
HMAC_Final(&c,md);
//second round
HMAC_Init(&c, NULL, key_len); //only performs memcpy
HMAC_Update(&c,d,n);
HMAC_Final(&c,md+SHA256_DIGEST_LENGTH);
HMAC_cleanup(&c);
return(md);
}
示例14: HMAC_CTX_init
unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
const unsigned char *d, size_t n, unsigned char *md,
unsigned int *md_len)
{
HMAC_CTX c;
static unsigned char m[EVP_MAX_MD_SIZE];
if (md == NULL) md=m;
HMAC_CTX_init(&c);
HMAC_Init(&c,key,key_len,evp_md);
HMAC_Update(&c,d,n);
HMAC_Final(&c,md,md_len);
HMAC_CTX_cleanup(&c);
return(md);
}
示例15: HMAC
void *
HMAC(const EVP_MD *md,
const void *key, size_t key_size,
const void *data, size_t data_size,
void *hash, unsigned int *hash_len)
{
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key, key_size, md, NULL);
HMAC_Update(&ctx, data, data_size);
HMAC_Final(&ctx, hash, hash_len);
HMAC_CTX_cleanup(&ctx);
return hash;
}