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