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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
sha1.h
00001 /** 00002 * \file sha1.h 00003 * 00004 * \brief This file contains SHA-1 definitions and functions. 00005 * 00006 * The Secure Hash Algorithm 1 (SHA-1) cryptographic hash function is defined in 00007 * <em>FIPS 180-4: Secure Hash Standard (SHS)</em>. 00008 * 00009 * \warning SHA-1 is considered a weak message digest and its use constitutes 00010 * a security risk. We recommend considering stronger message 00011 * digests instead. 00012 */ 00013 /* 00014 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved 00015 * SPDX-License-Identifier: Apache-2.0 00016 * 00017 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00018 * not use this file except in compliance with the License. 00019 * You may obtain a copy of the License at 00020 * 00021 * http://www.apache.org/licenses/LICENSE-2.0 00022 * 00023 * Unless required by applicable law or agreed to in writing, software 00024 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00025 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00026 * See the License for the specific language governing permissions and 00027 * limitations under the License. 00028 * 00029 * This file is part of Mbed TLS (https://tls.mbed.org) 00030 */ 00031 #ifndef MBEDTLS_SHA1_H 00032 #define MBEDTLS_SHA1_H 00033 00034 #if !defined(MBEDTLS_CONFIG_FILE) 00035 #include "mbedtls/config.h" 00036 #else 00037 #include MBEDTLS_CONFIG_FILE 00038 #endif 00039 00040 #include <stddef.h> 00041 #include <stdint.h> 00042 00043 /* MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED is deprecated and should not be used. */ 00044 #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */ 00045 #define MBEDTLS_ERR_SHA1_BAD_INPUT_DATA -0x0073 /**< SHA-1 input data was malformed. */ 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 #if !defined(MBEDTLS_SHA1_ALT) 00052 // Regular implementation 00053 // 00054 00055 /** 00056 * \brief The SHA-1 context structure. 00057 * 00058 * \warning SHA-1 is considered a weak message digest and its use 00059 * constitutes a security risk. We recommend considering 00060 * stronger message digests instead. 00061 * 00062 */ 00063 typedef struct mbedtls_sha1_context 00064 { 00065 uint32_t total [2]; /*!< The number of Bytes processed. */ 00066 uint32_t state [5]; /*!< The intermediate digest state. */ 00067 unsigned char buffer[64]; /*!< The data block being processed. */ 00068 } 00069 mbedtls_sha1_context; 00070 00071 #else /* MBEDTLS_SHA1_ALT */ 00072 #include "sha1_alt.h" 00073 #endif /* MBEDTLS_SHA1_ALT */ 00074 00075 /** 00076 * \brief This function initializes a SHA-1 context. 00077 * 00078 * \warning SHA-1 is considered a weak message digest and its use 00079 * constitutes a security risk. We recommend considering 00080 * stronger message digests instead. 00081 * 00082 * \param ctx The SHA-1 context to initialize. 00083 * This must not be \c NULL. 00084 * 00085 */ 00086 void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); 00087 00088 /** 00089 * \brief This function clears a SHA-1 context. 00090 * 00091 * \warning SHA-1 is considered a weak message digest and its use 00092 * constitutes a security risk. We recommend considering 00093 * stronger message digests instead. 00094 * 00095 * \param ctx The SHA-1 context to clear. This may be \c NULL, 00096 * in which case this function does nothing. If it is 00097 * not \c NULL, it must point to an initialized 00098 * SHA-1 context. 00099 * 00100 */ 00101 void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); 00102 00103 /** 00104 * \brief This function clones the state of a SHA-1 context. 00105 * 00106 * \warning SHA-1 is considered a weak message digest and its use 00107 * constitutes a security risk. We recommend considering 00108 * stronger message digests instead. 00109 * 00110 * \param dst The SHA-1 context to clone to. This must be initialized. 00111 * \param src The SHA-1 context to clone from. This must be initialized. 00112 * 00113 */ 00114 void mbedtls_sha1_clone( mbedtls_sha1_context *dst, 00115 const mbedtls_sha1_context *src ); 00116 00117 /** 00118 * \brief This function starts a SHA-1 checksum calculation. 00119 * 00120 * \warning SHA-1 is considered a weak message digest and its use 00121 * constitutes a security risk. We recommend considering 00122 * stronger message digests instead. 00123 * 00124 * \param ctx The SHA-1 context to initialize. This must be initialized. 00125 * 00126 * \return \c 0 on success. 00127 * \return A negative error code on failure. 00128 * 00129 */ 00130 int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx ); 00131 00132 /** 00133 * \brief This function feeds an input buffer into an ongoing SHA-1 00134 * checksum calculation. 00135 * 00136 * \warning SHA-1 is considered a weak message digest and its use 00137 * constitutes a security risk. We recommend considering 00138 * stronger message digests instead. 00139 * 00140 * \param ctx The SHA-1 context. This must be initialized 00141 * and have a hash operation started. 00142 * \param input The buffer holding the input data. 00143 * This must be a readable buffer of length \p ilen Bytes. 00144 * \param ilen The length of the input data \p input in Bytes. 00145 * 00146 * \return \c 0 on success. 00147 * \return A negative error code on failure. 00148 */ 00149 int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx, 00150 const unsigned char *input, 00151 size_t ilen ); 00152 00153 /** 00154 * \brief This function finishes the SHA-1 operation, and writes 00155 * the result to the output buffer. 00156 * 00157 * \warning SHA-1 is considered a weak message digest and its use 00158 * constitutes a security risk. We recommend considering 00159 * stronger message digests instead. 00160 * 00161 * \param ctx The SHA-1 context to use. This must be initialized and 00162 * have a hash operation started. 00163 * \param output The SHA-1 checksum result. This must be a writable 00164 * buffer of length \c 20 Bytes. 00165 * 00166 * \return \c 0 on success. 00167 * \return A negative error code on failure. 00168 */ 00169 int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx, 00170 unsigned char output[20] ); 00171 00172 /** 00173 * \brief SHA-1 process data block (internal use only). 00174 * 00175 * \warning SHA-1 is considered a weak message digest and its use 00176 * constitutes a security risk. We recommend considering 00177 * stronger message digests instead. 00178 * 00179 * \param ctx The SHA-1 context to use. This must be initialized. 00180 * \param data The data block being processed. This must be a 00181 * readable buffer of length \c 64 Bytes. 00182 * 00183 * \return \c 0 on success. 00184 * \return A negative error code on failure. 00185 * 00186 */ 00187 int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, 00188 const unsigned char data[64] ); 00189 00190 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 00191 #if defined(MBEDTLS_DEPRECATED_WARNING) 00192 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 00193 #else 00194 #define MBEDTLS_DEPRECATED 00195 #endif 00196 /** 00197 * \brief This function starts a SHA-1 checksum calculation. 00198 * 00199 * \warning SHA-1 is considered a weak message digest and its use 00200 * constitutes a security risk. We recommend considering 00201 * stronger message digests instead. 00202 * 00203 * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0. 00204 * 00205 * \param ctx The SHA-1 context to initialize. This must be initialized. 00206 * 00207 */ 00208 MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx ); 00209 00210 /** 00211 * \brief This function feeds an input buffer into an ongoing SHA-1 00212 * checksum calculation. 00213 * 00214 * \warning SHA-1 is considered a weak message digest and its use 00215 * constitutes a security risk. We recommend considering 00216 * stronger message digests instead. 00217 * 00218 * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0. 00219 * 00220 * \param ctx The SHA-1 context. This must be initialized and 00221 * have a hash operation started. 00222 * \param input The buffer holding the input data. 00223 * This must be a readable buffer of length \p ilen Bytes. 00224 * \param ilen The length of the input data \p input in Bytes. 00225 * 00226 */ 00227 MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx, 00228 const unsigned char *input, 00229 size_t ilen ); 00230 00231 /** 00232 * \brief This function finishes the SHA-1 operation, and writes 00233 * the result to the output buffer. 00234 * 00235 * \warning SHA-1 is considered a weak message digest and its use 00236 * constitutes a security risk. We recommend considering 00237 * stronger message digests instead. 00238 * 00239 * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0. 00240 * 00241 * \param ctx The SHA-1 context. This must be initialized and 00242 * have a hash operation started. 00243 * \param output The SHA-1 checksum result. 00244 * This must be a writable buffer of length \c 20 Bytes. 00245 */ 00246 MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, 00247 unsigned char output[20] ); 00248 00249 /** 00250 * \brief SHA-1 process data block (internal use only). 00251 * 00252 * \warning SHA-1 is considered a weak message digest and its use 00253 * constitutes a security risk. We recommend considering 00254 * stronger message digests instead. 00255 * 00256 * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0. 00257 * 00258 * \param ctx The SHA-1 context. This must be initialized. 00259 * \param data The data block being processed. 00260 * This must be a readable buffer of length \c 64 bytes. 00261 * 00262 */ 00263 MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx, 00264 const unsigned char data[64] ); 00265 00266 #undef MBEDTLS_DEPRECATED 00267 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 00268 00269 /** 00270 * \brief This function calculates the SHA-1 checksum of a buffer. 00271 * 00272 * The function allocates the context, performs the 00273 * calculation, and frees the context. 00274 * 00275 * The SHA-1 result is calculated as 00276 * output = SHA-1(input buffer). 00277 * 00278 * \warning SHA-1 is considered a weak message digest and its use 00279 * constitutes a security risk. We recommend considering 00280 * stronger message digests instead. 00281 * 00282 * \param input The buffer holding the input data. 00283 * This must be a readable buffer of length \p ilen Bytes. 00284 * \param ilen The length of the input data \p input in Bytes. 00285 * \param output The SHA-1 checksum result. 00286 * This must be a writable buffer of length \c 20 Bytes. 00287 * 00288 * \return \c 0 on success. 00289 * \return A negative error code on failure. 00290 * 00291 */ 00292 int mbedtls_sha1_ret( const unsigned char *input, 00293 size_t ilen, 00294 unsigned char output[20] ); 00295 00296 #if !defined(MBEDTLS_DEPRECATED_REMOVED) 00297 #if defined(MBEDTLS_DEPRECATED_WARNING) 00298 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 00299 #else 00300 #define MBEDTLS_DEPRECATED 00301 #endif 00302 /** 00303 * \brief This function calculates the SHA-1 checksum of a buffer. 00304 * 00305 * The function allocates the context, performs the 00306 * calculation, and frees the context. 00307 * 00308 * The SHA-1 result is calculated as 00309 * output = SHA-1(input buffer). 00310 * 00311 * \warning SHA-1 is considered a weak message digest and its use 00312 * constitutes a security risk. We recommend considering 00313 * stronger message digests instead. 00314 * 00315 * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0 00316 * 00317 * \param input The buffer holding the input data. 00318 * This must be a readable buffer of length \p ilen Bytes. 00319 * \param ilen The length of the input data \p input in Bytes. 00320 * \param output The SHA-1 checksum result. This must be a writable 00321 * buffer of size \c 20 Bytes. 00322 * 00323 */ 00324 MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input, 00325 size_t ilen, 00326 unsigned char output[20] ); 00327 00328 #undef MBEDTLS_DEPRECATED 00329 #endif /* !MBEDTLS_DEPRECATED_REMOVED */ 00330 00331 #if defined(MBEDTLS_SELF_TEST) 00332 00333 /** 00334 * \brief The SHA-1 checkup routine. 00335 * 00336 * \warning SHA-1 is considered a weak message digest and its use 00337 * constitutes a security risk. We recommend considering 00338 * stronger message digests instead. 00339 * 00340 * \return \c 0 on success. 00341 * \return \c 1 on failure. 00342 * 00343 */ 00344 int mbedtls_sha1_self_test( int verbose ); 00345 00346 #endif /* MBEDTLS_SELF_TEST */ 00347 00348 #ifdef __cplusplus 00349 } 00350 #endif 00351 00352 #endif /* mbedtls_sha1.h */
Generated on Tue Jul 12 2022 13:54:50 by
