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