]>
git.zerfleddert.de Git - proxmark3-svn/blob - common/mbedtls/sha512.h
3 * \brief This file contains SHA-384 and SHA-512 definitions and functions.
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>.
9 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
10 * SPDX-License-Identifier: GPL-2.0
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * This file is part of Mbed TLS (https://tls.mbed.org)
28 #ifndef MBEDTLS_SHA512_H
29 #define MBEDTLS_SHA512_H
31 #if !defined(MBEDTLS_CONFIG_FILE)
34 #include MBEDTLS_CONFIG_FILE
40 #define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 /**< SHA-512 hardware accelerator failed */
46 #if !defined(MBEDTLS_SHA512_ALT)
47 // Regular implementation
51 * \brief The SHA-512 context structure.
53 * The structure is used both for SHA-384 and for SHA-512
54 * checksum calculations. The choice between these two is
55 * made in the call to mbedtls_sha512_starts_ret().
57 typedef struct mbedtls_sha512_context
59 uint64_t total
[2]; /*!< The number of Bytes processed. */
60 uint64_t state
[8]; /*!< The intermediate digest state. */
61 unsigned char buffer
[128]; /*!< The data block being processed. */
62 int is384
; /*!< Determines which function to use:
63 0: Use SHA-512, or 1: Use SHA-384. */
65 mbedtls_sha512_context
;
67 #else /* MBEDTLS_SHA512_ALT */
68 #include "sha512_alt.h"
69 #endif /* MBEDTLS_SHA512_ALT */
72 * \brief This function initializes a SHA-512 context.
74 * \param ctx The SHA-512 context to initialize.
76 void mbedtls_sha512_init( mbedtls_sha512_context
*ctx
);
79 * \brief This function clears a SHA-512 context.
81 * \param ctx The SHA-512 context to clear.
83 void mbedtls_sha512_free( mbedtls_sha512_context
*ctx
);
86 * \brief This function clones the state of a SHA-512 context.
88 * \param dst The destination context.
89 * \param src The context to clone.
91 void mbedtls_sha512_clone( mbedtls_sha512_context
*dst
,
92 const mbedtls_sha512_context
*src
);
95 * \brief This function starts a SHA-384 or SHA-512 checksum
98 * \param ctx The SHA-512 context to initialize.
99 * \param is384 Determines which function to use:
100 * 0: Use SHA-512, or 1: Use SHA-384.
102 * \return \c 0 on success.
104 int mbedtls_sha512_starts_ret( mbedtls_sha512_context
*ctx
, int is384
);
107 * \brief This function feeds an input buffer into an ongoing
108 * SHA-512 checksum calculation.
110 * \param ctx The SHA-512 context.
111 * \param input The buffer holding the input data.
112 * \param ilen The length of the input data.
114 * \return \c 0 on success.
116 int mbedtls_sha512_update_ret( mbedtls_sha512_context
*ctx
,
117 const unsigned char *input
,
121 * \brief This function finishes the SHA-512 operation, and writes
122 * the result to the output buffer. This function is for
125 * \param ctx The SHA-512 context.
126 * \param output The SHA-384 or SHA-512 checksum result.
128 * \return \c 0 on success.
130 int mbedtls_sha512_finish_ret( mbedtls_sha512_context
*ctx
,
131 unsigned char output
[64] );
134 * \brief This function processes a single data block within
135 * the ongoing SHA-512 computation.
137 * \param ctx The SHA-512 context.
138 * \param data The buffer holding one block of data.
140 * \return \c 0 on success.
142 int mbedtls_internal_sha512_process( mbedtls_sha512_context
*ctx
,
143 const unsigned char data
[128] );
144 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
145 #if defined(MBEDTLS_DEPRECATED_WARNING)
146 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
148 #define MBEDTLS_DEPRECATED
151 * \brief This function starts a SHA-384 or SHA-512 checksum
154 * \deprecated Superseded by mbedtls_sha512_starts_ret() in 2.7.0
156 * \param ctx The SHA-512 context to initialize.
157 * \param is384 Determines which function to use:
158 * 0: Use SHA-512, or 1: Use SHA-384.
160 MBEDTLS_DEPRECATED
void mbedtls_sha512_starts( mbedtls_sha512_context
*ctx
,
164 * \brief This function feeds an input buffer into an ongoing
165 * SHA-512 checksum calculation.
167 * \deprecated Superseded by mbedtls_sha512_update_ret() in 2.7.0.
169 * \param ctx The SHA-512 context.
170 * \param input The buffer holding the data.
171 * \param ilen The length of the input data.
173 MBEDTLS_DEPRECATED
void mbedtls_sha512_update( mbedtls_sha512_context
*ctx
,
174 const unsigned char *input
,
178 * \brief This function finishes the SHA-512 operation, and writes
179 * the result to the output buffer.
181 * \deprecated Superseded by mbedtls_sha512_finish_ret() in 2.7.0.
183 * \param ctx The SHA-512 context.
184 * \param output The SHA-384 or SHA-512 checksum result.
186 MBEDTLS_DEPRECATED
void mbedtls_sha512_finish( mbedtls_sha512_context
*ctx
,
187 unsigned char output
[64] );
190 * \brief This function processes a single data block within
191 * the ongoing SHA-512 computation. This function is for
194 * \deprecated Superseded by mbedtls_internal_sha512_process() in 2.7.0.
196 * \param ctx The SHA-512 context.
197 * \param data The buffer holding one block of data.
199 MBEDTLS_DEPRECATED
void mbedtls_sha512_process(
200 mbedtls_sha512_context
*ctx
,
201 const unsigned char data
[128] );
203 #undef MBEDTLS_DEPRECATED
204 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
207 * \brief This function calculates the SHA-512 or SHA-384
208 * checksum of a buffer.
210 * The function allocates the context, performs the
211 * calculation, and frees the context.
213 * The SHA-512 result is calculated as
214 * output = SHA-512(input buffer).
216 * \param input The buffer holding the input data.
217 * \param ilen The length of the input data.
218 * \param output The SHA-384 or SHA-512 checksum result.
219 * \param is384 Determines which function to use:
220 * 0: Use SHA-512, or 1: Use SHA-384.
222 * \return \c 0 on success.
224 int mbedtls_sha512_ret( const unsigned char *input
,
226 unsigned char output
[64],
229 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
230 #if defined(MBEDTLS_DEPRECATED_WARNING)
231 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
233 #define MBEDTLS_DEPRECATED
236 * \brief This function calculates the SHA-512 or SHA-384
237 * checksum of a buffer.
239 * The function allocates the context, performs the
240 * calculation, and frees the context.
242 * The SHA-512 result is calculated as
243 * output = SHA-512(input buffer).
245 * \deprecated Superseded by mbedtls_sha512_ret() in 2.7.0
247 * \param input The buffer holding the data.
248 * \param ilen The length of the input data.
249 * \param output The SHA-384 or SHA-512 checksum result.
250 * \param is384 Determines which function to use:
251 * 0: Use SHA-512, or 1: Use SHA-384.
253 MBEDTLS_DEPRECATED
void mbedtls_sha512( const unsigned char *input
,
255 unsigned char output
[64],
258 #undef MBEDTLS_DEPRECATED
259 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
261 * \brief The SHA-384 or SHA-512 checkup routine.
263 * \return \c 0 on success.
264 * \return \c 1 on failure.
266 int mbedtls_sha512_self_test( int verbose
);
272 #endif /* mbedtls_sha512.h */