xref: /freebsd/crypto/libecc/include/libecc/hash/hmac.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1 #ifndef __HMAC_H__
2 #define __HMAC_H__
3 
4 #include <libecc/lib_ecc_config.h>
5 #ifdef WITH_HMAC
6 
7 #include <libecc/words/words.h>
8 #include <libecc/utils/utils.h>
9 #include <libecc/hash/hash_algs.h>
10 
11 #define HMAC_MAGIC ((word_t)(0x9849020187612083ULL))
12 #define HMAC_CHECK_INITIALIZED(A, ret, err) \
13         MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == HMAC_MAGIC) && ((A)->hash != NULL), ret, err)
14 
15 /* The HMAC structure is made of two hash contexts */
16 typedef struct {
17 	/* The hash mapping associated with the hmac */
18         const hash_mapping *hash;
19 	/* The two hash contexts (inner and outer) */
20         hash_context in_ctx;
21         hash_context out_ctx;
22         /* Initialization magic value */
23         word_t magic;
24 } hmac_context;
25 
26 ATTRIBUTE_WARN_UNUSED_RET int hmac_init(hmac_context *ctx, const u8 *hmackey, u32 hmackey_len, hash_alg_type hash_type);
27 
28 ATTRIBUTE_WARN_UNUSED_RET int hmac_update(hmac_context *ctx, const u8 *input, u32 ilen);
29 
30 ATTRIBUTE_WARN_UNUSED_RET int hmac_finalize(hmac_context *ctx, u8 *output, u8 *outlen);
31 
32 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);
33 
34 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);
35 
36 #endif /* WITH_HMAC */
37 
38 #endif /* __HMAC_H__ */
39