The Great Renaming

A simple execution of tmp/invoke-rename.pl
diff --git a/library/timing.c b/library/timing.c
index 751b0b4..33f5239 100644
--- a/library/timing.c
+++ b/library/timing.c
@@ -20,20 +20,20 @@
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#if !defined(POLARSSL_CONFIG_FILE)
+#if !defined(MBEDTLS_CONFIG_FILE)
 #include "mbedtls/config.h"
 #else
-#include POLARSSL_CONFIG_FILE
+#include MBEDTLS_CONFIG_FILE
 #endif
 
-#if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_PLATFORM_C)
+#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_PLATFORM_C)
 #include "mbedtls/platform.h"
 #else
 #include <stdio.h>
-#define polarssl_printf     printf
+#define mbedtls_printf     printf
 #endif
 
-#if defined(POLARSSL_TIMING_C) && !defined(POLARSSL_TIMING_ALT)
+#if defined(MBEDTLS_TIMING_C) && !defined(MBEDTLS_TIMING_ALT)
 
 #include "mbedtls/timing.h"
 
@@ -62,57 +62,57 @@
 
 #endif /* _WIN32 && !EFIX64 && !EFI32 */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
     ( defined(_MSC_VER) && defined(_M_IX86) ) || defined(__WATCOMC__)
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long tsc;
     __asm   rdtsc
     __asm   mov  [tsc], eax
     return( tsc );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           ( _MSC_VER && _M_IX86 ) || __WATCOMC__ */
 
 /* some versions of mingw-64 have 32-bit longs even on x84_64 */
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
     defined(__GNUC__) && ( defined(__i386__) || (                       \
     ( defined(__amd64__) || defined( __x86_64__) ) && __SIZEOF_LONG__ == 4 ) )
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long lo, hi;
     asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
     return( lo );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           __GNUC__ && __i386__ */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
     defined(__GNUC__) && ( defined(__amd64__) || defined(__x86_64__) )
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long lo, hi;
     asm volatile( "rdtsc" : "=a" (lo), "=d" (hi) );
     return( lo | ( hi << 32 ) );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           __GNUC__ && ( __amd64__ || __x86_64__ ) */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
     defined(__GNUC__) && ( defined(__powerpc__) || defined(__ppc__) )
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long tbl, tbu0, tbu1;
 
@@ -126,76 +126,76 @@
 
     return( tbl );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           __GNUC__ && ( __powerpc__ || __ppc__ ) */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
     defined(__GNUC__) && defined(__sparc64__)
 
 #if defined(__OpenBSD__)
 #warning OpenBSD does not allow access to tick register using software version instead
 #else
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long tick;
     asm volatile( "rdpr %%tick, %0;" : "=&r" (tick) );
     return( tick );
 }
 #endif /* __OpenBSD__ */
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           __GNUC__ && __sparc64__ */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&  \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&  \
     defined(__GNUC__) && defined(__sparc__) && !defined(__sparc64__)
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long tick;
     asm volatile( ".byte 0x83, 0x41, 0x00, 0x00" );
     asm volatile( "mov   %%g1, %0" : "=r" (tick) );
     return( tick );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           __GNUC__ && __sparc__ && !__sparc64__ */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&      \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&      \
     defined(__GNUC__) && defined(__alpha__)
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long cc;
     asm volatile( "rpcc %0" : "=r" (cc) );
     return( cc & 0xFFFFFFFF );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           __GNUC__ && __alpha__ */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(POLARSSL_HAVE_ASM) &&      \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) &&      \
     defined(__GNUC__) && defined(__ia64__)
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     unsigned long itc;
     asm volatile( "mov %0 = ar.itc" : "=r" (itc) );
     return( itc );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && POLARSSL_HAVE_ASM &&
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
           __GNUC__ && __ia64__ */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK) && defined(_MSC_VER) && \
+#if !defined(MBEDTLS_HAVE_HARDCLOCK) && defined(_MSC_VER) && \
     !defined(EFIX64) && !defined(EFI32)
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     LARGE_INTEGER offset;
 
@@ -203,16 +203,16 @@
 
     return( (unsigned long)( offset.QuadPart ) );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK && _MSC_VER && !EFIX64 && !EFI32 */
+#endif /* !MBEDTLS_HAVE_HARDCLOCK && _MSC_VER && !EFIX64 && !EFI32 */
 
-#if !defined(POLARSSL_HAVE_HARDCLOCK)
+#if !defined(MBEDTLS_HAVE_HARDCLOCK)
 
-#define POLARSSL_HAVE_HARDCLOCK
+#define MBEDTLS_HAVE_HARDCLOCK
 
 static int hardclock_init = 0;
 static struct timeval tv_init;
 
-unsigned long hardclock( void )
+unsigned long mbedtls_timing_hardclock( void )
 {
     struct timeval tv_cur;
 
@@ -226,13 +226,13 @@
     return( ( tv_cur.tv_sec  - tv_init.tv_sec  ) * 1000000
           + ( tv_cur.tv_usec - tv_init.tv_usec ) );
 }
-#endif /* !POLARSSL_HAVE_HARDCLOCK */
+#endif /* !MBEDTLS_HAVE_HARDCLOCK */
 
-volatile int alarmed = 0;
+volatile int mbedtls_timing_alarmed = 0;
 
 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
 
-unsigned long get_timer( struct hr_time *val, int reset )
+unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset )
 {
     unsigned long delta;
     LARGE_INTEGER offset, hfreq;
@@ -258,27 +258,27 @@
 {
     ((void) TimerContext);
     Sleep( alarmMs );
-    alarmed = 1;
+    mbedtls_timing_alarmed = 1;
     return( TRUE );
 }
 
-void set_alarm( int seconds )
+void mbedtls_set_alarm( int seconds )
 {
     DWORD ThreadId;
 
-    alarmed = 0;
+    mbedtls_timing_alarmed = 0;
     alarmMs = seconds * 1000;
     CloseHandle( CreateThread( NULL, 0, TimerProc, NULL, 0, &ThreadId ) );
 }
 
-void m_sleep( int milliseconds )
+void mbedtls_timing_m_sleep( int milliseconds )
 {
     Sleep( milliseconds );
 }
 
 #else /* _WIN32 && !EFIX64 && !EFI32 */
 
-unsigned long get_timer( struct hr_time *val, int reset )
+unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset )
 {
     unsigned long delta;
     struct timeval offset;
@@ -300,7 +300,7 @@
 }
 
 #if defined(INTEGRITY)
-void m_sleep( int milliseconds )
+void mbedtls_timing_m_sleep( int milliseconds )
 {
     usleep( milliseconds * 1000 );
 }
@@ -309,18 +309,18 @@
 
 static void sighandler( int signum )
 {
-    alarmed = 1;
+    mbedtls_timing_alarmed = 1;
     signal( signum, sighandler );
 }
 
-void set_alarm( int seconds )
+void mbedtls_set_alarm( int seconds )
 {
-    alarmed = 0;
+    mbedtls_timing_alarmed = 0;
     signal( SIGALRM, sighandler );
     alarm( seconds );
 }
 
-void m_sleep( int milliseconds )
+void mbedtls_timing_m_sleep( int milliseconds )
 {
     struct timeval tv;
 
@@ -333,26 +333,26 @@
 
 #endif /* _WIN32 && !EFIX64 && !EFI32 */
 
-#if defined(POLARSSL_SELF_TEST)
+#if defined(MBEDTLS_SELF_TEST)
 
-/* To test net_usleep against our functions */
-#if defined(POLARSSL_NET_C) && defined(POLARSSL_HAVE_TIME)
+/* To test mbedtls_net_usleep against our functions */
+#if defined(MBEDTLS_NET_C) && defined(MBEDTLS_HAVE_TIME)
 #include "mbedtls/net.h"
 #endif
 
 /*
  * Busy-waits for the given number of milliseconds.
- * Used for testing hardclock.
+ * Used for testing mbedtls_timing_hardclock.
  */
 static void busy_msleep( unsigned long msec )
 {
-    struct hr_time hires;
+    struct mbedtls_timing_hr_time hires;
     unsigned long i = 0; /* for busy-waiting */
     volatile unsigned long j; /* to prevent optimisation */
 
-    (void) get_timer( &hires, 1 );
+    (void) mbedtls_timing_get_timer( &hires, 1 );
 
-    while( get_timer( &hires, 0 ) < msec )
+    while( mbedtls_timing_get_timer( &hires, 0 ) < msec )
         i++;
 
     j = i;
@@ -365,66 +365,66 @@
  * Warning: this is work in progress, some tests may not be reliable enough
  * yet! False positives may happen.
  */
-int timing_self_test( int verbose )
+int mbedtls_timing_self_test( int verbose )
 {
     unsigned long cycles, ratio;
     unsigned long millisecs, secs;
     int hardfail;
-    struct hr_time hires;
+    struct mbedtls_timing_hr_time hires;
 
     if( verbose != 0 )
-        polarssl_printf( "  TIMING tests note: will take some time!\n" );
+        mbedtls_printf( "  TIMING tests note: will take some time!\n" );
 
     if( verbose != 0 )
-        polarssl_printf( "  TIMING test #1 (m_sleep   / get_timer): " );
+        mbedtls_printf( "  TIMING test #1 (m_sleep   / get_timer): " );
 
     for( secs = 1; secs <= 3; secs++ )
     {
-        (void) get_timer( &hires, 1 );
+        (void) mbedtls_timing_get_timer( &hires, 1 );
 
-        m_sleep( (int)( 500 * secs ) );
+        mbedtls_timing_m_sleep( (int)( 500 * secs ) );
 
-        millisecs = get_timer( &hires, 0 );
+        millisecs = mbedtls_timing_get_timer( &hires, 0 );
 
         if( millisecs < 450 * secs || millisecs > 550 * secs )
         {
             if( verbose != 0 )
-                polarssl_printf( "failed\n" );
+                mbedtls_printf( "failed\n" );
 
             return( 1 );
         }
     }
 
     if( verbose != 0 )
-        polarssl_printf( "passed\n" );
+        mbedtls_printf( "passed\n" );
 
     if( verbose != 0 )
-        polarssl_printf( "  TIMING test #2 (set_alarm / get_timer): " );
+        mbedtls_printf( "  TIMING test #2 (set_alarm / get_timer): " );
 
     for( secs = 1; secs <= 3; secs++ )
     {
-        (void) get_timer( &hires, 1 );
+        (void) mbedtls_timing_get_timer( &hires, 1 );
 
-        set_alarm( (int) secs );
-        while( !alarmed )
+        mbedtls_set_alarm( (int) secs );
+        while( !mbedtls_timing_alarmed )
             ;
 
-        millisecs = get_timer( &hires, 0 );
+        millisecs = mbedtls_timing_get_timer( &hires, 0 );
 
         if( millisecs < 900 * secs || millisecs > 1100 * secs )
         {
             if( verbose != 0 )
-                polarssl_printf( "failed\n" );
+                mbedtls_printf( "failed\n" );
 
             return( 1 );
         }
     }
 
     if( verbose != 0 )
-        polarssl_printf( "passed\n" );
+        mbedtls_printf( "passed\n" );
 
     if( verbose != 0 )
-        polarssl_printf( "  TIMING test #3 (hardclock / get_timer): " );
+        mbedtls_printf( "  TIMING test #3 (hardclock / get_timer): " );
 
     /*
      * Allow one failure for possible counter wrapping.
@@ -437,24 +437,24 @@
     if( hardfail > 1 )
     {
         if( verbose != 0 )
-            polarssl_printf( "failed\n" );
+            mbedtls_printf( "failed\n" );
 
         return( 1 );
     }
 
     /* Get a reference ratio cycles/ms */
     millisecs = 1;
-    cycles = hardclock();
+    cycles = mbedtls_timing_hardclock();
     busy_msleep( millisecs );
-    cycles = hardclock() - cycles;
+    cycles = mbedtls_timing_hardclock() - cycles;
     ratio = cycles / millisecs;
 
     /* Check that the ratio is mostly constant */
     for( millisecs = 2; millisecs <= 4; millisecs++ )
     {
-        cycles = hardclock();
+        cycles = mbedtls_timing_hardclock();
         busy_msleep( millisecs );
-        cycles = hardclock() - cycles;
+        cycles = mbedtls_timing_hardclock() - cycles;
 
         /* Allow variation up to 20% */
         if( cycles / millisecs < ratio - ratio / 5 ||
@@ -466,39 +466,39 @@
     }
 
     if( verbose != 0 )
-        polarssl_printf( "passed\n" );
+        mbedtls_printf( "passed\n" );
 
-#if defined(POLARSSL_NET_C) && defined(POLARSSL_HAVE_TIME)
+#if defined(MBEDTLS_NET_C) && defined(MBEDTLS_HAVE_TIME)
     if( verbose != 0 )
-        polarssl_printf( "  TIMING test #4 (net_usleep/ get_timer): " );
+        mbedtls_printf( "  TIMING test #4 (net_usleep/ get_timer): " );
 
     for( secs = 1; secs <= 3; secs++ )
     {
-        (void) get_timer( &hires, 1 );
+        (void) mbedtls_timing_get_timer( &hires, 1 );
 
-        net_usleep( 500000 * secs );
+        mbedtls_net_usleep( 500000 * secs );
 
-        millisecs = get_timer( &hires, 0 );
+        millisecs = mbedtls_timing_get_timer( &hires, 0 );
 
         if( millisecs < 450 * secs || millisecs > 550 * secs )
         {
             if( verbose != 0 )
-                polarssl_printf( "failed\n" );
+                mbedtls_printf( "failed\n" );
 
             return( 1 );
         }
     }
 
     if( verbose != 0 )
-        polarssl_printf( "passed\n" );
-#endif /* POLARSSL_NET_C */
+        mbedtls_printf( "passed\n" );
+#endif /* MBEDTLS_NET_C */
 
     if( verbose != 0 )
-        polarssl_printf( "\n" );
+        mbedtls_printf( "\n" );
 
     return( 0 );
 }
 
-#endif /* POLARSSL_SELF_TEST */
+#endif /* MBEDTLS_SELF_TEST */
 
-#endif /* POLARSSL_TIMING_C && !POLARSSL_TIMING_ALT */
+#endif /* MBEDTLS_TIMING_C && !MBEDTLS_TIMING_ALT */