Ability to provide alternate timing implementation
diff --git a/ChangeLog b/ChangeLog
index de84df0..3c26b01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
    * 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 cff5741..5c36ae6 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -160,6 +160,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
  *
  * Uncomment a macro to let PolarSSL use your alternate core implementation of
diff --git a/include/polarssl/timing.h b/include/polarssl/timing.h
index 5ab000e..cb6abe3 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 <polarssl_maintainer at polarssl.org>
@@ -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 @@
 }
 #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 1b4311c..c70b78c 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 <polarssl_maintainer at polarssl.org>
@@ -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"