2 ---------------------------------------------------------------------------
3 Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
5 The redistribution and use of this software (with or without changes)
6 is allowed without the payment of fees or royalties provided that:
8 source code distributions include the above copyright notice, this
9 list of conditions and the following disclaimer;
11 binary distributions include the above copyright notice, this list
12 of conditions and the following disclaimer in their documentation.
14 This software is provided 'as is' with no explicit or implied warranties
15 in respect of its operation, including, but not limited to, correctness
16 and fitness for purpose.
17 ---------------------------------------------------------------------------
18 Issue Date: 20/12/2007
20 This is an implementation of HMAC, the FIPS standard keyed hash function
29 #if defined(__cplusplus)
36 #if defined(SHA_224) || defined(SHA_256) || defined(SHA_384) || defined(SHA_512)
37 #define HMAC_MAX_OUTPUT_SIZE SHA2_MAX_DIGEST_SIZE
38 #define HMAC_MAX_BLOCK_SIZE SHA2_MAX_BLOCK_SIZE
40 #define HMAC_MAX_OUTPUT_SIZE SHA1_DIGEST_SIZE
41 #define HMAC_MAX_BLOCK_SIZE SHA1_BLOCK_SIZE
44 #define HMAC_IN_DATA 0xffffffff
69 typedef VOID_RETURN hf_begin(void*);
70 typedef VOID_RETURN hf_hash(const void*, unsigned long len, void*);
71 typedef VOID_RETURN hf_end(void*, void*);
77 unsigned char key[HMAC_MAX_BLOCK_SIZE];
96 unsigned long input_len;
97 unsigned long output_len;
101 /* returns the length of hash digest for the hash used */
102 /* mac_len must not be greater than this */
103 int hmac_sha_begin(enum hmac_hash hash, hmac_ctx cx[1]);
105 int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]);
107 void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]);
109 void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]);
111 void hmac_sha(enum hmac_hash hash, const unsigned char key[], unsigned long key_len,
112 const unsigned char data[], unsigned long data_len,
113 unsigned char mac[], unsigned long mac_len);
115 #if defined(__cplusplus)