Add Mbed TLS Platform module errors

1. Add error codes for platform setup \ teardown.
2. Reassign `reference_count` to 0 after terminating platform,
and remove condition for 0
pull/7099/head
Ron Eldor 2018-06-04 14:01:59 +03:00
parent ca94a49eff
commit c3b31bc500
3 changed files with 7 additions and 6 deletions

View File

@ -34,7 +34,7 @@ int crypto_platform_setup( crypto_platform_ctx *ctx )
NRF_CRYPTOCELL->ENABLE = 1;
if( SaSi_LibInit( &rndState, &rndWorkBuff ) != 0 )
return ( -1 );
return ( MBEDTLS_PLATFORM_HW_FAILED );
return ( 0 );
}

View File

@ -24,3 +24,6 @@
#if defined(MBEDTLS_CONFIG_HW_SUPPORT)
#include "mbedtls_device.h"
#endif
#define MBEDTLS_PLATFORM_INVALID_DATA -0x0080
#define MBEDTLS_PLATFORM_HW_FAILED -0x0082

View File

@ -27,7 +27,7 @@ int mbedtls_platform_setup( mbedtls_platform_context *ctx )
{
int ret = 0;
if( ctx == NULL )
return ( -1 );
return ( MBEDTLS_PLATFORM_INVALID_DATA );
reference_count++;
@ -44,15 +44,13 @@ void mbedtls_platform_teardown( mbedtls_platform_context *ctx )
if( ctx == NULL )
return;
if( reference_count == 0 )
return;
reference_count--;
if( reference_count == 0 )
if( reference_count <= 0 )
{
/* call platform specific code to terminate crypto driver*/
crypto_platform_terminate( &ctx->platform_impl_ctx );
reference_count = 0;
}
}