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