0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz * HMAC (RFC-2104) implementation.
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen * Copyright (c) 2011-2016 Florian Zeitz <florob@babelmonkeys.de>
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz * This software is released under the MIT license.
d8361cc8576d9ede93a037f9b96f2a3f9b7e9054Timo Sirainenvoid hmac_init(struct hmac_context *_ctx, const unsigned char *key,
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz size_t key_len, const struct hash_method *meth)
d8361cc8576d9ede93a037f9b96f2a3f9b7e9054Timo Sirainen struct hmac_context_priv *ctx = &_ctx->u.priv;
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz i_assert(meth->context_size <= HMAC_MAX_CONTEXT_SIZE);
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz for (i = 0; i < 64; i++) {
d8361cc8576d9ede93a037f9b96f2a3f9b7e9054Timo Sirainenvoid hmac_final(struct hmac_context *_ctx, unsigned char *digest)
d8361cc8576d9ede93a037f9b96f2a3f9b7e9054Timo Sirainen struct hmac_context_priv *ctx = &_ctx->u.priv;
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz ctx->hash->loop(ctx->ctxo, digest, ctx->hash->digest_size);
ffe51a1969f24d88bbfacb3ba2ec83d5b99ae774Aki Tuomibuffer_t *t_hmac_data(const struct hash_method *meth,
c147bff818798a979d93537f72f5c1f68f5d5ba8Aki Tuomi buffer_t *res = t_buffer_create(meth->digest_size);
ffe51a1969f24d88bbfacb3ba2ec83d5b99ae774Aki Tuomi unsigned char *buf = buffer_get_space_unsafe(res, 0, meth->digest_size);
ffe51a1969f24d88bbfacb3ba2ec83d5b99ae774Aki Tuomibuffer_t *t_hmac_buffer(const struct hash_method *meth,
ffe51a1969f24d88bbfacb3ba2ec83d5b99ae774Aki Tuomi return t_hmac_data(meth, key, key_len, data->data, data->used);
ffe51a1969f24d88bbfacb3ba2ec83d5b99ae774Aki Tuomibuffer_t *t_hmac_str(const struct hash_method *meth,
ffe51a1969f24d88bbfacb3ba2ec83d5b99ae774Aki Tuomi const char *data)