Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/eli/g_eli_hmac.c
Show All 38 Lines | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <openssl/evp.h> | #include <openssl/evp.h> | ||||
#define _OpenSSL_ | #define _OpenSSL_ | ||||
#endif | #endif | ||||
#include <geom/eli/g_eli.h> | #include <geom/eli/g_eli.h> | ||||
void | void | ||||
g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey, | g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const char hkey[], | ||||
size_t hkeylen) | size_t hkeylen) | ||||
{ | { | ||||
u_char k_ipad[128], k_opad[128], key[128]; | u_char k_ipad[128], k_opad[128], key[128]; | ||||
SHA512_CTX lctx; | SHA512_CTX lctx; | ||||
u_int i; | u_int i; | ||||
bzero(key, sizeof(key)); | bzero(key, sizeof(key)); | ||||
if (hkeylen == 0) | if (hkeylen == 0) | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize) | ||||
/* mdsize == 0 means "Give me the whole hash!" */ | /* mdsize == 0 means "Give me the whole hash!" */ | ||||
if (mdsize == 0) | if (mdsize == 0) | ||||
mdsize = SHA512_MDLEN; | mdsize = SHA512_MDLEN; | ||||
bcopy(digest, md, mdsize); | bcopy(digest, md, mdsize); | ||||
explicit_bzero(digest, sizeof(digest)); | explicit_bzero(digest, sizeof(digest)); | ||||
} | } | ||||
void | void | ||||
g_eli_crypto_hmac(const uint8_t *hkey, size_t hkeysize, const uint8_t *data, | g_eli_crypto_hmac(const char hkey[], size_t hkeysize, const uint8_t *data, | ||||
size_t datasize, uint8_t *md, size_t mdsize) | size_t datasize, uint8_t *md, size_t mdsize) | ||||
{ | { | ||||
struct hmac_ctx ctx; | struct hmac_ctx ctx; | ||||
g_eli_crypto_hmac_init(&ctx, hkey, hkeysize); | g_eli_crypto_hmac_init(&ctx, hkey, hkeysize); | ||||
g_eli_crypto_hmac_update(&ctx, data, datasize); | g_eli_crypto_hmac_update(&ctx, data, datasize); | ||||
g_eli_crypto_hmac_final(&ctx, md, mdsize); | g_eli_crypto_hmac_final(&ctx, md, mdsize); | ||||
} | } | ||||
Show All 34 Lines |