Skip to content

Commit

Permalink
Merge pull request #9452 from RonEld/crypto_platform_ranaming
Browse files Browse the repository at this point in the history
Crypto platform renaming
  • Loading branch information
Cruz Monrreal authored Jan 24, 2019
2 parents c767910 + cad40e1 commit e241b13
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion features/cryptocell/FEATURE_CRYPTOCELL310/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ To port your CC 310 driver to Mbed OS on your specific target, do the following:
1. In `features/cryptocell/FEATURE_CRYPTOCELL310/TARGET_<target name>`, add your platform-specific libraries for all toolchains in `TOOLCHAIN_ARM`, `TOOLCHAIN_GCC_ARM` and `TOOLCHAIN_IAR` respectively.
1. Add your CC setup code:
* Implement `crypto_platform_setup()` and `crypto_platform_terminate()` to enable CC on your platform, in case you have board-specific setup functionality, required for CC setup. You MUST call 'SaSi_LibInit()` and 'SaSi_LibFini()' respectively in these functions.
* Define `crypto_platform_ctx` in `crypto_platform.h` in a way that suits your implementation.
* Define `crypto_platform_ctx` in `crypto_device_platform.h` in a way that suits your implementation.

6 changes: 3 additions & 3 deletions features/cryptocell/FEATURE_CRYPTOCELL310/trng.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "trng_api.h"
#include "mbedtls/platform.h"

extern mbedtls_platform_context ctx;
extern mbedtls_platform_context plat_ctx;
static CRYS_RND_WorkBuff_t rndWorkBuff = { { 0 } };

/* Implementation that should never be optimized out by the compiler */
Expand All @@ -49,7 +49,7 @@ CRYSError_t LLF_RND_GetTrngSource(

void trng_init(trng_t *obj)
{
RNG_PLAT_SetUserRngParameters(&ctx.platform_impl_ctx.rndState, obj);
RNG_PLAT_SetUserRngParameters(&plat_ctx.platform_impl_ctx.rndState, obj);
}

void trng_free(trng_t *obj)
Expand All @@ -67,7 +67,7 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *outputLe
uint32_t actualLength;

ret = LLF_RND_GetTrngSource(
&ctx.platform_impl_ctx.rndState , /*in/out*/
&plat_ctx.platform_impl_ctx.rndState , /*in/out*/
obj, /*in/out*/
0, /*in*/
&entropySizeBits, /*in/out*/
Expand Down
2 changes: 1 addition & 1 deletion features/mbedtls/platform/inc/platform_alt.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define __PLATFORM_ALT__
#include "platform_mbed.h"
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
#include "crypto_platform.h"
#include "crypto_device_platform.h"
/**
* \brief The platform context structure.
*
Expand Down
16 changes: 8 additions & 8 deletions features/mbedtls/platform/src/platform_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
#include "mbed_critical.h"

mbedtls_platform_context ctx = { { 0 } };
mbedtls_platform_context plat_ctx = { { 0 } };

int mbedtls_platform_setup( mbedtls_platform_context *unused_ctx )
{
int ret = 0;

core_util_atomic_incr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
core_util_atomic_incr_u32( ( volatile uint32_t * )&plat_ctx.reference_count, 1 );

if( ctx.reference_count == 1 )
if( plat_ctx.reference_count == 1 )
{
/* call platform specific code to setup crypto driver */
ret = crypto_platform_setup( &ctx.platform_impl_ctx );
ret = crypto_platform_setup( &plat_ctx.platform_impl_ctx );
}
return ( ret );
}

void mbedtls_platform_teardown( mbedtls_platform_context *unused_ctx )
{
core_util_atomic_decr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
if( ctx.reference_count < 1 )
core_util_atomic_decr_u32( ( volatile uint32_t * )&plat_ctx.reference_count, 1 );
if( plat_ctx.reference_count < 1 )
{
/* call platform specific code to terminate crypto driver */
crypto_platform_terminate( &ctx.platform_impl_ctx );
ctx.reference_count = 0;
crypto_platform_terminate( &plat_ctx.platform_impl_ctx );
plat_ctx.reference_count = 0;
}
}

Expand Down

0 comments on commit e241b13

Please sign in to comment.