The Great Renaming

A simple execution of tmp/invoke-rename.pl
diff --git a/library/aes.c b/library/aes.c
index 4567534..9780e8f 100644
--- a/library/aes.c
+++ b/library/aes.c
@@ -26,37 +26,37 @@
  *  http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
  */
 
-#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_AES_C)
+#if defined(MBEDTLS_AES_C)
 
 #include <string.h>
 
 #include "mbedtls/aes.h"
-#if defined(POLARSSL_PADLOCK_C)
+#if defined(MBEDTLS_PADLOCK_C)
 #include "mbedtls/padlock.h"
 #endif
-#if defined(POLARSSL_AESNI_C)
+#if defined(MBEDTLS_AESNI_C)
 #include "mbedtls/aesni.h"
 #endif
 
-#if defined(POLARSSL_SELF_TEST)
-#if defined(POLARSSL_PLATFORM_C)
+#if defined(MBEDTLS_SELF_TEST)
+#if defined(MBEDTLS_PLATFORM_C)
 #include "mbedtls/platform.h"
 #else
 #include <stdio.h>
-#define polarssl_printf printf
-#endif /* POLARSSL_PLATFORM_C */
-#endif /* POLARSSL_SELF_TEST */
+#define mbedtls_printf printf
+#endif /* MBEDTLS_PLATFORM_C */
+#endif /* MBEDTLS_SELF_TEST */
 
-#if !defined(POLARSSL_AES_ALT)
+#if !defined(MBEDTLS_AES_ALT)
 
 /* Implementation that should never be optimized out by the compiler */
-static void polarssl_zeroize( void *v, size_t n ) {
+static void mbedtls_zeroize( void *v, size_t n ) {
     volatile unsigned char *p = v; while( n-- ) *p++ = 0;
 }
 
@@ -83,12 +83,12 @@
 }
 #endif
 
-#if defined(POLARSSL_PADLOCK_C) &&                      \
-    ( defined(POLARSSL_HAVE_X86) || defined(PADLOCK_ALIGN16) )
+#if defined(MBEDTLS_PADLOCK_C) &&                      \
+    ( defined(MBEDTLS_HAVE_X86) || defined(MBEDTLS_PADLOCK_ALIGN16) )
 static int aes_padlock_ace = -1;
 #endif
 
-#if defined(POLARSSL_AES_ROM_TABLES)
+#if defined(MBEDTLS_AES_ROM_TABLES)
 /*
  * Forward S-box
  */
@@ -353,7 +353,7 @@
     0x0000001B, 0x00000036
 };
 
-#else /* POLARSSL_AES_ROM_TABLES */
+#else /* MBEDTLS_AES_ROM_TABLES */
 
 /*
  * Forward S-box & tables
@@ -463,31 +463,31 @@
     }
 }
 
-#endif /* POLARSSL_AES_ROM_TABLES */
+#endif /* MBEDTLS_AES_ROM_TABLES */
 
-void aes_init( aes_context *ctx )
+void mbedtls_aes_init( mbedtls_aes_context *ctx )
 {
-    memset( ctx, 0, sizeof( aes_context ) );
+    memset( ctx, 0, sizeof( mbedtls_aes_context ) );
 }
 
-void aes_free( aes_context *ctx )
+void mbedtls_aes_free( mbedtls_aes_context *ctx )
 {
     if( ctx == NULL )
         return;
 
-    polarssl_zeroize( ctx, sizeof( aes_context ) );
+    mbedtls_zeroize( ctx, sizeof( mbedtls_aes_context ) );
 }
 
 /*
  * AES key schedule (encryption)
  */
-int aes_setkey_enc( aes_context *ctx, const unsigned char *key,
+int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
                     unsigned int keysize )
 {
     unsigned int i;
     uint32_t *RK;
 
-#if !defined(POLARSSL_AES_ROM_TABLES)
+#if !defined(MBEDTLS_AES_ROM_TABLES)
     if( aes_init_done == 0 )
     {
         aes_gen_tables();
@@ -501,22 +501,22 @@
         case 128: ctx->nr = 10; break;
         case 192: ctx->nr = 12; break;
         case 256: ctx->nr = 14; break;
-        default : return( POLARSSL_ERR_AES_INVALID_KEY_LENGTH );
+        default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH );
     }
 
-#if defined(POLARSSL_PADLOCK_C) && defined(PADLOCK_ALIGN16)
+#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_PADLOCK_ALIGN16)
     if( aes_padlock_ace == -1 )
-        aes_padlock_ace = padlock_supports( PADLOCK_ACE );
+        aes_padlock_ace = mbedtls_padlock_supports( MBEDTLS_PADLOCK_ACE );
 
     if( aes_padlock_ace )
-        ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf );
+        ctx->rk = RK = MBEDTLS_PADLOCK_ALIGN16( ctx->buf );
     else
 #endif
     ctx->rk = RK = ctx->buf;
 
-#if defined(POLARSSL_AESNI_C) && defined(POLARSSL_HAVE_X86_64)
-    if( aesni_supports( POLARSSL_AESNI_AES ) )
-        return( aesni_setkey_enc( (unsigned char *) ctx->rk, key, keysize ) );
+#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+    if( mbedtls_aesni_supports( MBEDTLS_AESNI_AES ) )
+        return( mbedtls_aesni_setkey_enc( (unsigned char *) ctx->rk, key, keysize ) );
 #endif
 
     for( i = 0; i < ( keysize >> 5 ); i++ )
@@ -593,36 +593,36 @@
 /*
  * AES key schedule (decryption)
  */
-int aes_setkey_dec( aes_context *ctx, const unsigned char *key,
+int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
                     unsigned int keysize )
 {
     int i, j, ret;
-    aes_context cty;
+    mbedtls_aes_context cty;
     uint32_t *RK;
     uint32_t *SK;
 
-    aes_init( &cty );
+    mbedtls_aes_init( &cty );
 
-#if defined(POLARSSL_PADLOCK_C) && defined(PADLOCK_ALIGN16)
+#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_PADLOCK_ALIGN16)
     if( aes_padlock_ace == -1 )
-        aes_padlock_ace = padlock_supports( PADLOCK_ACE );
+        aes_padlock_ace = mbedtls_padlock_supports( MBEDTLS_PADLOCK_ACE );
 
     if( aes_padlock_ace )
-        ctx->rk = RK = PADLOCK_ALIGN16( ctx->buf );
+        ctx->rk = RK = MBEDTLS_PADLOCK_ALIGN16( ctx->buf );
     else
 #endif
     ctx->rk = RK = ctx->buf;
 
     /* Also checks keysize */
-    if( ( ret = aes_setkey_enc( &cty, key, keysize ) ) != 0 )
+    if( ( ret = mbedtls_aes_setkey_enc( &cty, key, keysize ) ) != 0 )
         goto exit;
 
     ctx->nr = cty.nr;
 
-#if defined(POLARSSL_AESNI_C) && defined(POLARSSL_HAVE_X86_64)
-    if( aesni_supports( POLARSSL_AESNI_AES ) )
+#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+    if( mbedtls_aesni_supports( MBEDTLS_AESNI_AES ) )
     {
-        aesni_inverse_key( (unsigned char *) ctx->rk,
+        mbedtls_aesni_inverse_key( (unsigned char *) ctx->rk,
                            (const unsigned char *) cty.rk, ctx->nr );
         goto exit;
     }
@@ -652,7 +652,7 @@
     *RK++ = *SK++;
 
 exit:
-    aes_free( &cty );
+    mbedtls_aes_free( &cty );
 
     return( ret );
 }
@@ -706,7 +706,7 @@
 /*
  * AES-ECB block encryption/decryption
  */
-int aes_crypt_ecb( aes_context *ctx,
+int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
                     int mode,
                     const unsigned char input[16],
                     unsigned char output[16] )
@@ -714,15 +714,15 @@
     int i;
     uint32_t *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3;
 
-#if defined(POLARSSL_AESNI_C) && defined(POLARSSL_HAVE_X86_64)
-    if( aesni_supports( POLARSSL_AESNI_AES ) )
-        return( aesni_crypt_ecb( ctx, mode, input, output ) );
+#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+    if( mbedtls_aesni_supports( MBEDTLS_AESNI_AES ) )
+        return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) );
 #endif
 
-#if defined(POLARSSL_PADLOCK_C) && defined(POLARSSL_HAVE_X86)
+#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86)
     if( aes_padlock_ace )
     {
-        if( padlock_xcryptecb( ctx, mode, input, output ) == 0 )
+        if( mbedtls_padlock_xcryptecb( ctx, mode, input, output ) == 0 )
             return( 0 );
 
         // If padlock data misaligned, we just fall back to
@@ -738,7 +738,7 @@
     GET_UINT32_LE( X2, input,  8 ); X2 ^= *RK++;
     GET_UINT32_LE( X3, input, 12 ); X3 ^= *RK++;
 
-    if( mode == AES_DECRYPT )
+    if( mode == MBEDTLS_AES_DECRYPT )
     {
         for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- )
         {
@@ -772,7 +772,7 @@
                 ( (uint32_t) RSb[ ( Y1 >> 16 ) & 0xFF ] << 16 ) ^
                 ( (uint32_t) RSb[ ( Y0 >> 24 ) & 0xFF ] << 24 );
     }
-    else /* AES_ENCRYPT */
+    else /* MBEDTLS_AES_ENCRYPT */
     {
         for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- )
         {
@@ -815,11 +815,11 @@
     return( 0 );
 }
 
-#if defined(POLARSSL_CIPHER_MODE_CBC)
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
 /*
  * AES-CBC buffer encryption/decryption
  */
-int aes_crypt_cbc( aes_context *ctx,
+int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
                     int mode,
                     size_t length,
                     unsigned char iv[16],
@@ -830,12 +830,12 @@
     unsigned char temp[16];
 
     if( length % 16 )
-        return( POLARSSL_ERR_AES_INVALID_INPUT_LENGTH );
+        return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
 
-#if defined(POLARSSL_PADLOCK_C) && defined(POLARSSL_HAVE_X86)
+#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86)
     if( aes_padlock_ace )
     {
-        if( padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 )
+        if( mbedtls_padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 )
             return( 0 );
 
         // If padlock data misaligned, we just fall back to
@@ -844,12 +844,12 @@
     }
 #endif
 
-    if( mode == AES_DECRYPT )
+    if( mode == MBEDTLS_AES_DECRYPT )
     {
         while( length > 0 )
         {
             memcpy( temp, input, 16 );
-            aes_crypt_ecb( ctx, mode, input, output );
+            mbedtls_aes_crypt_ecb( ctx, mode, input, output );
 
             for( i = 0; i < 16; i++ )
                 output[i] = (unsigned char)( output[i] ^ iv[i] );
@@ -868,7 +868,7 @@
             for( i = 0; i < 16; i++ )
                 output[i] = (unsigned char)( input[i] ^ iv[i] );
 
-            aes_crypt_ecb( ctx, mode, output, output );
+            mbedtls_aes_crypt_ecb( ctx, mode, output, output );
             memcpy( iv, output, 16 );
 
             input  += 16;
@@ -879,13 +879,13 @@
 
     return( 0 );
 }
-#endif /* POLARSSL_CIPHER_MODE_CBC */
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
 
-#if defined(POLARSSL_CIPHER_MODE_CFB)
+#if defined(MBEDTLS_CIPHER_MODE_CFB)
 /*
  * AES-CFB128 buffer encryption/decryption
  */
-int aes_crypt_cfb128( aes_context *ctx,
+int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
                        int mode,
                        size_t length,
                        size_t *iv_off,
@@ -896,12 +896,12 @@
     int c;
     size_t n = *iv_off;
 
-    if( mode == AES_DECRYPT )
+    if( mode == MBEDTLS_AES_DECRYPT )
     {
         while( length-- )
         {
             if( n == 0 )
-                aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
+                mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
 
             c = *input++;
             *output++ = (unsigned char)( c ^ iv[n] );
@@ -915,7 +915,7 @@
         while( length-- )
         {
             if( n == 0 )
-                aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
+                mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
 
             iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
 
@@ -931,7 +931,7 @@
 /*
  * AES-CFB8 buffer encryption/decryption
  */
-int aes_crypt_cfb8( aes_context *ctx,
+int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
                        int mode,
                        size_t length,
                        unsigned char iv[16],
@@ -944,14 +944,14 @@
     while( length-- )
     {
         memcpy( ov, iv, 16 );
-        aes_crypt_ecb( ctx, AES_ENCRYPT, iv, iv );
+        mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
 
-        if( mode == AES_DECRYPT )
+        if( mode == MBEDTLS_AES_DECRYPT )
             ov[16] = *input;
 
         c = *output++ = (unsigned char)( iv[0] ^ *input++ );
 
-        if( mode == AES_ENCRYPT )
+        if( mode == MBEDTLS_AES_ENCRYPT )
             ov[16] = c;
 
         memcpy( iv, ov + 1, 16 );
@@ -959,13 +959,13 @@
 
     return( 0 );
 }
-#endif /*POLARSSL_CIPHER_MODE_CFB */
+#endif /*MBEDTLS_CIPHER_MODE_CFB */
 
-#if defined(POLARSSL_CIPHER_MODE_CTR)
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
 /*
  * AES-CTR buffer encryption/decryption
  */
-int aes_crypt_ctr( aes_context *ctx,
+int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
                        size_t length,
                        size_t *nc_off,
                        unsigned char nonce_counter[16],
@@ -979,7 +979,7 @@
     while( length-- )
     {
         if( n == 0 ) {
-            aes_crypt_ecb( ctx, AES_ENCRYPT, nonce_counter, stream_block );
+            mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block );
 
             for( i = 16; i > 0; i-- )
                 if( ++nonce_counter[i - 1] != 0 )
@@ -995,11 +995,11 @@
 
     return( 0 );
 }
-#endif /* POLARSSL_CIPHER_MODE_CTR */
+#endif /* MBEDTLS_CIPHER_MODE_CTR */
 
-#endif /* !POLARSSL_AES_ALT */
+#endif /* !MBEDTLS_AES_ALT */
 
-#if defined(POLARSSL_SELF_TEST)
+#if defined(MBEDTLS_SELF_TEST)
 /*
  * AES test vectors from:
  *
@@ -1025,7 +1025,7 @@
       0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
 };
 
-#if defined(POLARSSL_CIPHER_MODE_CBC)
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
 static const unsigned char aes_test_cbc_dec[3][16] =
 {
     { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73,
@@ -1045,9 +1045,9 @@
     { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5,
       0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 }
 };
-#endif /* POLARSSL_CIPHER_MODE_CBC */
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
 
-#if defined(POLARSSL_CIPHER_MODE_CFB)
+#if defined(MBEDTLS_CIPHER_MODE_CFB)
 /*
  * AES-CFB128 test vectors from:
  *
@@ -1111,9 +1111,9 @@
       0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8,
       0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 }
 };
-#endif /* POLARSSL_CIPHER_MODE_CFB */
+#endif /* MBEDTLS_CIPHER_MODE_CFB */
 
-#if defined(POLARSSL_CIPHER_MODE_CTR)
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
 /*
  * AES-CTR test vectors from:
  *
@@ -1174,32 +1174,32 @@
 
 static const int aes_test_ctr_len[3] =
     { 16, 32, 36 };
-#endif /* POLARSSL_CIPHER_MODE_CTR */
+#endif /* MBEDTLS_CIPHER_MODE_CTR */
 
 /*
  * Checkup routine
  */
-int aes_self_test( int verbose )
+int mbedtls_aes_self_test( int verbose )
 {
     int ret = 0, i, j, u, v;
     unsigned char key[32];
     unsigned char buf[64];
     unsigned char iv[16];
-#if defined(POLARSSL_CIPHER_MODE_CBC)
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
     unsigned char prv[16];
 #endif
-#if defined(POLARSSL_CIPHER_MODE_CTR) || defined(POLARSSL_CIPHER_MODE_CFB)
+#if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB)
     size_t offset;
 #endif
-#if defined(POLARSSL_CIPHER_MODE_CTR)
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
     int len;
     unsigned char nonce_counter[16];
     unsigned char stream_block[16];
 #endif
-    aes_context ctx;
+    mbedtls_aes_context ctx;
 
     memset( key, 0, 32 );
-    aes_init( &ctx );
+    mbedtls_aes_init( &ctx );
 
     /*
      * ECB mode
@@ -1210,22 +1210,22 @@
         v = i  & 1;
 
         if( verbose != 0 )
-            polarssl_printf( "  AES-ECB-%3d (%s): ", 128 + u * 64,
-                             ( v == AES_DECRYPT ) ? "dec" : "enc" );
+            mbedtls_printf( "  AES-ECB-%3d (%s): ", 128 + u * 64,
+                             ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
 
         memset( buf, 0, 16 );
 
-        if( v == AES_DECRYPT )
+        if( v == MBEDTLS_AES_DECRYPT )
         {
-            aes_setkey_dec( &ctx, key, 128 + u * 64 );
+            mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
 
             for( j = 0; j < 10000; j++ )
-                aes_crypt_ecb( &ctx, v, buf, buf );
+                mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
 
             if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1233,15 +1233,15 @@
         }
         else
         {
-            aes_setkey_enc( &ctx, key, 128 + u * 64 );
+            mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
 
             for( j = 0; j < 10000; j++ )
-                aes_crypt_ecb( &ctx, v, buf, buf );
+                mbedtls_aes_crypt_ecb( &ctx, v, buf, buf );
 
             if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1249,13 +1249,13 @@
         }
 
         if( verbose != 0 )
-            polarssl_printf( "passed\n" );
+            mbedtls_printf( "passed\n" );
     }
 
     if( verbose != 0 )
-        polarssl_printf( "\n" );
+        mbedtls_printf( "\n" );
 
-#if defined(POLARSSL_CIPHER_MODE_CBC)
+#if defined(MBEDTLS_CIPHER_MODE_CBC)
     /*
      * CBC mode
      */
@@ -1265,24 +1265,24 @@
         v = i  & 1;
 
         if( verbose != 0 )
-            polarssl_printf( "  AES-CBC-%3d (%s): ", 128 + u * 64,
-                             ( v == AES_DECRYPT ) ? "dec" : "enc" );
+            mbedtls_printf( "  AES-CBC-%3d (%s): ", 128 + u * 64,
+                             ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
 
         memset( iv , 0, 16 );
         memset( prv, 0, 16 );
         memset( buf, 0, 16 );
 
-        if( v == AES_DECRYPT )
+        if( v == MBEDTLS_AES_DECRYPT )
         {
-            aes_setkey_dec( &ctx, key, 128 + u * 64 );
+            mbedtls_aes_setkey_dec( &ctx, key, 128 + u * 64 );
 
             for( j = 0; j < 10000; j++ )
-                aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
+                mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
 
             if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1290,13 +1290,13 @@
         }
         else
         {
-            aes_setkey_enc( &ctx, key, 128 + u * 64 );
+            mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
 
             for( j = 0; j < 10000; j++ )
             {
                 unsigned char tmp[16];
 
-                aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
+                mbedtls_aes_crypt_cbc( &ctx, v, 16, iv, buf, buf );
 
                 memcpy( tmp, prv, 16 );
                 memcpy( prv, buf, 16 );
@@ -1306,7 +1306,7 @@
             if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1314,14 +1314,14 @@
         }
 
         if( verbose != 0 )
-            polarssl_printf( "passed\n" );
+            mbedtls_printf( "passed\n" );
     }
 
     if( verbose != 0 )
-        polarssl_printf( "\n" );
-#endif /* POLARSSL_CIPHER_MODE_CBC */
+        mbedtls_printf( "\n" );
+#endif /* MBEDTLS_CIPHER_MODE_CBC */
 
-#if defined(POLARSSL_CIPHER_MODE_CFB)
+#if defined(MBEDTLS_CIPHER_MODE_CFB)
     /*
      * CFB128 mode
      */
@@ -1331,24 +1331,24 @@
         v = i  & 1;
 
         if( verbose != 0 )
-            polarssl_printf( "  AES-CFB128-%3d (%s): ", 128 + u * 64,
-                             ( v == AES_DECRYPT ) ? "dec" : "enc" );
+            mbedtls_printf( "  AES-CFB128-%3d (%s): ", 128 + u * 64,
+                             ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
 
         memcpy( iv,  aes_test_cfb128_iv, 16 );
         memcpy( key, aes_test_cfb128_key[u], 16 + u * 8 );
 
         offset = 0;
-        aes_setkey_enc( &ctx, key, 128 + u * 64 );
+        mbedtls_aes_setkey_enc( &ctx, key, 128 + u * 64 );
 
-        if( v == AES_DECRYPT )
+        if( v == MBEDTLS_AES_DECRYPT )
         {
             memcpy( buf, aes_test_cfb128_ct[u], 64 );
-            aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
+            mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
 
             if( memcmp( buf, aes_test_cfb128_pt, 64 ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1357,12 +1357,12 @@
         else
         {
             memcpy( buf, aes_test_cfb128_pt, 64 );
-            aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
+            mbedtls_aes_crypt_cfb128( &ctx, v, 64, &offset, iv, buf, buf );
 
             if( memcmp( buf, aes_test_cfb128_ct[u], 64 ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1370,14 +1370,14 @@
         }
 
         if( verbose != 0 )
-            polarssl_printf( "passed\n" );
+            mbedtls_printf( "passed\n" );
     }
 
     if( verbose != 0 )
-        polarssl_printf( "\n" );
-#endif /* POLARSSL_CIPHER_MODE_CFB */
+        mbedtls_printf( "\n" );
+#endif /* MBEDTLS_CIPHER_MODE_CFB */
 
-#if defined(POLARSSL_CIPHER_MODE_CTR)
+#if defined(MBEDTLS_CIPHER_MODE_CTR)
     /*
      * CTR mode
      */
@@ -1387,27 +1387,27 @@
         v = i  & 1;
 
         if( verbose != 0 )
-            polarssl_printf( "  AES-CTR-128 (%s): ",
-                             ( v == AES_DECRYPT ) ? "dec" : "enc" );
+            mbedtls_printf( "  AES-CTR-128 (%s): ",
+                             ( v == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" );
 
         memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 );
         memcpy( key, aes_test_ctr_key[u], 16 );
 
         offset = 0;
-        aes_setkey_enc( &ctx, key, 128 );
+        mbedtls_aes_setkey_enc( &ctx, key, 128 );
 
-        if( v == AES_DECRYPT )
+        if( v == MBEDTLS_AES_DECRYPT )
         {
             len = aes_test_ctr_len[u];
             memcpy( buf, aes_test_ctr_ct[u], len );
 
-            aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
+            mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
                            buf, buf );
 
             if( memcmp( buf, aes_test_ctr_pt[u], len ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1418,13 +1418,13 @@
             len = aes_test_ctr_len[u];
             memcpy( buf, aes_test_ctr_pt[u], len );
 
-            aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
+            mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block,
                            buf, buf );
 
             if( memcmp( buf, aes_test_ctr_ct[u], len ) != 0 )
             {
                 if( verbose != 0 )
-                    polarssl_printf( "failed\n" );
+                    mbedtls_printf( "failed\n" );
 
                 ret = 1;
                 goto exit;
@@ -1432,21 +1432,21 @@
         }
 
         if( verbose != 0 )
-            polarssl_printf( "passed\n" );
+            mbedtls_printf( "passed\n" );
     }
 
     if( verbose != 0 )
-        polarssl_printf( "\n" );
-#endif /* POLARSSL_CIPHER_MODE_CTR */
+        mbedtls_printf( "\n" );
+#endif /* MBEDTLS_CIPHER_MODE_CTR */
 
     ret = 0;
 
 exit:
-    aes_free( &ctx );
+    mbedtls_aes_free( &ctx );
 
     return( ret );
 }
 
-#endif /* POLARSSL_SELF_TEST */
+#endif /* MBEDTLS_SELF_TEST */
 
-#endif /* POLARSSL_AES_C */
+#endif /* MBEDTLS_AES_C */