From 524d507363eb116aa73e07fb8224f1fec918fd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 22 May 2015 11:58:37 +0200 Subject: [PATCH] Disable timing.c Move hardclock implementation to entropy_pool.c to use that as a (pseudo) entropy source for now --- include/mbedtls/config.h | 2 +- include/mbedtls/entropy_poll.h | 2 +- library/entropy.c | 2 +- library/entropy_poll.c | 25 +++++++++++++++++++++++-- module.json | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h index 4d3b5961c..5885eb6ac 100644 --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h @@ -2150,7 +2150,7 @@ * * This module is used by the HAVEGE random number generator. */ -#define MBEDTLS_TIMING_C +//#define MBEDTLS_TIMING_C /** * \def MBEDTLS_VERSION_C diff --git a/include/mbedtls/entropy_poll.h b/include/mbedtls/entropy_poll.h index 4729b44f9..91b52d558 100644 --- a/include/mbedtls/entropy_poll.h +++ b/include/mbedtls/entropy_poll.h @@ -47,7 +47,7 @@ int mbedtls_havege_poll( void *data, unsigned char *output, size_t len, size_t *olen ); #endif -#if defined(MBEDTLS_TIMING_C) +#if defined(MBEDTLS_TIMING_C) || defined(TARGET_LIKE_CORTEX_M4) /** * \brief mbedtls_timing_hardclock-based entropy poll callback */ diff --git a/library/entropy.c b/library/entropy.c index 81122b5a6..8de8e5975 100644 --- a/library/entropy.c +++ b/library/entropy.c @@ -65,7 +65,7 @@ void mbedtls_entropy_init( mbedtls_entropy_context *ctx ) mbedtls_entropy_add_source( ctx, mbedtls_platform_entropy_poll, NULL, MBEDTLS_ENTROPY_MIN_PLATFORM ); #endif -#if defined(MBEDTLS_TIMING_C) +#if defined(MBEDTLS_TIMING_C) || defined(TARGET_LIKE_CORTEX_M4) mbedtls_entropy_add_source( ctx, mbedtls_hardclock_poll, NULL, MBEDTLS_ENTROPY_MIN_HARDCLOCK ); #endif #if defined(MBEDTLS_HAVEGE_C) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 84806d5d5..494423867 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -17,8 +17,10 @@ #include "mbedtls/entropy.h" #include "mbedtls/entropy_poll.h" -#if defined(MBEDTLS_TIMING_C) +#if defined(MBEDTLS_TIMING_C) || defined(TARGET_LIKE_CORTEX_M4) #include +#endif +#if defined(MBEDTLS_TIMING_C) #include "mbedtls/timing.h" #endif #if defined(MBEDTLS_HAVEGE_C) @@ -159,7 +161,26 @@ int mbedtls_platform_entropy_poll( void *data, #endif /* _WIN32 && !EFIX64 && !EFI32 */ #endif /* !MBEDTLS_NO_PLATFORM_ENTROPY */ -#if defined(MBEDTLS_TIMING_C) +#if defined(TARGET_LIKE_CORTEX_M4) + +#include "MK64F12.h" +#include "core_cm4.h" + +static unsigned long mbedtls_timing_hardclock( void ) +{ + static int dwt_started = 0; + + if( dwt_started == 0 ) + { + CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; + DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; + } + + return( DWT->CYCCNT ); +} +#endif + +#if defined(MBEDTLS_TIMING_C) || defined(TARGET_LIKE_CORTEX_M4) int mbedtls_hardclock_poll( void *data, unsigned char *output, size_t len, size_t *olen ) { diff --git a/module.json b/module.json index a5c78a973..705cb98c5 100644 --- a/module.json +++ b/module.json @@ -1,6 +1,6 @@ { "name": "mbedtls", - "version": "2.0.0-beta9", + "version": "2.0.0-beta9a", "private": true, "license": "mbed partner license", "extraIncludes": ["include"],