本文整理汇总了C++中HMAC_CTX_init函数的典型用法代码示例。如果您正苦于以下问题:C++ HMAC_CTX_init函数的具体用法?C++ HMAC_CTX_init怎么用?C++ HMAC_CTX_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HMAC_CTX_init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main() {
// The secret key for hashing
const char key[] = "012345678";
// The data that we're going to hash
char data[] = "hello world";
// Be careful of the length of string with the choosen hash engine. SHA1 needed 20 characters.
// Change the length accordingly with your choosen hash engine.
unsigned char* result;
unsigned int len = 20;
result = (unsigned char*)malloc(sizeof(char) * len);
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
// Using sha1 hash engine here.
// You may use other hash engines. e.g EVP_md5(), EVP_sha224, EVP_sha512, etc
HMAC_Init_ex(&ctx, key, strlen(key), EVP_sha1(), NULL);
HMAC_Update(&ctx, (unsigned char*)&data, strlen(data));
HMAC_Final(&ctx, result, &len);
HMAC_CTX_cleanup(&ctx);
printf("HMAC digest: ");
for (int i = 0; i != len; i++)
printf("%02x", (unsigned int)result[i]);
printf("\n");
free(result);
return 0;
}
开发者ID:rainycheng,项目名称:SeKV,代码行数:35,代码来源:hmac1.c
示例2: te_digest_init
//These functions should be replaced with VHMS API calls
int te_digest_init(EVP_MD_CTX *ctx) {
struct te_hmac_sha1_digest_ctx *c = ctx->md_data;
printf("Digest init. Current key: %s\n", c->key);
HMAC_CTX_init(&c->hctx);
HMAC_Init_ex(&c->hctx, c->key, c->key_ln, EVP_sha1(), 0);
return 1;
}
开发者ID:GarysRefererence2014,项目名称:vhsm,代码行数:8,代码来源:main.c
示例3: hmac_init
HMACCTX hmac_init(const void *key, int len, enum ssh_hmac_e 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 SSH_HMAC_SHA1:
HMAC_Init(ctx, key, len, EVP_sha1());
break;
case SSH_HMAC_MD5:
HMAC_Init(ctx, key, len, EVP_md5());
break;
default:
SAFE_FREE(ctx);
ctx = NULL;
}
return ctx;
}
开发者ID:R4wizard,项目名称:node-libssh,代码行数:26,代码来源:libcrypto.c
示例4: CryptoNative_HmacCreate
extern "C" HMAC_CTX* CryptoNative_HmacCreate(const uint8_t* key, int32_t keyLen, const EVP_MD* md)
{
assert(key != nullptr || keyLen == 0);
assert(keyLen >= 0);
assert(md != nullptr);
std::unique_ptr<HMAC_CTX> ctx(new (std::nothrow) HMAC_CTX);
if (ctx == nullptr)
{
// Allocation failed
return nullptr;
}
// NOTE: We can't pass nullptr as empty key since HMAC_Init_ex will interpret
// that as request to reuse the "existing" key.
uint8_t _;
if (keyLen == 0)
key = &_;
HMAC_CTX_init(ctx.get());
int ret = HMAC_Init_ex(ctx.get(), key, keyLen, md, nullptr);
if (!ret)
{
return nullptr;
}
return ctx.release();
}
开发者ID:AArnott,项目名称:corefx,代码行数:29,代码来源:pal_hmac.cpp
示例5: winpr_HMAC_Init
int winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, int md, const BYTE* key, size_t keylen)
{
#if defined(WITH_OPENSSL)
const EVP_MD* evp = winpr_openssl_get_evp_md(md);
if (!evp)
return -1;
HMAC_CTX_init((HMAC_CTX*) ctx);
#if (OPENSSL_VERSION_NUMBER < 0x10000000L)
HMAC_Init_ex((HMAC_CTX*) ctx, key, keylen, evp, NULL);
#else
if (HMAC_Init_ex((HMAC_CTX*) ctx, key, keylen, evp, NULL) != 1)
return -1;
#endif
#elif defined(WITH_MBEDTLS)
const mbedtls_md_info_t* md_info;
mbedtls_md_type_t md_type = winpr_mbedtls_get_md_type(md);
md_info = mbedtls_md_info_from_type(md_type);
if (!md_info)
return -1;
mbedtls_md_init((mbedtls_md_context_t*) ctx);
if (mbedtls_md_setup((mbedtls_md_context_t*) ctx, md_info, 1) != 0)
return -1;
if (mbedtls_md_hmac_starts((mbedtls_md_context_t*) ctx, key, keylen) != 0)
return -1;
#endif
return 0;
}
开发者ID:colemickens,项目名称:FreeRDP,代码行数:35,代码来源:hash.c
示例6: 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
示例7: hmac_fdigest
static int hmac_fdigest(lua_State *L)
{
HMAC_CTX c;
unsigned char digest[EVP_MAX_MD_SIZE];
size_t written = 0;
unsigned int i;
char *hex;
const char *t = luaL_checkstring(L, 1);
const char *s = luaL_checkstring(L, 2);
const char *k = luaL_checkstring(L, 3);
const EVP_MD *type = EVP_get_digestbyname(t);
if (type == NULL) {
luaL_argerror(L, 1, "invalid digest type");
return 0;
}
HMAC_CTX_init(&c);
HMAC_Init_ex(&c, k, lua_strlen(L, 3), type, NULL);
HMAC_Update(&c, (unsigned char *)s, lua_strlen(L, 2));
HMAC_Final(&c, digest, &written);
if (lua_toboolean(L, 4))
lua_pushlstring(L, (char *)digest, written);
else
{
hex = calloc(sizeof(char), written*2 + 1);
for (i = 0; i < written; i++)
sprintf(hex + 2*i, "%02x", digest[i]);
lua_pushlstring(L, hex, written*2);
free(hex);
}
return 1;
}
开发者ID:Odie,项目名称:moai-beta,代码行数:35,代码来源:lcrypto.c
示例8: calculate_reply_hash
static krb5_error_code
calculate_reply_hash(krb5_context context,
krb5_keyblock *key,
Kx509Response *rep)
{
krb5_error_code ret;
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key->keyvalue.data, key->keyvalue.length,
EVP_sha1(), NULL);
ret = krb5_data_alloc(rep->hash, HMAC_size(&ctx));
if (ret) {
HMAC_CTX_cleanup(&ctx);
krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
return ENOMEM;
}
HMAC_Update(&ctx, version_2_0, sizeof(version_2_0));
if (rep->error_code) {
int32_t t = *rep->error_code;
do {
unsigned char p = (t & 0xff);
HMAC_Update(&ctx, &p, 1);
t >>= 8;
} while (t);
}
开发者ID:Alexandr-Galko,项目名称:samba,代码行数:28,代码来源:kx509.c
示例9: winpr_HMAC_New
WINPR_HMAC_CTX* winpr_HMAC_New(void)
{
WINPR_HMAC_CTX* ctx = NULL;
#if defined(WITH_OPENSSL)
HMAC_CTX* hmac = NULL;
#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
if (!(hmac = (HMAC_CTX*) calloc(1, sizeof(HMAC_CTX))))
return NULL;
HMAC_CTX_init(hmac);
#else
if (!(hmac = HMAC_CTX_new()))
return NULL;
#endif
ctx = (WINPR_HMAC_CTX*) hmac;
#elif defined(WITH_MBEDTLS)
mbedtls_md_context_t* hmac;
if (!(hmac = (mbedtls_md_context_t*) calloc(1, sizeof(mbedtls_md_context_t))))
return NULL;
mbedtls_md_init(hmac);
ctx = (WINPR_HMAC_CTX*) hmac;
#endif
return ctx;
}
开发者ID:nogginware,项目名称:FreeRDP,代码行数:28,代码来源:hash.c
示例10: doFile
static void doFile(FILE *fp)
{
HMAC_CTX ctx;
unsigned char digest[EVP_MAX_MD_SIZE];
unsigned int i = 0, dlen = (unsigned int)sizeof(digest);
size_t rd = 0;
const char key[] = "etaonrishdlcupfm";
unsigned char buf[4096];
/* Initialise context */
HMAC_CTX_init(&ctx);
/* Set digest type and key in context */
HMAC_Init_ex(&ctx, key, strlen(key), EVP_sha1(), NULL);
/* Process input stream */
do {
rd = fread(buf,sizeof(char),sizeof(buf),fp);
if(ferror(fp) || ((rd < sizeof(buf)) && !feof(fp))) exit(3);
if(!HMAC_Update(&ctx, buf, (unsigned int)rd)) exit(4);
} while(!feof(fp));
/* Generate digest */
if(!HMAC_Final(&ctx, digest, &dlen)) exit(5);
HMAC_CTX_cleanup(&ctx);
/* Display digest in hex */
for(i = 0; i < dlen; i++) printf("%02x", digest[i]);
printf("\n");
return;
}
开发者ID:rjmangubat23,项目名称:openssl-android,代码行数:29,代码来源:fips_hmac.c
示例11: memcpy
HmacHash::HmacHash()
{
uint8 temp[SEED_KEY_SIZE] = { 0x38, 0xA7, 0x83, 0x15, 0xF8, 0x92, 0x25, 0x30, 0x71, 0x98, 0x67, 0xB1, 0x8C, 0x4, 0xE2, 0xAA };
memcpy(&m_key, &temp, SEED_KEY_SIZE);
HMAC_CTX_init(&m_ctx);
HMAC_Init_ex(&m_ctx, &m_key, SEED_KEY_SIZE, EVP_sha1(), NULL);
}
开发者ID:maximusmangos,项目名称:mangos,代码行数:7,代码来源:Hmac.cpp
示例12: verify_req_hash
static krb5_error_code
verify_req_hash(krb5_context context,
const Kx509Request *req,
krb5_keyblock *key)
{
unsigned char digest[SHA_DIGEST_LENGTH];
HMAC_CTX ctx;
if (req->pk_hash.length != sizeof(digest)) {
krb5_set_error_message(context, KRB5KDC_ERR_PREAUTH_FAILED,
"pk-hash have wrong length: %lu",
(unsigned long)req->pk_hash.length);
return KRB5KDC_ERR_PREAUTH_FAILED;
}
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx,
key->keyvalue.data, key->keyvalue.length,
EVP_sha1(), NULL);
if (sizeof(digest) != HMAC_size(&ctx))
krb5_abortx(context, "runtime error, hmac buffer wrong size in kx509");
HMAC_Update(&ctx, version_2_0, sizeof(version_2_0));
HMAC_Update(&ctx, req->pk_key.data, req->pk_key.length);
HMAC_Final(&ctx, digest, 0);
HMAC_CTX_cleanup(&ctx);
if (memcmp(req->pk_hash.data, digest, sizeof(digest)) != 0) {
krb5_set_error_message(context, KRB5KDC_ERR_PREAUTH_FAILED,
"pk-hash is not correct");
return KRB5KDC_ERR_PREAUTH_FAILED;
}
return 0;
}
开发者ID:Alexandr-Galko,项目名称:samba,代码行数:33,代码来源:kx509.c
示例13: rtmp_handshake_make_digest
static int rtmp_handshake_make_digest(const uint8_t* key, size_t len, const uint8_t* ptr, size_t ptrlen, const uint8_t* digest, uint8_t* dst)
{
static HMAC_CTX *hmac;
unsigned int digestlen;
if (hmac == NULL) {
#if OPENSSL_VERSION_NUMBER < 0x10100000L
static HMAC_CTX shmac;
hmac = &shmac;
HMAC_CTX_init(hmac);
#else
hmac = HMAC_CTX_new();
#endif
}
HMAC_Init_ex(hmac, key, len, EVP_sha256(), NULL);
if (digest)
{
assert(digest + SHA256_DIGEST_LENGTH <= ptr + ptrlen);
HMAC_Update(hmac, ptr, digest - ptr);
if (digest + SHA256_DIGEST_LENGTH < ptr + ptrlen)
HMAC_Update(hmac, digest + SHA256_DIGEST_LENGTH, ptrlen - (digest - ptr) - SHA256_DIGEST_LENGTH);
}
else
{
HMAC_Update(hmac, ptr, ptrlen);
}
HMAC_Final(hmac, dst, &digestlen);
assert(digestlen == SHA256_DIGEST_LENGTH);
return 0;
}
开发者ID:zousenming,项目名称:media-server,代码行数:31,代码来源:rtmp-handshake.c
示例14: check_hmac
static void
check_hmac(void)
{
unsigned char buf[4] = { 0, 0, 0, 0 };
char hmackey[] = "hello-world";
size_t hmackey_size = sizeof(hmackey);
unsigned int hmaclen;
unsigned char hmac[EVP_MAX_MD_SIZE];
HMAC_CTX c;
char answer[20] = "\x2c\xfa\x32\xb7\x2b\x8a\xf6\xdf\xcf\xda"
"\x6f\xd1\x52\x4d\x54\x58\x73\x0f\xf3\x24";
HMAC_CTX_init(&c);
HMAC_Init_ex(&c, hmackey, hmackey_size, EVP_sha1(), NULL);
HMAC_Update(&c, buf, sizeof(buf));
HMAC_Final(&c, hmac, &hmaclen);
HMAC_CTX_cleanup(&c);
if (hmaclen != 20)
errx(1, "hmaclen = %d\n", (int)hmaclen);
if (ct_memcmp(hmac, answer, hmaclen) != 0)
errx(1, "wrong answer\n");
}
开发者ID:Kendra123,项目名称:heimdal,代码行数:25,代码来源:validate.c
示例15: OPENSSL_malloc
static HMAC_CTX *HMAC_CTX_new(void)
{
HMAC_CTX *ctx = OPENSSL_malloc(sizeof(HMAC_CTX));
if (ctx != NULL)
HMAC_CTX_init(ctx);
return ctx;
}
开发者ID:mschmieder,项目名称:minizip,代码行数:7,代码来源:mz_crypt_openssl.c
示例16: 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
示例17: ENGINE_load_builtin_engines
//ignore
unsigned char *HMACRSA(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];
//TODO: get/set rsa engine struct
const char *engine_id = "rsa";
ENGINE_load_builtin_engines();
ENGINE *e = ENGINE_by_id(engine_id);//ENGINE_;
if(!e)
fprintf(stderr,"Engine not available\n");
ENGINE_init(e);
if (md == NULL)
md = m;
HMAC_CTX_init(&c);
if (!HMAC_Init_ex(&c, key, key_len, evp_md, NULL))
goto err;
if (!HMAC_Update(&c, d, n))
goto err;
if (!HMAC_Final(&c, md, md_len))
goto err;
HMAC_CTX_cleanup(&c);
ENGINE_free(e);
return md;
err:
HMAC_CTX_cleanup(&c);
ENGINE_free(e);
return NULL;
}
开发者ID:FireElementalNE,项目名称:CSCI6320-project,代码行数:31,代码来源:macLocal.c
示例18: HMAC_Init
void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
const EVP_MD *md)
{
if(key && md)
HMAC_CTX_init(ctx);
HMAC_Init_ex(ctx,key,len,md, NULL);
}
开发者ID:imgits,项目名称:rkanalyzer,代码行数:7,代码来源:hmac.c
示例19: EncodeHMACSHA256
unsigned char *
EncodeHMACSHA256(
unsigned char* key,
int keylen,
const char* data,
int datalen)
{
unsigned char *hmachash = malloc(32);
const unsigned char *datatohash = (unsigned char *)data;
unsigned char tk[SHA256_DIGEST_LENGTH];
// Initialise HMACh
HMAC_CTX HMAC;
unsigned int hmaclength = 32;
memset(hmachash, 0, hmaclength);
if (keylen > 64 ) {
SHA256(key, keylen, tk);
key = tk;
keylen = SHA256_DIGEST_LENGTH;
}
// Digest the key and message using SHA256
HMAC_CTX_init(&HMAC);
HMAC_Init_ex(&HMAC, key, keylen, EVP_sha256(),NULL);
HMAC_Update(&HMAC, datatohash, datalen);
HMAC_Final(&HMAC, hmachash, &hmaclength);
HMAC_CTX_cleanup(&HMAC);
return hmachash;
}
开发者ID:code-mx,项目名称:amanda,代码行数:31,代码来源:s3-util.c
示例20: Qiniu_Mac_SignToken
char* Qiniu_Mac_SignToken(Qiniu_Mac* self, char* policy_str)
{
char* token;
char* encoded_digest;
char digest[EVP_MAX_MD_SIZE + 1];
unsigned int dgtlen = sizeof(digest);
HMAC_CTX ctx;
Qiniu_Mac mac;
char* encoded_policy_str = Qiniu_String_Encode(policy_str);
if (self) {
mac = *self;
} else {
mac.accessKey = QINIU_ACCESS_KEY;
mac.secretKey = QINIU_SECRET_KEY;
}
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, mac.secretKey, strlen(mac.secretKey), EVP_sha1(), NULL);
HMAC_Update(&ctx, encoded_policy_str, strlen(encoded_policy_str));
HMAC_Final(&ctx, digest, &dgtlen);
HMAC_CTX_cleanup(&ctx);
encoded_digest = Qiniu_Memory_Encode(digest, dgtlen);
token = Qiniu_String_Concat(mac.accessKey, ":", encoded_digest, ":", encoded_policy_str, NULL);
free(encoded_policy_str);
free(encoded_digest);
return token;
}
开发者ID:icattlecoder,项目名称:c-sdk,代码行数:31,代码来源:auth_mac.c
注:本文中的HMAC_CTX_init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论