Use platform layer in programs for consistency.
diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c
index 73a59a9..3558103 100644
--- a/programs/pkey/dh_client.c
+++ b/programs/pkey/dh_client.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>
 
@@ -49,7 +58,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
+    polarssl_printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
            "and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
            "POLARSSL_SHA1_C and/or POLARSSL_FS_IO and/or "
            "POLARSSL_CTR_DRBG_C not defined.\n");
@@ -85,7 +94,7 @@
     /*
      * 1. Setup the RNG
      */
-    printf( "\n  . Seeding the random number generator" );
+    polarssl_printf( "\n  . Seeding the random number generator" );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -93,20 +102,20 @@
                                (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;
     }
 
     /*
      * 2. Read the server's public RSA key
      */
-    printf( "\n  . Reading public key from rsa_pub.txt" );
+    polarssl_printf( "\n  . Reading public key from rsa_pub.txt" );
     fflush( stdout );
 
     if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not open rsa_pub.txt\n" \
+        polarssl_printf( " failed\n  ! Could not open rsa_pub.txt\n" \
                 "  ! Please run rsa_genkey first\n\n" );
         goto exit;
     }
@@ -116,7 +125,7 @@
     if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
         ( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
         goto exit;
     }
 
@@ -127,35 +136,35 @@
     /*
      * 3. Initiate the connection
      */
-    printf( "\n  . Connecting to tcp/%s/%d", SERVER_NAME,
+    polarssl_printf( "\n  . Connecting to tcp/%s/%d", SERVER_NAME,
                                              SERVER_PORT );
     fflush( stdout );
 
     if( ( ret = net_connect( &server_fd, SERVER_NAME,
                                          SERVER_PORT ) ) != 0 )
     {
-        printf( " failed\n  ! net_connect returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_connect returned %d\n\n", ret );
         goto exit;
     }
 
     /*
      * 4a. First get the buffer length
      */
-    printf( "\n  . Receiving the server's DH parameters" );
+    polarssl_printf( "\n  . Receiving the server's DH parameters" );
     fflush( stdout );
 
     memset( buf, 0, sizeof( buf ) );
 
     if( ( ret = net_recv( &server_fd, buf, 2 ) ) != 2 )
     {
-        printf( " failed\n  ! net_recv returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_recv returned %d\n\n", ret );
         goto exit;
     }
 
     n = buflen = ( buf[0] << 8 ) | buf[1];
     if( buflen < 1 || buflen > sizeof( buf ) )
     {
-        printf( " failed\n  ! Got an invalid buffer length\n\n" );
+        polarssl_printf( " failed\n  ! Got an invalid buffer length\n\n" );
         goto exit;
     }
 
@@ -166,7 +175,7 @@
 
     if( ( ret = net_recv( &server_fd, buf, n ) ) != (int) n )
     {
-        printf( " failed\n  ! net_recv returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_recv returned %d\n\n", ret );
         goto exit;
     }
 
@@ -174,14 +183,14 @@
 
     if( ( ret = dhm_read_params( &dhm, &p, end ) ) != 0 )
     {
-        printf( " failed\n  ! dhm_read_params returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! dhm_read_params returned %d\n\n", ret );
         goto exit;
     }
 
     if( dhm.len < 64 || dhm.len > 512 )
     {
         ret = 1;
-        printf( " failed\n  ! Invalid DHM modulus size\n\n" );
+        polarssl_printf( " failed\n  ! Invalid DHM modulus size\n\n" );
         goto exit;
     }
 
@@ -189,7 +198,7 @@
      * 5. Check that the server's RSA signature matches
      *    the SHA-1 hash of (P,G,Ys)
      */
-    printf( "\n  . Verifying the server's RSA signature" );
+    polarssl_printf( "\n  . Verifying the server's RSA signature" );
     fflush( stdout );
 
     p += 2;
@@ -197,7 +206,7 @@
     if( ( n = (size_t) ( end - p ) ) != rsa.len )
     {
         ret = 1;
-        printf( " failed\n  ! Invalid RSA signature size\n\n" );
+        polarssl_printf( " failed\n  ! Invalid RSA signature size\n\n" );
         goto exit;
     }
 
@@ -206,46 +215,46 @@
     if( ( ret = rsa_pkcs1_verify( &rsa, NULL, NULL, RSA_PUBLIC,
                                   POLARSSL_MD_SHA1, 0, hash, p ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_verify returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_verify returned %d\n\n", ret );
         goto exit;
     }
 
     /*
      * 6. Send our public value: Yc = G ^ Xc mod P
      */
-    printf( "\n  . Sending own public value to server" );
+    polarssl_printf( "\n  . Sending own public value to server" );
     fflush( stdout );
 
     n = dhm.len;
     if( ( ret = dhm_make_public( &dhm, (int) dhm.len, buf, n,
                                  ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! dhm_make_public returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! dhm_make_public returned %d\n\n", ret );
         goto exit;
     }
 
     if( ( ret = net_send( &server_fd, buf, n ) ) != (int) n )
     {
-        printf( " failed\n  ! net_send returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_send returned %d\n\n", ret );
         goto exit;
     }
 
     /*
      * 7. Derive the shared secret: K = Ys ^ Xc mod P
      */
-    printf( "\n  . Shared secret: " );
+    polarssl_printf( "\n  . Shared secret: " );
     fflush( stdout );
 
     n = dhm.len;
     if( ( ret = dhm_calc_secret( &dhm, buf, &n,
                                  ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! dhm_calc_secret returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! dhm_calc_secret returned %d\n\n", ret );
         goto exit;
     }
 
     for( n = 0; n < 16; n++ )
-        printf( "%02x", buf[n] );
+        polarssl_printf( "%02x", buf[n] );
 
     /*
      * 8. Setup the AES-256 decryption key
@@ -255,7 +264,7 @@
      * the keying material for the encryption/decryption keys,
      * IVs and MACs.
      */
-    printf( "...\n  . Receiving and decrypting the ciphertext" );
+    polarssl_printf( "...\n  . Receiving and decrypting the ciphertext" );
     fflush( stdout );
 
     aes_setkey_dec( &aes, buf, 256 );
@@ -264,13 +273,13 @@
 
     if( ( ret = net_recv( &server_fd, buf, 16 ) ) != 16 )
     {
-        printf( " failed\n  ! net_recv returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_recv returned %d\n\n", ret );
         goto exit;
     }
 
     aes_crypt_ecb( &aes, AES_DECRYPT, buf, buf );
     buf[16] = '\0';
-    printf( "\n  . Plaintext is \"%s\"\n\n", (char *) buf );
+    polarssl_printf( "\n  . Plaintext is \"%s\"\n\n", (char *) buf );
 
 exit:
 
@@ -284,7 +293,7 @@
     entropy_free( &entropy );
 
 #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/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c
index 978e48a..df12e18 100644
--- a/programs/pkey/dh_genprime.c
+++ b/programs/pkey/dh_genprime.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 <stdio.h>
 
 #include "polarssl/bignum.h"
@@ -47,7 +56,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_FS_IO and/or POLARSSL_CTR_DRBG_C and/or "
            "POLARSSL_GENPRIME not defined.\n");
     return( 0 );
@@ -70,31 +79,31 @@
 
     if( ( ret = mpi_read_string( &G, 10, GENERATOR ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_read_string returned %d\n", ret );
+        polarssl_printf( " failed\n  ! mpi_read_string returned %d\n", ret );
         goto exit;
     }
 
-    printf( "\nWARNING: You should not generate and use your own DHM primes\n" );
-    printf( "         unless you are very certain of what you are doing!\n" );
-    printf( "         Failing to follow this instruction may result in\n" );
-    printf( "         weak security for your connections! Use the\n" );
-    printf( "         predefined DHM parameters from dhm.h instead!\n\n" );
-    printf( "============================================================\n\n" );
+    polarssl_printf( "\nWARNING: You should not generate and use your own DHM primes\n" );
+    polarssl_printf( "         unless you are very certain of what you are doing!\n" );
+    polarssl_printf( "         Failing to follow this instruction may result in\n" );
+    polarssl_printf( "         weak security for your connections! Use the\n" );
+    polarssl_printf( "         predefined DHM parameters from dhm.h instead!\n\n" );
+    polarssl_printf( "============================================================\n\n" );
 
-    printf( "  ! Generating large primes may take minutes!\n" );
+    polarssl_printf( "  ! Generating large primes may take minutes!\n" );
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
                                (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;
     }
 
-    printf( " ok\n  . Generating the modulus, please wait..." );
+    polarssl_printf( " ok\n  . Generating the modulus, please wait..." );
     fflush( stdout );
 
     /*
@@ -103,49 +112,49 @@
     if( ( ret = mpi_gen_prime( &P, DH_P_SIZE, 1,
                                ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_gen_prime returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_gen_prime returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( " ok\n  . Verifying that Q = (P-1)/2 is prime..." );
+    polarssl_printf( " ok\n  . Verifying that Q = (P-1)/2 is prime..." );
     fflush( stdout );
 
     if( ( ret = mpi_sub_int( &Q, &P, 1 ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_sub_int returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_sub_int returned %d\n\n", ret );
         goto exit;
     }
 
     if( ( ret = mpi_div_int( &Q, NULL, &Q, 2 ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_div_int returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_div_int returned %d\n\n", ret );
         goto exit;
     }
 
     if( ( ret = mpi_is_prime( &Q, ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_is_prime returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_is_prime returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( " ok\n  . Exporting the value in dh_prime.txt..." );
+    polarssl_printf( " ok\n  . Exporting the value in dh_prime.txt..." );
     fflush( stdout );
 
     if( ( fout = fopen( "dh_prime.txt", "wb+" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not create dh_prime.txt\n\n" );
+        polarssl_printf( " failed\n  ! Could not create dh_prime.txt\n\n" );
         goto exit;
     }
 
     if( ( ret = mpi_write_file( "P = ", &P, 16, fout ) != 0 ) ||
         ( ret = mpi_write_file( "G = ", &G, 16, fout ) != 0 ) )
     {
-        printf( " failed\n  ! mpi_write_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_write_file returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( " ok\n\n" );
+    polarssl_printf( " ok\n\n" );
     fclose( fout );
 
 exit:
@@ -155,7 +164,7 @@
     entropy_free( &entropy );
 
 #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/pkey/dh_server.c b/programs/pkey/dh_server.c
index bd8f0e8..b9b3a50 100644
--- a/programs/pkey/dh_server.c
+++ b/programs/pkey/dh_server.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>
 
@@ -49,7 +58,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
+    polarssl_printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
            "and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
            "POLARSSL_SHA1_C and/or POLARSSL_FS_IO and/or "
            "POLARSSL_CTR_DBRG_C not defined.\n");
@@ -86,7 +95,7 @@
     /*
      * 1. Setup the RNG
      */
-    printf( "\n  . Seeding the random number generator" );
+    polarssl_printf( "\n  . Seeding the random number generator" );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -94,20 +103,20 @@
                                (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;
     }
 
     /*
      * 2a. Read the server's private RSA key
      */
-    printf( "\n  . Reading private key from rsa_priv.txt" );
+    polarssl_printf( "\n  . Reading private key from rsa_priv.txt" );
     fflush( stdout );
 
     if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not open rsa_priv.txt\n" \
+        polarssl_printf( " failed\n  ! Could not open rsa_priv.txt\n" \
                 "  ! Please run rsa_genkey first\n\n" );
         goto exit;
     }
@@ -123,7 +132,7 @@
         ( ret = mpi_read_file( &rsa.DQ, 16, f ) ) != 0 ||
         ( ret = mpi_read_file( &rsa.QP, 16, f ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
         goto exit;
     }
 
@@ -134,13 +143,13 @@
     /*
      * 2b. Get the DHM modulus and generator
      */
-    printf( "\n  . Reading DH parameters from dh_prime.txt" );
+    polarssl_printf( "\n  . Reading DH parameters from dh_prime.txt" );
     fflush( stdout );
 
     if( ( f = fopen( "dh_prime.txt", "rb" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not open dh_prime.txt\n" \
+        polarssl_printf( " failed\n  ! Could not open dh_prime.txt\n" \
                 "  ! Please run dh_genprime first\n\n" );
         goto exit;
     }
@@ -148,7 +157,7 @@
     if( mpi_read_file( &dhm.P, 16, f ) != 0 ||
         mpi_read_file( &dhm.G, 16, f ) != 0 )
     {
-        printf( " failed\n  ! Invalid DH parameter file\n\n" );
+        polarssl_printf( " failed\n  ! Invalid DH parameter file\n\n" );
         goto exit;
     }
 
@@ -157,25 +166,25 @@
     /*
      * 3. Wait for a client to connect
      */
-    printf( "\n  . Waiting for a remote connection" );
+    polarssl_printf( "\n  . Waiting for a remote connection" );
     fflush( stdout );
 
     if( ( ret = net_bind( &listen_fd, NULL, SERVER_PORT ) ) != 0 )
     {
-        printf( " failed\n  ! net_bind returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_bind returned %d\n\n", ret );
         goto exit;
     }
 
     if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 )
     {
-        printf( " failed\n  ! net_accept returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_accept returned %d\n\n", ret );
         goto exit;
     }
 
     /*
      * 4. Setup the DH parameters (P,G,Ys)
      */
-    printf( "\n  . Sending the server's DH parameters" );
+    polarssl_printf( "\n  . Sending the server's DH parameters" );
     fflush( stdout );
 
     memset( buf, 0, sizeof( buf ) );
@@ -183,7 +192,7 @@
     if( ( ret = dhm_make_params( &dhm, (int) mpi_size( &dhm.P ), buf, &n,
                                  ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! dhm_make_params returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! dhm_make_params returned %d\n\n", ret );
         goto exit;
     }
 
@@ -198,7 +207,7 @@
     if( ( ret = rsa_pkcs1_sign( &rsa, NULL, NULL, RSA_PRIVATE, POLARSSL_MD_SHA1,
                                 0, hash, buf + n + 2 ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_sign returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_sign returned %d\n\n", ret );
         goto exit;
     }
 
@@ -209,14 +218,14 @@
     if( ( ret = net_send( &client_fd, buf2, 2 ) ) != 2 ||
         ( ret = net_send( &client_fd, buf, buflen ) ) != (int) buflen )
     {
-        printf( " failed\n  ! net_send returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_send returned %d\n\n", ret );
         goto exit;
     }
 
     /*
      * 6. Get the client's public value: Yc = G ^ Xc mod P
      */
-    printf( "\n  . Receiving the client's public value" );
+    polarssl_printf( "\n  . Receiving the client's public value" );
     fflush( stdout );
 
     memset( buf, 0, sizeof( buf ) );
@@ -224,31 +233,31 @@
 
     if( ( ret = net_recv( &client_fd, buf, n ) ) != (int) n )
     {
-        printf( " failed\n  ! net_recv returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_recv returned %d\n\n", ret );
         goto exit;
     }
 
     if( ( ret = dhm_read_public( &dhm, buf, dhm.len ) ) != 0 )
     {
-        printf( " failed\n  ! dhm_read_public returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! dhm_read_public returned %d\n\n", ret );
         goto exit;
     }
 
     /*
      * 7. Derive the shared secret: K = Ys ^ Xc mod P
      */
-    printf( "\n  . Shared secret: " );
+    polarssl_printf( "\n  . Shared secret: " );
     fflush( stdout );
 
     if( ( ret = dhm_calc_secret( &dhm, buf, &n,
                                  ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! dhm_calc_secret returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! dhm_calc_secret returned %d\n\n", ret );
         goto exit;
     }
 
     for( n = 0; n < 16; n++ )
-        printf( "%02x", buf[n] );
+        polarssl_printf( "%02x", buf[n] );
 
     /*
      * 8. Setup the AES-256 encryption key
@@ -258,7 +267,7 @@
      * the keying material for the encryption/decryption keys
      * and MACs.
      */
-    printf( "...\n  . Encrypting and sending the ciphertext" );
+    polarssl_printf( "...\n  . Encrypting and sending the ciphertext" );
     fflush( stdout );
 
     aes_setkey_enc( &aes, buf, 256 );
@@ -267,11 +276,11 @@
 
     if( ( ret = net_send( &client_fd, buf, 16 ) ) != 16 )
     {
-        printf( " failed\n  ! net_send returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! net_send returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( "\n\n" );
+    polarssl_printf( "\n\n" );
 
 exit:
 
@@ -285,7 +294,7 @@
     entropy_free( &entropy );
 
 #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/pkey/ecdsa.c b/programs/pkey/ecdsa.c
index 72c8c4d..aaec249 100644
--- a/programs/pkey/ecdsa.c
+++ b/programs/pkey/ecdsa.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 "polarssl/entropy.h"
 #include "polarssl/ctr_drbg.h"
 #include "polarssl/ecdsa.h"
@@ -54,7 +63,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_ECDSA_C and/or "
+    polarssl_printf("POLARSSL_ECDSA_C and/or "
            "POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C not defined\n");
     return( 0 );
 }
@@ -65,11 +74,11 @@
 {
     size_t i;
 
-    printf( "%s", title );
+    polarssl_printf( "%s", title );
     for( i = 0; i < len; i++ )
-        printf("%c%c", "0123456789ABCDEF" [buf[i] / 16],
+        polarssl_printf("%c%c", "0123456789ABCDEF" [buf[i] / 16],
                        "0123456789ABCDEF" [buf[i] % 16] );
-    printf( "\n" );
+    polarssl_printf( "\n" );
 }
 
 static void dump_pubkey( const char *title, ecdsa_context *key )
@@ -80,7 +89,7 @@
     if( ecp_point_write_binary( &key->grp, &key->Q,
                 POLARSSL_ECP_PF_UNCOMPRESSED, &len, buf, sizeof buf ) != 0 )
     {
-        printf("internal error\n");
+        polarssl_printf("internal error\n");
         return;
     }
 
@@ -111,10 +120,10 @@
 
     if( argc != 1 )
     {
-        printf( "usage: ecdsa\n" );
+        polarssl_printf( "usage: ecdsa\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
@@ -123,7 +132,7 @@
     /*
      * Generate a key pair for signing
      */
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -131,28 +140,28 @@
                                (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;
     }
 
-    printf( " ok\n  . Generating key pair..." );
+    polarssl_printf( " ok\n  . Generating key pair..." );
     fflush( stdout );
 
     if( ( ret = ecdsa_genkey( &ctx_sign, ECPARAMS,
                               ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! ecdsa_genkey returned %d\n", ret );
+        polarssl_printf( " failed\n  ! ecdsa_genkey returned %d\n", ret );
         goto exit;
     }
 
-    printf( " ok (key size: %d bits)\n", (int) ctx_sign.grp.pbits );
+    polarssl_printf( " ok (key size: %d bits)\n", (int) ctx_sign.grp.pbits );
 
     dump_pubkey( "  + Public key: ", &ctx_sign );
 
     /*
      * Sign some message hash
      */
-    printf( "  . Signing message..." );
+    polarssl_printf( "  . Signing message..." );
     fflush( stdout );
 
     if( ( ret = ecdsa_write_signature( &ctx_sign,
@@ -160,10 +169,10 @@
                                        sig, &sig_len,
                                        ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! ecdsa_genkey returned %d\n", ret );
+        polarssl_printf( " failed\n  ! ecdsa_genkey returned %d\n", ret );
         goto exit;
     }
-    printf( " ok (signature length = %u)\n", (unsigned int) sig_len );
+    polarssl_printf( " ok (signature length = %u)\n", (unsigned int) sig_len );
 
     dump_buf( "  + Hash: ", hash, sizeof hash );
     dump_buf( "  + Signature: ", sig, sig_len );
@@ -184,18 +193,18 @@
      * chose to use a new one in order to make it clear that the verifying
      * context only needs the public key (Q), and not the private key (d).
      */
-    printf( "  . Preparing verification context..." );
+    polarssl_printf( "  . Preparing verification context..." );
     fflush( stdout );
 
     if( ( ret = ecp_group_copy( &ctx_verify.grp, &ctx_sign.grp ) ) != 0 )
     {
-        printf( " failed\n  ! ecp_group_copy returned %d\n", ret );
+        polarssl_printf( " failed\n  ! ecp_group_copy returned %d\n", ret );
         goto exit;
     }
 
     if( ( ret = ecp_copy( &ctx_verify.Q, &ctx_sign.Q ) ) != 0 )
     {
-        printf( " failed\n  ! ecp_copy returned %d\n", ret );
+        polarssl_printf( " failed\n  ! ecp_copy returned %d\n", ret );
         goto exit;
     }
 
@@ -204,23 +213,23 @@
     /*
      * Verify signature
      */
-    printf( " ok\n  . Verifying signature..." );
+    polarssl_printf( " ok\n  . Verifying signature..." );
     fflush( stdout );
 
     if( ( ret = ecdsa_read_signature( &ctx_verify,
                                       hash, sizeof( hash ),
                                       sig, sig_len ) ) != 0 )
     {
-        printf( " failed\n  ! ecdsa_read_signature returned %d\n", ret );
+        polarssl_printf( " failed\n  ! ecdsa_read_signature returned %d\n", ret );
         goto exit;
     }
 
-    printf( " ok\n" );
+    polarssl_printf( " ok\n" );
 
 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
 
diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c
index 5470b57..e968786 100644
--- a/programs/pkey/gen_key.c
+++ b/programs/pkey/gen_key.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_PK_WRITE_C and/or POLARSSL_FS_IO and/or "
+    polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO and/or "
             "POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C "
             "not defined.\n" );
     return( 0 );
@@ -204,13 +213,13 @@
     {
     usage:
         ret = 1;
-        printf( USAGE );
+        polarssl_printf( USAGE );
 #if defined(POLARSSL_ECP_C)
-        printf( " availabled ec_curve values:\n" );
+        polarssl_printf( " availabled ec_curve values:\n" );
         curve_info = ecp_curve_list();
-        printf( "    %s (default)\n", curve_info->name );
+        polarssl_printf( "    %s (default)\n", curve_info->name );
         while( ( ++curve_info )->name != NULL )
-            printf( "    %s\n", curve_info->name );
+            polarssl_printf( "    %s\n", curve_info->name );
 #endif
         goto exit;
     }
@@ -274,7 +283,7 @@
             goto usage;
     }
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -284,11 +293,11 @@
         if( ( ret = entropy_add_source( &entropy, dev_random_entropy_poll,
                                         NULL, DEV_RANDOM_THRESHOLD ) ) != 0 )
         {
-            printf( " failed\n  ! entropy_add_source returned -0x%04x\n", -ret );
+            polarssl_printf( " failed\n  ! entropy_add_source returned -0x%04x\n", -ret );
             goto exit;
         }
 
-        printf("\n    Using /dev/random, so can take a long time! " );
+        polarssl_printf("\n    Using /dev/random, so can take a long time! " );
         fflush( stdout );
     }
 #endif /* !_WIN32 && POLARSSL_FS_IO */
@@ -297,19 +306,19 @@
                                (const unsigned char *) pers,
                                strlen( pers ) ) ) != 0 )
     {
-        printf( " failed\n  ! ctr_drbg_init returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! ctr_drbg_init returned -0x%04x\n", -ret );
         goto exit;
     }
 
     /*
      * 1.1. Generate the key
      */
-    printf( "\n  . Generating the private key ..." );
+    polarssl_printf( "\n  . Generating the private key ..." );
     fflush( stdout );
 
     if( ( ret = pk_init_ctx( &key, pk_info_from_type( opt.type ) ) ) != 0 )
     {
-        printf( " failed\n  !  pk_init_ctx returned -0x%04x", -ret );
+        polarssl_printf( " failed\n  !  pk_init_ctx returned -0x%04x", -ret );
         goto exit;
     }
 
@@ -320,7 +329,7 @@
                            opt.rsa_keysize, 65537 );
         if( ret != 0 )
         {
-            printf( " failed\n  !  rsa_gen_key returned -0x%04x", -ret );
+            polarssl_printf( " failed\n  !  rsa_gen_key returned -0x%04x", -ret );
             goto exit;
         }
     }
@@ -333,21 +342,21 @@
                           ctr_drbg_random, &ctr_drbg );
         if( ret != 0 )
         {
-            printf( " failed\n  !  rsa_gen_key returned -0x%04x", -ret );
+            polarssl_printf( " failed\n  !  rsa_gen_key returned -0x%04x", -ret );
             goto exit;
         }
     }
     else
 #endif /* POLARSSL_ECP_C */
     {
-        printf( " failed\n  !  key type not supported\n" );
+        polarssl_printf( " failed\n  !  key type not supported\n" );
         goto exit;
     }
 
     /*
      * 1.2 Print the key
      */
-    printf( " ok\n  . Key information:\n" );
+    polarssl_printf( " ok\n  . Key information:\n" );
 
 #if defined(POLARSSL_RSA_C)
     if( pk_get_type( &key ) == POLARSSL_PK_RSA )
@@ -368,7 +377,7 @@
     if( pk_get_type( &key ) == POLARSSL_PK_ECKEY )
     {
         ecp_keypair *ecp = pk_ec( key );
-        printf( "curve: %s\n",
+        polarssl_printf( "curve: %s\n",
                 ecp_curve_info_from_grp_id( ecp->grp.id )->name );
         mpi_write_file( "X_Q:   ", &ecp->Q.X, 16, NULL );
         mpi_write_file( "Y_Q:   ", &ecp->Q.Y, 16, NULL );
@@ -376,20 +385,20 @@
     }
     else
 #endif
-        printf("  ! key type not supported\n");
+        polarssl_printf("  ! key type not supported\n");
 
     /*
      * 1.3 Export key
      */
-    printf( "  . Writing key to file..." );
+    polarssl_printf( "  . Writing key to file..." );
 
     if( ( ret = write_private_key( &key, opt.filename ) ) != 0 )
     {
-        printf( " failed\n" );
+        polarssl_printf( " failed\n" );
         goto exit;
     }
 
-    printf( " ok\n" );
+    polarssl_printf( " ok\n" );
 
 exit:
 
@@ -397,9 +406,9 @@
     {
 #ifdef POLARSSL_ERROR_C
         polarssl_strerror( ret, buf, sizeof( buf ) );
-        printf( " - %s\n", buf );
+        polarssl_printf( " - %s\n", buf );
 #else
-        printf("\n");
+        polarssl_printf("\n");
 #endif
     }
 
@@ -408,7 +417,7 @@
     entropy_free( &entropy );
 
 #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/pkey/key_app.c b/programs/pkey/key_app.c
index 3637d6d..a161829 100644
--- a/programs/pkey/key_app.c
+++ b/programs/pkey/key_app.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>
@@ -41,7 +50,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_BIGNUM_C and/or "
+    polarssl_printf("POLARSSL_BIGNUM_C and/or "
            "POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
     return( 0 );
 }
@@ -94,7 +103,7 @@
     if( argc == 0 )
     {
     usage:
-        printf( USAGE );
+        polarssl_printf( USAGE );
         goto exit;
     }
 
@@ -133,7 +142,7 @@
     {
         if( strlen( opt.password ) && strlen( opt.password_file ) )
         {
-            printf( "Error: cannot have both password and password_file\n" );
+            polarssl_printf( "Error: cannot have both password and password_file\n" );
             goto usage;
         }
 
@@ -141,16 +150,16 @@
         {
             FILE *f;
 
-            printf( "\n  . Loading the password file ..." );
+            polarssl_printf( "\n  . Loading the password file ..." );
             if( ( f = fopen( opt.password_file, "rb" ) ) == NULL )
             {
-                printf( " failed\n  !  fopen returned NULL\n" );
+                polarssl_printf( " failed\n  !  fopen returned NULL\n" );
                 goto exit;
             }
             if( fgets( buf, sizeof(buf), f ) == NULL )
             {
                 fclose( f );
-                printf( "Error: fgets() failed to retrieve password\n" );
+                polarssl_printf( "Error: fgets() failed to retrieve password\n" );
                 goto exit;
             }
             fclose( f );
@@ -164,23 +173,23 @@
         /*
          * 1.1. Load the key
          */
-        printf( "\n  . Loading the private key ..." );
+        polarssl_printf( "\n  . Loading the private key ..." );
         fflush( stdout );
 
         ret = pk_parse_keyfile( &pk, opt.filename, opt.password );
 
         if( ret != 0 )
         {
-            printf( " failed\n  !  pk_parse_keyfile returned -0x%04x\n", -ret );
+            polarssl_printf( " failed\n  !  pk_parse_keyfile returned -0x%04x\n", -ret );
             goto exit;
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
         /*
          * 1.2 Print the key
          */
-        printf( "  . Key information    ...\n" );
+        polarssl_printf( "  . Key information    ...\n" );
 #if defined(POLARSSL_RSA_C)
         if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
         {
@@ -208,7 +217,7 @@
         else
 #endif
         {
-            printf("Do not know how to print key information for this type\n" );
+            polarssl_printf("Do not know how to print key information for this type\n" );
             goto exit;
         }
     }
@@ -217,20 +226,20 @@
         /*
          * 1.1. Load the key
          */
-        printf( "\n  . Loading the public key ..." );
+        polarssl_printf( "\n  . Loading the public key ..." );
         fflush( stdout );
 
         ret = pk_parse_public_keyfile( &pk, opt.filename );
 
         if( ret != 0 )
         {
-            printf( " failed\n  !  pk_parse_public_keyfile returned -0x%04x\n", -ret );
+            polarssl_printf( " failed\n  !  pk_parse_public_keyfile returned -0x%04x\n", -ret );
             goto exit;
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
-        printf( "  . Key information    ...\n" );
+        polarssl_printf( "  . Key information    ...\n" );
 #if defined(POLARSSL_RSA_C)
         if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
         {
@@ -251,7 +260,7 @@
         else
 #endif
         {
-            printf("Do not know how to print key information for this type\n" );
+            polarssl_printf("Do not know how to print key information for this type\n" );
             goto exit;
         }
     }
@@ -262,13 +271,13 @@
 
 #if defined(POLARSSL_ERROR_C)
     polarssl_strerror( ret, buf, sizeof(buf) );
-    printf( "  !  Last error was: %s\n", buf );
+    polarssl_printf( "  !  Last error was: %s\n", buf );
 #endif
 
     pk_free( &pk );
 
 #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/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c
index 18e6442..6862835 100644
--- a/programs/pkey/key_app_writer.c
+++ b/programs/pkey/key_app_writer.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>
@@ -40,7 +49,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
+    polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
     return( 0 );
 }
 #else
@@ -201,7 +210,7 @@
     {
     usage:
         ret = 1;
-        printf( USAGE );
+        polarssl_printf( USAGE );
         goto exit;
     }
 
@@ -258,13 +267,13 @@
 
     if( opt.mode == MODE_NONE && opt.output_mode != OUTPUT_MODE_NONE )
     {
-        printf( "\nCannot output a key without reading one.\n");
+        polarssl_printf( "\nCannot output a key without reading one.\n");
         goto exit;
     }
 
     if( opt.mode == MODE_PUBLIC && opt.output_mode == OUTPUT_MODE_PRIVATE )
     {
-        printf( "\nCannot output a private key from a public key.\n");
+        polarssl_printf( "\nCannot output a private key from a public key.\n");
         goto exit;
     }
 
@@ -273,7 +282,7 @@
         /*
          * 1.1. Load the key
          */
-        printf( "\n  . Loading the private key ..." );
+        polarssl_printf( "\n  . Loading the private key ..." );
         fflush( stdout );
 
         ret = pk_parse_keyfile( &key, opt.filename, NULL );
@@ -281,16 +290,16 @@
         if( ret != 0 )
         {
             polarssl_strerror( ret, (char *) buf, sizeof(buf) );
-            printf( " failed\n  !  pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
+            polarssl_printf( " failed\n  !  pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
             goto exit;
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
         /*
          * 1.2 Print the key
          */
-        printf( "  . Key information    ...\n" );
+        polarssl_printf( "  . Key information    ...\n" );
 
 #if defined(POLARSSL_RSA_C)
         if( pk_get_type( &key ) == POLARSSL_PK_RSA )
@@ -318,7 +327,7 @@
         }
         else
 #endif
-            printf("key type not supported yet\n");
+            polarssl_printf("key type not supported yet\n");
 
     }
     else if( opt.mode == MODE_PUBLIC )
@@ -326,7 +335,7 @@
         /*
          * 1.1. Load the key
          */
-        printf( "\n  . Loading the public key ..." );
+        polarssl_printf( "\n  . Loading the public key ..." );
         fflush( stdout );
 
         ret = pk_parse_public_keyfile( &key, opt.filename );
@@ -334,16 +343,16 @@
         if( ret != 0 )
         {
             polarssl_strerror( ret, (char *) buf, sizeof(buf) );
-            printf( " failed\n  !  pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
+            polarssl_printf( " failed\n  !  pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
             goto exit;
         }
 
-        printf( " ok\n" );
+        polarssl_printf( " ok\n" );
 
         /*
          * 1.2 Print the key
          */
-        printf( "  . Key information    ...\n" );
+        polarssl_printf( "  . Key information    ...\n" );
 
 #if defined(POLARSSL_RSA_C)
         if( pk_get_type( &key ) == POLARSSL_PK_RSA )
@@ -364,7 +373,7 @@
         }
         else
 #endif
-            printf("key type not supported yet\n");
+            polarssl_printf("key type not supported yet\n");
     }
     else
         goto usage;
@@ -384,16 +393,16 @@
     {
 #ifdef POLARSSL_ERROR_C
         polarssl_strerror( ret, buf, sizeof( buf ) );
-        printf( " - %s\n", buf );
+        polarssl_printf( " - %s\n", buf );
 #else
-        printf("\n");
+        polarssl_printf("\n");
 #endif
     }
 
     pk_free( &key );
 
 #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/pkey/mpi_demo.c b/programs/pkey/mpi_demo.c
index b0ece44..bf277fd 100644
--- a/programs/pkey/mpi_demo.c
+++ b/programs/pkey/mpi_demo.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 <stdio.h>
 
 #include "polarssl/bignum.h"
@@ -36,7 +45,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_BIGNUM_C and/or POLARSSL_FS_IO not defined.\n");
+    polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_FS_IO not defined.\n");
     return( 0 );
 }
 #else
@@ -56,11 +65,11 @@
     mpi_read_string( &E, 10,  "257" );
     mpi_mul_mpi( &N, &P, &Q );
 
-    printf( "\n  Public key:\n\n" );
+    polarssl_printf( "\n  Public key:\n\n" );
     mpi_write_file( "  N = ", &N, 10, NULL );
     mpi_write_file( "  E = ", &E, 10, NULL );
 
-    printf( "\n  Private key:\n\n" );
+    polarssl_printf( "\n  Private key:\n\n" );
     mpi_write_file( "  P = ", &P, 10, NULL );
     mpi_write_file( "  Q = ", &Q, 10, NULL );
 
@@ -73,24 +82,24 @@
     mpi_write_file( "  D = E^-1 mod (P-1)*(Q-1) = ",
                     &D, 10, NULL );
 #else
-    printf("\nTest skipped (POLARSSL_GENPRIME not defined).\n\n");
+    polarssl_printf("\nTest skipped (POLARSSL_GENPRIME not defined).\n\n");
 #endif
     mpi_read_string( &X, 10, "55555" );
     mpi_exp_mod( &Y, &X, &E, &N, NULL );
     mpi_exp_mod( &Z, &Y, &D, &N, NULL );
 
-    printf( "\n  RSA operation:\n\n" );
+    polarssl_printf( "\n  RSA operation:\n\n" );
     mpi_write_file( "  X (plaintext)  = ", &X, 10, NULL );
     mpi_write_file( "  Y (ciphertext) = X^E mod N = ", &Y, 10, NULL );
     mpi_write_file( "  Z (decrypted)  = Y^D mod N = ", &Z, 10, NULL );
-    printf( "\n" );
+    polarssl_printf( "\n" );
 
     mpi_free( &E ); mpi_free( &P ); mpi_free( &Q ); mpi_free( &N );
     mpi_free( &H ); mpi_free( &D ); mpi_free( &X ); mpi_free( &Y );
     mpi_free( &Z );
 
 #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/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c
index f80c1e2..314aad3 100644
--- a/programs/pkey/pk_decrypt.c
+++ b/programs/pkey/pk_decrypt.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>
 
@@ -42,7 +51,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
+    polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
            "POLARSSL_FS_IO and/or POLARSSL_ENTROPY_C and/or "
            "POLARSSL_CTR_DRBG_C not defined.\n");
     return( 0 );
@@ -66,16 +75,16 @@
 
     if( argc != 2 )
     {
-        printf( "usage: pk_decrypt <key_file>\n" );
+        polarssl_printf( "usage: pk_decrypt <key_file>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -83,18 +92,18 @@
                                (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;
     }
 
-    printf( "\n  . Reading private key from '%s'", argv[1] );
+    polarssl_printf( "\n  . Reading private key from '%s'", argv[1] );
     fflush( stdout );
 
     pk_init( &pk );
 
     if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
     {
-        printf( " failed\n  ! pk_parse_keyfile returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! pk_parse_keyfile returned -0x%04x\n", -ret );
         goto exit;
     }
 
@@ -105,7 +114,7 @@
 
     if( ( f = fopen( "result-enc.txt", "rb" ) ) == NULL )
     {
-        printf( "\n  ! Could not open %s\n\n", "result-enc.txt" );
+        polarssl_printf( "\n  ! Could not open %s\n\n", "result-enc.txt" );
         goto exit;
     }
 
@@ -120,19 +129,19 @@
     /*
      * Decrypt the encrypted RSA data and print the result.
      */
-    printf( "\n  . Decrypting the encrypted data" );
+    polarssl_printf( "\n  . Decrypting the encrypted data" );
     fflush( stdout );
 
     if( ( ret = pk_decrypt( &pk, buf, i, result, &olen, sizeof(result),
                             ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! pk_decrypt returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! pk_decrypt returned -0x%04x\n", -ret );
         goto exit;
     }
 
-    printf( "\n  . OK\n\n" );
+    polarssl_printf( "\n  . OK\n\n" );
 
-    printf( "The decrypted result is: '%s'\n\n", result );
+    polarssl_printf( "The decrypted result is: '%s'\n\n", result );
 
     ret = 0;
 
@@ -142,11 +151,11 @@
 
 #if defined(POLARSSL_ERROR_C)
     polarssl_strerror( ret, (char *) buf, sizeof(buf) );
-    printf( "  !  Last error was: %s\n", buf );
+    polarssl_printf( "  !  Last error was: %s\n", buf );
 #endif
 
 #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/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c
index 223044b..9f29849 100644
--- a/programs/pkey/pk_encrypt.c
+++ b/programs/pkey/pk_encrypt.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>
 
@@ -42,7 +51,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
+    polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
            "POLARSSL_ENTROPY_C and/or POLARSSL_FS_IO and/or "
            "POLARSSL_CTR_DRBG_C not defined.\n");
     return( 0 );
@@ -64,16 +73,16 @@
 
     if( argc != 3 )
     {
-        printf( "usage: pk_encrypt <key_file> <string of max 100 characters>\n" );
+        polarssl_printf( "usage: pk_encrypt <key_file> <string of max 100 characters>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -81,24 +90,24 @@
                                (const unsigned char *) pers,
                                strlen( pers ) ) ) != 0 )
     {
-        printf( " failed\n  ! ctr_drbg_init returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! ctr_drbg_init returned -0x%04x\n", -ret );
         goto exit;
     }
 
-    printf( "\n  . Reading public key from '%s'", argv[1] );
+    polarssl_printf( "\n  . Reading public key from '%s'", argv[1] );
     fflush( stdout );
 
     pk_init( &pk );
 
     if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 )
     {
-        printf( " failed\n  ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
         goto exit;
     }
 
     if( strlen( argv[2] ) > 100 )
     {
-        printf( " Input data larger than 100 characters.\n\n" );
+        polarssl_printf( " Input data larger than 100 characters.\n\n" );
         goto exit;
     }
 
@@ -107,14 +116,14 @@
     /*
      * Calculate the RSA encryption of the hash.
      */
-    printf( "\n  . Generating the encrypted value" );
+    polarssl_printf( "\n  . Generating the encrypted value" );
     fflush( stdout );
 
     if( ( ret = pk_encrypt( &pk, input, strlen( argv[2] ),
                             buf, &olen, sizeof(buf),
                             ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! pk_encrypt returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! pk_encrypt returned -0x%04x\n", -ret );
         goto exit;
     }
 
@@ -124,17 +133,17 @@
     if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not create %s\n\n", "result-enc.txt" );
+        polarssl_printf( " failed\n  ! Could not create %s\n\n", "result-enc.txt" );
         goto exit;
     }
 
     for( i = 0; i < olen; i++ )
-        fprintf( f, "%02X%s", buf[i],
+        polarssl_fprintf( f, "%02X%s", buf[i],
                  ( i + 1 ) % 16 == 0 ? "\r\n" : " " );
 
     fclose( f );
 
-    printf( "\n  . Done (created \"%s\")\n\n", "result-enc.txt" );
+    polarssl_printf( "\n  . Done (created \"%s\")\n\n", "result-enc.txt" );
 
 exit:
     ctr_drbg_free( &ctr_drbg );
@@ -142,11 +151,11 @@
 
 #if defined(POLARSSL_ERROR_C)
     polarssl_strerror( ret, (char *) buf, sizeof(buf) );
-    printf( "  !  Last error was: %s\n", buf );
+    polarssl_printf( "  !  Last error was: %s\n", buf );
 #endif
 
 #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/pkey/pk_sign.c b/programs/pkey/pk_sign.c
index 151e263..d032691 100644
--- a/programs/pkey/pk_sign.c
+++ b/programs/pkey/pk_sign.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>
 
@@ -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_SHA1_C and/or "
            "POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO and/or "
            "POLARSSL_CTR_DRBG_C not defined.\n");
@@ -74,33 +83,33 @@
 
     if( argc != 3 )
     {
-        printf( "usage: pk_sign <key_file> <filename>\n" );
+        polarssl_printf( "usage: pk_sign <key_file> <filename>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
                                (const unsigned char *) pers,
                                strlen( pers ) ) ) != 0 )
     {
-        printf( " failed\n  ! ctr_drbg_init returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! ctr_drbg_init returned -0x%04x\n", -ret );
         goto exit;
     }
 
-    printf( "\n  . Reading private key from '%s'", argv[1] );
+    polarssl_printf( "\n  . Reading private key from '%s'", argv[1] );
     fflush( stdout );
 
     if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
     {
         ret = 1;
-        printf( " failed\n  ! Could not open '%s'\n", argv[1] );
+        polarssl_printf( " failed\n  ! Could not open '%s'\n", argv[1] );
         goto exit;
     }
 
@@ -108,19 +117,19 @@
      * Compute the SHA-1 hash of the input file,
      * then calculate the signature of the hash.
      */
-    printf( "\n  . Generating the SHA-1 signature" );
+    polarssl_printf( "\n  . Generating the SHA-1 signature" );
     fflush( stdout );
 
     if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
     {
-        printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
+        polarssl_printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
         goto exit;
     }
 
     if( ( ret = pk_sign( &pk, POLARSSL_MD_SHA1, hash, 0, buf, &olen,
                          ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! pk_sign returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! pk_sign returned -0x%04x\n", -ret );
         goto exit;
     }
 
@@ -132,19 +141,19 @@
     if( ( f = fopen( filename, "wb+" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not create %s\n\n", filename );
+        polarssl_printf( " failed\n  ! Could not create %s\n\n", filename );
         goto exit;
     }
 
     if( fwrite( buf, 1, olen, f ) != olen )
     {
-        printf( "failed\n  ! fwrite failed\n\n" );
+        polarssl_printf( "failed\n  ! fwrite failed\n\n" );
         goto exit;
     }
 
     fclose( f );
 
-    printf( "\n  . Done (created \"%s\")\n\n", filename );
+    polarssl_printf( "\n  . Done (created \"%s\")\n\n", filename );
 
 exit:
     pk_free( &pk );
@@ -153,11 +162,11 @@
 
 #if defined(POLARSSL_ERROR_C)
     polarssl_strerror( ret, (char *) buf, sizeof(buf) );
-    printf( "  !  Last error was: %s\n", buf );
+    polarssl_printf( "  !  Last error was: %s\n", buf );
 #endif
 
 #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/pkey/pk_verify.c b/programs/pkey/pk_verify.c
index f2e5eb3..89e9cc1 100644
--- a/programs/pkey/pk_verify.c
+++ b/programs/pkey/pk_verify.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>
 
@@ -46,7 +55,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf("POLARSSL_BIGNUM_C and/or "
+    polarssl_printf("POLARSSL_BIGNUM_C and/or "
            "POLARSSL_SHA1_C and/or POLARSSL_PK_PARSE_C and/or "
            "POLARSSL_FS_IO not defined.\n");
     return( 0 );
@@ -66,21 +75,21 @@
 
     if( argc != 3 )
     {
-        printf( "usage: pk_verify <key_file> <filename>\n" );
+        polarssl_printf( "usage: pk_verify <key_file> <filename>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Reading public key from '%s'", argv[1] );
+    polarssl_printf( "\n  . Reading public key from '%s'", argv[1] );
     fflush( stdout );
 
     if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 )
     {
-        printf( " failed\n  ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
         goto exit;
     }
 
@@ -92,7 +101,7 @@
 
     if( ( f = fopen( filename, "rb" ) ) == NULL )
     {
-        printf( "\n  ! Could not open %s\n\n", filename );
+        polarssl_printf( "\n  ! Could not open %s\n\n", filename );
         goto exit;
     }
 
@@ -105,23 +114,23 @@
      * Compute the SHA-1 hash of the input file and compare
      * it with the hash decrypted from the signature.
      */
-    printf( "\n  . Verifying the SHA-1 signature" );
+    polarssl_printf( "\n  . Verifying the SHA-1 signature" );
     fflush( stdout );
 
     if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
     {
-        printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
+        polarssl_printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
         goto exit;
     }
 
     if( ( ret = pk_verify( &pk, POLARSSL_MD_SHA1, hash, 0,
                            buf, i ) ) != 0 )
     {
-        printf( " failed\n  ! pk_verify returned -0x%04x\n", -ret );
+        polarssl_printf( " failed\n  ! pk_verify returned -0x%04x\n", -ret );
         goto exit;
     }
 
-    printf( "\n  . OK (the decrypted SHA-1 hash matches)\n\n" );
+    polarssl_printf( "\n  . OK (the decrypted SHA-1 hash matches)\n\n" );
 
     ret = 0;
 
@@ -130,11 +139,11 @@
 
 #if defined(POLARSSL_ERROR_C)
     polarssl_strerror( ret, (char *) buf, sizeof(buf) );
-    printf( "  !  Last error was: %s\n", buf );
+    polarssl_printf( "  !  Last error was: %s\n", buf );
 #endif
 
 #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/pkey/rsa_decrypt.c b/programs/pkey/rsa_decrypt.c
index 4d42bc1..1e187a8 100644
--- a/programs/pkey/rsa_decrypt.c
+++ b/programs/pkey/rsa_decrypt.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>
 
@@ -41,7 +50,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_FS_IO and/or POLARSSL_ENTROPY_C and/or "
            "POLARSSL_CTR_DRBG_C not defined.\n");
     return( 0 );
@@ -65,16 +74,16 @@
 
     if( argc != 1 )
     {
-        printf( "usage: rsa_decrypt\n" );
+        polarssl_printf( "usage: rsa_decrypt\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -82,16 +91,16 @@
                                (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;
     }
 
-    printf( "\n  . Reading private key from rsa_priv.txt" );
+    polarssl_printf( "\n  . Reading private key from rsa_priv.txt" );
     fflush( stdout );
 
     if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
     {
-        printf( " failed\n  ! Could not open rsa_priv.txt\n" \
+        polarssl_printf( " failed\n  ! Could not open rsa_priv.txt\n" \
                 "  ! Please run rsa_genkey first\n\n" );
         goto exit;
     }
@@ -107,7 +116,7 @@
         ( ret = mpi_read_file( &rsa.DQ, 16, f ) ) != 0 ||
         ( ret = mpi_read_file( &rsa.QP, 16, f ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
         goto exit;
     }
 
@@ -122,7 +131,7 @@
 
     if( ( f = fopen( "result-enc.txt", "rb" ) ) == NULL )
     {
-        printf( "\n  ! Could not open %s\n\n", "result-enc.txt" );
+        polarssl_printf( "\n  ! Could not open %s\n\n", "result-enc.txt" );
         goto exit;
     }
 
@@ -136,27 +145,27 @@
 
     if( i != rsa.len )
     {
-        printf( "\n  ! Invalid RSA signature format\n\n" );
+        polarssl_printf( "\n  ! Invalid RSA signature format\n\n" );
         goto exit;
     }
 
     /*
      * Decrypt the encrypted RSA data and print the result.
      */
-    printf( "\n  . Decrypting the encrypted data" );
+    polarssl_printf( "\n  . Decrypting the encrypted data" );
     fflush( stdout );
 
     if( ( ret = rsa_pkcs1_decrypt( &rsa, ctr_drbg_random, &ctr_drbg,
                                    RSA_PRIVATE, &i, buf, result,
                                    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 );
         goto exit;
     }
 
-    printf( "\n  . OK\n\n" );
+    polarssl_printf( "\n  . OK\n\n" );
 
-    printf( "The decrypted result is: '%s'\n\n", result );
+    polarssl_printf( "The decrypted result is: '%s'\n\n", result );
 
     ret = 0;
 
@@ -165,7 +174,7 @@
     entropy_free( &entropy );
 
 #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/pkey/rsa_encrypt.c b/programs/pkey/rsa_encrypt.c
index 69ffbcd..e8c00d3 100644
--- a/programs/pkey/rsa_encrypt.c
+++ b/programs/pkey/rsa_encrypt.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>
 
@@ -41,7 +50,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_ENTROPY_C and/or POLARSSL_FS_IO and/or "
            "POLARSSL_CTR_DRBG_C not defined.\n");
     return( 0 );
@@ -63,16 +72,16 @@
 
     if( argc != 2 )
     {
-        printf( "usage: rsa_encrypt <string of max 100 characters>\n" );
+        polarssl_printf( "usage: rsa_encrypt <string of max 100 characters>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -80,17 +89,17 @@
                                (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;
     }
 
-    printf( "\n  . Reading public key from rsa_pub.txt" );
+    polarssl_printf( "\n  . Reading public key from rsa_pub.txt" );
     fflush( stdout );
 
     if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not open rsa_pub.txt\n" \
+        polarssl_printf( " failed\n  ! Could not open rsa_pub.txt\n" \
                 "  ! Please run rsa_genkey first\n\n" );
         goto exit;
     }
@@ -100,7 +109,7 @@
     if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
         ( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
         goto exit;
     }
 
@@ -110,7 +119,7 @@
 
     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;
     }
 
@@ -119,14 +128,14 @@
     /*
      * Calculate the RSA encryption of the hash.
      */
-    printf( "\n  . Generating the RSA encrypted value" );
+    polarssl_printf( "\n  . Generating the RSA encrypted value" );
     fflush( stdout );
 
     if( ( ret = rsa_pkcs1_encrypt( &rsa, ctr_drbg_random, &ctr_drbg,
                                    RSA_PUBLIC, strlen( argv[1] ),
                                    input, buf ) ) != 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;
     }
 
@@ -136,24 +145,24 @@
     if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not create %s\n\n", "result-enc.txt" );
+        polarssl_printf( " failed\n  ! Could not create %s\n\n", "result-enc.txt" );
         goto exit;
     }
 
     for( i = 0; i < rsa.len; i++ )
-        fprintf( f, "%02X%s", buf[i],
+        polarssl_fprintf( f, "%02X%s", buf[i],
                  ( i + 1 ) % 16 == 0 ? "\r\n" : " " );
 
     fclose( f );
 
-    printf( "\n  . Done (created \"%s\")\n\n", "result-enc.txt" );
+    polarssl_printf( "\n  . Done (created \"%s\")\n\n", "result-enc.txt" );
 
 exit:
     ctr_drbg_free( &ctr_drbg );
     entropy_free( &entropy );
 
 #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/pkey/rsa_genkey.c b/programs/pkey/rsa_genkey.c
index 556718c..955f819 100644
--- a/programs/pkey/rsa_genkey.c
+++ b/programs/pkey/rsa_genkey.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 <stdio.h>
 
 #include "polarssl/entropy.h"
@@ -45,7 +54,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_RSA_C and/or POLARSSL_GENPRIME and/or "
            "POLARSSL_FS_IO and/or POLARSSL_CTR_DRBG_C not defined.\n");
     return( 0 );
@@ -64,7 +73,7 @@
     ((void) argc);
     ((void) argv);
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     entropy_init( &entropy );
@@ -72,11 +81,11 @@
                                (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;
     }
 
-    printf( " ok\n  . Generating the RSA key [ %d-bit ]...", KEY_SIZE );
+    polarssl_printf( " ok\n  . Generating the RSA key [ %d-bit ]...", KEY_SIZE );
     fflush( stdout );
 
     rsa_init( &rsa, RSA_PKCS_V15, 0 );
@@ -84,16 +93,16 @@
     if( ( ret = rsa_gen_key( &rsa, ctr_drbg_random, &ctr_drbg, KEY_SIZE,
                              EXPONENT ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_gen_key returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! rsa_gen_key returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( " ok\n  . Exporting the public  key in rsa_pub.txt...." );
+    polarssl_printf( " ok\n  . Exporting the public  key in rsa_pub.txt...." );
     fflush( stdout );
 
     if( ( fpub = fopen( "rsa_pub.txt", "wb+" ) ) == NULL )
     {
-        printf( " failed\n  ! could not open rsa_pub.txt for writing\n\n" );
+        polarssl_printf( " failed\n  ! could not open rsa_pub.txt for writing\n\n" );
         ret = 1;
         goto exit;
     }
@@ -101,16 +110,16 @@
     if( ( ret = mpi_write_file( "N = ", &rsa.N, 16, fpub ) ) != 0 ||
         ( ret = mpi_write_file( "E = ", &rsa.E, 16, fpub ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_write_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_write_file returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( " ok\n  . Exporting the private key in rsa_priv.txt..." );
+    polarssl_printf( " ok\n  . Exporting the private key in rsa_priv.txt..." );
     fflush( stdout );
 
     if( ( fpriv = fopen( "rsa_priv.txt", "wb+" ) ) == NULL )
     {
-        printf( " failed\n  ! could not open rsa_priv.txt for writing\n" );
+        polarssl_printf( " failed\n  ! could not open rsa_priv.txt for writing\n" );
         ret = 1;
         goto exit;
     }
@@ -124,11 +133,11 @@
         ( ret = mpi_write_file( "DQ = ", &rsa.DQ, 16, fpriv ) ) != 0 ||
         ( ret = mpi_write_file( "QP = ", &rsa.QP, 16, fpriv ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_write_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_write_file returned %d\n\n", ret );
         goto exit;
     }
 /*
-    printf( " ok\n  . Generating the certificate..." );
+    polarssl_printf( " ok\n  . Generating the certificate..." );
 
     x509write_init_raw( &cert );
     x509write_add_pubkey( &cert, &rsa );
@@ -140,7 +149,7 @@
     x509write_crtfile( &cert, "cert.pem", X509_OUTPUT_PEM );
     x509write_free_raw( &cert );
 */
-    printf( " ok\n\n" );
+    polarssl_printf( " ok\n\n" );
 
 exit:
 
@@ -155,7 +164,7 @@
     entropy_free( &entropy );
 
 #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/pkey/rsa_sign.c b/programs/pkey/rsa_sign.c
index c466919..27d1474 100644
--- a/programs/pkey/rsa_sign.c
+++ b/programs/pkey/rsa_sign.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>
 
@@ -39,7 +48,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_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
     return( 0 );
 }
@@ -57,22 +66,22 @@
 
     if( argc != 2 )
     {
-        printf( "usage: rsa_sign <filename>\n" );
+        polarssl_printf( "usage: rsa_sign <filename>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Reading private key from rsa_priv.txt" );
+    polarssl_printf( "\n  . Reading private key from rsa_priv.txt" );
     fflush( stdout );
 
     if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not open rsa_priv.txt\n" \
+        polarssl_printf( " failed\n  ! Could not open rsa_priv.txt\n" \
                 "  ! Please run rsa_genkey first\n\n" );
         goto exit;
     }
@@ -88,7 +97,7 @@
         ( ret = mpi_read_file( &rsa.DQ, 16, f ) ) != 0 ||
         ( ret = mpi_read_file( &rsa.QP, 16, f ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
         goto exit;
     }
 
@@ -96,11 +105,11 @@
 
     fclose( f );
 
-    printf( "\n  . Checking the private key" );
+    polarssl_printf( "\n  . Checking the private key" );
     fflush( stdout );
     if( ( ret = rsa_check_privkey( &rsa ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_check_privkey failed with -0x%0x\n", -ret );
+        polarssl_printf( " failed\n  ! rsa_check_privkey failed with -0x%0x\n", -ret );
         goto exit;
     }
 
@@ -108,19 +117,19 @@
      * Compute the SHA-1 hash of the input file,
      * then calculate the RSA signature of the hash.
      */
-    printf( "\n  . Generating the RSA/SHA-1 signature" );
+    polarssl_printf( "\n  . Generating the RSA/SHA-1 signature" );
     fflush( stdout );
 
     if( ( ret = sha1_file( argv[1], hash ) ) != 0 )
     {
-        printf( " failed\n  ! Could not open or read %s\n\n", argv[1] );
+        polarssl_printf( " failed\n  ! Could not open or read %s\n\n", argv[1] );
         goto exit;
     }
 
     if( ( ret = rsa_pkcs1_sign( &rsa, NULL, NULL, RSA_PRIVATE, POLARSSL_MD_SHA1,
                                 20, hash, buf ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_sign returned -0x%0x\n\n", -ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_sign returned -0x%0x\n\n", -ret );
         goto exit;
     }
 
@@ -132,22 +141,22 @@
     if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not create %s\n\n", argv[1] );
+        polarssl_printf( " failed\n  ! Could not create %s\n\n", argv[1] );
         goto exit;
     }
 
     for( i = 0; i < rsa.len; i++ )
-        fprintf( f, "%02X%s", buf[i],
+        polarssl_fprintf( f, "%02X%s", buf[i],
                  ( i + 1 ) % 16 == 0 ? "\r\n" : " " );
 
     fclose( f );
 
-    printf( "\n  . Done (created \"%s\")\n\n", argv[1] );
+    polarssl_printf( "\n  . Done (created \"%s\")\n\n", argv[1] );
 
 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
 
diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c
index d537611..3c9cbdb 100644
--- a/programs/pkey/rsa_sign_pss.c
+++ b/programs/pkey/rsa_sign_pss.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>
 
@@ -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_RSA_C and/or POLARSSL_SHA1_C and/or "
            "POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO and/or "
            "POLARSSL_CTR_DRBG_C not defined.\n");
@@ -74,41 +83,41 @@
 
     if( argc != 3 )
     {
-        printf( "usage: rsa_sign_pss <key_file> <filename>\n" );
+        polarssl_printf( "usage: rsa_sign_pss <key_file> <filename>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Seeding the random number generator..." );
+    polarssl_printf( "\n  . Seeding the random number generator..." );
     fflush( stdout );
 
     if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
                                (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;
     }
 
-    printf( "\n  . Reading private key from '%s'", argv[1] );
+    polarssl_printf( "\n  . Reading private key from '%s'", argv[1] );
     fflush( stdout );
 
     if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
     {
         ret = 1;
-        printf( " failed\n  ! Could not read key from '%s'\n", argv[1] );
-        printf( "  ! pk_parse_public_keyfile returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! Could not read key from '%s'\n", argv[1] );
+        polarssl_printf( "  ! pk_parse_public_keyfile returned %d\n\n", ret );
         goto exit;
     }
 
     if( !pk_can_do( &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;
     }
 
@@ -118,19 +127,19 @@
      * Compute the SHA-1 hash of the input file,
      * then calculate the RSA signature of the hash.
      */
-    printf( "\n  . Generating the RSA/SHA-1 signature" );
+    polarssl_printf( "\n  . Generating the RSA/SHA-1 signature" );
     fflush( stdout );
 
     if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
     {
-        printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
+        polarssl_printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
         goto exit;
     }
 
     if( ( ret = pk_sign( &pk, POLARSSL_MD_SHA1, hash, 0, buf, &olen,
                          ctr_drbg_random, &ctr_drbg ) ) != 0 )
     {
-        printf( " failed\n  ! pk_sign returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! pk_sign returned %d\n\n", ret );
         goto exit;
     }
 
@@ -142,19 +151,19 @@
     if( ( f = fopen( filename, "wb+" ) ) == NULL )
     {
         ret = 1;
-        printf( " failed\n  ! Could not create %s\n\n", filename );
+        polarssl_printf( " failed\n  ! Could not create %s\n\n", filename );
         goto exit;
     }
 
     if( fwrite( buf, 1, olen, f ) != olen )
     {
-        printf( "failed\n  ! fwrite failed\n\n" );
+        polarssl_printf( "failed\n  ! fwrite failed\n\n" );
         goto exit;
     }
 
     fclose( f );
 
-    printf( "\n  . Done (created \"%s\")\n\n", filename );
+    polarssl_printf( "\n  . Done (created \"%s\")\n\n", filename );
 
 exit:
     pk_free( &pk );
@@ -162,7 +171,7 @@
     entropy_free( &entropy );
 
 #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/pkey/rsa_verify.c b/programs/pkey/rsa_verify.c
index 7405df7..43b742e 100644
--- a/programs/pkey/rsa_verify.c
+++ b/programs/pkey/rsa_verify.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>
 
@@ -39,7 +48,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_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
     return( 0 );
 }
@@ -56,21 +65,21 @@
     ret = 1;
     if( argc != 2 )
     {
-        printf( "usage: rsa_verify <filename>\n" );
+        polarssl_printf( "usage: rsa_verify <filename>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Reading public key from rsa_pub.txt" );
+    polarssl_printf( "\n  . Reading public key from rsa_pub.txt" );
     fflush( stdout );
 
     if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
     {
-        printf( " failed\n  ! Could not open rsa_pub.txt\n" \
+        polarssl_printf( " failed\n  ! Could not open rsa_pub.txt\n" \
                 "  ! Please run rsa_genkey first\n\n" );
         goto exit;
     }
@@ -80,7 +89,7 @@
     if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
         ( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
     {
-        printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! mpi_read_file returned %d\n\n", ret );
         goto exit;
     }
 
@@ -97,7 +106,7 @@
 
     if( ( f = fopen( argv[1], "rb" ) ) == NULL )
     {
-        printf( "\n  ! Could not open %s\n\n", argv[1] );
+        polarssl_printf( "\n  ! Could not open %s\n\n", argv[1] );
         goto exit;
     }
 
@@ -111,7 +120,7 @@
 
     if( i != rsa.len )
     {
-        printf( "\n  ! Invalid RSA signature format\n\n" );
+        polarssl_printf( "\n  ! Invalid RSA signature format\n\n" );
         goto exit;
     }
 
@@ -119,30 +128,30 @@
      * Compute the SHA-1 hash of the input file and compare
      * it with the hash decrypted from the RSA signature.
      */
-    printf( "\n  . Verifying the RSA/SHA-1 signature" );
+    polarssl_printf( "\n  . Verifying the RSA/SHA-1 signature" );
     fflush( stdout );
 
     if( ( ret = sha1_file( argv[1], hash ) ) != 0 )
     {
-        printf( " failed\n  ! Could not open or read %s\n\n", argv[1] );
+        polarssl_printf( " failed\n  ! Could not open or read %s\n\n", argv[1] );
         goto exit;
     }
 
     if( ( ret = rsa_pkcs1_verify( &rsa, NULL, NULL, RSA_PUBLIC,
                                   POLARSSL_MD_SHA1, 20, hash, buf ) ) != 0 )
     {
-        printf( " failed\n  ! rsa_pkcs1_verify returned -0x%0x\n\n", -ret );
+        polarssl_printf( " failed\n  ! rsa_pkcs1_verify returned -0x%0x\n\n", -ret );
         goto exit;
     }
 
-    printf( "\n  . OK (the decrypted SHA-1 hash matches)\n\n" );
+    polarssl_printf( "\n  . OK (the decrypted SHA-1 hash matches)\n\n" );
 
     ret = 0;
 
 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
 
diff --git a/programs/pkey/rsa_verify_pss.c b/programs/pkey/rsa_verify_pss.c
index f331b2f..3f79262 100644
--- a/programs/pkey/rsa_verify_pss.c
+++ b/programs/pkey/rsa_verify_pss.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>
 
@@ -47,7 +56,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_SHA1_C and/or POLARSSL_PK_PARSE_C and/or "
            "POLARSSL_FS_IO not defined.\n");
     return( 0 );
@@ -67,29 +76,29 @@
 
     if( argc != 3 )
     {
-        printf( "usage: rsa_verify_pss <key_file> <filename>\n" );
+        polarssl_printf( "usage: rsa_verify_pss <key_file> <filename>\n" );
 
 #if defined(_WIN32)
-        printf( "\n" );
+        polarssl_printf( "\n" );
 #endif
 
         goto exit;
     }
 
-    printf( "\n  . Reading public key from '%s'", argv[1] );
+    polarssl_printf( "\n  . Reading public key from '%s'", argv[1] );
     fflush( stdout );
 
     if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 )
     {
-        printf( " failed\n  ! Could not read key from '%s'\n", argv[1] );
-        printf( "  ! pk_parse_public_keyfile returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! Could not read key from '%s'\n", argv[1] );
+        polarssl_printf( "  ! pk_parse_public_keyfile returned %d\n\n", ret );
         goto exit;
     }
 
     if( !pk_can_do( &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;
     }
 
@@ -103,7 +112,7 @@
 
     if( ( f = fopen( filename, "rb" ) ) == NULL )
     {
-        printf( "\n  ! Could not open %s\n\n", filename );
+        polarssl_printf( "\n  ! Could not open %s\n\n", filename );
         goto exit;
     }
 
@@ -116,23 +125,23 @@
      * Compute the SHA-1 hash of the input file and compare
      * it with the hash decrypted from the RSA signature.
      */
-    printf( "\n  . Verifying the RSA/SHA-1 signature" );
+    polarssl_printf( "\n  . Verifying the RSA/SHA-1 signature" );
     fflush( stdout );
 
     if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
     {
-        printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
+        polarssl_printf( " failed\n  ! Could not open or read %s\n\n", argv[2] );
         goto exit;
     }
 
     if( ( ret = pk_verify( &pk, POLARSSL_MD_SHA1, hash, 0,
                            buf, i ) ) != 0 )
     {
-        printf( " failed\n  ! pk_verify returned %d\n\n", ret );
+        polarssl_printf( " failed\n  ! pk_verify returned %d\n\n", ret );
         goto exit;
     }
 
-    printf( "\n  . OK (the decrypted SHA-1 hash matches)\n\n" );
+    polarssl_printf( "\n  . OK (the decrypted SHA-1 hash matches)\n\n" );
 
     ret = 0;
 
@@ -140,7 +149,7 @@
     pk_free( &pk );
 
 #if defined(_WIN32)
-    printf( "  + Press Enter to exit this program.\n" );
+    polarssl_printf( "  + Press Enter to exit this program.\n" );
     fflush( stdout ); getchar();
 #endif