]> git.zerfleddert.de Git - proxmark3-svn/blob - common/mbedtls/sha1.h
move from polarssl to mbedtls (#708)
[proxmark3-svn] / common / mbedtls / sha1.h
1 /**
2 * \file sha1.h
3 *
4 * \brief This file contains SHA-1 definitions and functions.
5 *
6 * The Secure Hash Algorithm 1 (SHA-1) cryptographic hash function is defined in
7 * <em>FIPS 180-4: Secure Hash Standard (SHS)</em>.
8 *
9 * \warning SHA-1 is considered a weak message digest and its use constitutes
10 * a security risk. We recommend considering stronger message
11 * digests instead.
12 */
13 /*
14 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
15 * SPDX-License-Identifier: GPL-2.0
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 *
31 * This file is part of Mbed TLS (https://tls.mbed.org)
32 */
33 #ifndef MBEDTLS_SHA1_H
34 #define MBEDTLS_SHA1_H
35
36 #if !defined(MBEDTLS_CONFIG_FILE)
37 #include "config.h"
38 #else
39 #include MBEDTLS_CONFIG_FILE
40 #endif
41
42 #include <stddef.h>
43 #include <stdint.h>
44
45 #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 #if !defined(MBEDTLS_SHA1_ALT)
52 // Regular implementation
53 //
54
55 /**
56 * \brief The SHA-1 context structure.
57 *
58 * \warning SHA-1 is considered a weak message digest and its use
59 * constitutes a security risk. We recommend considering
60 * stronger message digests instead.
61 *
62 */
63 typedef struct mbedtls_sha1_context
64 {
65 uint32_t total[2]; /*!< The number of Bytes processed. */
66 uint32_t state[5]; /*!< The intermediate digest state. */
67 unsigned char buffer[64]; /*!< The data block being processed. */
68 }
69 mbedtls_sha1_context;
70
71 #else /* MBEDTLS_SHA1_ALT */
72 #include "sha1_alt.h"
73 #endif /* MBEDTLS_SHA1_ALT */
74
75 /**
76 * \brief This function initializes a SHA-1 context.
77 *
78 * \warning SHA-1 is considered a weak message digest and its use
79 * constitutes a security risk. We recommend considering
80 * stronger message digests instead.
81 *
82 * \param ctx The SHA-1 context to initialize.
83 *
84 */
85 void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
86
87 /**
88 * \brief This function clears a SHA-1 context.
89 *
90 * \warning SHA-1 is considered a weak message digest and its use
91 * constitutes a security risk. We recommend considering
92 * stronger message digests instead.
93 *
94 * \param ctx The SHA-1 context to clear.
95 *
96 */
97 void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
98
99 /**
100 * \brief This function clones the state of a SHA-1 context.
101 *
102 * \warning SHA-1 is considered a weak message digest and its use
103 * constitutes a security risk. We recommend considering
104 * stronger message digests instead.
105 *
106 * \param dst The SHA-1 context to clone to.
107 * \param src The SHA-1 context to clone from.
108 *
109 */
110 void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
111 const mbedtls_sha1_context *src );
112
113 /**
114 * \brief This function starts a SHA-1 checksum calculation.
115 *
116 * \warning SHA-1 is considered a weak message digest and its use
117 * constitutes a security risk. We recommend considering
118 * stronger message digests instead.
119 *
120 * \param ctx The SHA-1 context to initialize.
121 *
122 * \return \c 0 on success.
123 *
124 */
125 int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
126
127 /**
128 * \brief This function feeds an input buffer into an ongoing SHA-1
129 * checksum calculation.
130 *
131 * \warning SHA-1 is considered a weak message digest and its use
132 * constitutes a security risk. We recommend considering
133 * stronger message digests instead.
134 *
135 * \param ctx The SHA-1 context.
136 * \param input The buffer holding the input data.
137 * \param ilen The length of the input data.
138 *
139 * \return \c 0 on success.
140 */
141 int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
142 const unsigned char *input,
143 size_t ilen );
144
145 /**
146 * \brief This function finishes the SHA-1 operation, and writes
147 * the result to the output buffer.
148 *
149 * \warning SHA-1 is considered a weak message digest and its use
150 * constitutes a security risk. We recommend considering
151 * stronger message digests instead.
152 *
153 * \param ctx The SHA-1 context.
154 * \param output The SHA-1 checksum result.
155 *
156 * \return \c 0 on success.
157 */
158 int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
159 unsigned char output[20] );
160
161 /**
162 * \brief SHA-1 process data block (internal use only).
163 *
164 * \warning SHA-1 is considered a weak message digest and its use
165 * constitutes a security risk. We recommend considering
166 * stronger message digests instead.
167 *
168 * \param ctx The SHA-1 context.
169 * \param data The data block being processed.
170 *
171 * \return \c 0 on success.
172 *
173 */
174 int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
175 const unsigned char data[64] );
176
177 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
178 #if defined(MBEDTLS_DEPRECATED_WARNING)
179 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
180 #else
181 #define MBEDTLS_DEPRECATED
182 #endif
183 /**
184 * \brief This function starts a SHA-1 checksum calculation.
185 *
186 * \warning SHA-1 is considered a weak message digest and its use
187 * constitutes a security risk. We recommend considering
188 * stronger message digests instead.
189 *
190 * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0.
191 *
192 * \param ctx The SHA-1 context to initialize.
193 *
194 */
195 MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
196
197 /**
198 * \brief This function feeds an input buffer into an ongoing SHA-1
199 * checksum calculation.
200 *
201 * \warning SHA-1 is considered a weak message digest and its use
202 * constitutes a security risk. We recommend considering
203 * stronger message digests instead.
204 *
205 * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0.
206 *
207 * \param ctx The SHA-1 context.
208 * \param input The buffer holding the input data.
209 * \param ilen The length of the input data.
210 *
211 */
212 MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
213 const unsigned char *input,
214 size_t ilen );
215
216 /**
217 * \brief This function finishes the SHA-1 operation, and writes
218 * the result to the output buffer.
219 *
220 * \warning SHA-1 is considered a weak message digest and its use
221 * constitutes a security risk. We recommend considering
222 * stronger message digests instead.
223 *
224 * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0.
225 *
226 * \param ctx The SHA-1 context.
227 * \param output The SHA-1 checksum result.
228 *
229 */
230 MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
231 unsigned char output[20] );
232
233 /**
234 * \brief SHA-1 process data block (internal use only).
235 *
236 * \warning SHA-1 is considered a weak message digest and its use
237 * constitutes a security risk. We recommend considering
238 * stronger message digests instead.
239 *
240 * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0.
241 *
242 * \param ctx The SHA-1 context.
243 * \param data The data block being processed.
244 *
245 */
246 MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
247 const unsigned char data[64] );
248
249 #undef MBEDTLS_DEPRECATED
250 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
251
252 /**
253 * \brief This function calculates the SHA-1 checksum of a buffer.
254 *
255 * The function allocates the context, performs the
256 * calculation, and frees the context.
257 *
258 * The SHA-1 result is calculated as
259 * output = SHA-1(input buffer).
260 *
261 * \warning SHA-1 is considered a weak message digest and its use
262 * constitutes a security risk. We recommend considering
263 * stronger message digests instead.
264 *
265 * \param input The buffer holding the input data.
266 * \param ilen The length of the input data.
267 * \param output The SHA-1 checksum result.
268 *
269 * \return \c 0 on success.
270 *
271 */
272 int mbedtls_sha1_ret( const unsigned char *input,
273 size_t ilen,
274 unsigned char output[20] );
275
276 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
277 #if defined(MBEDTLS_DEPRECATED_WARNING)
278 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
279 #else
280 #define MBEDTLS_DEPRECATED
281 #endif
282 /**
283 * \brief This function calculates the SHA-1 checksum of a buffer.
284 *
285 * The function allocates the context, performs the
286 * calculation, and frees the context.
287 *
288 * The SHA-1 result is calculated as
289 * output = SHA-1(input buffer).
290 *
291 * \warning SHA-1 is considered a weak message digest and its use
292 * constitutes a security risk. We recommend considering
293 * stronger message digests instead.
294 *
295 * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0
296 *
297 * \param input The buffer holding the input data.
298 * \param ilen The length of the input data.
299 * \param output The SHA-1 checksum result.
300 *
301 */
302 MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
303 size_t ilen,
304 unsigned char output[20] );
305
306 #undef MBEDTLS_DEPRECATED
307 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
308
309 /**
310 * \brief The SHA-1 checkup routine.
311 *
312 * \warning SHA-1 is considered a weak message digest and its use
313 * constitutes a security risk. We recommend considering
314 * stronger message digests instead.
315 *
316 * \return \c 0 on success.
317 * \return \c 1 on failure.
318 *
319 */
320 int mbedtls_sha1_self_test( int verbose );
321
322 #ifdef __cplusplus
323 }
324 #endif
325
326 #endif /* mbedtls_sha1.h */
Impressum, Datenschutz