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