Build without WITH_CONTENT_SCAN.
[exim.git] / src / src / pdkim / sha1.h
1 /**
2 * \file sha1.h
3 *
4 * Copyright (C) 2006-2009, Paul Bakker <polarssl_maintainer at polarssl.org>
5 * All rights reserved.
6 *
7 * Joined copyright on original XySSL code with: Christophe Devine
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
24 /* $Cambridge: exim/src/src/pdkim/sha1.h,v 1.3 2009/12/07 13:05:07 tom Exp $ */
25
26 #ifndef POLARSSL_SHA1_H
27 #define POLARSSL_SHA1_H
28
29 /**
30 * \brief SHA-1 context structure
31 */
32
33 #ifndef HAVE_SHA1_CONTEXT
34 #define HAVE_SHA1_CONTEXT
35 typedef struct sha1_context sha1_context;
36 #endif
37
38 struct sha1_context
39 {
40 unsigned long total[2]; /*!< number of bytes processed */
41 unsigned long state[5]; /*!< intermediate digest state */
42 unsigned char buffer[64]; /*!< data block being processed */
43
44 unsigned char ipad[64]; /*!< HMAC: inner padding */
45 unsigned char opad[64]; /*!< HMAC: outer padding */
46 };
47
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 /**
54 * \brief SHA-1 context setup
55 *
56 * \param ctx context to be initialized
57 */
58 void sha1_starts( sha1_context *ctx );
59
60 /**
61 * \brief SHA-1 process buffer
62 *
63 * \param ctx SHA-1 context
64 * \param input buffer holding the data
65 * \param ilen length of the input data
66 */
67 void sha1_update( sha1_context *ctx, unsigned char *input, int ilen );
68
69 /**
70 * \brief SHA-1 final digest
71 *
72 * \param ctx SHA-1 context
73 * \param output SHA-1 checksum result
74 */
75 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
76
77 /**
78 * \brief Output = SHA-1( input buffer )
79 *
80 * \param input buffer holding the data
81 * \param ilen length of the input data
82 * \param output SHA-1 checksum result
83 */
84 void sha1( unsigned char *input, int ilen, unsigned char output[20] );
85
86 /**
87 * \brief Output = SHA-1( file contents )
88 *
89 * \param path input file name
90 * \param output SHA-1 checksum result
91 *
92 * \return 0 if successful, 1 if fopen failed,
93 * or 2 if fread failed
94 */
95 int sha1_file( char *path, unsigned char output[20] );
96
97 /**
98 * \brief SHA-1 HMAC context setup
99 *
100 * \param ctx HMAC context to be initialized
101 * \param key HMAC secret key
102 * \param keylen length of the HMAC key
103 */
104 void sha1_hmac_starts( sha1_context *ctx, unsigned char *key, int keylen );
105
106 /**
107 * \brief SHA-1 HMAC process buffer
108 *
109 * \param ctx HMAC context
110 * \param input buffer holding the data
111 * \param ilen length of the input data
112 */
113 void sha1_hmac_update( sha1_context *ctx, unsigned char *input, int ilen );
114
115 /**
116 * \brief SHA-1 HMAC final digest
117 *
118 * \param ctx HMAC context
119 * \param output SHA-1 HMAC checksum result
120 */
121 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
122
123 /**
124 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
125 *
126 * \param key HMAC secret key
127 * \param keylen length of the HMAC key
128 * \param input buffer holding the data
129 * \param ilen length of the input data
130 * \param output HMAC-SHA-1 result
131 */
132 void sha1_hmac( unsigned char *key, int keylen,
133 unsigned char *input, int ilen,
134 unsigned char output[20] );
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* sha1.h */