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 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 79 | void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 80 | |
| 81 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 82 | * \brief This function clears a SHA-256 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 83 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 84 | * \param ctx The SHA-256 context to clear. This may be \c NULL, in which |
| 85 | * case this function returns immediately. If it is not \c NULL, |
| 86 | * it must point to an initialized SHA-256 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 87 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 88 | void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 89 | |
| 90 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 91 | * \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] | 92 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 93 | * \param dst The destination context. This must be initialized. |
| 94 | * \param src The context to clone. This must be initialized. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 95 | */ |
| 96 | void mbedtls_sha256_clone( mbedtls_sha256_context *dst, |
| 97 | const mbedtls_sha256_context *src ); |
| 98 | |
| 99 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 100 | * \brief This function starts a SHA-224 or SHA-256 checksum |
| 101 | * calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 102 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 103 | * \param ctx The context to use. This must be initialized. |
| 104 | * \param is224 This determines which function to use. This must be |
| 105 | * 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] | 106 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 107 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 108 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 109 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 110 | int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 111 | |
| 112 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 113 | * \brief This function feeds an input buffer into an ongoing |
| 114 | * SHA-256 checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 115 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 116 | * \param ctx The SHA-256 context. This must be initialized |
| 117 | * and have a hash operation started. |
| 118 | * \param input The buffer holding the data. This must be a readable |
| 119 | * buffer of length \p ilen Bytes. |
| 120 | * \param ilen The length of the input data in Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 121 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 122 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 123 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 124 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 125 | int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 126 | const unsigned char *input, |
| 127 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 128 | |
| 129 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 130 | * \brief This function finishes the SHA-256 operation, and writes |
| 131 | * the result to the output buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 132 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 133 | * \param ctx The SHA-256 context. This must be initialized |
| 134 | * and have a hash operation started. |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 135 | * \param output The SHA-224 or SHA-256 checksum result. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 136 | * This must be a writable buffer of length \c 32 Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 137 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 138 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 139 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 140 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 141 | int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 142 | unsigned char output[32] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 143 | |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 144 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 145 | * \brief This function processes a single data block within |
| 146 | * the ongoing SHA-256 computation. This function is for |
| 147 | * internal use only. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 148 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 149 | * \param ctx The SHA-256 context. This must be initialized. |
| 150 | * \param data The buffer holding one block of data. This must |
| 151 | * be a readable buffer of length \c 64 Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 152 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 153 | * \return \c 0 on success. |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 154 | * \return A negative error code on failure. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 155 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 156 | int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, |
| 157 | const unsigned char data[64] ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 158 | |
| 159 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 160 | /** |
Rose Zadik | bde68b4 | 2018-03-27 12:59:13 +0100 | [diff] [blame] | 161 | * \brief This function starts a SHA-224 or SHA-256 checksum |
| 162 | * calculation. |
| 163 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 164 | * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 165 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 166 | * \param ctx The context to use. This must be initialized. |
| 167 | * \param is224 Determines which function to use. This must be |
| 168 | * 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] | 169 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 170 | MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, |
| 171 | int is224 ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 172 | |
| 173 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 174 | * \brief This function feeds an input buffer into an ongoing |
| 175 | * SHA-256 checksum calculation. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 176 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 177 | * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 178 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 179 | * \param ctx The SHA-256 context to use. This must be |
| 180 | * initialized and have a hash operation started. |
| 181 | * \param input The buffer holding the data. This must be a readable |
| 182 | * buffer of length \p ilen Bytes. |
| 183 | * \param ilen The length of the input data in Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 184 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 185 | MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx, |
| 186 | const unsigned char *input, |
| 187 | size_t ilen ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 188 | |
| 189 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 190 | * \brief This function finishes the SHA-256 operation, and writes |
| 191 | * the result to the output buffer. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 192 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 193 | * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 194 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 195 | * \param ctx The SHA-256 context. This must be initialized and |
| 196 | * have a hash operation started. |
| 197 | * \param output The SHA-224 or SHA-256 checksum result. This must be |
| 198 | * a writable buffer of length \c 32 Bytes. |
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_finish( mbedtls_sha256_context *ctx, |
| 201 | unsigned char output[32] ); |
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 processes a single data block within |
| 205 | * the ongoing SHA-256 computation. This function is for |
| 206 | * internal use only. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 207 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 208 | * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 209 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 210 | * \param ctx The SHA-256 context. This must be initialized. |
| 211 | * \param data The buffer holding one block of data. This must be |
| 212 | * a readable buffer of size \c 64 Bytes. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 213 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 214 | MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx, |
| 215 | const unsigned char data[64] ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 216 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 217 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 218 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 219 | * \brief This function calculates the SHA-224 or SHA-256 |
| 220 | * checksum of a buffer. |
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 | * The function allocates the context, performs the |
| 223 | * calculation, and frees the context. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 224 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 225 | * The SHA-256 result is calculated as |
| 226 | * output = SHA-256(input buffer). |
| 227 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 228 | * \param input The buffer holding the data. This must be a readable |
| 229 | * buffer of length \p ilen Bytes. |
| 230 | * \param ilen The length of the input data in Bytes. |
| 231 | * \param output The SHA-224 or SHA-256 checksum result. This must |
| 232 | * be a writable buffer of length \c 32 Bytes. |
| 233 | * \param is224 Determines which function to use. This must be |
| 234 | * either \c 0 for SHA-256, or \c 1 for SHA-224. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 235 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 236 | int mbedtls_sha256_ret( const unsigned char *input, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 237 | size_t ilen, |
| 238 | unsigned char output[32], |
| 239 | int is224 ); |
| 240 | |
| 241 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 242 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 243 | * \brief This function calculates the SHA-224 or SHA-256 checksum |
| 244 | * of a buffer. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 245 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 246 | * The function allocates the context, performs the |
| 247 | * calculation, and frees the context. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 248 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 249 | * The SHA-256 result is calculated as |
| 250 | * output = SHA-256(input buffer). |
| 251 | * |
| 252 | * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0. |
| 253 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 254 | * \param input The buffer holding the data. This must be a readable |
| 255 | * buffer of length \p ilen Bytes. |
| 256 | * \param ilen The length of the input data in Bytes. |
| 257 | * \param output The SHA-224 or SHA-256 checksum result. This must be |
| 258 | * a writable buffer of length \c 32 Bytes. |
| 259 | * \param is224 Determines which function to use. This must be either |
| 260 | * \c 0 for SHA-256, or \c 1 for SHA-224. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 261 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 262 | MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input, |
| 263 | size_t ilen, |
| 264 | unsigned char output[32], |
| 265 | int is224 ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 266 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 267 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 268 | #if defined(MBEDTLS_SELF_TEST) |
| 269 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 270 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 271 | * \brief The SHA-224 and SHA-256 checkup routine. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 272 | * |
Rose Zadik | bde68b4 | 2018-03-27 12:59:13 +0100 | [diff] [blame] | 273 | * \return \c 0 on success. |
| 274 | * \return \c 1 on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 275 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 276 | int mbedtls_sha256_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 277 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 278 | #endif /* MBEDTLS_SELF_TEST */ |
| 279 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 280 | #ifdef __cplusplus |
| 281 | } |
| 282 | #endif |
| 283 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 284 | #endif /* mbedtls_sha256.h */ |