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 | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 4 | * \brief The SHA-1 cryptographic hash function. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 5 | * |
| 6 | * \warning SHA-1 is considered a weak message digest and its use constitutes |
| 7 | * a security risk. We recommend considering stronger message |
| 8 | * digests instead. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 9 | */ |
| 10 | /* |
Bence Szépkúti | 44bfbe3 | 2020-08-19 16:54:51 +0200 | [diff] [blame] | 11 | * Copyright The Mbed TLS Contributors |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 12 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 13 | * |
| 14 | * This file is provided under the Apache License 2.0, or the |
| 15 | * GNU General Public License v2.0 or later. |
| 16 | * |
| 17 | * ********** |
| 18 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | * not use this file except in compliance with the License. |
| 22 | * You may obtain a copy of the License at |
| 23 | * |
| 24 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | * |
| 26 | * Unless required by applicable law or agreed to in writing, software |
| 27 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 29 | * See the License for the specific language governing permissions and |
| 30 | * limitations under the License. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 31 | * |
Bence Szépkúti | 4e9f712 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 32 | * ********** |
| 33 | * |
| 34 | * ********** |
| 35 | * GNU General Public License v2.0 or later: |
| 36 | * |
| 37 | * This program is free software; you can redistribute it and/or modify |
| 38 | * it under the terms of the GNU General Public License as published by |
| 39 | * the Free Software Foundation; either version 2 of the License, or |
| 40 | * (at your option) any later version. |
| 41 | * |
| 42 | * This program is distributed in the hope that it will be useful, |
| 43 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 44 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 45 | * GNU General Public License for more details. |
| 46 | * |
| 47 | * You should have received a copy of the GNU General Public License along |
| 48 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 49 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 50 | * |
| 51 | * ********** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 52 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 53 | #ifndef MBEDTLS_SHA1_H |
| 54 | #define MBEDTLS_SHA1_H |
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 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 57 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 58 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 59 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 60 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 61 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 62 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 63 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 64 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 65 | #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */ |
| 66 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 67 | #if !defined(MBEDTLS_SHA1_ALT) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 68 | // Regular implementation |
| 69 | // |
| 70 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 71 | #ifdef __cplusplus |
| 72 | extern "C" { |
| 73 | #endif |
| 74 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 75 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 76 | * \brief The SHA-1 context structure. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 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 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 82 | */ |
| 83 | typedef struct |
| 84 | { |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 85 | uint32_t total[2]; /*!< The number of Bytes processed. */ |
| 86 | uint32_t state[5]; /*!< The intermediate digest state. */ |
| 87 | unsigned char buffer[64]; /*!< The data block being processed. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 88 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 89 | mbedtls_sha1_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 90 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 91 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 92 | * \brief This function initializes a SHA-1 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 93 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 94 | * \param ctx The SHA-1 context to initialize. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 95 | * |
| 96 | * \warning SHA-1 is considered a weak message digest and its use |
| 97 | * constitutes a security risk. We recommend considering |
| 98 | * stronger message digests instead. |
| 99 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 100 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 101 | void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 102 | |
| 103 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 104 | * \brief This function clears a SHA-1 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 105 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 106 | * \param ctx The SHA-1 context to clear. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 107 | * |
| 108 | * \warning SHA-1 is considered a weak message digest and its use |
| 109 | * constitutes a security risk. We recommend considering |
| 110 | * stronger message digests instead. |
| 111 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 112 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 113 | void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 114 | |
| 115 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 116 | * \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] | 117 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 118 | * \param dst The destination context. |
| 119 | * \param src The context to clone. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 120 | * |
| 121 | * \warning SHA-1 is considered a weak message digest and its use |
| 122 | * constitutes a security risk. We recommend considering |
| 123 | * stronger message digests instead. |
| 124 | * |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 125 | */ |
| 126 | void mbedtls_sha1_clone( mbedtls_sha1_context *dst, |
| 127 | const mbedtls_sha1_context *src ); |
| 128 | |
| 129 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 130 | * \brief This function starts a SHA-1 checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 131 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 132 | * \param ctx The context to initialize. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 133 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 134 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 135 | * |
| 136 | * \warning SHA-1 is considered a weak message digest and its use |
| 137 | * constitutes a security risk. We recommend considering |
| 138 | * stronger message digests instead. |
| 139 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 140 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 141 | int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 142 | |
| 143 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 144 | * \brief This function feeds an input buffer into an ongoing SHA-1 |
| 145 | * checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 146 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 147 | * \param ctx The SHA-1 context. |
| 148 | * \param input The buffer holding the input data. |
| 149 | * \param ilen The length of the input data. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 150 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 151 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 152 | * |
| 153 | * \warning SHA-1 is considered a weak message digest and its use |
| 154 | * constitutes a security risk. We recommend considering |
| 155 | * stronger message digests instead. |
| 156 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 157 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 158 | int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 159 | const unsigned char *input, |
| 160 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 161 | |
| 162 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 163 | * \brief This function finishes the SHA-1 operation, and writes |
| 164 | * the result to the output buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 165 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 166 | * \param ctx The SHA-1 context. |
| 167 | * \param output The SHA-1 checksum result. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 168 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 169 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 170 | * |
| 171 | * \warning SHA-1 is considered a weak message digest and its use |
| 172 | * constitutes a security risk. We recommend considering |
| 173 | * stronger message digests instead. |
| 174 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 175 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 176 | int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 177 | unsigned char output[20] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 178 | |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 179 | /** |
| 180 | * \brief SHA-1 process data block (internal use only) |
| 181 | * |
| 182 | * \param ctx SHA-1 context |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 183 | * \param data The data block being processed. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 184 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 185 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 186 | * |
| 187 | * \warning SHA-1 is considered a weak message digest and its use |
| 188 | * constitutes a security risk. We recommend considering |
| 189 | * stronger message digests instead. |
| 190 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 191 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 192 | int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, |
| 193 | const unsigned char data[64] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 194 | |
| 195 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 196 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 197 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 198 | #else |
| 199 | #define MBEDTLS_DEPRECATED |
| 200 | #endif |
| 201 | /** |
| 202 | * \brief SHA-1 context setup |
| 203 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 204 | * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 205 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 206 | * \param ctx The SHA-1 context to be initialized. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 207 | * |
| 208 | * \warning SHA-1 is considered a weak message digest and its use |
| 209 | * constitutes a security risk. We recommend considering |
| 210 | * stronger message digests instead. |
| 211 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 212 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 213 | MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * \brief SHA-1 process buffer |
| 217 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 218 | * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 219 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 220 | * \param ctx The SHA-1 context. |
| 221 | * \param input The buffer holding the input data. |
| 222 | * \param ilen The length of the input data. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 223 | * |
| 224 | * \warning SHA-1 is considered a weak message digest and its use |
| 225 | * constitutes a security risk. We recommend considering |
| 226 | * stronger message digests instead. |
| 227 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 228 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 229 | MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx, |
| 230 | const unsigned char *input, |
| 231 | size_t ilen ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * \brief SHA-1 final digest |
| 235 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 236 | * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 237 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 238 | * \param ctx The SHA-1 context. |
| 239 | * \param output The SHA-1 checksum result. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 240 | * |
| 241 | * \warning SHA-1 is considered a weak message digest and its use |
| 242 | * constitutes a security risk. We recommend considering |
| 243 | * stronger message digests instead. |
| 244 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 245 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 246 | MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, |
| 247 | unsigned char output[20] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * \brief SHA-1 process data block (internal use only) |
| 251 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 252 | * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 253 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 254 | * \param ctx The SHA-1 context. |
| 255 | * \param data The data block being processed. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 256 | * |
| 257 | * \warning SHA-1 is considered a weak message digest and its use |
| 258 | * constitutes a security risk. We recommend considering |
| 259 | * stronger message digests instead. |
| 260 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 261 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 262 | MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx, |
| 263 | const unsigned char data[64] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 264 | |
| 265 | #undef MBEDTLS_DEPRECATED |
| 266 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 267 | |
| 268 | #ifdef __cplusplus |
| 269 | } |
| 270 | #endif |
| 271 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 272 | #else /* MBEDTLS_SHA1_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 273 | #include "sha1_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 274 | #endif /* MBEDTLS_SHA1_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 275 | |
| 276 | #ifdef __cplusplus |
| 277 | extern "C" { |
| 278 | #endif |
| 279 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 280 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 281 | * \brief This function calculates the SHA-1 checksum of a buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 282 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 283 | * The function allocates the context, performs the |
| 284 | * calculation, and frees the context. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 285 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 286 | * The SHA-1 result is calculated as |
| 287 | * output = SHA-1(input buffer). |
| 288 | * |
| 289 | * \param input The buffer holding the input data. |
| 290 | * \param ilen The length of the input data. |
| 291 | * \param output The SHA-1 checksum result. |
| 292 | * |
| 293 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 294 | * |
| 295 | * \warning SHA-1 is considered a weak message digest and its use |
| 296 | * constitutes a security risk. We recommend considering |
| 297 | * stronger message digests instead. |
| 298 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 299 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 300 | int mbedtls_sha1_ret( const unsigned char *input, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 301 | size_t ilen, |
| 302 | unsigned char output[20] ); |
| 303 | |
| 304 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 305 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 306 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 307 | #else |
| 308 | #define MBEDTLS_DEPRECATED |
| 309 | #endif |
| 310 | /** |
| 311 | * \brief Output = SHA-1( input buffer ) |
| 312 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 313 | * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 314 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 315 | * \param input The buffer holding the input data. |
| 316 | * \param ilen The length of the input data. |
| 317 | * \param output The SHA-1 checksum result. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 318 | * |
| 319 | * \warning SHA-1 is considered a weak message digest and its use |
| 320 | * constitutes a security risk. We recommend considering |
| 321 | * stronger message digests instead. |
| 322 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 323 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 324 | MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input, |
| 325 | size_t ilen, |
| 326 | unsigned char output[20] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 327 | |
| 328 | #undef MBEDTLS_DEPRECATED |
| 329 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 330 | |
| 331 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 332 | * \brief The SHA-1 checkup routine. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 333 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 334 | * \return \c 0 on success, or \c 1 on failure. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 335 | * |
| 336 | * \warning SHA-1 is considered a weak message digest and its use |
| 337 | * constitutes a security risk. We recommend considering |
| 338 | * stronger message digests instead. |
| 339 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 340 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 341 | int mbedtls_sha1_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 342 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 343 | #ifdef __cplusplus |
| 344 | } |
| 345 | #endif |
| 346 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 347 | #endif /* mbedtls_sha1.h */ |