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 sha256.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Rose Zadik | bde68b4 | 2018-03-27 12:59:13 +0100 | [diff] [blame] | 4 | * \brief This file contains SHA-224 and SHA-256 definitions and functions. |
| 5 | * |
| 6 | * The Secure Hash Algorithms 224 and 256 (SHA-224 and SHA-256) cryptographic |
| 7 | * hash functions are defined in <em>FIPS 180-4: Secure Hash Standard (SHS)</em>. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 8 | */ |
| 9 | /* |
Bence Szépkúti | a2947ac | 2020-08-19 16:37:36 +0200 | [diff] [blame] | 10 | * Copyright The Mbed TLS Contributors |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 12 | * |
| 13 | * This file is provided under the Apache License 2.0, or the |
| 14 | * GNU General Public License v2.0 or later. |
| 15 | * |
| 16 | * ********** |
| 17 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 18 | * |
| 19 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 20 | * not use this file except in compliance with the License. |
| 21 | * You may obtain a copy of the License at |
| 22 | * |
| 23 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 24 | * |
| 25 | * Unless required by applicable law or agreed to in writing, software |
| 26 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 27 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 28 | * See the License for the specific language governing permissions and |
| 29 | * limitations under the License. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 30 | * |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 31 | * ********** |
| 32 | * |
| 33 | * ********** |
| 34 | * GNU General Public License v2.0 or later: |
| 35 | * |
| 36 | * This program is free software; you can redistribute it and/or modify |
| 37 | * it under the terms of the GNU General Public License as published by |
| 38 | * the Free Software Foundation; either version 2 of the License, or |
| 39 | * (at your option) any later version. |
| 40 | * |
| 41 | * This program is distributed in the hope that it will be useful, |
| 42 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 43 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 44 | * GNU General Public License for more details. |
| 45 | * |
| 46 | * You should have received a copy of the GNU General Public License along |
| 47 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 48 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 49 | * |
| 50 | * ********** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | #ifndef MBEDTLS_SHA256_H |
| 53 | #define MBEDTLS_SHA256_H |
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 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 56 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 57 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 59 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 60 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 61 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 62 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 63 | |
Ron Eldor | 9924bdc | 2018-10-04 10:59:13 +0300 | [diff] [blame] | 64 | /* MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED is deprecated and should not be used. */ |
Gilles Peskine | 1990fab | 2021-07-26 18:48:10 +0200 | [diff] [blame] | 65 | /** SHA-256 hardware accelerator failed */ |
| 66 | #define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 |
| 67 | /** SHA-256 input data was malformed. */ |
| 68 | #define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA -0x0074 |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 69 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 70 | #ifdef __cplusplus |
| 71 | extern "C" { |
| 72 | #endif |
| 73 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 74 | #if !defined(MBEDTLS_SHA256_ALT) |
| 75 | // Regular implementation |
| 76 | // |
| 77 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 78 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 79 | * \brief The SHA-256 context structure. |
| 80 | * |
| 81 | * The structure is used both for SHA-256 and for SHA-224 |
| 82 | * checksum calculations. The choice between these two is |
| 83 | * made in the call to mbedtls_sha256_starts_ret(). |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 84 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 85 | typedef struct mbedtls_sha256_context |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 86 | { |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 87 | uint32_t total[2]; /*!< The number of Bytes processed. */ |
| 88 | uint32_t state[8]; /*!< The intermediate digest state. */ |
| 89 | unsigned char buffer[64]; /*!< The data block being processed. */ |
Rose Zadik | bde68b4 | 2018-03-27 12:59:13 +0100 | [diff] [blame] | 90 | int is224; /*!< Determines which function to use: |
| 91 | 0: Use SHA-256, or 1: Use SHA-224. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 92 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 93 | mbedtls_sha256_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 94 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 95 | #else /* MBEDTLS_SHA256_ALT */ |
| 96 | #include "sha256_alt.h" |
| 97 | #endif /* MBEDTLS_SHA256_ALT */ |
| 98 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 99 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 100 | * \brief This function initializes a SHA-256 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 101 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 102 | * \param ctx The SHA-256 context to initialize. This must not be \c NULL. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 103 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 104 | void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 105 | |
| 106 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 107 | * \brief This function clears a SHA-256 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 108 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 109 | * \param ctx The SHA-256 context to clear. This may be \c NULL, in which |
| 110 | * case this function returns immediately. If it is not \c NULL, |
| 111 | * it must point to an initialized SHA-256 context. |
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_sha256_free( mbedtls_sha256_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 114 | |
| 115 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 116 | * \brief This function clones the state of a SHA-256 context. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 117 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 118 | * \param dst The destination context. This must be initialized. |
| 119 | * \param src The context to clone. This must be initialized. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 120 | */ |
| 121 | void mbedtls_sha256_clone( mbedtls_sha256_context *dst, |
| 122 | const mbedtls_sha256_context *src ); |
| 123 | |
| 124 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 125 | * \brief This function starts a SHA-224 or SHA-256 checksum |
| 126 | * calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 127 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 128 | * \param ctx The context to use. This must be initialized. |
| 129 | * \param is224 This determines which function to use. This must be |
| 130 | * either \c 0 for SHA-256, or \c 1 for SHA-224. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 131 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 132 | * \return \c 0 on success. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 133 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 134 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 135 | int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 136 | |
| 137 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 138 | * \brief This function feeds an input buffer into an ongoing |
| 139 | * SHA-256 checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 140 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 141 | * \param ctx The SHA-256 context. This must be initialized |
| 142 | * and have a hash operation started. |
| 143 | * \param input The buffer holding the data. This must be a readable |
| 144 | * buffer of length \p ilen Bytes. |
Hanno Becker | fc2a0b2 | 2018-12-18 16:31:48 +0000 | [diff] [blame] | 145 | * \param ilen The length of the input data in Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 146 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 147 | * \return \c 0 on success. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 148 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 149 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 150 | int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 151 | const unsigned char *input, |
| 152 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 153 | |
| 154 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 155 | * \brief This function finishes the SHA-256 operation, and writes |
| 156 | * the result to the output buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 157 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 158 | * \param ctx The SHA-256 context. This must be initialized |
| 159 | * and have a hash operation started. |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 160 | * \param output The SHA-224 or SHA-256 checksum result. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 161 | * This must be a writable buffer of length \c 32 Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 162 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 163 | * \return \c 0 on success. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 164 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 165 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 166 | int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 167 | unsigned char output[32] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 168 | |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 169 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 170 | * \brief This function processes a single data block within |
| 171 | * the ongoing SHA-256 computation. This function is for |
| 172 | * internal use only. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 173 | * |
Hanno Becker | 3f1f4ad | 2018-12-18 23:19:37 +0000 | [diff] [blame] | 174 | * \param ctx The SHA-256 context. This must be initialized. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 175 | * \param data The buffer holding one block of data. This must |
| 176 | * be a readable buffer of length \c 64 Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 177 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 178 | * \return \c 0 on success. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 179 | * \return A negative error code on failure. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 180 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 181 | int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, |
| 182 | const unsigned char data[64] ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 183 | |
| 184 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 185 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 186 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 187 | #else |
| 188 | #define MBEDTLS_DEPRECATED |
| 189 | #endif |
| 190 | /** |
Rose Zadik | bde68b4 | 2018-03-27 12:59:13 +0100 | [diff] [blame] | 191 | * \brief This function starts a SHA-224 or SHA-256 checksum |
| 192 | * calculation. |
| 193 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 194 | * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 195 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 196 | * \param ctx The context to use. This must be initialized. |
| 197 | * \param is224 Determines which function to use. This must be |
| 198 | * either \c 0 for SHA-256, or \c 1 for SHA-224. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 199 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 200 | MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, |
| 201 | int is224 ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 202 | |
| 203 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 204 | * \brief This function feeds an input buffer into an ongoing |
| 205 | * SHA-256 checksum calculation. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 206 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 207 | * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 208 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 209 | * \param ctx The SHA-256 context to use. This must be |
| 210 | * initialized and have a hash operation started. |
| 211 | * \param input The buffer holding the data. This must be a readable |
| 212 | * buffer of length \p ilen Bytes. |
Hanno Becker | fc2a0b2 | 2018-12-18 16:31:48 +0000 | [diff] [blame] | 213 | * \param ilen The length of the input data in Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 214 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 215 | MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx, |
| 216 | const unsigned char *input, |
| 217 | size_t ilen ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 218 | |
| 219 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 220 | * \brief This function finishes the SHA-256 operation, and writes |
| 221 | * the result to the output buffer. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 222 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 223 | * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 224 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 225 | * \param ctx The SHA-256 context. This must be initialized and |
Hanno Becker | fc2a0b2 | 2018-12-18 16:31:48 +0000 | [diff] [blame] | 226 | * have a hash operation started. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 227 | * \param output The SHA-224 or SHA-256 checksum result. This must be |
| 228 | * a writable buffer of length \c 32 Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 229 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 230 | MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, |
| 231 | unsigned char output[32] ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 232 | |
| 233 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 234 | * \brief This function processes a single data block within |
| 235 | * the ongoing SHA-256 computation. This function is for |
| 236 | * internal use only. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 237 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 238 | * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 239 | * |
Hanno Becker | 3f1f4ad | 2018-12-18 23:19:37 +0000 | [diff] [blame] | 240 | * \param ctx The SHA-256 context. This must be initialized. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 241 | * \param data The buffer holding one block of data. This must be |
| 242 | * a readable buffer of size \c 64 Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 243 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 244 | MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx, |
| 245 | const unsigned char data[64] ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 246 | |
| 247 | #undef MBEDTLS_DEPRECATED |
| 248 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 249 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 250 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 251 | * \brief This function calculates the SHA-224 or SHA-256 |
| 252 | * checksum of a buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 253 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 254 | * The function allocates the context, performs the |
| 255 | * calculation, and frees the context. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 256 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 257 | * The SHA-256 result is calculated as |
| 258 | * output = SHA-256(input buffer). |
| 259 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 260 | * \param input The buffer holding the data. This must be a readable |
| 261 | * buffer of length \p ilen Bytes. |
Hanno Becker | fc2a0b2 | 2018-12-18 16:31:48 +0000 | [diff] [blame] | 262 | * \param ilen The length of the input data in Bytes. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 263 | * \param output The SHA-224 or SHA-256 checksum result. This must |
| 264 | * be a writable buffer of length \c 32 Bytes. |
| 265 | * \param is224 Determines which function to use. This must be |
| 266 | * either \c 0 for SHA-256, or \c 1 for SHA-224. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 267 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 268 | int mbedtls_sha256_ret( const unsigned char *input, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 269 | size_t ilen, |
| 270 | unsigned char output[32], |
| 271 | int is224 ); |
| 272 | |
| 273 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 274 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 275 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 276 | #else |
| 277 | #define MBEDTLS_DEPRECATED |
| 278 | #endif |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 279 | |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 280 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 281 | * \brief This function calculates the SHA-224 or SHA-256 checksum |
| 282 | * of a buffer. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 283 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 284 | * The function allocates the context, performs the |
| 285 | * calculation, and frees the context. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 286 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 287 | * The SHA-256 result is calculated as |
| 288 | * output = SHA-256(input buffer). |
| 289 | * |
| 290 | * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0. |
| 291 | * |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 292 | * \param input The buffer holding the data. This must be a readable |
| 293 | * buffer of length \p ilen Bytes. |
Hanno Becker | fc2a0b2 | 2018-12-18 16:31:48 +0000 | [diff] [blame] | 294 | * \param ilen The length of the input data in Bytes. |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 295 | * \param output The SHA-224 or SHA-256 checksum result. This must be |
| 296 | * a writable buffer of length \c 32 Bytes. |
Hanno Becker | fc2a0b2 | 2018-12-18 16:31:48 +0000 | [diff] [blame] | 297 | * \param is224 Determines which function to use. This must be either |
Hanno Becker | 77886af | 2018-12-18 14:54:04 +0000 | [diff] [blame] | 298 | * \c 0 for SHA-256, or \c 1 for SHA-224. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 299 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 300 | MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input, |
| 301 | size_t ilen, |
| 302 | unsigned char output[32], |
| 303 | int is224 ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +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 | |
Ron Eldor | fa8f635 | 2017-06-20 15:48:46 +0300 | [diff] [blame] | 308 | #if defined(MBEDTLS_SELF_TEST) |
| 309 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 310 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 311 | * \brief The SHA-224 and SHA-256 checkup routine. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 312 | * |
Rose Zadik | bde68b4 | 2018-03-27 12:59:13 +0100 | [diff] [blame] | 313 | * \return \c 0 on success. |
| 314 | * \return \c 1 on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 315 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 316 | int mbedtls_sha256_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 317 | |
Ron Eldor | fa8f635 | 2017-06-20 15:48:46 +0300 | [diff] [blame] | 318 | #endif /* MBEDTLS_SELF_TEST */ |
| 319 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 320 | #ifdef __cplusplus |
| 321 | } |
| 322 | #endif |
| 323 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 324 | #endif /* mbedtls_sha256.h */ |