Knight KE / Mbed OS Game_Master
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sha256_alt.h Source File

sha256_alt.h

00001 /*
00002  *  sha256_alt.h
00003  *
00004  *  Copyright (C) 2018, Arm Limited, All Rights Reserved
00005  *  SPDX-License-Identifier: Apache-2.0
00006  *
00007  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00008  *  not use this file except in compliance with the License.
00009  *  You may obtain a copy of the License at
00010  *
00011  *  http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  *  Unless required by applicable law or agreed to in writing, software
00014  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00015  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  *  See the License for the specific language governing permissions and
00017  *  limitations under the License.
00018  *
00019  */
00020 
00021 #ifndef __SHA256_ALT__
00022 #define __SHA256_ALT__
00023 
00024 #if defined(MBEDTLS_SHA256_ALT)
00025 
00026 #include "crys_hash.h"
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 
00032 /**
00033  * \brief          SHA-256 context structure
00034  */
00035 typedef struct
00036 {
00037     CRYS_HASHUserContext_t  crys_hash_ctx;
00038 } mbedtls_sha256_context;
00039 
00040 
00041 /**
00042  * \brief          This function initializes a SHA-256 context.
00043  *
00044  * \param ctx      The SHA-256 context to initialize.
00045  */
00046 void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
00047 
00048 /**
00049  * \brief          This function clears a SHA-256 context.
00050  *
00051  * \param ctx      The SHA-256 context to clear.
00052  */
00053 void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
00054 
00055 /**
00056  * \brief          This function clones the state of a SHA-256 context.
00057  *
00058  * \param dst      The destination context.
00059  * \param src      The context to clone.
00060  */
00061 void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
00062                            const mbedtls_sha256_context *src );
00063 
00064 /**
00065  * \brief          This function starts a SHA-224 or SHA-256 checksum
00066  *                 calculation.
00067  *
00068  * \param ctx      The context to initialize.
00069  * \param is224    Determines which function to use.
00070  *                 <ul><li>0: Use SHA-256.</li>
00071  *                 <li>1: Use SHA-224.</li></ul>
00072  *
00073  * \return         \c 0 on success.
00074  */
00075 int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
00076 
00077 /**
00078  * \brief          This function feeds an input buffer into an ongoing
00079  *                 SHA-256 checksum calculation.
00080  *
00081  * \param ctx      SHA-256 context
00082  * \param input    buffer holding the data
00083  * \param ilen     length of the input data
00084  *
00085  * \return         \c 0 on success.
00086  */
00087 int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
00088                                const unsigned char *input,
00089                                size_t ilen );
00090 
00091 /**
00092  * \brief          This function finishes the SHA-256 operation, and writes
00093  *                 the result to the output buffer.
00094  *
00095  * \param ctx      The SHA-256 context.
00096  * \param output   The SHA-224 or SHA-256 checksum result.
00097  *
00098  * \return         \c 0 on success.
00099  */
00100 int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
00101                                unsigned char output[32] );
00102 
00103 /**
00104  * \brief          This function processes a single data block within
00105  *                 the ongoing SHA-256 computation. This function is for
00106  *                 internal use only.
00107  *
00108  * \param ctx      The SHA-256 context.
00109  * \param data     The buffer holding one block of data.
00110  *
00111  * \return         \c 0 on success.
00112  */
00113 int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
00114                                      const unsigned char data[64] );
00115 
00116 #ifdef __cplusplus
00117 }
00118 #endif
00119 
00120 #endif // MBEDTLS_SHA256_ALT__
00121 #endif //__SHA256_ALT__