2
* HMAC-SHA1 (RFC-2104) implementation.
4
* Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>
5
* Copyright (c) 2011 Florian Zeitz <florob@babelmonkeys.de>
7
* This software is released under the MIT license.
11
#include "hmac-sha1.h"
12
#include "safe-memset.h"
14
void hmac_sha1_init(struct hmac_sha1_context *ctx,
15
const unsigned char *key, size_t key_len)
18
unsigned char sha1key[20];
19
unsigned char k_ipad[64];
20
unsigned char k_opad[64];
23
sha1_get_digest(key, key_len, sha1key);
28
memcpy(k_ipad, key, key_len);
29
memset(k_ipad + key_len, 0, 64 - key_len);
30
memcpy(k_opad, k_ipad, 64);
32
for (i = 0; i < 64; i++) {
38
sha1_loop(&ctx->ctx, k_ipad, 64);
39
sha1_init(&ctx->ctxo);
40
sha1_loop(&ctx->ctxo, k_opad, 64);
42
safe_memset(k_ipad, 0, 64);
43
safe_memset(k_opad, 0, 64);
46
void hmac_sha1_final(struct hmac_sha1_context *ctx, unsigned char *digest)
48
sha1_result(&ctx->ctx, digest);
50
sha1_loop(&ctx->ctxo, digest, 20);
51
sha1_result(&ctx->ctxo, digest);