Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sha512.h Source File

sha512.h

Go to the documentation of this file.
00001 /**
00002  * \file sha512.h
00003  *
00004  * \brief The SHA-384 and SHA-512 cryptographic hash function.
00005  */
00006 /*
00007  *  Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
00008  *  SPDX-License-Identifier: Apache-2.0
00009  *
00010  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00011  *  not use this file except in compliance with the License.
00012  *  You may obtain a copy of the License at
00013  *
00014  *  http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  *  Unless required by applicable law or agreed to in writing, software
00017  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00018  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  *  See the License for the specific language governing permissions and
00020  *  limitations under the License.
00021  *
00022  *  This file is part of Mbed TLS (https://tls.mbed.org)
00023  */
00024 #ifndef MBEDTLS_SHA512_H
00025 #define MBEDTLS_SHA512_H
00026 
00027 #if !defined(MBEDTLS_CONFIG_FILE)
00028 #include "config.h"
00029 #else
00030 #include MBEDTLS_CONFIG_FILE
00031 #endif
00032 
00033 #include <stddef.h>
00034 #include <stdint.h>
00035 
00036 #define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED                -0x0039  /**< SHA-512 hardware accelerator failed */
00037 
00038 #if !defined(MBEDTLS_SHA512_ALT)
00039 // Regular implementation
00040 //
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 /**
00047  * \brief          The SHA-512 context structure.
00048  *
00049  *                 The structure is used both for SHA-384 and for SHA-512
00050  *                 checksum calculations. The choice between these two is
00051  *                 made in the call to mbedtls_sha512_starts_ret().
00052  */
00053 typedef struct
00054 {
00055     uint64_t total[2];          /*!< The number of Bytes processed. */
00056     uint64_t state[8];          /*!< The intermediate digest state. */
00057     unsigned char buffer[128];  /*!< The data block being processed. */
00058     int is384;                  /*!< Determines which function to use.
00059                                  *   <ul><li>0: Use SHA-512.</li>
00060                                  *   <li>1: Use SHA-384.</li></ul> */
00061 }
00062 mbedtls_sha512_context;
00063 
00064 /**
00065  * \brief          This function initializes a SHA-512 context.
00066  *
00067  * \param ctx      The SHA-512 context to initialize.
00068  */
00069 void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
00070 
00071 /**
00072  * \brief          This function clears a SHA-512 context.
00073  *
00074  * \param ctx      The SHA-512 context to clear.
00075  */
00076 void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
00077 
00078 /**
00079  * \brief          This function clones the state of a SHA-512 context.
00080  *
00081  * \param dst      The destination context.
00082  * \param src      The context to clone.
00083  */
00084 void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
00085                            const mbedtls_sha512_context *src );
00086 
00087 /**
00088  * \brief          This function starts a SHA-384 or SHA-512 checksum
00089  *                 calculation.
00090  *
00091  * \param ctx      The SHA-512 context to initialize.
00092  * \param is384    Determines which function to use.
00093  *                 <ul><li>0: Use SHA-512.</li>
00094  *                 <li>1: Use SHA-384.</li></ul>
00095  *
00096  * \return         \c 0 on success.
00097  */
00098 int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
00099 
00100 /**
00101  * \brief          This function feeds an input buffer into an ongoing
00102  *                 SHA-512 checksum calculation.
00103  *
00104  * \param ctx      The SHA-512 context.
00105  * \param input    The buffer holding the input data.
00106  * \param ilen     The length of the input data.
00107  *
00108  * \return         \c 0 on success.
00109  */
00110 int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
00111                     const unsigned char *input,
00112                     size_t ilen );
00113 
00114 /**
00115  * \brief          This function finishes the SHA-512 operation, and writes
00116  *                 the result to the output buffer. This function is for
00117  *                 internal use only.
00118  *
00119  * \param ctx      The SHA-512 context.
00120  * \param output   The SHA-384 or SHA-512 checksum result.
00121  *
00122  * \return         \c 0 on success.
00123  */
00124 int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
00125                                unsigned char output[64] );
00126 
00127 /**
00128  * \brief          This function processes a single data block within
00129  *                 the ongoing SHA-512 computation.
00130  *
00131  * \param ctx      The SHA-512 context.
00132  * \param data     The buffer holding one block of data.
00133  *
00134  * \return         \c 0 on success.
00135  */
00136 int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
00137                                      const unsigned char data[128] );
00138 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00139 #if defined(MBEDTLS_DEPRECATED_WARNING)
00140 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00141 #else
00142 #define MBEDTLS_DEPRECATED
00143 #endif
00144 /**
00145  * \brief          This function starts a SHA-384 or SHA-512 checksum
00146  *                 calculation.
00147  *
00148  * \deprecated     Superseded by mbedtls_sha512_starts_ret() in 2.7.0
00149  *
00150  * \param ctx      The SHA-512 context to initialize.
00151  * \param is384    Determines which function to use.
00152  *                 <ul><li>0: Use SHA-512.</li>
00153  *                 <li>1: Use SHA-384.</li></ul>
00154  */
00155 MBEDTLS_DEPRECATED void mbedtls_sha512_starts( mbedtls_sha512_context *ctx,
00156                                                int is384 );
00157 
00158 /**
00159  * \brief          This function feeds an input buffer into an ongoing
00160  *                 SHA-512 checksum calculation.
00161  *
00162  * \deprecated     Superseded by mbedtls_sha512_update_ret() in 2.7.0
00163  *
00164  * \param ctx      The SHA-512 context.
00165  * \param input    The buffer holding the data.
00166  * \param ilen     The length of the input data.
00167  */
00168 MBEDTLS_DEPRECATED void mbedtls_sha512_update( mbedtls_sha512_context *ctx,
00169                                                const unsigned char *input,
00170                                                size_t ilen );
00171 
00172 /**
00173  * \brief          This function finishes the SHA-512 operation, and writes
00174  *                 the result to the output buffer.
00175  *
00176  * \deprecated     Superseded by mbedtls_sha512_finish_ret() in 2.7.0
00177  *
00178  * \param ctx      The SHA-512 context.
00179  * \param output   The SHA-384 or SHA-512 checksum result.
00180  */
00181 MBEDTLS_DEPRECATED void mbedtls_sha512_finish( mbedtls_sha512_context *ctx,
00182                                                unsigned char output[64] );
00183 
00184 /**
00185  * \brief          This function processes a single data block within
00186  *                 the ongoing SHA-512 computation. This function is for
00187  *                 internal use only.
00188  *
00189  * \deprecated     Superseded by mbedtls_internal_sha512_process() in 2.7.0
00190  *
00191  * \param ctx      The SHA-512 context.
00192  * \param data     The buffer holding one block of data.
00193  */
00194 MBEDTLS_DEPRECATED void mbedtls_sha512_process(
00195                                             mbedtls_sha512_context *ctx,
00196                                             const unsigned char data[128] );
00197 
00198 #undef MBEDTLS_DEPRECATED
00199 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00200 
00201 #ifdef __cplusplus
00202 }
00203 #endif
00204 
00205 #else  /* MBEDTLS_SHA512_ALT */
00206 #include "sha512_alt.h"
00207 #endif /* MBEDTLS_SHA512_ALT */
00208 
00209 #ifdef __cplusplus
00210 extern "C" {
00211 #endif
00212 
00213 /**
00214  * \brief          This function calculates the SHA-512 or SHA-384
00215  *                 checksum of a buffer.
00216  *
00217  *                 The function allocates the context, performs the
00218  *                 calculation, and frees the context.
00219  *
00220  *                 The SHA-512 result is calculated as
00221  *                 output = SHA-512(input buffer).
00222  *
00223  * \param input    The buffer holding the input data.
00224  * \param ilen     The length of the input data.
00225  * \param output   The SHA-384 or SHA-512 checksum result.
00226  * \param is384    Determines which function to use.
00227  *                 <ul><li>0: Use SHA-512.</li>
00228  *                 <li>1: Use SHA-384.</li></ul>
00229  *
00230  * \return         \c 0 on success.
00231  */
00232 int mbedtls_sha512_ret( const unsigned char *input,
00233                         size_t ilen,
00234                         unsigned char output[64],
00235                         int is384 );
00236 
00237 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00238 #if defined(MBEDTLS_DEPRECATED_WARNING)
00239 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00240 #else
00241 #define MBEDTLS_DEPRECATED
00242 #endif
00243 /**
00244  * \brief          This function calculates the SHA-512 or SHA-384
00245  *                 checksum of a buffer.
00246  *
00247  *                 The function allocates the context, performs the
00248  *                 calculation, and frees the context.
00249  *
00250  *                 The SHA-512 result is calculated as
00251  *                 output = SHA-512(input buffer).
00252  *
00253  * \deprecated     Superseded by mbedtls_sha512_ret() in 2.7.0
00254  *
00255  * \param input    The buffer holding the data.
00256  * \param ilen     The length of the input data.
00257  * \param output   The SHA-384 or SHA-512 checksum result.
00258  * \param is384    Determines which function to use.
00259  *                 <ul><li>0: Use SHA-512.</li>
00260  *                 <li>1: Use SHA-384.</li></ul>
00261  */
00262 MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
00263                                         size_t ilen,
00264                                         unsigned char output[64],
00265                                         int is384 );
00266 
00267 #undef MBEDTLS_DEPRECATED
00268 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00269  /**
00270  * \brief          The SHA-384 or SHA-512 checkup routine.
00271  *
00272  * \return         \c 0 on success, or \c 1 on failure.
00273  */
00274 int mbedtls_sha512_self_test( int verbose );
00275 
00276 #ifdef __cplusplus
00277 }
00278 #endif
00279 
00280 #endif /* mbedtls_sha512.h */