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