]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Labs/Source/mbedtls/include/mbedtls/sha256.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Source / mbedtls / include / mbedtls / sha256.h
diff --git a/FreeRTOS-Labs/Source/mbedtls/include/mbedtls/sha256.h b/FreeRTOS-Labs/Source/mbedtls/include/mbedtls/sha256.h
new file mode 100644 (file)
index 0000000..4b87418
--- /dev/null
@@ -0,0 +1,297 @@
+/**\r
+ * \file sha256.h\r
+ *\r
+ * \brief This file contains SHA-224 and SHA-256 definitions and functions.\r
+ *\r
+ * The Secure Hash Algorithms 224 and 256 (SHA-224 and SHA-256) cryptographic\r
+ * hash functions are defined in <em>FIPS 180-4: Secure Hash Standard (SHS)</em>.\r
+ */\r
+/*\r
+ *  Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved\r
+ *  SPDX-License-Identifier: Apache-2.0\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may\r
+ *  not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *  http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ *\r
+ *  This file is part of Mbed TLS (https://tls.mbed.org)\r
+ */\r
+#ifndef MBEDTLS_SHA256_H\r
+#define MBEDTLS_SHA256_H\r
+\r
+#if !defined(MBEDTLS_CONFIG_FILE)\r
+#include "config.h"\r
+#else\r
+#include MBEDTLS_CONFIG_FILE\r
+#endif\r
+\r
+#include <stddef.h>\r
+#include <stdint.h>\r
+\r
+/* MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED is deprecated and should not be used. */\r
+#define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED                -0x0037  /**< SHA-256 hardware accelerator failed */\r
+#define MBEDTLS_ERR_SHA256_BAD_INPUT_DATA                 -0x0074  /**< SHA-256 input data was malformed. */\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#if !defined(MBEDTLS_SHA256_ALT)\r
+// Regular implementation\r
+//\r
+\r
+/**\r
+ * \brief          The SHA-256 context structure.\r
+ *\r
+ *                 The structure is used both for SHA-256 and for SHA-224\r
+ *                 checksum calculations. The choice between these two is\r
+ *                 made in the call to mbedtls_sha256_starts_ret().\r
+ */\r
+typedef struct mbedtls_sha256_context\r
+{\r
+    uint32_t total[2];          /*!< The number of Bytes processed.  */\r
+    uint32_t state[8];          /*!< The intermediate digest state.  */\r
+    unsigned char buffer[64];   /*!< The data block being processed. */\r
+    int is224;                  /*!< Determines which function to use:\r
+                                     0: Use SHA-256, or 1: Use SHA-224. */\r
+}\r
+mbedtls_sha256_context;\r
+\r
+#else  /* MBEDTLS_SHA256_ALT */\r
+#include "sha256_alt.h"\r
+#endif /* MBEDTLS_SHA256_ALT */\r
+\r
+/**\r
+ * \brief          This function initializes a SHA-256 context.\r
+ *\r
+ * \param ctx      The SHA-256 context to initialize. This must not be \c NULL.\r
+ */\r
+void mbedtls_sha256_init( mbedtls_sha256_context *ctx );\r
+\r
+/**\r
+ * \brief          This function clears a SHA-256 context.\r
+ *\r
+ * \param ctx      The SHA-256 context to clear. This may be \c NULL, in which\r
+ *                 case this function returns immediately. If it is not \c NULL,\r
+ *                 it must point to an initialized SHA-256 context.\r
+ */\r
+void mbedtls_sha256_free( mbedtls_sha256_context *ctx );\r
+\r
+/**\r
+ * \brief          This function clones the state of a SHA-256 context.\r
+ *\r
+ * \param dst      The destination context. This must be initialized.\r
+ * \param src      The context to clone. This must be initialized.\r
+ */\r
+void mbedtls_sha256_clone( mbedtls_sha256_context *dst,\r
+                           const mbedtls_sha256_context *src );\r
+\r
+/**\r
+ * \brief          This function starts a SHA-224 or SHA-256 checksum\r
+ *                 calculation.\r
+ *\r
+ * \param ctx      The context to use. This must be initialized.\r
+ * \param is224    This determines which function to use. This must be\r
+ *                 either \c 0 for SHA-256, or \c 1 for SHA-224.\r
+ *\r
+ * \return         \c 0 on success.\r
+ * \return         A negative error code on failure.\r
+ */\r
+int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );\r
+\r
+/**\r
+ * \brief          This function feeds an input buffer into an ongoing\r
+ *                 SHA-256 checksum calculation.\r
+ *\r
+ * \param ctx      The SHA-256 context. This must be initialized\r
+ *                 and have a hash operation started.\r
+ * \param input    The buffer holding the data. This must be a readable\r
+ *                 buffer of length \p ilen Bytes.\r
+ * \param ilen     The length of the input data in Bytes.\r
+ *\r
+ * \return         \c 0 on success.\r
+ * \return         A negative error code on failure.\r
+ */\r
+int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,\r
+                               const unsigned char *input,\r
+                               size_t ilen );\r
+\r
+/**\r
+ * \brief          This function finishes the SHA-256 operation, and writes\r
+ *                 the result to the output buffer.\r
+ *\r
+ * \param ctx      The SHA-256 context. This must be initialized\r
+ *                 and have a hash operation started.\r
+ * \param output   The SHA-224 or SHA-256 checksum result.\r
+ *                 This must be a writable buffer of length \c 32 Bytes.\r
+ *\r
+ * \return         \c 0 on success.\r
+ * \return         A negative error code on failure.\r
+ */\r
+int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,\r
+                               unsigned char output[32] );\r
+\r
+/**\r
+ * \brief          This function processes a single data block within\r
+ *                 the ongoing SHA-256 computation. This function is for\r
+ *                 internal use only.\r
+ *\r
+ * \param ctx      The SHA-256 context. This must be initialized.\r
+ * \param data     The buffer holding one block of data. This must\r
+ *                 be a readable buffer of length \c 64 Bytes.\r
+ *\r
+ * \return         \c 0 on success.\r
+ * \return         A negative error code on failure.\r
+ */\r
+int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,\r
+                                     const unsigned char data[64] );\r
+\r
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)\r
+#if defined(MBEDTLS_DEPRECATED_WARNING)\r
+#define MBEDTLS_DEPRECATED      __attribute__((deprecated))\r
+#else\r
+#define MBEDTLS_DEPRECATED\r
+#endif\r
+/**\r
+ * \brief          This function starts a SHA-224 or SHA-256 checksum\r
+ *                 calculation.\r
+ *\r
+ * \deprecated     Superseded by mbedtls_sha256_starts_ret() in 2.7.0.\r
+ *\r
+ * \param ctx      The context to use. This must be initialized.\r
+ * \param is224    Determines which function to use. This must be\r
+ *                 either \c 0 for SHA-256, or \c 1 for SHA-224.\r
+ */\r
+MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,\r
+                                               int is224 );\r
+\r
+/**\r
+ * \brief          This function feeds an input buffer into an ongoing\r
+ *                 SHA-256 checksum calculation.\r
+ *\r
+ * \deprecated     Superseded by mbedtls_sha256_update_ret() in 2.7.0.\r
+ *\r
+ * \param ctx      The SHA-256 context to use. This must be\r
+ *                 initialized and have a hash operation started.\r
+ * \param input    The buffer holding the data. This must be a readable\r
+ *                 buffer of length \p ilen Bytes.\r
+ * \param ilen     The length of the input data in Bytes.\r
+ */\r
+MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,\r
+                                               const unsigned char *input,\r
+                                               size_t ilen );\r
+\r
+/**\r
+ * \brief          This function finishes the SHA-256 operation, and writes\r
+ *                 the result to the output buffer.\r
+ *\r
+ * \deprecated     Superseded by mbedtls_sha256_finish_ret() in 2.7.0.\r
+ *\r
+ * \param ctx      The SHA-256 context. This must be initialized and\r
+ *                 have a hash operation started.\r
+ * \param output   The SHA-224 or SHA-256 checksum result. This must be\r
+ *                 a writable buffer of length \c 32 Bytes.\r
+ */\r
+MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,\r
+                                               unsigned char output[32] );\r
+\r
+/**\r
+ * \brief          This function processes a single data block within\r
+ *                 the ongoing SHA-256 computation. This function is for\r
+ *                 internal use only.\r
+ *\r
+ * \deprecated     Superseded by mbedtls_internal_sha256_process() in 2.7.0.\r
+ *\r
+ * \param ctx      The SHA-256 context. This must be initialized.\r
+ * \param data     The buffer holding one block of data. This must be\r
+ *                 a readable buffer of size \c 64 Bytes.\r
+ */\r
+MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,\r
+                                                const unsigned char data[64] );\r
+\r
+#undef MBEDTLS_DEPRECATED\r
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */\r
+\r
+/**\r
+ * \brief          This function calculates the SHA-224 or SHA-256\r
+ *                 checksum of a buffer.\r
+ *\r
+ *                 The function allocates the context, performs the\r
+ *                 calculation, and frees the context.\r
+ *\r
+ *                 The SHA-256 result is calculated as\r
+ *                 output = SHA-256(input buffer).\r
+ *\r
+ * \param input    The buffer holding the data. This must be a readable\r
+ *                 buffer of length \p ilen Bytes.\r
+ * \param ilen     The length of the input data in Bytes.\r
+ * \param output   The SHA-224 or SHA-256 checksum result. This must\r
+ *                 be a writable buffer of length \c 32 Bytes.\r
+ * \param is224    Determines which function to use. This must be\r
+ *                 either \c 0 for SHA-256, or \c 1 for SHA-224.\r
+ */\r
+int mbedtls_sha256_ret( const unsigned char *input,\r
+                        size_t ilen,\r
+                        unsigned char output[32],\r
+                        int is224 );\r
+\r
+#if !defined(MBEDTLS_DEPRECATED_REMOVED)\r
+#if defined(MBEDTLS_DEPRECATED_WARNING)\r
+#define MBEDTLS_DEPRECATED      __attribute__((deprecated))\r
+#else\r
+#define MBEDTLS_DEPRECATED\r
+#endif\r
+\r
+/**\r
+ * \brief          This function calculates the SHA-224 or SHA-256 checksum\r
+ *                 of a buffer.\r
+ *\r
+ *                 The function allocates the context, performs the\r
+ *                 calculation, and frees the context.\r
+ *\r
+ *                 The SHA-256 result is calculated as\r
+ *                 output = SHA-256(input buffer).\r
+ *\r
+ * \deprecated     Superseded by mbedtls_sha256_ret() in 2.7.0.\r
+ *\r
+ * \param input    The buffer holding the data. This must be a readable\r
+ *                 buffer of length \p ilen Bytes.\r
+ * \param ilen     The length of the input data in Bytes.\r
+ * \param output   The SHA-224 or SHA-256 checksum result. This must be\r
+ *                 a writable buffer of length \c 32 Bytes.\r
+ * \param is224    Determines which function to use. This must be either\r
+ *                 \c 0 for SHA-256, or \c 1 for SHA-224.\r
+ */\r
+MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,\r
+                                        size_t ilen,\r
+                                        unsigned char output[32],\r
+                                        int is224 );\r
+\r
+#undef MBEDTLS_DEPRECATED\r
+#endif /* !MBEDTLS_DEPRECATED_REMOVED */\r
+\r
+#if defined(MBEDTLS_SELF_TEST)\r
+\r
+/**\r
+ * \brief          The SHA-224 and SHA-256 checkup routine.\r
+ *\r
+ * \return         \c 0 on success.\r
+ * \return         \c 1 on failure.\r
+ */\r
+int mbedtls_sha256_self_test( int verbose );\r
+\r
+#endif /* MBEDTLS_SELF_TEST */\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* mbedtls_sha256.h */\r