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 | /* |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 11 | * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved |
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 | * ********** |
| 52 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 53 | * This file is part of Mbed TLS (https://tls.mbed.org) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | #ifndef MBEDTLS_SHA1_H |
| 56 | #define MBEDTLS_SHA1_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 57 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 59 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 60 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 61 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 62 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 63 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 64 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 65 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 66 | |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 67 | #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */ |
| 68 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 69 | #if !defined(MBEDTLS_SHA1_ALT) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 70 | // Regular implementation |
| 71 | // |
| 72 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 73 | #ifdef __cplusplus |
| 74 | extern "C" { |
| 75 | #endif |
| 76 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 77 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 78 | * \brief The SHA-1 context structure. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 79 | * |
| 80 | * \warning SHA-1 is considered a weak message digest and its use |
| 81 | * constitutes a security risk. We recommend considering |
| 82 | * stronger message digests instead. |
| 83 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 84 | */ |
| 85 | typedef struct |
| 86 | { |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 87 | uint32_t total[2]; /*!< The number of Bytes processed. */ |
| 88 | uint32_t state[5]; /*!< The intermediate digest state. */ |
| 89 | unsigned char buffer[64]; /*!< The data block being processed. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 90 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 91 | mbedtls_sha1_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 92 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 93 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 94 | * \brief This function initializes a SHA-1 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 95 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 96 | * \param ctx The SHA-1 context to initialize. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 97 | * |
| 98 | * \warning SHA-1 is considered a weak message digest and its use |
| 99 | * constitutes a security risk. We recommend considering |
| 100 | * stronger message digests instead. |
| 101 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 102 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 103 | void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 106 | * \brief This function clears a SHA-1 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 107 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 108 | * \param ctx The SHA-1 context to clear. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 109 | * |
| 110 | * \warning SHA-1 is considered a weak message digest and its use |
| 111 | * constitutes a security risk. We recommend considering |
| 112 | * stronger message digests instead. |
| 113 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 114 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 115 | void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 116 | |
| 117 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 118 | * \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] | 119 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 120 | * \param dst The destination context. |
| 121 | * \param src The context to clone. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 122 | * |
| 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 | * |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 127 | */ |
| 128 | void mbedtls_sha1_clone( mbedtls_sha1_context *dst, |
| 129 | const mbedtls_sha1_context *src ); |
| 130 | |
| 131 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 132 | * \brief This function starts a SHA-1 checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 133 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 134 | * \param ctx The context to initialize. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 135 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 136 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 137 | * |
| 138 | * \warning SHA-1 is considered a weak message digest and its use |
| 139 | * constitutes a security risk. We recommend considering |
| 140 | * stronger message digests instead. |
| 141 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 142 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 143 | int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 144 | |
| 145 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 146 | * \brief This function feeds an input buffer into an ongoing SHA-1 |
| 147 | * checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 148 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 149 | * \param ctx The SHA-1 context. |
| 150 | * \param input The buffer holding the input data. |
| 151 | * \param ilen The length of the input data. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 152 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 153 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 154 | * |
| 155 | * \warning SHA-1 is considered a weak message digest and its use |
| 156 | * constitutes a security risk. We recommend considering |
| 157 | * stronger message digests instead. |
| 158 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 159 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 160 | int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 161 | const unsigned char *input, |
| 162 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 163 | |
| 164 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 165 | * \brief This function finishes the SHA-1 operation, and writes |
| 166 | * the result to the output buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 167 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 168 | * \param ctx The SHA-1 context. |
| 169 | * \param output The SHA-1 checksum result. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 170 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 171 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 172 | * |
| 173 | * \warning SHA-1 is considered a weak message digest and its use |
| 174 | * constitutes a security risk. We recommend considering |
| 175 | * stronger message digests instead. |
| 176 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 177 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 178 | int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 179 | unsigned char output[20] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 180 | |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 181 | /** |
| 182 | * \brief SHA-1 process data block (internal use only) |
| 183 | * |
| 184 | * \param ctx SHA-1 context |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 185 | * \param data The data block being processed. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 186 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 187 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 188 | * |
| 189 | * \warning SHA-1 is considered a weak message digest and its use |
| 190 | * constitutes a security risk. We recommend considering |
| 191 | * stronger message digests instead. |
| 192 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 193 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 194 | int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, |
| 195 | const unsigned char data[64] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 196 | |
| 197 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 198 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 199 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 200 | #else |
| 201 | #define MBEDTLS_DEPRECATED |
| 202 | #endif |
| 203 | /** |
| 204 | * \brief SHA-1 context setup |
| 205 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 206 | * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 207 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 208 | * \param ctx The SHA-1 context to be initialized. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 209 | * |
| 210 | * \warning SHA-1 is considered a weak message digest and its use |
| 211 | * constitutes a security risk. We recommend considering |
| 212 | * stronger message digests instead. |
| 213 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 214 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 215 | MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * \brief SHA-1 process buffer |
| 219 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 220 | * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 221 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 222 | * \param ctx The SHA-1 context. |
| 223 | * \param input The buffer holding the input data. |
| 224 | * \param ilen The length of the input data. |
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 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 230 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 231 | MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx, |
| 232 | const unsigned char *input, |
| 233 | size_t ilen ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 234 | |
| 235 | /** |
| 236 | * \brief SHA-1 final digest |
| 237 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 238 | * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 239 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 240 | * \param ctx The SHA-1 context. |
| 241 | * \param output The SHA-1 checksum result. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 242 | * |
| 243 | * \warning SHA-1 is considered a weak message digest and its use |
| 244 | * constitutes a security risk. We recommend considering |
| 245 | * stronger message digests instead. |
| 246 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 247 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 248 | MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, |
| 249 | unsigned char output[20] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 250 | |
| 251 | /** |
| 252 | * \brief SHA-1 process data block (internal use only) |
| 253 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 254 | * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 255 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 256 | * \param ctx The SHA-1 context. |
| 257 | * \param data The data block being processed. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 258 | * |
| 259 | * \warning SHA-1 is considered a weak message digest and its use |
| 260 | * constitutes a security risk. We recommend considering |
| 261 | * stronger message digests instead. |
| 262 | * |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 263 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 264 | MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx, |
| 265 | const unsigned char data[64] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 266 | |
| 267 | #undef MBEDTLS_DEPRECATED |
| 268 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 269 | |
| 270 | #ifdef __cplusplus |
| 271 | } |
| 272 | #endif |
| 273 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 274 | #else /* MBEDTLS_SHA1_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 275 | #include "sha1_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 276 | #endif /* MBEDTLS_SHA1_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 277 | |
| 278 | #ifdef __cplusplus |
| 279 | extern "C" { |
| 280 | #endif |
| 281 | |
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 | * \brief This function calculates the SHA-1 checksum of a buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 284 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 285 | * The function allocates the context, performs the |
| 286 | * calculation, and frees the context. |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 287 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 288 | * The SHA-1 result is calculated as |
| 289 | * output = SHA-1(input buffer). |
| 290 | * |
| 291 | * \param input The buffer holding the input data. |
| 292 | * \param ilen The length of the input data. |
| 293 | * \param output The SHA-1 checksum result. |
| 294 | * |
| 295 | * \return \c 0 if successful |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 296 | * |
| 297 | * \warning SHA-1 is considered a weak message digest and its use |
| 298 | * constitutes a security risk. We recommend considering |
| 299 | * stronger message digests instead. |
| 300 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 301 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 302 | int mbedtls_sha1_ret( const unsigned char *input, |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 303 | size_t ilen, |
| 304 | unsigned char output[20] ); |
| 305 | |
| 306 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 307 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 308 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 309 | #else |
| 310 | #define MBEDTLS_DEPRECATED |
| 311 | #endif |
| 312 | /** |
| 313 | * \brief Output = SHA-1( input buffer ) |
| 314 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 315 | * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0 |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 316 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 317 | * \param input The buffer holding the input data. |
| 318 | * \param ilen The length of the input data. |
| 319 | * \param output The SHA-1 checksum result. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 320 | * |
| 321 | * \warning SHA-1 is considered a weak message digest and its use |
| 322 | * constitutes a security risk. We recommend considering |
| 323 | * stronger message digests instead. |
| 324 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 325 | */ |
Jaeden Amero | a53ff8d | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 326 | MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input, |
| 327 | size_t ilen, |
| 328 | unsigned char output[20] ); |
Andres Amaya Garcia | 034ea7e | 2017-04-28 15:14:50 +0100 | [diff] [blame] | 329 | |
| 330 | #undef MBEDTLS_DEPRECATED |
| 331 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 332 | |
| 333 | /** |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 334 | * \brief The SHA-1 checkup routine. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 335 | * |
Rose Zadik | 44833d9 | 2018-01-26 08:41:09 +0000 | [diff] [blame] | 336 | * \return \c 0 on success, or \c 1 on failure. |
Hanno Becker | bbca8c5 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 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. |
| 341 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 342 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 343 | int mbedtls_sha1_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 344 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 345 | #ifdef __cplusplus |
| 346 | } |
| 347 | #endif |
| 348 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 349 | #endif /* mbedtls_sha1.h */ |