forked from ANSSI-FR/libecc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhmac.h
38 lines (27 loc) · 1.35 KB
/
hmac.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef __HMAC_H__
#define __HMAC_H__
#include "../lib_ecc_config.h"
#ifdef WITH_HMAC
#include "../words/words.h"
#include "../utils/utils.h"
#include "hash_algs.h"
#define HMAC_MAGIC ((word_t)(0x9849020187612083ULL))
#define HMAC_CHECK_INITIALIZED(A, ret, err) \
MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == HMAC_MAGIC) && ((A)->hash != NULL), ret, err)
/* The HMAC structure is made of two hash contexts */
typedef struct {
/* The hash mapping associated with the hmac */
const hash_mapping *hash;
/* The two hash contexts (inner and outer) */
hash_context in_ctx;
hash_context out_ctx;
/* Initialization magic value */
word_t magic;
} hmac_context;
ATTRIBUTE_WARN_UNUSED_RET int hmac_init(hmac_context *ctx, const u8 *hmackey, u32 hmackey_len, hash_alg_type hash_type);
ATTRIBUTE_WARN_UNUSED_RET int hmac_update(hmac_context *ctx, const u8 *input, u32 ilen);
ATTRIBUTE_WARN_UNUSED_RET int hmac_finalize(hmac_context *ctx, u8 *output, u8 *outlen);
ATTRIBUTE_WARN_UNUSED_RET int hmac(const u8 *hmackey, u32 hmackey_len, hash_alg_type hash_type, const u8 *input, u32 ilen, u8 *output, u8 *outlen);
ATTRIBUTE_WARN_UNUSED_RET int hmac_scattered(const u8 *hmackey, u32 hmackey_len, hash_alg_type hash_type, const u8 **inputs, const u32 *ilens, u8 *output, u8 *outlen);
#endif /* WITH_HMAC */
#endif /* __HMAC_H__ */