Initial checking of what was revision 56 on http://luks.endorphin.org/svn/cryptsetup
[platform/upstream/cryptsetup.git] / luks / sha / hmac.h.orig
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 #if !defined(USE_SHA1) && !defined(USE_SHA256)
46 #error define USE_SHA1 or USE_SHA256 to set the HMAC hash algorithm
47 #endif
48
49 #ifdef USE_SHA1
50
51 #include "sha1.h"
52
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
59
60 #endif
61
62 #ifdef USE_SHA256
63
64 #include "sha2.h"
65
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
72
73 #endif
74
75 #define HMAC_OK                0
76 #define HMAC_BAD_MODE         -1
77 #define HMAC_IN_DATA  0xffffffff
78
79 typedef struct
80 {   unsigned char   key[HASH_INPUT_SIZE];
81     sha_ctx         ctx[1];
82     unsigned long   klen;
83 } hmac_ctx;
84
85 void hmac_sha_begin(hmac_ctx cx[1]);
86
87 int  hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]);
88
89 void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]);
90
91 void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]);
92
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);
96
97 #if defined(__cplusplus)
98 }
99 #endif
100
101 #endif