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 | |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 38 | #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ |
| 39 | !defined(inline) && !defined(__cplusplus) |
| 40 | #define inline __inline |
| 41 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 42 | #if !defined(MBEDTLS_SHA256_ALT) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 43 | // Regular implementation |
| 44 | // |
| 45 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 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 | */ |
| 57 | typedef struct |
| 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. */ |
| 62 | int is224; /*!< Determines which function to use. |
| 63 | <ul><li>0: Use SHA-256.</li> |
| 64 | <li>1: Use SHA-224.</li></ul> */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 65 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 66 | mbedtls_sha256_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 67 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 68 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 69 | * \brief This function initializes a SHA-256 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 70 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 71 | * \param ctx The SHA-256 context to initialize. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 72 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 73 | void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 74 | |
| 75 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 76 | * \brief This function clears a SHA-256 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 77 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 78 | * \param ctx The SHA-256 context to clear. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 79 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | void mbedtls_sha256_free( 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 clones the state of a SHA-256 context. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 84 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 85 | * \param dst The destination context. |
| 86 | * \param src The context to clone. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 87 | */ |
| 88 | void mbedtls_sha256_clone( mbedtls_sha256_context *dst, |
| 89 | const mbedtls_sha256_context *src ); |
| 90 | |
| 91 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 92 | * \brief This function starts a SHA-224 or SHA-256 checksum |
| 93 | * calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 94 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 95 | * \param ctx The context to initialize. |
| 96 | * \param is224 Determines which function to use. |
| 97 | * <ul><li>0: Use SHA-256.</li> |
| 98 | * <li>1: Use SHA-224.</li></ul> |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 99 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 100 | * \return \c 0 on success. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 101 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 102 | int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 103 | |
| 104 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 105 | * \brief This function feeds an input buffer into an ongoing |
| 106 | * SHA-256 checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 107 | * |
| 108 | * \param ctx SHA-256 context |
Andres Amaya Garcia | a21247e | 2017-07-20 14:01:08 +0100 | [diff] [blame] | 109 | * \param input buffer holding the data |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 110 | * \param ilen length of the input data |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 111 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 112 | * \return \c 0 on success. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 113 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 114 | int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 115 | const unsigned char *input, |
| 116 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 117 | |
| 118 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 119 | * \brief This function finishes the SHA-256 operation, and writes |
| 120 | * the result to the output buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 121 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 122 | * \param ctx The SHA-256 context. |
| 123 | * \param output The SHA-224 or SHA-256 checksum result. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 124 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 125 | * \return \c 0 on success. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 126 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 127 | int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 128 | unsigned char output[32] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 129 | |
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 | * \brief This function processes a single data block within |
| 132 | * the ongoing SHA-256 computation. This function is for |
| 133 | * internal use only. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 134 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 135 | * \param ctx The SHA-256 context. |
| 136 | * \param data The buffer holding one block of data. |
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. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 139 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 140 | int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, |
| 141 | const unsigned char data[64] ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 142 | |
| 143 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 144 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 145 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 146 | #else |
| 147 | #define MBEDTLS_DEPRECATED |
| 148 | #endif |
| 149 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 150 | * \brief This function starts a SHA-256 checksum calculation. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 151 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 152 | * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 153 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 154 | * \param ctx The SHA-256 context to initialize. |
| 155 | * \param is224 Determines which function to use. |
| 156 | * <ul><li>0: Use SHA-256.</li> |
| 157 | * <li>1: Use SHA-224.</li></ul> |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 158 | */ |
| 159 | MBEDTLS_DEPRECATED static inline void mbedtls_sha256_starts( |
| 160 | mbedtls_sha256_context *ctx, |
| 161 | int is224 ) |
| 162 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 163 | mbedtls_sha256_starts_ret( ctx, is224 ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 167 | * \brief This function feeds an input buffer into an ongoing |
| 168 | * SHA-256 checksum calculation. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 169 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 170 | * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 171 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 172 | * \param ctx The SHA-256 context to initialize. |
| 173 | * \param input The buffer holding the data. |
| 174 | * \param ilen The length of the input data. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 175 | */ |
| 176 | MBEDTLS_DEPRECATED static inline void mbedtls_sha256_update( |
| 177 | mbedtls_sha256_context *ctx, |
| 178 | const unsigned char *input, |
| 179 | size_t ilen ) |
| 180 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 181 | mbedtls_sha256_update_ret( ctx, input, ilen ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 185 | * \brief This function finishes the SHA-256 operation, and writes |
| 186 | * the result to the output buffer. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 187 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 188 | * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 189 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 190 | * \param ctx The SHA-256 context. |
| 191 | * \param output The SHA-224or SHA-256 checksum result. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 192 | */ |
| 193 | MBEDTLS_DEPRECATED static inline void mbedtls_sha256_finish( |
| 194 | mbedtls_sha256_context *ctx, |
| 195 | unsigned char output[32] ) |
| 196 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 197 | mbedtls_sha256_finish_ret( ctx, output ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 201 | * \brief This function processes a single data block within |
| 202 | * the ongoing SHA-256 computation. This function is for |
| 203 | * internal use only. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 204 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 205 | * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 206 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 207 | * \param ctx The SHA-256 context. |
| 208 | * \param data The buffer holding one block of data. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 209 | */ |
| 210 | MBEDTLS_DEPRECATED static inline void mbedtls_sha256_process( |
| 211 | mbedtls_sha256_context *ctx, |
| 212 | const unsigned char data[64] ) |
| 213 | { |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 214 | mbedtls_internal_sha256_process( ctx, data ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | #undef MBEDTLS_DEPRECATED |
| 218 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 219 | #ifdef __cplusplus |
| 220 | } |
| 221 | #endif |
| 222 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | #else /* MBEDTLS_SHA256_ALT */ |
Paul Bakker | d2681d8 | 2013-06-30 14:49:12 +0200 | [diff] [blame] | 224 | #include "sha256_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 225 | #endif /* MBEDTLS_SHA256_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 226 | |
| 227 | #ifdef __cplusplus |
| 228 | extern "C" { |
| 229 | #endif |
| 230 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 231 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 232 | * \brief This function calculates the SHA-224 or SHA-256 |
| 233 | * checksum of a buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 234 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 235 | * The function allocates the context, performs the |
| 236 | * calculation, and frees the context. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 237 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 238 | * The SHA-256 result is calculated as |
| 239 | * output = SHA-256(input buffer). |
| 240 | * |
| 241 | * \param input The buffer holding the input data. |
| 242 | * \param ilen The length of the input data. |
| 243 | * \param output The SHA-224 or SHA-256 checksum result. |
| 244 | * \param is224 Determines which function to use. |
| 245 | * <ul><li>0: Use SHA-256.</li> |
| 246 | * <li>1: Use SHA-224.</li></ul> |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 247 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 248 | int mbedtls_sha256_ret( const unsigned char *input, |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 249 | size_t ilen, |
| 250 | unsigned char output[32], |
| 251 | int is224 ); |
| 252 | |
| 253 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 254 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 255 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 256 | #else |
| 257 | #define MBEDTLS_DEPRECATED |
| 258 | #endif |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 259 | |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 260 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 261 | * \brief This function calculates the SHA-224 or SHA-256 checksum |
| 262 | * of a buffer. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 263 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 264 | * The function allocates the context, performs the |
| 265 | * calculation, and frees the context. |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 266 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 267 | * The SHA-256 result is calculated as |
| 268 | * output = SHA-256(input buffer). |
| 269 | * |
| 270 | * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0. |
| 271 | * |
| 272 | * \param input The buffer holding the data. |
| 273 | * \param ilen The length of the input data. |
| 274 | * \param output The SHA-224 or SHA-256 checksum result. |
| 275 | * \param is224 Determines which function to use. |
| 276 | * <ul><li>0: Use SHA-256.</li> |
| 277 | * <li>1: Use SHA-224.</li></ul> |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 278 | */ |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 279 | MBEDTLS_DEPRECATED static inline void mbedtls_sha256( |
| 280 | const unsigned char *input, |
| 281 | size_t ilen, |
| 282 | unsigned char output[32], |
| 283 | int is224 ) |
| 284 | { |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 285 | mbedtls_sha256_ret( input, ilen, output, is224 ); |
Andres Amaya Garcia | 72a7f53 | 2017-05-02 11:38:47 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | #undef MBEDTLS_DEPRECATED |
| 289 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 290 | |
| 291 | /** |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 292 | * \brief The SHA-224 and SHA-256 checkup routine. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 293 | * |
Rose Zadik | 602285e | 2018-01-26 11:00:39 +0000 | [diff] [blame] | 294 | * \return \c 0 on success, or \c 1 on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 295 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 296 | int mbedtls_sha256_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 297 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 298 | #ifdef __cplusplus |
| 299 | } |
| 300 | #endif |
| 301 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 302 | #endif /* mbedtls_sha256.h */ |