Lines 240-246
Link Here
|
240 |
g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey, |
240 |
g_eli_crypto_hmac_init(struct hmac_ctx *ctx, const uint8_t *hkey, |
241 |
size_t hkeylen) |
241 |
size_t hkeylen) |
242 |
{ |
242 |
{ |
243 |
u_char k_ipad[128], key[128]; |
243 |
u_char k_ipad[128], k_opad[128], key[128]; |
244 |
SHA512_CTX lctx; |
244 |
SHA512_CTX lctx; |
245 |
u_int i; |
245 |
u_int i; |
246 |
|
246 |
|
Lines 259-271
Link Here
|
259 |
/* XOR key with ipad and opad values. */ |
259 |
/* XOR key with ipad and opad values. */ |
260 |
for (i = 0; i < sizeof(key); i++) { |
260 |
for (i = 0; i < sizeof(key); i++) { |
261 |
k_ipad[i] = key[i] ^ 0x36; |
261 |
k_ipad[i] = key[i] ^ 0x36; |
262 |
ctx->k_opad[i] = key[i] ^ 0x5c; |
262 |
k_opad[i] = key[i] ^ 0x5c; |
263 |
} |
263 |
} |
264 |
bzero(key, sizeof(key)); |
264 |
bzero(key, sizeof(key)); |
265 |
/* Perform inner SHA512. */ |
265 |
/* Start inner SHA512. */ |
266 |
SHA512_Init(&ctx->shactx); |
266 |
SHA512_Init(&ctx->innerctx); |
267 |
SHA512_Update(&ctx->shactx, k_ipad, sizeof(k_ipad)); |
267 |
SHA512_Update(&ctx->innerctx, k_ipad, sizeof(k_ipad)); |
268 |
bzero(k_ipad, sizeof(k_ipad)); |
268 |
bzero(k_ipad, sizeof(k_ipad)); |
|
|
269 |
/* Start outer SHA512. */ |
270 |
SHA512_Init(&ctx->outerctx); |
271 |
SHA512_Update(&ctx->outerctx, k_opad, sizeof(k_opad)); |
272 |
bzero(k_opad, sizeof(k_opad)); |
269 |
} |
273 |
} |
270 |
|
274 |
|
271 |
void |
275 |
void |
Lines 280-295
Link Here
|
280 |
g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize) |
284 |
g_eli_crypto_hmac_final(struct hmac_ctx *ctx, uint8_t *md, size_t mdsize) |
281 |
{ |
285 |
{ |
282 |
u_char digest[SHA512_MDLEN]; |
286 |
u_char digest[SHA512_MDLEN]; |
283 |
SHA512_CTX lctx; |
|
|
284 |
|
287 |
|
285 |
SHA512_Final(digest, &ctx->shactx); |
288 |
/* Complete inner hash */ |
286 |
/* Perform outer SHA512. */ |
289 |
SHA512_Final(digest, &ctx->innerctx); |
287 |
SHA512_Init(&lctx); |
290 |
|
288 |
SHA512_Update(&lctx, ctx->k_opad, sizeof(ctx->k_opad)); |
291 |
/* Complete outer hash */ |
|
|
292 |
SHA512_Update(&ctx->outerctx, digest, sizeof(digest)); |
293 |
SHA512_Final(digest, &ctx->outerctx); |
294 |
|
289 |
bzero(ctx, sizeof(*ctx)); |
295 |
bzero(ctx, sizeof(*ctx)); |
290 |
SHA512_Update(&lctx, digest, sizeof(digest)); |
|
|
291 |
SHA512_Final(digest, &lctx); |
292 |
bzero(&lctx, sizeof(lctx)); |
293 |
/* mdsize == 0 means "Give me the whole hash!" */ |
296 |
/* mdsize == 0 means "Give me the whole hash!" */ |
294 |
if (mdsize == 0) |
297 |
if (mdsize == 0) |
295 |
mdsize = SHA512_MDLEN; |
298 |
mdsize = SHA512_MDLEN; |