748093cee98ca077f3d817213098bd42161d9bba
[users/jgh/exim.git] / src / src / pdkim / sha1.h
1 /* $Cambridge: exim/src/src/pdkim/sha1.h,v 1.1.2.3 2009/03/17 14:56:55 tom Exp $ */
2 /**
3  * \file sha1.h
4  *
5  *  Based on XySSL: Copyright (C) 2006-2008  Christophe Devine
6  *
7  *  Copyright (C) 2009  Paul Bakker <polarssl_maintainer at polarssl dot org>
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License along
20  *  with this program; if not, write to the Free Software Foundation, Inc.,
21  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 #ifndef POLARSSL_SHA1_H
24 #define POLARSSL_SHA1_H
25
26 /**
27  * \brief          SHA-1 context structure
28  */
29 #ifndef HAVE_SHA1_CONTEXT
30 #define HAVE_SHA1_CONTEXT
31 typedef struct sha1_context sha1_context;
32 #endif
33
34 struct sha1_context
35 {
36     unsigned long total[2];     /*!< number of bytes processed  */
37     unsigned long state[5];     /*!< intermediate digest state  */
38     unsigned char buffer[64];   /*!< data block being processed */
39
40     unsigned char ipad[64];     /*!< HMAC: inner padding        */
41     unsigned char opad[64];     /*!< HMAC: outer padding        */
42 };
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /**
49  * \brief          SHA-1 context setup
50  *
51  * \param ctx      context to be initialized
52  */
53 void sha1_starts( sha1_context *ctx );
54
55 /**
56  * \brief          SHA-1 process buffer
57  *
58  * \param ctx      SHA-1 context
59  * \param input    buffer holding the  data
60  * \param ilen     length of the input data
61  */
62 void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
63
64 /**
65  * \brief          SHA-1 final digest
66  *
67  * \param ctx      SHA-1 context
68  * \param output   SHA-1 checksum result
69  */
70 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
71
72 /**
73  * \brief          Output = SHA-1( input buffer )
74  *
75  * \param input    buffer holding the  data
76  * \param ilen     length of the input data
77  * \param output   SHA-1 checksum result
78  */
79 void sha1_oneshot( unsigned char *input, int ilen, unsigned char output[20] );
80
81 /**
82  * \brief          Output = SHA-1( file contents )
83  *
84  * \param path     input file name
85  * \param output   SHA-1 checksum result
86  *
87  * \return         0 if successful, 1 if fopen failed,
88  *                 or 2 if fread failed
89  */
90 int sha1_file( char *path, unsigned char output[20] );
91
92 /**
93  * \brief          SHA-1 HMAC context setup
94  *
95  * \param ctx      HMAC context to be initialized
96  * \param key      HMAC secret key
97  * \param keylen   length of the HMAC key
98  */
99 void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen );
100
101 /**
102  * \brief          SHA-1 HMAC process buffer
103  *
104  * \param ctx      HMAC context
105  * \param input    buffer holding the  data
106  * \param ilen     length of the input data
107  */
108 void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen );
109
110 /**
111  * \brief          SHA-1 HMAC final digest
112  *
113  * \param ctx      HMAC context
114  * \param output   SHA-1 HMAC checksum result
115  */
116 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
117
118 /**
119  * \brief          Output = HMAC-SHA-1( hmac key, input buffer )
120  *
121  * \param key      HMAC secret key
122  * \param keylen   length of the HMAC key
123  * \param input    buffer holding the  data
124  * \param ilen     length of the input data
125  * \param output   HMAC-SHA-1 result
126  */
127 void sha1_hmac( unsigned char *key, int keylen,
128                 unsigned char *input, int ilen,
129                 unsigned char output[20] );
130
131 #ifdef __cplusplus
132 }
133 #endif
134
135 #endif /* sha1.h */