Use platform layer in programs for consistency.
diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
index 239d968..6b505e9 100644
--- a/programs/test/benchmark.c
+++ b/programs/test/benchmark.c
@@ -26,6 +26,15 @@
 #include POLARSSL_CONFIG_FILE
 #endif
 
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf     printf
+#define polarssl_fprintf    fprintf
+#define polarssl_malloc     malloc
+#define polarssl_free       free
+#endif
+
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -68,7 +77,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_TIMING_C not defined.\n");
+    polarssl_printf("POLARSSL_TIMING_C not defined.\n");
     return( 0 );
 }
 #else
@@ -100,7 +109,7 @@
 do {                                                                    \
     unsigned long i, j, tsc;                                            \
                                                                         \
-    printf( HEADER_FORMAT, TITLE );                                     \
+    polarssl_printf( HEADER_FORMAT, TITLE );                                     \
     fflush( stdout );                                                   \
                                                                         \
     set_alarm( 1 );                                                     \
@@ -115,17 +124,17 @@
         CODE;                                                           \
     }                                                                   \
                                                                         \
-    printf( "%9lu Kb/s,  %9lu cycles/byte\n", i * BUFSIZE / 1024,       \
+    polarssl_printf( "%9lu Kb/s,  %9lu cycles/byte\n", i * BUFSIZE / 1024,       \
                     ( hardclock() - tsc ) / ( j * BUFSIZE ) );          \
 } while( 0 )
 
 #if defined(POLARSSL_ERROR_C)
 #define PRINT_ERROR                                                     \
         polarssl_strerror( ret, ( char * )tmp, sizeof( tmp ) );         \
-        printf( "FAILED: %s\n", tmp );
+        polarssl_printf( "FAILED: %s\n", tmp );
 #else
 #define PRINT_ERROR                                                     \
-        printf( "FAILED: -0x%04x\n", -ret );
+        polarssl_printf( "FAILED: -0x%04x\n", -ret );
 #endif
 
 #define TIME_PUBLIC( TITLE, TYPE, CODE )                                \
@@ -133,7 +142,7 @@
     unsigned long i;                                                    \
     int ret;                                                            \
                                                                         \
-    printf( HEADER_FORMAT, TITLE );                                     \
+    polarssl_printf( HEADER_FORMAT, TITLE );                                     \
     fflush( stdout );                                                   \
     set_alarm( 3 );                                                     \
                                                                         \
@@ -148,7 +157,7 @@
 PRINT_ERROR;                                                            \
     }                                                                   \
     else                                                                \
-        printf( "%9lu " TYPE "/s\n", i / 3 );                           \
+        polarssl_printf( "%9lu " TYPE "/s\n", i / 3 );                           \
 } while( 0 )
 
 unsigned char buf[BUFSIZE];
@@ -225,13 +234,13 @@
                 todo.ecdh = 1;
             else
             {
-                printf( "Unrecognized option: %s\n", argv[i] );
-                printf( "Available options: " OPTIONS );
+                polarssl_printf( "Unrecognized option: %s\n", argv[i] );
+                polarssl_printf( "Available options: " OPTIONS );
             }
         }
     }
 
-    printf( "\n" );
+    polarssl_printf( "\n" );
 
     memset( buf, 0xAA, sizeof( buf ) );
     memset( tmp, 0xBB, sizeof( tmp ) );
@@ -631,10 +640,10 @@
         }
     }
 #endif
-    printf( "\n" );
+    polarssl_printf( "\n" );
 
 #if defined(_WIN32)
-    printf( "  Press Enter to exit this program.\n" );
+    polarssl_printf( "  Press Enter to exit this program.\n" );
     fflush( stdout ); getchar();
 #endif
 
diff --git a/programs/test/o_p_test.c b/programs/test/o_p_test.c
index 7f0f00b..6cbf299 100644
--- a/programs/test/o_p_test.c
+++ b/programs/test/o_p_test.c
@@ -26,6 +26,15 @@
 #include POLARSSL_CONFIG_FILE
 #endif
 
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf     printf
+#define polarssl_fprintf    fprintf
+#define polarssl_malloc     malloc
+#define polarssl_free       free
+#endif
+
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -51,7 +60,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
+    polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
            "POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
     return( 0 );
 }
@@ -82,7 +91,7 @@
                     (const unsigned char *) pers,
                     strlen( pers ) ) ) != 0 )
     {
-        printf( " failed\n  ! ctr_drbg_init returned %d\n", ret );
+        polarssl_printf( " failed\n  ! ctr_drbg_init returned %d\n", ret );
         goto exit;
     }
     ERR_load_crypto_strings();
@@ -91,38 +100,38 @@
 
     if( argc != 3 )
     {
-        printf( "usage: o_p_test <keyfile with private_key> <string of max 100 characters>\n" );
+        polarssl_printf( "usage: o_p_test <keyfile with private_key> <string of max 100 characters>\n" );
 
 #ifdef WIN32
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "  . Reading private key from %s into mbed TLS ...", argv[1] );
+    polarssl_printf( "  . Reading private key from %s into mbed TLS ...", argv[1] );
     fflush( stdout );
 
     pk_init( &p_pk );
     if( pk_parse_keyfile( &p_pk, argv[1], NULL ) != 0 )
     {
         ret = 1;
-        printf( " failed\n  ! Could not load key.\n\n" );
+        polarssl_printf( " failed\n  ! Could not load key.\n\n" );
         goto exit;
     }
 
     if( !pk_can_do( &p_pk, POLARSSL_PK_RSA ) )
     {
         ret = 1;
-        printf( " failed\n  ! Key is not an RSA key\n" );
+        polarssl_printf( " failed\n  ! Key is not an RSA key\n" );
         goto exit;
     }
 
     p_rsa = pk_rsa( p_pk );
 
-    printf( " passed\n");
+    polarssl_printf( " passed\n");
 
-    printf( "  . Reading private key from %s into OpenSSL  ...", argv[1] );
+    polarssl_printf( "  . Reading private key from %s into OpenSSL  ...", argv[1] );
     fflush( stdout );
 
     key_file = fopen( argv[1], "r" );
@@ -131,16 +140,16 @@
     if( o_rsa == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not load key.\n\n" );
+        polarssl_printf( " failed\n  ! Could not load key.\n\n" );
         goto exit;
     }
 
-    printf( " passed\n");
-    printf( "\n" );
+    polarssl_printf( " passed\n");
+    polarssl_printf( "\n" );
 
     if( strlen( argv[1] ) > 100 )
     {
-        printf( " Input data larger than 100 characters.\n\n" );
+        polarssl_printf( " Input data larger than 100 characters.\n\n" );
         goto exit;
     }
 
@@ -149,117 +158,117 @@
     /*
      * Calculate the RSA encryption with public key.
      */
-    printf( "  . Generating the RSA encrypted value with mbed TLS (RSA_PUBLIC)  ..." );
+    polarssl_printf( "  . Generating the RSA encrypted value with mbed TLS (RSA_PUBLIC)  ..." );
     fflush( stdout );
 
     if( ( ret = rsa_pkcs1_encrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PUBLIC, strlen( argv[2] ), input, p_pub_encrypted ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_encrypt returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_encrypt returned %d\n\n", ret );
         goto exit;
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
-    printf( "  . Generating the RSA encrypted value with OpenSSL (PUBLIC)       ..." );
+    polarssl_printf( "  . Generating the RSA encrypted value with OpenSSL (PUBLIC)       ..." );
     fflush( stdout );
 
     if( ( ret = RSA_public_encrypt( strlen( argv[2] ), input, o_pub_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
     {
         unsigned long code = ERR_get_error();
-        printf( " failed\n  ! RSA_public_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
+        polarssl_printf( " failed\n  ! RSA_public_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
         goto exit;
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
     /*
      * Calculate the RSA encryption with private key.
      */
-    printf( "  . Generating the RSA encrypted value with mbed TLS (RSA_PRIVATE) ..." );
+    polarssl_printf( "  . Generating the RSA encrypted value with mbed TLS (RSA_PRIVATE) ..." );
     fflush( stdout );
 
     if( ( ret = rsa_pkcs1_encrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, strlen( argv[2] ), input, p_priv_encrypted ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_encrypt returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_encrypt returned %d\n\n", ret );
         goto exit;
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
-    printf( "  . Generating the RSA encrypted value with OpenSSL (PRIVATE)      ..." );
+    polarssl_printf( "  . Generating the RSA encrypted value with OpenSSL (PRIVATE)      ..." );
     fflush( stdout );
 
     if( ( ret = RSA_private_encrypt( strlen( argv[2] ), input, o_priv_encrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
     {
         unsigned long code = ERR_get_error();
-        printf( " failed\n  ! RSA_private_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
+        polarssl_printf( " failed\n  ! RSA_private_encrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
         goto exit;
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
-    printf( "\n" );
+    polarssl_printf( "\n" );
 
     /*
      * Calculate the RSA decryption with private key.
      */
-    printf( "  . Generating the RSA decrypted value for OpenSSL (PUBLIC) with mbed TLS (PRIVATE) ..." );
+    polarssl_printf( "  . Generating the RSA decrypted value for OpenSSL (PUBLIC) with mbed TLS (PRIVATE) ..." );
     fflush( stdout );
 
     if( ( ret = rsa_pkcs1_decrypt( p_rsa, ctr_drbg_random, &ctr_drbg, RSA_PRIVATE, &olen, o_pub_encrypted, p_pub_decrypted, 1024 ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_decrypt returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_decrypt returned %d\n\n", ret );
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
-    printf( "  . Generating the RSA decrypted value for mbed TLS (PUBLIC) with OpenSSL (PRIVATE) ..." );
+    polarssl_printf( "  . Generating the RSA decrypted value for mbed TLS (PUBLIC) with OpenSSL (PRIVATE) ..." );
     fflush( stdout );
 
     if( ( ret = RSA_private_decrypt( p_rsa->len, p_pub_encrypted, o_pub_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
     {
         unsigned long code = ERR_get_error();
-        printf( " failed\n  ! RSA_private_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
+        polarssl_printf( " failed\n  ! RSA_private_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
     /*
      * Calculate the RSA decryption with public key.
      */
-    printf( "  . Generating the RSA decrypted value for OpenSSL (PRIVATE) with mbed TLS (PUBLIC) ..." );
+    polarssl_printf( "  . Generating the RSA decrypted value for OpenSSL (PRIVATE) with mbed TLS (PUBLIC) ..." );
     fflush( stdout );
 
     if( ( ret = rsa_pkcs1_decrypt( p_rsa, NULL, NULL, RSA_PUBLIC, &olen, o_priv_encrypted, p_priv_decrypted, 1024 ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_decrypt returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_decrypt returned %d\n\n", ret );
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
-    printf( "  . Generating the RSA decrypted value for mbed TLS (PRIVATE) with OpenSSL (PUBLIC) ..." );
+    polarssl_printf( "  . Generating the RSA decrypted value for mbed TLS (PRIVATE) with OpenSSL (PUBLIC) ..." );
     fflush( stdout );
 
     if( ( ret = RSA_public_decrypt( p_rsa->len, p_priv_encrypted, o_priv_decrypted, o_rsa, RSA_PKCS1_PADDING ) ) == -1 )
     {
         unsigned long code = ERR_get_error();
-        printf( " failed\n  ! RSA_public_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
+        polarssl_printf( " failed\n  ! RSA_public_decrypt returned %d %s\n\n", ret, ERR_error_string( code, NULL ) );
     }
     else
-        printf( " passed\n");
+        polarssl_printf( " passed\n");
 
-    printf( "\n" );
-    printf( "String value (OpenSSL Public Encrypt, mbed TLS Private Decrypt): '%s'\n", p_pub_decrypted );
-    printf( "String value (mbed TLS Public Encrypt, OpenSSL Private Decrypt): '%s'\n", o_pub_decrypted );
-    printf( "String value (OpenSSL Private Encrypt, mbed TLS Public Decrypt): '%s'\n", p_priv_decrypted );
-    printf( "String value (mbed TLS Private Encrypt, OpenSSL Public Decrypt): '%s'\n", o_priv_decrypted );
+    polarssl_printf( "\n" );
+    polarssl_printf( "String value (OpenSSL Public Encrypt, mbed TLS Private Decrypt): '%s'\n", p_pub_decrypted );
+    polarssl_printf( "String value (mbed TLS Public Encrypt, OpenSSL Private Decrypt): '%s'\n", o_pub_decrypted );
+    polarssl_printf( "String value (OpenSSL Private Encrypt, mbed TLS Public Decrypt): '%s'\n", p_priv_decrypted );
+    polarssl_printf( "String value (mbed TLS Private Encrypt, OpenSSL Public Decrypt): '%s'\n", o_priv_decrypted );
 
 exit:
     ctr_drbg_free( &ctr_drbg );
     entropy_free( &entropy );
 
 #ifdef WIN32
-    printf( "  + Press Enter to exit this program.\n" );
+    polarssl_printf( "  + Press Enter to exit this program.\n" );
     fflush( stdout ); getchar();
 #endif
 
diff --git a/programs/test/selftest.c b/programs/test/selftest.c
index 15a63d0..339b07c 100644
--- a/programs/test/selftest.c
+++ b/programs/test/selftest.c
@@ -26,6 +26,15 @@
 #include POLARSSL_CONFIG_FILE
 #endif
 
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf     printf
+#define polarssl_fprintf    fprintf
+#define polarssl_malloc     malloc
+#define polarssl_free       free
+#endif
+
 #include <string.h>
 #include <stdio.h>
 
@@ -72,7 +81,7 @@
     else
     {
         v = 1;
-        printf( "\n" );
+        polarssl_printf( "\n" );
     }
 
 #if defined(POLARSSL_SELF_TEST)
@@ -215,7 +224,7 @@
 #endif
 
 #else
-    printf( " POLARSSL_SELF_TEST not defined.\n" );
+    polarssl_printf( " POLARSSL_SELF_TEST not defined.\n" );
 #endif
 
     if( v != 0 )
@@ -234,9 +243,9 @@
 
     if( v != 0 )
     {
-        printf( "  [ All tests passed ]\n\n" );
+        polarssl_printf( "  [ All tests passed ]\n\n" );
 #if defined(_WIN32)
-        printf( "  Press Enter to exit this program.\n" );
+        polarssl_printf( "  Press Enter to exit this program.\n" );
         fflush( stdout ); getchar();
 #endif
     }
diff --git a/programs/test/ssl_cert_test.c b/programs/test/ssl_cert_test.c
index c41b1be..30e95c9 100644
--- a/programs/test/ssl_cert_test.c
+++ b/programs/test/ssl_cert_test.c
@@ -26,6 +26,15 @@
 #include POLARSSL_CONFIG_FILE
 #endif
 
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf     printf
+#define polarssl_fprintf    fprintf
+#define polarssl_malloc     malloc
+#define polarssl_free       free
+#endif
+
 #include <string.h>
 #include <stdio.h>
 
@@ -36,7 +45,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_RSA_C and/or POLARSSL_X509_CRT_PARSE_C "
+    polarssl_printf("POLARSSL_RSA_C and/or POLARSSL_X509_CRT_PARSE_C "
            "POLARSSL_FS_IO and/or POLARSSL_X509_CRL_PARSE_C "
            "not defined.\n");
     return( 0 );
@@ -93,7 +102,7 @@
     /*
      * 1.1. Load the trusted CA
      */
-    printf( "\n  . Loading the CA root certificate ..." );
+    polarssl_printf( "\n  . Loading the CA root certificate ..." );
     fflush( stdout );
 
     /*
@@ -103,32 +112,32 @@
     ret = x509_crt_parse_file( &cacert, "ssl/test-ca/test-ca.crt" );
     if( ret != 0 )
     {
-        printf( " failed\n  !  x509_crt_parse_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  !  x509_crt_parse_file returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( " ok\n" );
+    polarssl_printf( " ok\n" );
 
     x509_crt_info( buf, 1024, "CRT: ", &cacert );
-    printf("%s\n", buf );
+    polarssl_printf("%s\n", buf );
 
     /*
      * 1.2. Load the CRL
      */
-    printf( "  . Loading the CRL ..." );
+    polarssl_printf( "  . Loading the CRL ..." );
     fflush( stdout );
 
     ret = x509_crl_parse_file( &crl, "ssl/test-ca/crl.pem" );
     if( ret != 0 )
     {
-        printf( " failed\n  !  x509_crl_parse_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  !  x509_crl_parse_file returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( " ok\n" );
+    polarssl_printf( " ok\n" );
 
     x509_crl_info( buf, 1024, "CRL: ", &crl );
-    printf("%s\n", buf );
+    polarssl_printf("%s\n", buf );
 
     for( i = 0; i < MAX_CLIENT_CERTS; i++ )
     {
@@ -145,22 +154,22 @@
 
         snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]);
 
-        printf( "  . Loading the client certificate %s...", name );
+        polarssl_printf( "  . Loading the client certificate %s...", name );
         fflush( stdout );
 
         ret = x509_crt_parse_file( &clicert, name );
         if( ret != 0 )
         {
-            printf( " failed\n  !  x509_crt_parse_file returned %d\n\n", ret );
+            polarssl_printf( " failed\n  !  x509_crt_parse_file returned %d\n\n", ret );
             goto exit;
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
         /*
          * 1.4. Verify certificate validity with CA certificate
          */
-        printf( "  . Verify the client certificate with CA certificate..." );
+        polarssl_printf( "  . Verify the client certificate with CA certificate..." );
         fflush( stdout );
 
         ret = x509_crt_verify( &clicert, &cacert, &crl, NULL, &flags, NULL,
@@ -170,53 +179,53 @@
             if( ret == POLARSSL_ERR_X509_CERT_VERIFY_FAILED )
             {
                 if( flags & BADCERT_CN_MISMATCH )
-                    printf( " CN_MISMATCH " );
+                    polarssl_printf( " CN_MISMATCH " );
                 if( flags & BADCERT_EXPIRED )
-                    printf( " EXPIRED " );
+                    polarssl_printf( " EXPIRED " );
                 if( flags & BADCERT_REVOKED )
-                    printf( " REVOKED " );
+                    polarssl_printf( " REVOKED " );
                 if( flags & BADCERT_NOT_TRUSTED )
-                    printf( " NOT_TRUSTED " );
+                    polarssl_printf( " NOT_TRUSTED " );
                 if( flags & BADCRL_NOT_TRUSTED )
-                    printf( " CRL_NOT_TRUSTED " );
+                    polarssl_printf( " CRL_NOT_TRUSTED " );
                 if( flags & BADCRL_EXPIRED )
-                    printf( " CRL_EXPIRED " );
+                    polarssl_printf( " CRL_EXPIRED " );
             } else {
-                printf( " failed\n  !  x509_crt_verify returned %d\n\n", ret );
+                polarssl_printf( " failed\n  !  x509_crt_verify returned %d\n\n", ret );
                 goto exit;
             }
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
         /*
          * 1.5. Load own private key
          */
         snprintf(name, 512, "ssl/test-ca/%s", client_private_keys[i]);
 
-        printf( "  . Loading the client private key %s...", name );
+        polarssl_printf( "  . Loading the client private key %s...", name );
         fflush( stdout );
 
         ret = pk_parse_keyfile( &pk, name, NULL );
         if( ret != 0 )
         {
-            printf( " failed\n  !  pk_parse_keyfile returned %d\n\n", ret );
+            polarssl_printf( " failed\n  !  pk_parse_keyfile returned %d\n\n", ret );
             goto exit;
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
         /*
          * 1.6. Verify certificate validity with private key
          */
-        printf( "  . Verify the client certificate with private key..." );
+        polarssl_printf( "  . Verify the client certificate with private key..." );
         fflush( stdout );
 
 
         /* EC NOT IMPLEMENTED YET */
         if( ! pk_can_do( &clicert.pk, POLARSSL_PK_RSA ) )
         {
-            printf( " failed\n  !  certificate's key is not RSA\n\n" );
+            polarssl_printf( " failed\n  !  certificate's key is not RSA\n\n" );
             ret = POLARSSL_ERR_X509_FEATURE_UNAVAILABLE;
             goto exit;
         }
@@ -224,25 +233,25 @@
         ret = mpi_cmp_mpi(&pk_rsa( pk )->N, &pk_rsa( clicert.pk )->N);
         if( ret != 0 )
         {
-            printf( " failed\n  !  mpi_cmp_mpi for N returned %d\n\n", ret );
+            polarssl_printf( " failed\n  !  mpi_cmp_mpi for N returned %d\n\n", ret );
             goto exit;
         }
 
         ret = mpi_cmp_mpi(&pk_rsa( pk )->E, &pk_rsa( clicert.pk )->E);
         if( ret != 0 )
         {
-            printf( " failed\n  !  mpi_cmp_mpi for E returned %d\n\n", ret );
+            polarssl_printf( " failed\n  !  mpi_cmp_mpi for E returned %d\n\n", ret );
             goto exit;
         }
 
         ret = rsa_check_privkey( pk_rsa( pk ) );
         if( ret != 0 )
         {
-            printf( " failed\n  !  rsa_check_privkey returned %d\n\n", ret );
+            polarssl_printf( " failed\n  !  rsa_check_privkey returned %d\n\n", ret );
             goto exit;
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
         x509_crt_free( &clicert );
         pk_free( &pk );
@@ -253,7 +262,7 @@
     x509_crl_free( &crl );
 
 #if defined(_WIN32)
-    printf( "  + Press Enter to exit this program.\n" );
+    polarssl_printf( "  + Press Enter to exit this program.\n" );
     fflush( stdout ); getchar();
 #endif
 
diff --git a/programs/test/ssl_test.c b/programs/test/ssl_test.c
index 3b2e2d7..7f58e3d 100644
--- a/programs/test/ssl_test.c
+++ b/programs/test/ssl_test.c
@@ -26,6 +26,15 @@
 #include POLARSSL_CONFIG_FILE
 #endif
 
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf     printf
+#define polarssl_fprintf    fprintf
+#define polarssl_malloc     malloc
+#define polarssl_free       free
+#endif
+
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -49,7 +58,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
+    polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
            "POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
            "POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
            "POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C and/or "
@@ -131,7 +140,7 @@
 static void my_debug( void *ctx, int level, const char *str )
 {
     if( level < ((struct options *) ctx)->debug_level )
-        fprintf( stderr, "%s", str );
+        polarssl_fprintf( stderr, "%s", str );
 }
 
 /*
@@ -175,7 +184,7 @@
                                (const unsigned char *) pers,
                                strlen( pers ) ) ) != 0 )
     {
-        printf( "  ! ctr_drbg_init returned %d\n", ret );
+        polarssl_printf( "  ! ctr_drbg_init returned %d\n", ret );
         goto exit;
     }
 
@@ -192,13 +201,13 @@
         if( ( ret = net_connect( &client_fd, opt->server_name,
                                              opt->server_port ) ) != 0 )
         {
-            printf( "  ! net_connect returned %d\n\n", ret );
+            polarssl_printf( "  ! net_connect returned %d\n\n", ret );
             return( ret );
         }
 
         if( ( ret = ssl_init( &ssl ) ) != 0 )
         {
-            printf( "  ! ssl_init returned %d\n\n", ret );
+            polarssl_printf( "  ! ssl_init returned %d\n\n", ret );
             goto exit;
         }
 
@@ -208,14 +217,14 @@
     if( opt->opmode == OPMODE_SERVER )
     {
 #if !defined(POLARSSL_CERTS_C)
-        printf("POLARSSL_CERTS_C not defined.\n");
+        polarssl_printf("POLARSSL_CERTS_C not defined.\n");
         goto exit;
 #else
         ret =  x509_crt_parse( &srvcert, (const unsigned char *) test_srv_crt,
                                strlen( test_srv_crt ) );
         if( ret != 0 )
         {
-            printf( "  !  x509_crt_parse returned %d\n\n", ret );
+            polarssl_printf( "  !  x509_crt_parse returned %d\n\n", ret );
             goto exit;
         }
 
@@ -223,7 +232,7 @@
                                strlen( test_ca_list ) );
         if( ret != 0 )
         {
-            printf( "  !  x509_crt_parse returned %d\n\n", ret );
+            polarssl_printf( "  !  x509_crt_parse returned %d\n\n", ret );
             goto exit;
         }
 
@@ -231,7 +240,7 @@
                              strlen( test_srv_key ), NULL, 0 );
         if( ret != 0 )
         {
-            printf( "  !  pk_parse_key returned %d\n\n", ret );
+            polarssl_printf( "  !  pk_parse_key returned %d\n\n", ret );
             goto exit;
         }
 #endif
@@ -241,20 +250,20 @@
             if( ( ret = net_bind( &server_fd, NULL,
                                    opt->server_port ) ) != 0 )
             {
-                printf( "  ! net_bind returned %d\n\n", ret );
+                polarssl_printf( "  ! net_bind returned %d\n\n", ret );
                 return( ret );
             }
         }
 
         if( ( ret = net_accept( server_fd, &client_fd, NULL ) ) != 0 )
         {
-            printf( "  ! net_accept returned %d\n\n", ret );
+            polarssl_printf( "  ! net_accept returned %d\n\n", ret );
             return( ret );
         }
 
         if( ( ret = ssl_init( &ssl ) ) != 0 )
         {
-            printf( "  ! ssl_init returned %d\n\n", ret );
+            polarssl_printf( "  ! ssl_init returned %d\n\n", ret );
             return( ret );
         }
 
@@ -262,7 +271,7 @@
         ssl_set_ca_chain( &ssl, srvcert.next, NULL, NULL );
         if( ( ret = ssl_set_own_cert( &ssl, &srvcert, &pkey ) ) != 0 )
         {
-            printf( " failed\n  ! ssl_set_own_cert returned %d\n\n", ret );
+            polarssl_printf( " failed\n  ! ssl_set_own_cert returned %d\n\n", ret );
             goto exit;
         }
     }
@@ -281,17 +290,17 @@
     {
         if( ( ret = net_set_nonblock( client_fd ) ) != 0 )
         {
-            printf( "  ! net_set_nonblock returned %d\n\n", ret );
+            polarssl_printf( "  ! net_set_nonblock returned %d\n\n", ret );
             return( ret );
         }
     }
 
-     read_buf = (unsigned char *) malloc( opt->buffer_size );
-    write_buf = (unsigned char *) malloc( opt->buffer_size );
+     read_buf = (unsigned char *) polarssl_malloc( opt->buffer_size );
+    write_buf = (unsigned char *) polarssl_malloc( opt->buffer_size );
 
     if( read_buf == NULL || write_buf == NULL )
     {
-        printf( "  ! malloc(%d bytes) failed\n\n", opt->buffer_size );
+        polarssl_printf( "  ! polarssl_malloc(%d bytes) failed\n\n", opt->buffer_size );
         goto exit;
     }
 
@@ -333,7 +342,7 @@
             if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
                 ret != POLARSSL_ERR_NET_WANT_WRITE )
             {
-                printf( "  ! ssl_write returned %d\n\n", ret );
+                polarssl_printf( "  ! ssl_write returned %d\n\n", ret );
                 break;
             }
         }
@@ -357,7 +366,7 @@
                         (unsigned char) lcppm5( read_state ) )
                     {
                         ret = 1;
-                        printf( "  ! plaintext mismatch\n\n" );
+                        polarssl_printf( "  ! plaintext mismatch\n\n" );
                         goto exit;
                     }
                 }
@@ -379,7 +388,7 @@
             if( ret < 0 && ret != POLARSSL_ERR_NET_WANT_READ &&
                 ret != POLARSSL_ERR_NET_WANT_WRITE )
             {
-                printf( "  ! ssl_read returned %d\n\n", ret );
+                polarssl_printf( "  ! ssl_read returned %d\n\n", ret );
                 break;
             }
         }
@@ -458,15 +467,15 @@
     if( argc == 1 )
     {
     usage:
-        printf( USAGE );
+        polarssl_printf( USAGE );
 
         list = ssl_list_ciphersuites();
         while( *list )
         {
-            printf("    %s\n", ssl_get_ciphersuite_name( *list ) );
+            polarssl_printf("    %s\n", ssl_get_ciphersuite_name( *list ) );
             list++;
         }
-        printf("\n");
+        polarssl_printf("\n");
         goto exit;
     }
 
@@ -611,7 +620,7 @@
 exit:
 
 #if defined(_WIN32)
-    printf( "  Press Enter to exit this program.\n" );
+    polarssl_printf( "  Press Enter to exit this program.\n" );
     fflush( stdout ); getchar();
 #endif