Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sha256.h Source File

sha256.h

Go to the documentation of this file.
00001 /**
00002  * \file sha256.h
00003  *
00004  * \brief The SHA-224 and SHA-256 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_SHA256_H
00025 #define MBEDTLS_SHA256_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_SHA256_HW_ACCEL_FAILED                -0x0037  /**< SHA-256 hardware accelerator failed */
00037 
00038 #if !defined(MBEDTLS_SHA256_ALT)
00039 // Regular implementation
00040 //
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 /**
00047  * \brief          The SHA-256 context structure.
00048  *
00049  *                 The structure is used both for SHA-256 and for SHA-224
00050  *                 checksum calculations. The choice between these two is
00051  *                 made in the call to mbedtls_sha256_starts_ret().
00052  */
00053 typedef struct
00054 {
00055     uint32_t total[2];          /*!< The number of Bytes processed.  */
00056     uint32_t state[8];          /*!< The intermediate digest state.  */
00057     unsigned char buffer[64];   /*!< The data block being processed. */
00058     int is224;                  /*!< Determines which function to use.
00059                                      <ul><li>0: Use SHA-256.</li>
00060                                      <li>1: Use SHA-224.</li></ul> */
00061 }
00062 mbedtls_sha256_context;
00063 
00064 /**
00065  * \brief          This function initializes a SHA-256 context.
00066  *
00067  * \param ctx      The SHA-256 context to initialize.
00068  */
00069 void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
00070 
00071 /**
00072  * \brief          This function clears a SHA-256 context.
00073  *
00074  * \param ctx      The SHA-256 context to clear.
00075  */
00076 void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
00077 
00078 /**
00079  * \brief          This function clones the state of a SHA-256 context.
00080  *
00081  * \param dst      The destination context.
00082  * \param src      The context to clone.
00083  */
00084 void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
00085                            const mbedtls_sha256_context *src );
00086 
00087 /**
00088  * \brief          This function starts a SHA-224 or SHA-256 checksum
00089  *                 calculation.
00090  *
00091  * \param ctx      The context to initialize.
00092  * \param is224    Determines which function to use.
00093  *                 <ul><li>0: Use SHA-256.</li>
00094  *                 <li>1: Use SHA-224.</li></ul>
00095  *
00096  * \return         \c 0 on success.
00097  */
00098 int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
00099 
00100 /**
00101  * \brief          This function feeds an input buffer into an ongoing
00102  *                 SHA-256 checksum calculation.
00103  *
00104  * \param ctx      SHA-256 context
00105  * \param input    buffer holding the data
00106  * \param ilen     length of the input data
00107  *
00108  * \return         \c 0 on success.
00109  */
00110 int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
00111                                const unsigned char *input,
00112                                size_t ilen );
00113 
00114 /**
00115  * \brief          This function finishes the SHA-256 operation, and writes
00116  *                 the result to the output buffer.
00117  *
00118  * \param ctx      The SHA-256 context.
00119  * \param output   The SHA-224 or SHA-256 checksum result.
00120  *
00121  * \return         \c 0 on success.
00122  */
00123 int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
00124                                unsigned char output[32] );
00125 
00126 /**
00127  * \brief          This function processes a single data block within
00128  *                 the ongoing SHA-256 computation. This function is for
00129  *                 internal use only.
00130  *
00131  * \param ctx      The SHA-256 context.
00132  * \param data     The buffer holding one block of data.
00133  *
00134  * \return         \c 0 on success.
00135  */
00136 int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
00137                                      const unsigned char data[64] );
00138 
00139 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00140 #if defined(MBEDTLS_DEPRECATED_WARNING)
00141 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00142 #else
00143 #define MBEDTLS_DEPRECATED
00144 #endif
00145 /**
00146  * \brief          This function starts a SHA-256 checksum calculation.
00147  *
00148  * \deprecated     Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
00149  *
00150  * \param ctx      The SHA-256 context to initialize.
00151  * \param is224    Determines which function to use.
00152  *                 <ul><li>0: Use SHA-256.</li>
00153  *                 <li>1: Use SHA-224.</li></ul>
00154  */
00155 MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
00156                                                int is224 );
00157 
00158 /**
00159  * \brief          This function feeds an input buffer into an ongoing
00160  *                 SHA-256 checksum calculation.
00161  *
00162  * \deprecated     Superseded by mbedtls_sha256_update_ret() in 2.7.0.
00163  *
00164  * \param ctx      The SHA-256 context to initialize.
00165  * \param input    The buffer holding the data.
00166  * \param ilen     The length of the input data.
00167  */
00168 MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
00169                                                const unsigned char *input,
00170                                                size_t ilen );
00171 
00172 /**
00173  * \brief          This function finishes the SHA-256 operation, and writes
00174  *                 the result to the output buffer.
00175  *
00176  * \deprecated     Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
00177  *
00178  * \param ctx      The SHA-256 context.
00179  * \param output   The SHA-224or SHA-256 checksum result.
00180  */
00181 MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
00182                                                unsigned char output[32] );
00183 
00184 /**
00185  * \brief          This function processes a single data block within
00186  *                 the ongoing SHA-256 computation. This function is for
00187  *                 internal use only.
00188  *
00189  * \deprecated     Superseded by mbedtls_internal_sha256_process() in 2.7.0.
00190  *
00191  * \param ctx      The SHA-256 context.
00192  * \param data     The buffer holding one block of data.
00193  */
00194 MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
00195                                                 const unsigned char data[64] );
00196 
00197 #undef MBEDTLS_DEPRECATED
00198 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00199 #ifdef __cplusplus
00200 }
00201 #endif
00202 
00203 #else  /* MBEDTLS_SHA256_ALT */
00204 #include "sha256_alt.h"
00205 #endif /* MBEDTLS_SHA256_ALT */
00206 
00207 #ifdef __cplusplus
00208 extern "C" {
00209 #endif
00210 
00211 /**
00212  * \brief          This function calculates the SHA-224 or SHA-256
00213  *                 checksum of a buffer.
00214  *
00215  *                 The function allocates the context, performs the
00216  *                 calculation, and frees the context.
00217  *
00218  *                 The SHA-256 result is calculated as
00219  *                 output = SHA-256(input buffer).
00220  *
00221  * \param input    The buffer holding the input data.
00222  * \param ilen     The length of the input data.
00223  * \param output   The SHA-224 or SHA-256 checksum result.
00224  * \param is224    Determines which function to use.
00225  *                 <ul><li>0: Use SHA-256.</li>
00226  *                 <li>1: Use SHA-224.</li></ul>
00227  */
00228 int mbedtls_sha256_ret( const unsigned char *input,
00229                         size_t ilen,
00230                         unsigned char output[32],
00231                         int is224 );
00232 
00233 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00234 #if defined(MBEDTLS_DEPRECATED_WARNING)
00235 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00236 #else
00237 #define MBEDTLS_DEPRECATED
00238 #endif
00239 
00240 /**
00241  * \brief          This function calculates the SHA-224 or SHA-256 checksum
00242  *                 of a buffer.
00243  *
00244  *                 The function allocates the context, performs the
00245  *                 calculation, and frees the context.
00246  *
00247  *                 The SHA-256 result is calculated as
00248  *                 output = SHA-256(input buffer).
00249  *
00250  * \deprecated     Superseded by mbedtls_sha256_ret() in 2.7.0.
00251  *
00252  * \param input    The buffer holding the data.
00253  * \param ilen     The length of the input data.
00254  * \param output   The SHA-224 or SHA-256 checksum result.
00255  * \param is224    Determines which function to use.
00256  *                 <ul><li>0: Use SHA-256.</li>
00257  *                 <li>1: Use SHA-224.</li></ul>
00258  */
00259 MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
00260                                         size_t ilen,
00261                                         unsigned char output[32],
00262                                         int is224 );
00263 
00264 #undef MBEDTLS_DEPRECATED
00265 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00266 
00267 /**
00268  * \brief          The SHA-224 and SHA-256 checkup routine.
00269  *
00270  * \return         \c 0 on success, or \c 1 on failure.
00271  */
00272 int mbedtls_sha256_self_test( int verbose );
00273 
00274 #ifdef __cplusplus
00275 }
00276 #endif
00277 
00278 #endif /* mbedtls_sha256.h */