]>
git.zerfleddert.de Git - proxmark3-svn/blob - common/mbedtls/sha1.h
872fe1b059187a56ec790f8eca22c224f12d1424
4 * \brief This file contains SHA-1 definitions and functions.
6 * The Secure Hash Algorithm 1 (SHA-1) cryptographic hash function is defined in
7 * <em>FIPS 180-4: Secure Hash Standard (SHS)</em>.
9 * \warning SHA-1 is considered a weak message digest and its use constitutes
10 * a security risk. We recommend considering stronger message
14 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
15 * SPDX-License-Identifier: GPL-2.0
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.
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.
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.
31 * This file is part of Mbed TLS (https://tls.mbed.org)
33 #ifndef MBEDTLS_SHA1_H
34 #define MBEDTLS_SHA1_H
36 #if !defined(MBEDTLS_CONFIG_FILE)
39 #include MBEDTLS_CONFIG_FILE
45 #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
51 #if !defined(MBEDTLS_SHA1_ALT)
52 // Regular implementation
56 * \brief The SHA-1 context structure.
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.
63 typedef struct mbedtls_sha1_context
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. */
71 #else /* MBEDTLS_SHA1_ALT */
73 #endif /* MBEDTLS_SHA1_ALT */
76 * \brief This function initializes a SHA-1 context.
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.
82 * \param ctx The SHA-1 context to initialize.
85 void mbedtls_sha1_init( mbedtls_sha1_context
*ctx
);
88 * \brief This function clears a SHA-1 context.
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.
94 * \param ctx The SHA-1 context to clear.
97 void mbedtls_sha1_free( mbedtls_sha1_context
*ctx
);
100 * \brief This function clones the state of a SHA-1 context.
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.
106 * \param dst The SHA-1 context to clone to.
107 * \param src The SHA-1 context to clone from.
110 void mbedtls_sha1_clone( mbedtls_sha1_context
*dst
,
111 const mbedtls_sha1_context
*src
);
114 * \brief This function starts a SHA-1 checksum calculation.
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.
120 * \param ctx The SHA-1 context to initialize.
122 * \return \c 0 on success.
125 int mbedtls_sha1_starts_ret( mbedtls_sha1_context
*ctx
);
128 * \brief This function feeds an input buffer into an ongoing SHA-1
129 * checksum calculation.
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.
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.
139 * \return \c 0 on success.
141 int mbedtls_sha1_update_ret( mbedtls_sha1_context
*ctx
,
142 const unsigned char *input
,
146 * \brief This function finishes the SHA-1 operation, and writes
147 * the result to the output buffer.
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.
153 * \param ctx The SHA-1 context.
154 * \param output The SHA-1 checksum result.
156 * \return \c 0 on success.
158 int mbedtls_sha1_finish_ret( mbedtls_sha1_context
*ctx
,
159 unsigned char output
[20] );
162 * \brief SHA-1 process data block (internal use only).
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.
168 * \param ctx The SHA-1 context.
169 * \param data The data block being processed.
171 * \return \c 0 on success.
174 int mbedtls_internal_sha1_process( mbedtls_sha1_context
*ctx
,
175 const unsigned char data
[64] );
177 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
178 #if defined(MBEDTLS_DEPRECATED_WARNING)
179 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
181 #define MBEDTLS_DEPRECATED
184 * \brief This function starts a SHA-1 checksum calculation.
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.
190 * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0.
192 * \param ctx The SHA-1 context to initialize.
195 MBEDTLS_DEPRECATED
void mbedtls_sha1_starts( mbedtls_sha1_context
*ctx
);
198 * \brief This function feeds an input buffer into an ongoing SHA-1
199 * checksum calculation.
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.
205 * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0.
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.
212 MBEDTLS_DEPRECATED
void mbedtls_sha1_update( mbedtls_sha1_context
*ctx
,
213 const unsigned char *input
,
217 * \brief This function finishes the SHA-1 operation, and writes
218 * the result to the output buffer.
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.
224 * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0.
226 * \param ctx The SHA-1 context.
227 * \param output The SHA-1 checksum result.
230 MBEDTLS_DEPRECATED
void mbedtls_sha1_finish( mbedtls_sha1_context
*ctx
,
231 unsigned char output
[20] );
234 * \brief SHA-1 process data block (internal use only).
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.
240 * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0.
242 * \param ctx The SHA-1 context.
243 * \param data The data block being processed.
246 MBEDTLS_DEPRECATED
void mbedtls_sha1_process( mbedtls_sha1_context
*ctx
,
247 const unsigned char data
[64] );
249 #undef MBEDTLS_DEPRECATED
250 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
253 * \brief This function calculates the SHA-1 checksum of a buffer.
255 * The function allocates the context, performs the
256 * calculation, and frees the context.
258 * The SHA-1 result is calculated as
259 * output = SHA-1(input buffer).
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.
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.
269 * \return \c 0 on success.
272 int mbedtls_sha1_ret( const unsigned char *input
,
274 unsigned char output
[20] );
276 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
277 #if defined(MBEDTLS_DEPRECATED_WARNING)
278 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
280 #define MBEDTLS_DEPRECATED
283 * \brief This function calculates the SHA-1 checksum of a buffer.
285 * The function allocates the context, performs the
286 * calculation, and frees the context.
288 * The SHA-1 result is calculated as
289 * output = SHA-1(input buffer).
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.
295 * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0
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.
302 MBEDTLS_DEPRECATED
void mbedtls_sha1( const unsigned char *input
,
304 unsigned char output
[20] );
306 #undef MBEDTLS_DEPRECATED
307 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
310 * \brief The SHA-1 checkup routine.
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.
316 * \return \c 0 on success.
317 * \return \c 1 on failure.
320 int mbedtls_sha1_self_test( int verbose
);
326 #endif /* mbedtls_sha1.h */