Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sha512_alt.c Source File

sha512_alt.c

00001 /*
00002  *  sha512_alt.c
00003  *
00004  *  Copyright (C) 2019, 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 #include "mbedtls/sha512.h"
00022 #if defined(MBEDTLS_SHA512_ALT)
00023 #include <string.h>
00024 #include "mbedtls/platform.h"
00025 
00026 void mbedtls_sha512_init( mbedtls_sha512_context *ctx )
00027 {
00028     memset( ctx, 0, sizeof( mbedtls_sha512_context ) );
00029 }
00030 
00031 void mbedtls_sha512_free( mbedtls_sha512_context *ctx )
00032 {
00033     if( ctx == NULL )
00034         return;
00035     CRYS_HASH_Free( &ctx->crys_hash_ctx );
00036     memset( ctx, 0, sizeof( mbedtls_sha512_context ) );
00037 }
00038 
00039 void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
00040                            const mbedtls_sha512_context *src )
00041 {
00042     memcpy(dst,src,sizeof(mbedtls_sha512_context));
00043 }
00044 
00045 
00046 int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 )
00047 {
00048     if( is384 )
00049         return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
00050     if( CRYS_HASH_Init( &ctx->crys_hash_ctx, CRYS_HASH_SHA512_mode  ) != CRYS_OK )
00051         return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
00052     return ( 0 );
00053 }
00054 
00055 int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
00056                                      const unsigned char data[128] )
00057 {
00058     return( MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED );
00059 }
00060 
00061 int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
00062                                const unsigned char *input,
00063                                size_t ilen )
00064 {
00065     if( CRYS_HASH_Update( &ctx->crys_hash_ctx, (uint8_t*)input, ilen ) != CRYS_OK )
00066         return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
00067     return ( 0 );
00068 }
00069 
00070 int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
00071                                unsigned char output[64] )
00072 {
00073     CRYSError_t  crys_err = CRYS_OK;
00074     CRYS_HASH_Result_t  crys_result = {0};
00075     crys_err = CRYS_HASH_Finish( &ctx->crys_hash_ctx, crys_result );
00076     if( crys_err == CRYS_OK )
00077     {
00078         memcpy(output,crys_result,64);
00079         return ( 0 );
00080     }
00081     else
00082         return ( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
00083 }
00084 #endif //MBEDTLS_SHA512_ALT