AbZip  1.0.0
hmac.h
1 /*
2  ---------------------------------------------------------------------------
3  Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved.
4 
5  LICENSE TERMS
6 
7  The free distribution and use of this software in both source and binary
8  form is allowed (with or without changes) provided that:
9 
10  1. distributions of this source code include the above copyright
11  notice, this list of conditions and the following disclaimer;
12 
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;
16 
17  3. the copyright holder's name is not used to endorse products
18  built using this software without specific written permission.
19 
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.
23 
24  DISCLAIMER
25 
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
31 
32  This is an implementation of HMAC, the FIPS standard keyed hash function
33 */
34 
35 #ifndef _HMAC_H
36 #define _HMAC_H
37 
38 #include <memory.h>
39 
40 #if defined(__cplusplus)
41 extern "C"
42 {
43 #endif
44 
45 #define USE_SHA1
46 
47 #if !defined(USE_SHA1) && !defined(USE_SHA256)
48 #error define USE_SHA1 or USE_SHA256 to set the HMAC hash algorithm
49 #endif
50 
51 #ifdef USE_SHA1
52 
53 #include "sha1.h"
54 
55 #define HASH_INPUT_SIZE SHA1_BLOCK_SIZE
56 #define HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE
57 #define sha_ctx sha1_ctx
58 #define sha_begin sha1_begin
59 #define sha_hash sha1_hash
60 #define sha_end sha1_end
61 
62 #endif
63 
64 #ifdef USE_SHA256
65 
66 #include "sha2.h"
67 
68 #define HASH_INPUT_SIZE SHA256_BLOCK_SIZE
69 #define HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE
70 #define sha_ctx sha256_ctx
71 #define sha_begin sha256_begin
72 #define sha_hash sha256_hash
73 #define sha_end sha256_end
74 
75 #endif
76 
77 #define HMAC_OK 0
78 #define HMAC_BAD_MODE -1
79 #define HMAC_IN_DATA 0xffffffff
80 
81 typedef struct
82 { unsigned char key[HASH_INPUT_SIZE];
83  sha_ctx ctx[1];
84  unsigned long klen;
85 } hmac_ctx;
86 
87 void hmac_sha_begin(hmac_ctx cx[1]);
88 
89 int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]);
90 
91 void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]);
92 
93 void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]);
94 
95 void hmac_sha(const unsigned char key[], unsigned long key_len,
96  const unsigned char data[], unsigned long data_len,
97  unsigned char mac[], unsigned long mac_len);
98 
99 #if defined(__cplusplus)
100 }
101 #endif
102 
103 #endif
Definition: hmac.h:81