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

« Back to documentation index

Show/hide line numbers platform_alt.c Source File

platform_alt.c

00001  /*
00002   *  platform_alt.c
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 #include "mbedtls/platform.h"
00022 #if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
00023 #include "sns_silib.h"
00024 
00025 /* once https://github.com/ARMmbed/mbedtls/issues/1200 will be supported,
00026  * rndState should be part of mbedtls_platform_context
00027  * Until then, we should keep it global and extern */
00028 
00029 CRYS_RND_State_t      rndState = { { 0 } } ;
00030 CRYS_RND_WorkBuff_t   rndWorkBuff = { { 0 } } ;
00031 
00032 
00033 int mbedtls_platform_setup( mbedtls_platform_context *ctx )
00034 {
00035     int ret = 0;
00036     if( ctx == NULL )
00037         return ( -1 );
00038 
00039     /* call platform specific code to setup CC driver*/
00040     if( ( ret = cc_platform_setup( &ctx->platform_impl_ctx ) ) != 0 )
00041         return ( ret );
00042 
00043     if( SaSi_LibInit( &rndState, &rndWorkBuff ) != 0 )
00044         return ( -1 );
00045     return ( 0 );
00046 }
00047 
00048 void mbedtls_platform_teardown( mbedtls_platform_context *ctx )
00049 {
00050     if( ctx == NULL )
00051         return;
00052 
00053     SaSi_LibFini( &rndState );
00054     cc_platform_terminate( &ctx->platform_impl_ctx );
00055 }
00056 
00057 #endif /* MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT*/