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 sha512.h |
Rose Zadik | 1a6275a | 2018-03-27 13:03:42 +0100 | [diff] [blame] | 3 | * \brief This file contains SHA-384 and SHA-512 definitions and functions. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 4 | * |
Rose Zadik | 1a6275a | 2018-03-27 13:03:42 +0100 | [diff] [blame] | 5 | * The Secure Hash Algorithms 384 and 512 (SHA-384 and SHA-512) cryptographic |
| 6 | * 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] | 7 | */ |
| 8 | /* |
Bence Szépkúti | a2947ac | 2020-08-19 16:37:36 +0200 | [diff] [blame] | 9 | * Copyright The Mbed TLS Contributors |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 11 | * |
| 12 | * This file is provided under the Apache License 2.0, or the |
| 13 | * GNU General Public License v2.0 or later. |
| 14 | * |
| 15 | * ********** |
| 16 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 17 | * |
| 18 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 19 | * not use this file except in compliance with the License. |
| 20 | * You may obtain a copy of the License at |
| 21 | * |
| 22 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 23 | * |
| 24 | * Unless required by applicable law or agreed to in writing, software |
| 25 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 27 | * See the License for the specific language governing permissions and |
| 28 | * limitations under the License. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 29 | * |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame] | 30 | * ********** |
| 31 | * |
| 32 | * ********** |
| 33 | * GNU General Public License v2.0 or later: |
| 34 | * |
| 35 | * This program is free software; you can redistribute it and/or modify |
| 36 | * it under the terms of the GNU General Public License as published by |
| 37 | * the Free Software Foundation; either version 2 of the License, or |
| 38 | * (at your option) any later version. |
| 39 | * |
| 40 | * This program is distributed in the hope that it will be useful, |
| 41 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 43 | * GNU General Public License for more details. |
| 44 | * |
| 45 | * You should have received a copy of the GNU General Public License along |
| 46 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 47 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 48 | * |
| 49 | * ********** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 50 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 51 | #ifndef MBEDTLS_SHA512_H |
| 52 | #define MBEDTLS_SHA512_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 53 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 54 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 55 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 56 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 57 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 58 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 59 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 60 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 61 | #include <stdint.h> |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 62 | |
Ron Eldor | 9924bdc | 2018-10-04 10:59:13 +0300 | [diff] [blame] | 63 | /* MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED is deprecated and should not be used. */ |
Gilles Peskine | 1990fab | 2021-07-26 18:48:10 +0200 | [diff] [blame] | 64 | /** SHA-512 hardware accelerator failed */ |
| 65 | #define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 |
| 66 | /** SHA-512 input data was malformed. */ |
| 67 | #define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA -0x0075 |
Gilles Peskine | a381fe8 | 2018-01-23 18:16:11 +0100 | [diff] [blame] | 68 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 69 | #ifdef __cplusplus |
| 70 | extern "C" { |
| 71 | #endif |
| 72 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 73 | #if !defined(MBEDTLS_SHA512_ALT) |
| 74 | // Regular implementation |
| 75 | // |
| 76 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 77 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 78 | * \brief The SHA-512 context structure. |
| 79 | * |
| 80 | * The structure is used both for SHA-384 and for SHA-512 |
| 81 | * checksum calculations. The choice between these two is |
| 82 | * made in the call to mbedtls_sha512_starts_ret(). |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 83 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 84 | typedef struct mbedtls_sha512_context |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 85 | { |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 86 | uint64_t total[2]; /*!< The number of Bytes processed. */ |
| 87 | uint64_t state[8]; /*!< The intermediate digest state. */ |
| 88 | unsigned char buffer[128]; /*!< The data block being processed. */ |
Rose Zadik | 1a6275a | 2018-03-27 13:03:42 +0100 | [diff] [blame] | 89 | int is384; /*!< Determines which function to use: |
| 90 | 0: Use SHA-512, or 1: Use SHA-384. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 91 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 92 | mbedtls_sha512_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 93 | |
Ron Eldor | b2aacec | 2017-05-18 16:53:08 +0300 | [diff] [blame] | 94 | #else /* MBEDTLS_SHA512_ALT */ |
| 95 | #include "sha512_alt.h" |
| 96 | #endif /* MBEDTLS_SHA512_ALT */ |
| 97 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 98 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 99 | * \brief This function initializes a SHA-512 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 100 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 101 | * \param ctx The SHA-512 context to initialize. This must |
| 102 | * not be \c NULL. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 103 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 104 | void mbedtls_sha512_init( mbedtls_sha512_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 105 | |
| 106 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 107 | * \brief This function clears a SHA-512 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 108 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 109 | * \param ctx The SHA-512 context to clear. This may be \c NULL, |
| 110 | * in which case this function does nothing. If it |
| 111 | * is not \c NULL, it must point to an initialized |
| 112 | * SHA-512 context. |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 113 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 114 | void mbedtls_sha512_free( mbedtls_sha512_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 115 | |
| 116 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 117 | * \brief This function clones the state of a SHA-512 context. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 118 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 119 | * \param dst The destination context. This must be initialized. |
| 120 | * \param src The context to clone. This must be initialized. |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 121 | */ |
| 122 | void mbedtls_sha512_clone( mbedtls_sha512_context *dst, |
| 123 | const mbedtls_sha512_context *src ); |
| 124 | |
| 125 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 126 | * \brief This function starts a SHA-384 or SHA-512 checksum |
| 127 | * calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 128 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 129 | * \param ctx The SHA-512 context to use. This must be initialized. |
| 130 | * \param is384 Determines which function to use. This must be |
| 131 | * either \c for SHA-512, or \c 1 for SHA-384. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 132 | * |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 133 | * \return \c 0 on success. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 134 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 135 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 136 | int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 137 | |
| 138 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 139 | * \brief This function feeds an input buffer into an ongoing |
| 140 | * SHA-512 checksum calculation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 141 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 142 | * \param ctx The SHA-512 context. This must be initialized |
| 143 | * and have a hash operation started. |
| 144 | * \param input The buffer holding the input data. This must |
| 145 | * be a readable buffer of length \p ilen Bytes. |
Hanno Becker | ca6f458 | 2018-12-18 15:37:22 +0000 | [diff] [blame] | 146 | * \param ilen The length of the input data in Bytes. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 147 | * |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 148 | * \return \c 0 on success. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 149 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 150 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 151 | int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 152 | const unsigned char *input, |
| 153 | size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 154 | |
| 155 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 156 | * \brief This function finishes the SHA-512 operation, and writes |
Gilles Peskine | e3645ee | 2020-11-22 13:59:43 +0100 | [diff] [blame] | 157 | * the result to the output buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 158 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 159 | * \param ctx The SHA-512 context. This must be initialized |
| 160 | * and have a hash operation started. |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 161 | * \param output The SHA-384 or SHA-512 checksum result. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 162 | * This must be a writable buffer of length \c 64 Bytes. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 163 | * |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 164 | * \return \c 0 on success. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 165 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 166 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 167 | int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx, |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 168 | unsigned char output[64] ); |
| 169 | |
| 170 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 171 | * \brief This function processes a single data block within |
| 172 | * the ongoing SHA-512 computation. |
Gilles Peskine | e3645ee | 2020-11-22 13:59:43 +0100 | [diff] [blame] | 173 | * This function is for internal use only. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 174 | * |
Hanno Becker | bb186f8 | 2018-12-19 10:27:24 +0000 | [diff] [blame] | 175 | * \param ctx The SHA-512 context. This must be initialized. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 176 | * \param data The buffer holding one block of data. This |
| 177 | * must be a readable buffer of length \c 128 Bytes. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 178 | * |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 179 | * \return \c 0 on success. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 180 | * \return A negative error code on failure. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 181 | */ |
Andres Amaya Garcia | cccfe08 | 2017-06-28 10:36:39 +0100 | [diff] [blame] | 182 | int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, |
| 183 | const unsigned char data[128] ); |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 184 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 185 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 186 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 187 | #else |
| 188 | #define MBEDTLS_DEPRECATED |
| 189 | #endif |
| 190 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 191 | * \brief This function starts a SHA-384 or SHA-512 checksum |
| 192 | * calculation. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 193 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 194 | * \deprecated Superseded by mbedtls_sha512_starts_ret() in 2.7.0 |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 195 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 196 | * \param ctx The SHA-512 context to use. This must be initialized. |
| 197 | * \param is384 Determines which function to use. This must be either |
| 198 | * \c 0 for SHA-512 or \c 1 for SHA-384. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 199 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 200 | MBEDTLS_DEPRECATED void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, |
| 201 | int is384 ); |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 202 | |
| 203 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 204 | * \brief This function feeds an input buffer into an ongoing |
| 205 | * SHA-512 checksum calculation. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 206 | * |
Rose Zadik | 1a6275a | 2018-03-27 13:03:42 +0100 | [diff] [blame] | 207 | * \deprecated Superseded by mbedtls_sha512_update_ret() in 2.7.0. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 208 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 209 | * \param ctx The SHA-512 context. This must be initialized |
| 210 | * and have a hash operation started. |
| 211 | * \param input The buffer holding the data. This must be a readable |
Hanno Becker | ca6f458 | 2018-12-18 15:37:22 +0000 | [diff] [blame] | 212 | * buffer of length \p ilen Bytes. |
| 213 | * \param ilen The length of the input data in Bytes. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 214 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 215 | MBEDTLS_DEPRECATED void mbedtls_sha512_update( mbedtls_sha512_context *ctx, |
| 216 | const unsigned char *input, |
| 217 | size_t ilen ); |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 218 | |
| 219 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 220 | * \brief This function finishes the SHA-512 operation, and writes |
| 221 | * the result to the output buffer. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 222 | * |
Rose Zadik | 1a6275a | 2018-03-27 13:03:42 +0100 | [diff] [blame] | 223 | * \deprecated Superseded by mbedtls_sha512_finish_ret() in 2.7.0. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 224 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 225 | * \param ctx The SHA-512 context. This must be initialized |
| 226 | * and have a hash operation started. |
| 227 | * \param output The SHA-384 or SHA-512 checksum result. This must |
| 228 | * be a writable buffer of size \c 64 Bytes. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 229 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 230 | MBEDTLS_DEPRECATED void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, |
| 231 | unsigned char output[64] ); |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 232 | |
| 233 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 234 | * \brief This function processes a single data block within |
| 235 | * the ongoing SHA-512 computation. This function is for |
| 236 | * internal use only. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 237 | * |
Rose Zadik | 1a6275a | 2018-03-27 13:03:42 +0100 | [diff] [blame] | 238 | * \deprecated Superseded by mbedtls_internal_sha512_process() in 2.7.0. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 239 | * |
Hanno Becker | bb186f8 | 2018-12-19 10:27:24 +0000 | [diff] [blame] | 240 | * \param ctx The SHA-512 context. This must be initialized. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 241 | * \param data The buffer holding one block of data. This must be |
| 242 | * a readable buffer of length \c 128 Bytes. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 243 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 244 | MBEDTLS_DEPRECATED void mbedtls_sha512_process( |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 245 | mbedtls_sha512_context *ctx, |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 246 | const unsigned char data[128] ); |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 247 | |
| 248 | #undef MBEDTLS_DEPRECATED |
| 249 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 250 | |
| 251 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 252 | * \brief This function calculates the SHA-512 or SHA-384 |
| 253 | * checksum of a buffer. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 254 | * |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 255 | * The function allocates the context, performs the |
| 256 | * calculation, and frees the context. |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 257 | * |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 258 | * The SHA-512 result is calculated as |
| 259 | * output = SHA-512(input buffer). |
| 260 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 261 | * \param input The buffer holding the input data. This must be |
Hanno Becker | ca6f458 | 2018-12-18 15:37:22 +0000 | [diff] [blame] | 262 | * a readable buffer of length \p ilen Bytes. |
| 263 | * \param ilen The length of the input data in Bytes. |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 264 | * \param output The SHA-384 or SHA-512 checksum result. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 265 | * This must be a writable buffer of length \c 64 Bytes. |
| 266 | * \param is384 Determines which function to use. This must be either |
| 267 | * \c 0 for SHA-512, or \c 1 for SHA-384. |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 268 | * |
| 269 | * \return \c 0 on success. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 270 | * \return A negative error code on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 271 | */ |
Gilles Peskine | 9e4f77c | 2018-01-22 11:48:08 +0100 | [diff] [blame] | 272 | int mbedtls_sha512_ret( const unsigned char *input, |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 273 | size_t ilen, |
| 274 | unsigned char output[64], |
| 275 | int is384 ); |
| 276 | |
| 277 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 278 | #if defined(MBEDTLS_DEPRECATED_WARNING) |
| 279 | #define MBEDTLS_DEPRECATED __attribute__((deprecated)) |
| 280 | #else |
| 281 | #define MBEDTLS_DEPRECATED |
| 282 | #endif |
Ron Eldor | fa8f635 | 2017-06-20 15:48:46 +0300 | [diff] [blame] | 283 | |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 284 | /** |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 285 | * \brief This function calculates the SHA-512 or SHA-384 |
| 286 | * checksum of a buffer. |
| 287 | * |
| 288 | * The function allocates the context, performs the |
| 289 | * calculation, and frees the context. |
| 290 | * |
| 291 | * The SHA-512 result is calculated as |
| 292 | * output = SHA-512(input buffer). |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 293 | * |
Gilles Peskine | 3e28d70 | 2018-01-22 12:18:59 +0100 | [diff] [blame] | 294 | * \deprecated Superseded by mbedtls_sha512_ret() in 2.7.0 |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 295 | * |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 296 | * \param input The buffer holding the data. This must be a |
Hanno Becker | ca6f458 | 2018-12-18 15:37:22 +0000 | [diff] [blame] | 297 | * readable buffer of length \p ilen Bytes. |
| 298 | * \param ilen The length of the input data in Bytes. |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 299 | * \param output The SHA-384 or SHA-512 checksum result. This must |
| 300 | * be a writable buffer of length \c 64 Bytes. |
Hanno Becker | 3f2d1ef | 2018-12-18 18:41:40 +0000 | [diff] [blame] | 301 | * \param is384 Determines which function to use. This must be either |
Hanno Becker | b5c99f5 | 2018-12-18 15:29:32 +0000 | [diff] [blame] | 302 | * \c 0 for SHA-512, or \c 1 for SHA-384. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 303 | */ |
Jaeden Amero | 041039f | 2018-02-19 15:28:08 +0000 | [diff] [blame] | 304 | MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input, |
| 305 | size_t ilen, |
| 306 | unsigned char output[64], |
| 307 | int is384 ); |
Andres Amaya Garcia | 614c689 | 2017-05-02 12:07:26 +0100 | [diff] [blame] | 308 | |
| 309 | #undef MBEDTLS_DEPRECATED |
| 310 | #endif /* !MBEDTLS_DEPRECATED_REMOVED */ |
Ron Eldor | fa8f635 | 2017-06-20 15:48:46 +0300 | [diff] [blame] | 311 | |
| 312 | #if defined(MBEDTLS_SELF_TEST) |
| 313 | |
Rose Zadik | 27ff120 | 2018-01-26 11:01:31 +0000 | [diff] [blame] | 314 | /** |
| 315 | * \brief The SHA-384 or SHA-512 checkup routine. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 316 | * |
Rose Zadik | 1a6275a | 2018-03-27 13:03:42 +0100 | [diff] [blame] | 317 | * \return \c 0 on success. |
| 318 | * \return \c 1 on failure. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 319 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 320 | int mbedtls_sha512_self_test( int verbose ); |
Ron Eldor | fa8f635 | 2017-06-20 15:48:46 +0300 | [diff] [blame] | 321 | #endif /* MBEDTLS_SELF_TEST */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 322 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 323 | #ifdef __cplusplus |
| 324 | } |
| 325 | #endif |
| 326 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 327 | #endif /* mbedtls_sha512.h */ |