Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 2 | * \file sha1.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 4 | * \brief This file contains SHA-1 definitions and functions. |
| 5 | * |
Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 6 | * The Secure Hash Algorithm 1 (SHA-1) cryptographic hash function is defined in |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 7 | * <em>FIPS 180-4: Secure Hash Standard (SHS)</em>. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 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. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 12 | */ |
| 13 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 14 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 7ff7965 | 2023-11-03 12:04:52 +0000 | [diff] [blame] | 15 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 16 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 17 | #ifndef MBEDTLS_SHA1_H |
| 18 | #define MBEDTLS_SHA1_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 19 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 20 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 21 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 22 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 23 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 24 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 25 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 26 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 27 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 28 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 29 | /* MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED is deprecated and should not be used. */ |
Gilles Peskine | a397443 | 2021-07-26 18:48:10 +0200 | [diff] [blame] | 30 | /** SHA-1 hardware accelerator failed */ |
| 31 | #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 |
| 32 | /** SHA-1 input data was malformed. */ |
| 33 | #define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073 |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 34 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 39 | #if !defined(MBEDTLS_SHA1_ALT) |
| 40 | // Regular implementation |
| 41 | // |
| 42 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 43 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 44 | * \brief The SHA-1 context structure. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 45 | * |
| 46 | * \warning SHA-1 is considered a weak message digest and its use |
| 47 | * constitutes a security risk. We recommend considering |
| 48 | * stronger message digests instead. |
| 49 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 50 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 51 | typedef struct mbedtls_sha1_context { |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 52 | uint32_t total[2]; /*!< The number of Bytes processed. */ |
| 53 | uint32_t state[5]; /*!< The intermediate digest state. */ |
| 54 | unsigned char buffer[64]; /*!< The data block being processed. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 55 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 56 | mbedtls_sha1_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 57 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 58 | #else /* MBEDTLS_SHA1_ALT */ |
| 59 | #include "sha1_alt.h" |
| 60 | #endif /* MBEDTLS_SHA1_ALT */ |
| 61 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 62 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 63 | * \brief This function initializes a SHA-1 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 64 | * |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 65 | * \warning SHA-1 is considered a weak message digest and its use |
| 66 | * constitutes a security risk. We recommend considering |
| 67 | * stronger message digests instead. |
| 68 | * |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 69 | * \param ctx The SHA-1 context to initialize. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 70 | * This must not be \c NULL. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 71 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 72 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 73 | void mbedtls_sha1_init(mbedtls_sha1_context *ctx); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 74 | |
| 75 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 76 | * \brief This function clears a SHA-1 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 77 | * |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 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 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 82 | * \param ctx The SHA-1 context to clear. This may be \c NULL, |
| 83 | * in which case this function does nothing. If it is |
| 84 | * not \c NULL, it must point to an initialized |
| 85 | * SHA-1 context. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 86 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 87 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 88 | void mbedtls_sha1_free(mbedtls_sha1_context *ctx); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 89 | |
| 90 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 91 | * \brief This function clones the state of a SHA-1 context. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 92 | * |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 93 | * \warning SHA-1 is considered a weak message digest and its use |
| 94 | * constitutes a security risk. We recommend considering |
| 95 | * stronger message digests instead. |
| 96 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 97 | * \param dst The SHA-1 context to clone to. This must be initialized. |
| 98 | * \param src The SHA-1 context to clone from. This must be initialized. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 99 | * |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 100 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 101 | void mbedtls_sha1_clone(mbedtls_sha1_context *dst, |
| 102 | const mbedtls_sha1_context *src); |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 103 | |
| 104 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 105 | * \brief This function starts a SHA-1 checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 106 | * |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 107 | * \warning SHA-1 is considered a weak message digest and its use |
| 108 | * constitutes a security risk. We recommend considering |
| 109 | * stronger message digests instead. |
| 110 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 111 | * \param ctx The SHA-1 context to initialize. This must be initialized. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 112 | * |
| 113 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 114 | * \return A negative error code on failure. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 115 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 116 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 117 | int mbedtls_sha1_starts_ret(mbedtls_sha1_context *ctx); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 118 | |
| 119 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 120 | * \brief This function feeds an input buffer into an ongoing SHA-1 |
| 121 | * checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 122 | * |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 123 | * \warning SHA-1 is considered a weak message digest and its use |
| 124 | * constitutes a security risk. We recommend considering |
| 125 | * stronger message digests instead. |
| 126 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 127 | * \param ctx The SHA-1 context. This must be initialized |
| 128 | * and have a hash operation started. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 129 | * \param input The buffer holding the input data. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 130 | * This must be a readable buffer of length \p ilen Bytes. |
| 131 | * \param ilen The length of the input data \p input in Bytes. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 132 | * |
| 133 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 134 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 135 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 136 | int mbedtls_sha1_update_ret(mbedtls_sha1_context *ctx, |
| 137 | const unsigned char *input, |
| 138 | size_t ilen); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 139 | |
| 140 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 141 | * \brief This function finishes the SHA-1 operation, and writes |
| 142 | * the result to the output buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 143 | * |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 144 | * \warning SHA-1 is considered a weak message digest and its use |
| 145 | * constitutes a security risk. We recommend considering |
| 146 | * stronger message digests instead. |
| 147 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 148 | * \param ctx The SHA-1 context to use. This must be initialized and |
| 149 | * have a hash operation started. |
| 150 | * \param output The SHA-1 checksum result. This must be a writable |
| 151 | * buffer of length \c 20 Bytes. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 152 | * |
| 153 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 154 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 155 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 156 | int mbedtls_sha1_finish_ret(mbedtls_sha1_context *ctx, |
| 157 | unsigned char output[20]); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 158 | |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 159 | /** |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 160 | * \brief SHA-1 process data block (internal use only). |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 161 | * |
| 162 | * \warning SHA-1 is considered a weak message digest and its use |
| 163 | * constitutes a security risk. We recommend considering |
| 164 | * stronger message digests instead. |
| 165 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 166 | * \param ctx The SHA-1 context to use. This must be initialized. |
| 167 | * \param data The data block being processed. This must be a |
| 168 | * readable buffer of length \c 64 Bytes. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 169 | * |
| 170 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 171 | * \return A negative error code on failure. |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 172 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 173 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 174 | int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, |
| 175 | const unsigned char data[64]); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 176 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 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. This must be initialized. |
| 193 | * |
| 194 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 195 | MBEDTLS_DEPRECATED void mbedtls_sha1_starts(mbedtls_sha1_context *ctx); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 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. This must be initialized and |
| 208 | * have a hash operation started. |
| 209 | * \param input The buffer holding the input data. |
| 210 | * This must be a readable buffer of length \p ilen Bytes. |
| 211 | * \param ilen The length of the input data \p input in Bytes. |
| 212 | * |
| 213 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 214 | MBEDTLS_DEPRECATED void mbedtls_sha1_update(mbedtls_sha1_context *ctx, |
| 215 | const unsigned char *input, |
| 216 | size_t ilen); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * \brief This function finishes the SHA-1 operation, and writes |
| 220 | * the result to the output buffer. |
| 221 | * |
| 222 | * \warning SHA-1 is considered a weak message digest and its use |
| 223 | * constitutes a security risk. We recommend considering |
| 224 | * stronger message digests instead. |
| 225 | * |
| 226 | * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0. |
| 227 | * |
| 228 | * \param ctx The SHA-1 context. This must be initialized and |
| 229 | * have a hash operation started. |
| 230 | * \param output The SHA-1 checksum result. |
| 231 | * This must be a writable buffer of length \c 20 Bytes. |
| 232 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 233 | MBEDTLS_DEPRECATED void mbedtls_sha1_finish(mbedtls_sha1_context *ctx, |
| 234 | unsigned char output[20]); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * \brief SHA-1 process data block (internal use only). |
| 238 | * |
| 239 | * \warning SHA-1 is considered a weak message digest and its use |
| 240 | * constitutes a security risk. We recommend considering |
| 241 | * stronger message digests instead. |
| 242 | * |
| 243 | * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0. |
| 244 | * |
| 245 | * \param ctx The SHA-1 context. This must be initialized. |
| 246 | * \param data The data block being processed. |
| 247 | * This must be a readable buffer of length \c 64 bytes. |
| 248 | * |
| 249 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 250 | MBEDTLS_DEPRECATED void mbedtls_sha1_process(mbedtls_sha1_context *ctx, |
| 251 | const unsigned char data[64]); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 252 | |
| 253 | #undef MBEDTLS_DEPRECATED |
| 254 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| 255 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 256 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 257 | * \brief This function calculates the SHA-1 checksum of a buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 258 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 259 | * The function allocates the context, performs the |
| 260 | * calculation, and frees the context. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 261 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 262 | * The SHA-1 result is calculated as |
| 263 | * output = SHA-1(input buffer). |
| 264 | * |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 265 | * \warning SHA-1 is considered a weak message digest and its use |
| 266 | * constitutes a security risk. We recommend considering |
| 267 | * stronger message digests instead. |
| 268 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 269 | * \param input The buffer holding the input data. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 270 | * This must be a readable buffer of length \p ilen Bytes. |
| 271 | * \param ilen The length of the input data \p input in Bytes. |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 272 | * \param output The SHA-1 checksum result. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 273 | * This must be a writable buffer of length \c 20 Bytes. |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 274 | * |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 275 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 276 | * \return A negative error code on failure. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 277 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 278 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 279 | int mbedtls_sha1_ret(const unsigned char *input, |
| 280 | size_t ilen, |
| 281 | unsigned char output[20]); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 282 | |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 283 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 284 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 285 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 286 | #else |
| 287 | #define MBEDTLS_DEPRECATED |
| 288 | #endif |
| 289 | /** |
| 290 | * \brief This function calculates the SHA-1 checksum of a buffer. |
| 291 | * |
| 292 | * The function allocates the context, performs the |
| 293 | * calculation, and frees the context. |
| 294 | * |
| 295 | * The SHA-1 result is calculated as |
| 296 | * output = SHA-1(input buffer). |
| 297 | * |
| 298 | * \warning SHA-1 is considered a weak message digest and its use |
| 299 | * constitutes a security risk. We recommend considering |
| 300 | * stronger message digests instead. |
| 301 | * |
| 302 | * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0 |
| 303 | * |
| 304 | * \param input The buffer holding the input data. |
| 305 | * This must be a readable buffer of length \p ilen Bytes. |
| 306 | * \param ilen The length of the input data \p input in Bytes. |
| 307 | * \param output The SHA-1 checksum result. This must be a writable |
| 308 | * buffer of size \c 20 Bytes. |
| 309 | * |
| 310 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 311 | MBEDTLS_DEPRECATED void mbedtls_sha1(const unsigned char *input, |
| 312 | size_t ilen, |
| 313 | unsigned char output[20]); |
Manuel Pégourié-Gonnard | 93c0847 | 2021-04-15 12:23:55 +0200 | [diff] [blame] | 314 | |
| 315 | #undef MBEDTLS_DEPRECATED |
| 316 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
| 317 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 318 | #if defined(MBEDTLS_SELF_TEST) |
| 319 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 320 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 321 | * \brief The SHA-1 checkup routine. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 322 | * |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 323 | * \warning SHA-1 is considered a weak message digest and its use |
| 324 | * constitutes a security risk. We recommend considering |
| 325 | * stronger message digests instead. |
| 326 | * |
Rose Zadik | 8274142 | 2018-03-27 12:49:48 +0100 | [diff] [blame] | 327 | * \return \c 0 on success. |
| 328 | * \return \c 1 on failure. |
| 329 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 330 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 331 | int mbedtls_sha1_self_test(int verbose); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 332 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 333 | #endif /* MBEDTLS_SELF_TEST */ |
| 334 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 335 | #ifdef __cplusplus |
| 336 | } |
| 337 | #endif |
| 338 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 339 | #endif /* mbedtls_sha1.h */ |