]> cvs.zerfleddert.de Git - proxmark3-svn/blame_incremental - common/mbedtls/sha512.h
Added ATR decoding (RfidResearchGroup PRs 67/68 by @merlokk) (#749)
[proxmark3-svn] / common / mbedtls / sha512.h
... / ...
CommitLineData
1/**
2 * \file sha512.h
3 * \brief This file contains SHA-384 and SHA-512 definitions and functions.
4 *
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>.
7 */
8/*
9 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
10 * SPDX-License-Identifier: GPL-2.0
11 *
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.
16 *
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.
21 *
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.
25 *
26 * This file is part of Mbed TLS (https://tls.mbed.org)
27 */
28#ifndef MBEDTLS_SHA512_H
29#define MBEDTLS_SHA512_H
30
31#if !defined(MBEDTLS_CONFIG_FILE)
32#include "config.h"
33#else
34#include MBEDTLS_CONFIG_FILE
35#endif
36
37#include <stddef.h>
38#include <stdint.h>
39
40#define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 /**< SHA-512 hardware accelerator failed */
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#if !defined(MBEDTLS_SHA512_ALT)
47// Regular implementation
48//
49
50/**
51 * \brief The SHA-512 context structure.
52 *
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().
56 */
57typedef struct mbedtls_sha512_context
58{
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. */
64}
65mbedtls_sha512_context;
66
67#else /* MBEDTLS_SHA512_ALT */
68#include "sha512_alt.h"
69#endif /* MBEDTLS_SHA512_ALT */
70
71/**
72 * \brief This function initializes a SHA-512 context.
73 *
74 * \param ctx The SHA-512 context to initialize.
75 */
76void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
77
78/**
79 * \brief This function clears a SHA-512 context.
80 *
81 * \param ctx The SHA-512 context to clear.
82 */
83void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
84
85/**
86 * \brief This function clones the state of a SHA-512 context.
87 *
88 * \param dst The destination context.
89 * \param src The context to clone.
90 */
91void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
92 const mbedtls_sha512_context *src );
93
94/**
95 * \brief This function starts a SHA-384 or SHA-512 checksum
96 * calculation.
97 *
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.
101 *
102 * \return \c 0 on success.
103 */
104int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
105
106/**
107 * \brief This function feeds an input buffer into an ongoing
108 * SHA-512 checksum calculation.
109 *
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.
113 *
114 * \return \c 0 on success.
115 */
116int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
117 const unsigned char *input,
118 size_t ilen );
119
120/**
121 * \brief This function finishes the SHA-512 operation, and writes
122 * the result to the output buffer. This function is for
123 * internal use only.
124 *
125 * \param ctx The SHA-512 context.
126 * \param output The SHA-384 or SHA-512 checksum result.
127 *
128 * \return \c 0 on success.
129 */
130int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
131 unsigned char output[64] );
132
133/**
134 * \brief This function processes a single data block within
135 * the ongoing SHA-512 computation.
136 *
137 * \param ctx The SHA-512 context.
138 * \param data The buffer holding one block of data.
139 *
140 * \return \c 0 on success.
141 */
142int 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))
147#else
148#define MBEDTLS_DEPRECATED
149#endif
150/**
151 * \brief This function starts a SHA-384 or SHA-512 checksum
152 * calculation.
153 *
154 * \deprecated Superseded by mbedtls_sha512_starts_ret() in 2.7.0
155 *
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.
159 */
160MBEDTLS_DEPRECATED void mbedtls_sha512_starts( mbedtls_sha512_context *ctx,
161 int is384 );
162
163/**
164 * \brief This function feeds an input buffer into an ongoing
165 * SHA-512 checksum calculation.
166 *
167 * \deprecated Superseded by mbedtls_sha512_update_ret() in 2.7.0.
168 *
169 * \param ctx The SHA-512 context.
170 * \param input The buffer holding the data.
171 * \param ilen The length of the input data.
172 */
173MBEDTLS_DEPRECATED void mbedtls_sha512_update( mbedtls_sha512_context *ctx,
174 const unsigned char *input,
175 size_t ilen );
176
177/**
178 * \brief This function finishes the SHA-512 operation, and writes
179 * the result to the output buffer.
180 *
181 * \deprecated Superseded by mbedtls_sha512_finish_ret() in 2.7.0.
182 *
183 * \param ctx The SHA-512 context.
184 * \param output The SHA-384 or SHA-512 checksum result.
185 */
186MBEDTLS_DEPRECATED void mbedtls_sha512_finish( mbedtls_sha512_context *ctx,
187 unsigned char output[64] );
188
189/**
190 * \brief This function processes a single data block within
191 * the ongoing SHA-512 computation. This function is for
192 * internal use only.
193 *
194 * \deprecated Superseded by mbedtls_internal_sha512_process() in 2.7.0.
195 *
196 * \param ctx The SHA-512 context.
197 * \param data The buffer holding one block of data.
198 */
199MBEDTLS_DEPRECATED void mbedtls_sha512_process(
200 mbedtls_sha512_context *ctx,
201 const unsigned char data[128] );
202
203#undef MBEDTLS_DEPRECATED
204#endif /* !MBEDTLS_DEPRECATED_REMOVED */
205
206/**
207 * \brief This function calculates the SHA-512 or SHA-384
208 * checksum of a buffer.
209 *
210 * The function allocates the context, performs the
211 * calculation, and frees the context.
212 *
213 * The SHA-512 result is calculated as
214 * output = SHA-512(input buffer).
215 *
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.
221 *
222 * \return \c 0 on success.
223 */
224int mbedtls_sha512_ret( const unsigned char *input,
225 size_t ilen,
226 unsigned char output[64],
227 int is384 );
228
229#if !defined(MBEDTLS_DEPRECATED_REMOVED)
230#if defined(MBEDTLS_DEPRECATED_WARNING)
231#define MBEDTLS_DEPRECATED __attribute__((deprecated))
232#else
233#define MBEDTLS_DEPRECATED
234#endif
235/**
236 * \brief This function calculates the SHA-512 or SHA-384
237 * checksum of a buffer.
238 *
239 * The function allocates the context, performs the
240 * calculation, and frees the context.
241 *
242 * The SHA-512 result is calculated as
243 * output = SHA-512(input buffer).
244 *
245 * \deprecated Superseded by mbedtls_sha512_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-384 or SHA-512 checksum result.
250 * \param is384 Determines which function to use:
251 * 0: Use SHA-512, or 1: Use SHA-384.
252 */
253MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
254 size_t ilen,
255 unsigned char output[64],
256 int is384 );
257
258#undef MBEDTLS_DEPRECATED
259#endif /* !MBEDTLS_DEPRECATED_REMOVED */
260 /**
261 * \brief The SHA-384 or SHA-512 checkup routine.
262 *
263 * \return \c 0 on success.
264 * \return \c 1 on failure.
265 */
266int mbedtls_sha512_self_test( int verbose );
267
268#ifdef __cplusplus
269}
270#endif
271
272#endif /* mbedtls_sha512.h */
Impressum, Datenschutz