39 #include <openssl/hmac.h>
43 const uint8_t* data, uint32_t data_length,
44 uint8_t* mac, int32_t* mac_length )
46 HMAC(EVP_sha1(), key, key_length,
47 data, data_length, mac,
48 reinterpret_cast<uint32_t*>(mac_length) );
52 const uint8_t* data_chunks[],
53 uint32_t data_chunck_length[],
54 uint8_t* mac, int32_t* mac_length ) {
57 HMAC_Init_ex(&ctx, key, key_length, EVP_sha1(), NULL);
58 while (*data_chunks) {
59 HMAC_Update(&ctx, *data_chunks, *data_chunck_length);
61 data_chunck_length ++;
63 HMAC_Final(&ctx, mac, reinterpret_cast<uint32_t*>(mac_length));
64 HMAC_CTX_cleanup(&ctx);
69 HMAC_CTX* ctx = (HMAC_CTX*)malloc(
sizeof(HMAC_CTX));
72 HMAC_Init_ex(ctx, key, key_length, EVP_sha1(), NULL);
76 void hmacSha1Ctx(
void* ctx,
const uint8_t* data, uint32_t data_length,
77 uint8_t* mac, int32_t* mac_length)
79 HMAC_CTX* pctx = (HMAC_CTX*)ctx;
81 HMAC_Init_ex(pctx, NULL, 0, NULL, NULL );
82 HMAC_Update(pctx, data, data_length );
83 HMAC_Final(pctx, mac, reinterpret_cast<uint32_t*>(mac_length) );
86 void hmacSha1Ctx(
void* ctx,
const uint8_t* data[], uint32_t data_length[],
87 uint8_t* mac, int32_t* mac_length )
89 HMAC_CTX* pctx = (HMAC_CTX*)ctx;
91 HMAC_Init_ex(pctx, NULL, 0, NULL, NULL );
93 HMAC_Update(pctx, *data, *data_length);
97 HMAC_Final(pctx, mac, reinterpret_cast<uint32_t*>(mac_length) );
103 HMAC_CTX_cleanup((HMAC_CTX*)ctx);
Functions to compute SHA1 HAMAC.
void freeSha1HmacContext(void *ctx)
Free SHA1 HMAC context.
void * createSha1HmacContext(uint8_t *key, int32_t key_length)
Create and initialize a SHA1 HMAC context.
void hmacSha1Ctx(void *ctx, const uint8_t *data, uint32_t data_length, uint8_t *mac, int32_t *mac_length)
Compute SHA1 HMAC.
void hmac_sha1(uint8_t *key, int32_t key_length, const uint8_t *data, uint32_t data_length, uint8_t *mac, int32_t *mac_length)
Compute SHA1 HMAC.