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