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