text
[RRG-proxmark3.git] / common / mbedtls / sha1.h
blob4a9d7565b9004bda30ffe519ac10c7520f40e9b4
1 /**
2 * \file sha1.h
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
11 * digests instead.
14 * Copyright The Mbed TLS Contributors
15 * SPDX-License-Identifier: Apache-2.0
17 * Licensed under the Apache License, Version 2.0 (the "License"); you may
18 * not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
21 * http://www.apache.org/licenses/LICENSE-2.0
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
29 #ifndef MBEDTLS_SHA1_H
30 #define MBEDTLS_SHA1_H
32 #if !defined(MBEDTLS_CONFIG_FILE)
33 #include "mbedtls/config.h"
34 #else
35 #include MBEDTLS_CONFIG_FILE
36 #endif
38 #include <stddef.h>
39 #include <stdint.h>
41 /* MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED is deprecated and should not be used. */
42 #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
43 #define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073 /**< SHA-1 input data was malformed. */
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
49 #if !defined(MBEDTLS_SHA1_ALT)
50 // Regular implementation
53 /**
54 * \brief The SHA-1 context structure.
56 * \warning SHA-1 is considered a weak message digest and its use
57 * constitutes a security risk. We recommend considering
58 * stronger message digests instead.
61 typedef struct mbedtls_sha1_context {
62 uint32_t total[2]; /*!< The number of Bytes processed. */
63 uint32_t state[5]; /*!< The intermediate digest state. */
64 unsigned char buffer[64]; /*!< The data block being processed. */
66 mbedtls_sha1_context;
68 #else /* MBEDTLS_SHA1_ALT */
69 #include "sha1_alt.h"
70 #endif /* MBEDTLS_SHA1_ALT */
72 /**
73 * \brief This function initializes a SHA-1 context.
75 * \warning SHA-1 is considered a weak message digest and its use
76 * constitutes a security risk. We recommend considering
77 * stronger message digests instead.
79 * \param ctx The SHA-1 context to initialize.
80 * This must not be \c NULL.
83 void mbedtls_sha1_init(mbedtls_sha1_context *ctx);
85 /**
86 * \brief This function clears a SHA-1 context.
88 * \warning SHA-1 is considered a weak message digest and its use
89 * constitutes a security risk. We recommend considering
90 * stronger message digests instead.
92 * \param ctx The SHA-1 context to clear. This may be \c NULL,
93 * in which case this function does nothing. If it is
94 * not \c NULL, it must point to an initialized
95 * SHA-1 context.
98 void mbedtls_sha1_free(mbedtls_sha1_context *ctx);
101 * \brief This function clones the state of a SHA-1 context.
103 * \warning SHA-1 is considered a weak message digest and its use
104 * constitutes a security risk. We recommend considering
105 * stronger message digests instead.
107 * \param dst The SHA-1 context to clone to. This must be initialized.
108 * \param src The SHA-1 context to clone from. This must be initialized.
111 void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
112 const mbedtls_sha1_context *src);
115 * \brief This function starts a SHA-1 checksum calculation.
117 * \warning SHA-1 is considered a weak message digest and its use
118 * constitutes a security risk. We recommend considering
119 * stronger message digests instead.
121 * \param ctx The SHA-1 context to initialize. This must be initialized.
123 * \return \c 0 on success.
124 * \return A negative error code on failure.
127 int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx);
130 * \brief This function feeds an input buffer into an ongoing SHA-1
131 * checksum calculation.
133 * \warning SHA-1 is considered a weak message digest and its use
134 * constitutes a security risk. We recommend considering
135 * stronger message digests instead.
137 * \param ctx The SHA-1 context. This must be initialized
138 * and have a hash operation started.
139 * \param input The buffer holding the input data.
140 * This must be a readable buffer of length \p ilen Bytes.
141 * \param ilen The length of the input data \p input in Bytes.
143 * \return \c 0 on success.
144 * \return A negative error code on failure.
146 int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx,
147 const unsigned char *input,
148 size_t ilen);
151 * \brief This function finishes the SHA-1 operation, and writes
152 * the result to the output buffer.
154 * \warning SHA-1 is considered a weak message digest and its use
155 * constitutes a security risk. We recommend considering
156 * stronger message digests instead.
158 * \param ctx The SHA-1 context to use. This must be initialized and
159 * have a hash operation started.
160 * \param output The SHA-1 checksum result. This must be a writable
161 * buffer of length \c 20 Bytes.
163 * \return \c 0 on success.
164 * \return A negative error code on failure.
166 int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx,
167 unsigned char output[20]);
170 * \brief SHA-1 process data block (internal use only).
172 * \warning SHA-1 is considered a weak message digest and its use
173 * constitutes a security risk. We recommend considering
174 * stronger message digests instead.
176 * \param ctx The SHA-1 context to use. This must be initialized.
177 * \param data The data block being processed. This must be a
178 * readable buffer of length \c 64 Bytes.
180 * \return \c 0 on success.
181 * \return A negative error code on failure.
184 int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx,
185 const unsigned char data[64]);
187 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
188 #if defined(MBEDTLS_DEPRECATED_WARNING)
189 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
190 #else
191 #define MBEDTLS_DEPRECATED
192 #endif
194 * \brief This function starts a SHA-1 checksum calculation.
196 * \warning SHA-1 is considered a weak message digest and its use
197 * constitutes a security risk. We recommend considering
198 * stronger message digests instead.
200 * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0.
202 * \param ctx The SHA-1 context to initialize. This must be initialized.
205 MBEDTLS_DEPRECATED void mbedtls_sha1_starts(mbedtls_sha1_context *ctx);
208 * \brief This function feeds an input buffer into an ongoing SHA-1
209 * checksum calculation.
211 * \warning SHA-1 is considered a weak message digest and its use
212 * constitutes a security risk. We recommend considering
213 * stronger message digests instead.
215 * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0.
217 * \param ctx The SHA-1 context. This must be initialized and
218 * have a hash operation started.
219 * \param input The buffer holding the input data.
220 * This must be a readable buffer of length \p ilen Bytes.
221 * \param ilen The length of the input data \p input in Bytes.
224 MBEDTLS_DEPRECATED void mbedtls_sha1_update(mbedtls_sha1_context *ctx,
225 const unsigned char *input,
226 size_t ilen);
229 * \brief This function finishes the SHA-1 operation, and writes
230 * the result to the output buffer.
232 * \warning SHA-1 is considered a weak message digest and its use
233 * constitutes a security risk. We recommend considering
234 * stronger message digests instead.
236 * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0.
238 * \param ctx The SHA-1 context. This must be initialized and
239 * have a hash operation started.
240 * \param output The SHA-1 checksum result.
241 * This must be a writable buffer of length \c 20 Bytes.
243 MBEDTLS_DEPRECATED void mbedtls_sha1_finish(mbedtls_sha1_context *ctx,
244 unsigned char output[20]);
247 * \brief SHA-1 process data block (internal use only).
249 * \warning SHA-1 is considered a weak message digest and its use
250 * constitutes a security risk. We recommend considering
251 * stronger message digests instead.
253 * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0.
255 * \param ctx The SHA-1 context. This must be initialized.
256 * \param data The data block being processed.
257 * This must be a readable buffer of length \c 64 bytes.
260 MBEDTLS_DEPRECATED void mbedtls_sha1_process(mbedtls_sha1_context *ctx,
261 const unsigned char data[64]);
263 #undef MBEDTLS_DEPRECATED
264 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
267 * \brief This function calculates the SHA-1 checksum of a buffer.
269 * The function allocates the context, performs the
270 * calculation, and frees the context.
272 * The SHA-1 result is calculated as
273 * output = SHA-1(input buffer).
275 * \warning SHA-1 is considered a weak message digest and its use
276 * constitutes a security risk. We recommend considering
277 * stronger message digests instead.
279 * \param input The buffer holding the input data.
280 * This must be a readable buffer of length \p ilen Bytes.
281 * \param ilen The length of the input data \p input in Bytes.
282 * \param output The SHA-1 checksum result.
283 * This must be a writable buffer of length \c 20 Bytes.
285 * \return \c 0 on success.
286 * \return A negative error code on failure.
289 int mbedtls_sha1_ret(const unsigned char *input,
290 size_t ilen,
291 unsigned char output[20]);
293 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
294 #if defined(MBEDTLS_DEPRECATED_WARNING)
295 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
296 #else
297 #define MBEDTLS_DEPRECATED
298 #endif
300 * \brief This function calculates the SHA-1 checksum of a buffer.
302 * The function allocates the context, performs the
303 * calculation, and frees the context.
305 * The SHA-1 result is calculated as
306 * output = SHA-1(input buffer).
308 * \warning SHA-1 is considered a weak message digest and its use
309 * constitutes a security risk. We recommend considering
310 * stronger message digests instead.
312 * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0
314 * \param input The buffer holding the input data.
315 * This must be a readable buffer of length \p ilen Bytes.
316 * \param ilen The length of the input data \p input in Bytes.
317 * \param output The SHA-1 checksum result. This must be a writable
318 * buffer of size \c 20 Bytes.
321 MBEDTLS_DEPRECATED void mbedtls_sha1(const unsigned char *input,
322 size_t ilen,
323 unsigned char output[20]);
325 #undef MBEDTLS_DEPRECATED
326 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
328 #if defined(MBEDTLS_SELF_TEST)
331 * \brief The SHA-1 checkup routine.
333 * \warning SHA-1 is considered a weak message digest and its use
334 * constitutes a security risk. We recommend considering
335 * stronger message digests instead.
337 * \return \c 0 on success.
338 * \return \c 1 on failure.
341 int mbedtls_sha1_self_test(int verbose);
343 #endif /* MBEDTLS_SELF_TEST */
345 #ifdef __cplusplus
347 #endif
349 #endif /* mbedtls_sha1.h */