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