Commit | Line | Data |
---|---|---|
80a47a2c TK |
1 | /** |
2 | * \file sha1.h | |
3 | * | |
62d3e98d TK |
4 | * Copyright (C) 2006-2010, Brainspark B.V. |
5 | * | |
6 | * This file is part of PolarSSL (http://www.polarssl.org) | |
7 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> | |
80a47a2c | 8 | * |
62d3e98d | 9 | * All rights reserved. |
80a47a2c TK |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
22 | * with this program; if not, write to the Free Software Foundation, Inc., | |
23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
24 | */ | |
80a47a2c TK |
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 | |
80a47a2c TK |
35 | struct sha1_context |
36 | { | |
37 | unsigned long total[2]; /*!< number of bytes processed */ | |
38 | unsigned long state[5]; /*!< intermediate digest state */ | |
39 | unsigned char buffer[64]; /*!< data block being processed */ | |
40 | ||
41 | unsigned char ipad[64]; /*!< HMAC: inner padding */ | |
42 | unsigned char opad[64]; /*!< HMAC: outer padding */ | |
43 | }; | |
44 | ||
45 | #ifdef __cplusplus | |
46 | extern "C" { | |
47 | #endif | |
48 | ||
49 | /** | |
50 | * \brief SHA-1 context setup | |
51 | * | |
52 | * \param ctx context to be initialized | |
53 | */ | |
54 | void sha1_starts( sha1_context *ctx ); | |
55 | ||
56 | /** | |
57 | * \brief SHA-1 process buffer | |
58 | * | |
59 | * \param ctx SHA-1 context | |
60 | * \param input buffer holding the data | |
61 | * \param ilen length of the input data | |
62 | */ | |
62d3e98d | 63 | void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ); |
80a47a2c TK |
64 | |
65 | /** | |
66 | * \brief SHA-1 final digest | |
67 | * | |
68 | * \param ctx SHA-1 context | |
69 | * \param output SHA-1 checksum result | |
70 | */ | |
71 | void sha1_finish( sha1_context *ctx, unsigned char output[20] ); | |
72 | ||
73 | /** | |
74 | * \brief Output = SHA-1( input buffer ) | |
75 | * | |
76 | * \param input buffer holding the data | |
77 | * \param ilen length of the input data | |
78 | * \param output SHA-1 checksum result | |
79 | */ | |
0d04a285 | 80 | void polarssl_sha1( const unsigned char *input, int ilen, unsigned char output[20] ); |
80a47a2c TK |
81 | |
82 | /** | |
83 | * \brief Output = SHA-1( file contents ) | |
84 | * | |
85 | * \param path input file name | |
86 | * \param output SHA-1 checksum result | |
87 | * | |
88 | * \return 0 if successful, 1 if fopen failed, | |
89 | * or 2 if fread failed | |
90 | */ | |
62d3e98d | 91 | int sha1_file( const char *path, unsigned char output[20] ); |
80a47a2c TK |
92 | |
93 | /** | |
94 | * \brief SHA-1 HMAC context setup | |
95 | * | |
96 | * \param ctx HMAC context to be initialized | |
97 | * \param key HMAC secret key | |
98 | * \param keylen length of the HMAC key | |
99 | */ | |
62d3e98d | 100 | void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen ); |
80a47a2c TK |
101 | |
102 | /** | |
103 | * \brief SHA-1 HMAC process buffer | |
104 | * | |
105 | * \param ctx HMAC context | |
106 | * \param input buffer holding the data | |
107 | * \param ilen length of the input data | |
108 | */ | |
62d3e98d | 109 | void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen ); |
80a47a2c TK |
110 | |
111 | /** | |
112 | * \brief SHA-1 HMAC final digest | |
113 | * | |
114 | * \param ctx HMAC context | |
115 | * \param output SHA-1 HMAC checksum result | |
116 | */ | |
117 | void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] ); | |
118 | ||
62d3e98d TK |
119 | /** |
120 | * \brief SHA-1 HMAC context reset | |
121 | * | |
122 | * \param ctx HMAC context to be reset | |
123 | */ | |
124 | void sha1_hmac_reset( sha1_context *ctx ); | |
125 | ||
80a47a2c TK |
126 | /** |
127 | * \brief Output = HMAC-SHA-1( hmac key, input buffer ) | |
128 | * | |
129 | * \param key HMAC secret key | |
130 | * \param keylen length of the HMAC key | |
131 | * \param input buffer holding the data | |
132 | * \param ilen length of the input data | |
133 | * \param output HMAC-SHA-1 result | |
134 | */ | |
62d3e98d TK |
135 | void sha1_hmac( const unsigned char *key, int keylen, |
136 | const unsigned char *input, int ilen, | |
80a47a2c TK |
137 | unsigned char output[20] ); |
138 | ||
ac3ad426 AM |
139 | /** |
140 | * \brief Checkup routine | |
141 | * | |
142 | * \return 0 if successful, or 1 if the test failed | |
143 | */ | |
144 | int sha1_self_test( int verbose ); | |
145 | ||
80a47a2c TK |
146 | #ifdef __cplusplus |
147 | } | |
148 | #endif | |
149 | ||
150 | #endif /* sha1.h */ |