diff --git a/ChangeLog b/ChangeLog index de84df058..3c26b017c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ Features * Support for RSASSA-PSS keys and signatures in certificates, CSRs and CRLs * Single Platform compatilibity layer (for memory / printf / fprintf) + * Ability to provide alternate timing implementation Changes * Deprecated the Memory layer diff --git a/include/polarssl/config.h b/include/polarssl/config.h index cff574185..5c36ae6b3 100644 --- a/include/polarssl/config.h +++ b/include/polarssl/config.h @@ -159,6 +159,19 @@ * \{ */ +/** + * \def POLARSSL_TIMING_ALT + * + * Uncomment to provide your own alternate implementation for hardclock(), + * get_timer(), set_alarm() and m_sleep(). + * + * Only works if you have POLARSSL_TIMING_C enabled. + * + * You will need to provide a header "timing_alt.h" and an implementation at + * compile time. + */ +//#define POLARSSL_TIMING_ALT + /** * \def POLARSSL_XXX_ALT * diff --git a/include/polarssl/timing.h b/include/polarssl/timing.h index 5ab000e10..cb6abe35e 100644 --- a/include/polarssl/timing.h +++ b/include/polarssl/timing.h @@ -3,7 +3,7 @@ * * \brief Portable interface to the CPU cycle counter * - * Copyright (C) 2006-2013, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -27,6 +27,12 @@ #ifndef POLARSSL_TIMING_H #define POLARSSL_TIMING_H +#include "config.h" + +#if !defined(POLARSSL_TIMING_ALT) +// Regular implementation +// + #ifdef __cplusplus extern "C" { #endif @@ -72,4 +78,8 @@ void m_sleep( int milliseconds ); } #endif +#else /* POLARSSL_TIMING_ALT */ +#include "timing_alt.h" +#endif /* POLARSSL_TIMING_ALT */ + #endif /* timing.h */ diff --git a/library/timing.c b/library/timing.c index 1b4311cbc..c70b78c26 100644 --- a/library/timing.c +++ b/library/timing.c @@ -1,7 +1,7 @@ /* * Portable interface to the CPU cycle counter * - * Copyright (C) 2006-2010, Brainspark B.V. + * Copyright (C) 2006-2014, Brainspark B.V. * * This file is part of PolarSSL (http://www.polarssl.org) * Lead Maintainer: Paul Bakker @@ -25,7 +25,7 @@ #include "polarssl/config.h" -#if defined(POLARSSL_TIMING_C) +#if defined(POLARSSL_TIMING_C) && !defined(POLARSSL_TIMING_ALT) #include "polarssl/timing.h"