2 ---------------------------------------------------------------------------
3 Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved.
7 The free distribution and use of this software in both source and binary
8 form is allowed (with or without changes) provided that:
10 1. distributions of this source code include the above copyright
11 notice, this list of conditions and the following disclaimer;
13 2. distributions in binary form include the above copyright
14 notice, this list of conditions and the following disclaimer
15 in the documentation and/or other associated materials;
17 3. the copyright holder's name is not used to endorse products
18 built using this software without specific written permission.
20 ALTERNATIVELY, provided that this notice is retained in full, this product
21 may be distributed under the terms of the GNU General Public License (GPL),
22 in which case the provisions of the GPL apply INSTEAD OF those given above.
26 This software is provided 'as is' with no explicit or implied warranties
27 in respect of its properties, including, but not limited to, correctness
28 and/or fitness for purpose.
29 ---------------------------------------------------------------------------
30 Issue Date: 26/08/2003
32 This is an implementation of HMAC, the FIPS standard keyed hash function
40 #if defined(__cplusplus)
45 #if !defined(USE_SHA1) && !defined(USE_SHA256)
46 #error define USE_SHA1 or USE_SHA256 to set the HMAC hash algorithm
53 #define HASH_INPUT_SIZE SHA1_BLOCK_SIZE
54 #define HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE
55 #define sha_ctx sha1_ctx
56 #define sha_begin sha1_begin
57 #define sha_hash sha1_hash
58 #define sha_end sha1_end
66 #define HASH_INPUT_SIZE SHA256_BLOCK_SIZE
67 #define HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE
68 #define sha_ctx sha256_ctx
69 #define sha_begin sha256_begin
70 #define sha_hash sha256_hash
71 #define sha_end sha256_end
76 #define HMAC_BAD_MODE -1
77 #define HMAC_IN_DATA 0xffffffff
80 { unsigned char key[HASH_INPUT_SIZE];
85 void hmac_sha_begin(hmac_ctx cx[1]);
87 int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]);
89 void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]);
91 void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]);
93 void hmac_sha(const unsigned char key[], unsigned long key_len,
94 const unsigned char data[], unsigned long data_len,
95 unsigned char mac[], unsigned long mac_len);
97 #if defined(__cplusplus)