Merge branch 'development' into dtls
* development: (46 commits)
Fix url again
Fix small bug in base64_encode()
Fix depend that was checked but not documented
Fix dependency that was not checked
Minor gitginore fixes
Move some ignore patterns to subdirectories
Ignore CMake/MSVC-related build files.
Re-categorize changelog entry
Fix misattribution
Minor nits with stdout/stderr.
Add cmake compatibility targets
Add script for polarssl symlink creation
Fix more stdio inclusion issues
Add debug info for cert/suite selection
Fix possible portability issue
Fix bug in ssl_get_verify_result()
aescrypt2.c local char array not initial
Update Changelog
Fix mips64 bignum implementation
Fix usage string of ssl_client2
...
Conflicts:
include/polarssl/ssl.h
library/CMakeLists.txt
library/Makefile
programs/Makefile
programs/ssl/ssl_client2.c
programs/ssl/ssl_server2.c
visualc/VS2010/PolarSSL.sln
visualc/VS2010/mbedTLS.vcxproj
visualc/VS6/mbedtls.dsp
visualc/VS6/mbedtls.dsw
diff --git a/programs/.gitignore b/programs/.gitignore
index 233947a..c25ee3e 100644
--- a/programs/.gitignore
+++ b/programs/.gitignore
@@ -1,4 +1,7 @@
*/Makefile
+*.sln
+*.vcxproj
+
aes/aescrypt2
aes/crypt_and_hash
hash/generic_sum
diff --git a/programs/Makefile b/programs/Makefile
index a0b8c8c..0ebcf1f 100644
--- a/programs/Makefile
+++ b/programs/Makefile
@@ -5,7 +5,7 @@
CFLAGS += -I../include -D_FILE_OFFSET_BITS=64 -Wall -W -Wdeclaration-after-statement
OFLAGS = -O2
-LDFLAGS += -L../library -lpolarssl $(SYS_LDFLAGS)
+LDFLAGS += -L../library -lmbedtls $(SYS_LDFLAGS)
ifdef DEBUG
CFLAGS += -g3
@@ -59,199 +59,203 @@
all: $(APPS)
-aes/aescrypt2: aes/aescrypt2.c ../library/libpolarssl.a
+aes/aescrypt2: aes/aescrypt2.c ../library/libmbedtls.a
echo " CC aes/aescrypt2.c"
$(CC) $(CFLAGS) $(OFLAGS) aes/aescrypt2.c $(LDFLAGS) -o $@
-aes/crypt_and_hash: aes/crypt_and_hash.c ../library/libpolarssl.a
+aes/crypt_and_hash: aes/crypt_and_hash.c ../library/libmbedtls.a
echo " CC aes/crypt_and_hash.c"
$(CC) $(CFLAGS) $(OFLAGS) aes/crypt_and_hash.c $(LDFLAGS) -o $@
-hash/hello: hash/hello.c ../library/libpolarssl.a
+hash/hello: hash/hello.c ../library/libmbedtls.a
echo " CC hash/hello.c"
$(CC) $(CFLAGS) $(OFLAGS) hash/hello.c $(LDFLAGS) -o $@
-hash/generic_sum: hash/generic_sum.c ../library/libpolarssl.a
+hash/generic_sum: hash/generic_sum.c ../library/libmbedtls.a
echo " CC hash/generic_sum.c"
$(CC) $(CFLAGS) $(OFLAGS) hash/generic_sum.c $(LDFLAGS) -o $@
-hash/md5sum: hash/md5sum.c ../library/libpolarssl.a
+hash/md5sum: hash/md5sum.c ../library/libmbedtls.a
echo " CC hash/md5sum.c"
$(CC) $(CFLAGS) $(OFLAGS) hash/md5sum.c $(LDFLAGS) -o $@
-hash/sha1sum: hash/sha1sum.c ../library/libpolarssl.a
+hash/sha1sum: hash/sha1sum.c ../library/libmbedtls.a
echo " CC hash/sha1sum.c"
$(CC) $(CFLAGS) $(OFLAGS) hash/sha1sum.c $(LDFLAGS) -o $@
-hash/sha2sum: hash/sha2sum.c ../library/libpolarssl.a
+hash/sha2sum: hash/sha2sum.c ../library/libmbedtls.a
echo " CC hash/sha2sum.c"
$(CC) $(CFLAGS) $(OFLAGS) hash/sha2sum.c $(LDFLAGS) -o $@
-pkey/dh_client: pkey/dh_client.c ../library/libpolarssl.a
+pkey/dh_client: pkey/dh_client.c ../library/libmbedtls.a
echo " CC pkey/dh_client.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/dh_client.c $(LDFLAGS) -o $@
-pkey/dh_genprime: pkey/dh_genprime.c ../library/libpolarssl.a
+pkey/dh_genprime: pkey/dh_genprime.c ../library/libmbedtls.a
echo " CC pkey/dh_genprime.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/dh_genprime.c $(LDFLAGS) -o $@
-pkey/dh_server: pkey/dh_server.c ../library/libpolarssl.a
+pkey/dh_server: pkey/dh_server.c ../library/libmbedtls.a
echo " CC pkey/dh_server.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/dh_server.c $(LDFLAGS) -o $@
-pkey/ecdsa: pkey/ecdsa.c ../library/libpolarssl.a
+pkey/ecdsa: pkey/ecdsa.c ../library/libmbedtls.a
echo " CC pkey/ecdsa.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/ecdsa.c $(LDFLAGS) -o $@
-pkey/gen_key: pkey/gen_key.c ../library/libpolarssl.a
+pkey/gen_key: pkey/gen_key.c ../library/libmbedtls.a
echo " CC pkey/gen_key.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/gen_key.c $(LDFLAGS) -o $@
-pkey/key_app: pkey/key_app.c ../library/libpolarssl.a
+pkey/key_app: pkey/key_app.c ../library/libmbedtls.a
echo " CC pkey/key_app.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/key_app.c $(LDFLAGS) -o $@
-pkey/key_app_writer: pkey/key_app_writer.c ../library/libpolarssl.a
+pkey/key_app_writer: pkey/key_app_writer.c ../library/libmbedtls.a
echo " CC pkey/key_app_writer.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/key_app_writer.c $(LDFLAGS) -o $@
-pkey/mpi_demo: pkey/mpi_demo.c ../library/libpolarssl.a
+pkey/mpi_demo: pkey/mpi_demo.c ../library/libmbedtls.a
echo " CC pkey/mpi_demo.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/mpi_demo.c $(LDFLAGS) -o $@
-pkey/pk_decrypt: pkey/pk_decrypt.c ../library/libpolarssl.a
+pkey/pk_decrypt: pkey/pk_decrypt.c ../library/libmbedtls.a
echo " CC pkey/pk_decrypt.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/pk_decrypt.c $(LDFLAGS) -o $@
-pkey/pk_encrypt: pkey/pk_encrypt.c ../library/libpolarssl.a
+pkey/pk_encrypt: pkey/pk_encrypt.c ../library/libmbedtls.a
echo " CC pkey/pk_encrypt.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/pk_encrypt.c $(LDFLAGS) -o $@
-pkey/pk_sign: pkey/pk_sign.c ../library/libpolarssl.a
+pkey/pk_sign: pkey/pk_sign.c ../library/libmbedtls.a
echo " CC pkey/pk_sign.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/pk_sign.c $(LDFLAGS) -o $@
-pkey/pk_verify: pkey/pk_verify.c ../library/libpolarssl.a
+pkey/pk_verify: pkey/pk_verify.c ../library/libmbedtls.a
echo " CC pkey/pk_verify.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/pk_verify.c $(LDFLAGS) -o $@
-pkey/rsa_genkey: pkey/rsa_genkey.c ../library/libpolarssl.a
+pkey/rsa_genkey: pkey/rsa_genkey.c ../library/libmbedtls.a
echo " CC pkey/rsa_genkey.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/rsa_genkey.c $(LDFLAGS) -o $@
-pkey/rsa_sign: pkey/rsa_sign.c ../library/libpolarssl.a
+pkey/rsa_sign: pkey/rsa_sign.c ../library/libmbedtls.a
echo " CC pkey/rsa_sign.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/rsa_sign.c $(LDFLAGS) -o $@
-pkey/rsa_verify: pkey/rsa_verify.c ../library/libpolarssl.a
+pkey/rsa_verify: pkey/rsa_verify.c ../library/libmbedtls.a
echo " CC pkey/rsa_verify.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/rsa_verify.c $(LDFLAGS) -o $@
-pkey/rsa_sign_pss: pkey/rsa_sign_pss.c ../library/libpolarssl.a
+pkey/rsa_sign_pss: pkey/rsa_sign_pss.c ../library/libmbedtls.a
echo " CC pkey/rsa_sign_pss.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/rsa_sign_pss.c $(LDFLAGS) -o $@
-pkey/rsa_verify_pss: pkey/rsa_verify_pss.c ../library/libpolarssl.a
+pkey/rsa_verify_pss: pkey/rsa_verify_pss.c ../library/libmbedtls.a
echo " CC pkey/rsa_verify_pss.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/rsa_verify_pss.c $(LDFLAGS) -o $@
-pkey/rsa_decrypt: pkey/rsa_decrypt.c ../library/libpolarssl.a
+pkey/rsa_decrypt: pkey/rsa_decrypt.c ../library/libmbedtls.a
echo " CC pkey/rsa_decrypt.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/rsa_decrypt.c $(LDFLAGS) -o $@
-pkey/rsa_encrypt: pkey/rsa_encrypt.c ../library/libpolarssl.a
+pkey/rsa_encrypt: pkey/rsa_encrypt.c ../library/libmbedtls.a
echo " CC pkey/rsa_encrypt.c"
$(CC) $(CFLAGS) $(OFLAGS) pkey/rsa_encrypt.c $(LDFLAGS) -o $@
-random/gen_entropy: random/gen_entropy.c ../library/libpolarssl.a
+random/gen_entropy: random/gen_entropy.c ../library/libmbedtls.a
echo " CC random/gen_entropy.c"
$(CC) $(CFLAGS) $(OFLAGS) random/gen_entropy.c $(LDFLAGS) -o $@
-random/gen_random_havege: random/gen_random_havege.c ../library/libpolarssl.a
+random/gen_random_havege: random/gen_random_havege.c ../library/libmbedtls.a
echo " CC random/gen_random_havege.c"
$(CC) $(CFLAGS) $(OFLAGS) random/gen_random_havege.c $(LDFLAGS) -o $@
-random/gen_random_ctr_drbg: random/gen_random_ctr_drbg.c ../library/libpolarssl.a
+random/gen_random_ctr_drbg: random/gen_random_ctr_drbg.c ../library/libmbedtls.a
echo " CC random/gen_random_ctr_drbg.c"
$(CC) $(CFLAGS) $(OFLAGS) random/gen_random_ctr_drbg.c $(LDFLAGS) -o $@
-ssl/dtls_client: ssl/dtls_client.c ../library/libpolarssl.a
+ssl/dtls_client: ssl/dtls_client.c ../library/libmbedtls.a
echo " CC ssl/dtls_client.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/dtls_client.c $(LDFLAGS) -o $@
-ssl/dtls_server: ssl/dtls_server.c ../library/libpolarssl.a
+ssl/dtls_server: ssl/dtls_server.c ../library/libmbedtls.a
echo " CC ssl/dtls_server.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/dtls_server.c $(LDFLAGS) -o $@
-ssl/ssl_client1: ssl/ssl_client1.c ../library/libpolarssl.a
+ssl/ssl_client1: ssl/ssl_client1.c ../library/libmbedtls.a
echo " CC ssl/ssl_client1.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/ssl_client1.c $(LDFLAGS) -o $@
-ssl/ssl_client2: ssl/ssl_client2.c ../library/libpolarssl.a
+ssl/ssl_client2: ssl/ssl_client2.c ../library/libmbedtls.a
echo " CC ssl/ssl_client2.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/ssl_client2.c $(LDFLAGS) -o $@
-ssl/ssl_server: ssl/ssl_server.c ../library/libpolarssl.a
+ssl/ssl_server: ssl/ssl_server.c ../library/libmbedtls.a
echo " CC ssl/ssl_server.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/ssl_server.c $(LDFLAGS) -o $@
-ssl/ssl_server2: ssl/ssl_server2.c ../library/libpolarssl.a
+ssl/ssl_server2: ssl/ssl_server2.c ../library/libmbedtls.a
echo " CC ssl/ssl_server2.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/ssl_server2.c $(LDFLAGS) -o $@
-ssl/ssl_fork_server: ssl/ssl_fork_server.c ../library/libpolarssl.a
+ssl/ssl_fork_server: ssl/ssl_fork_server.c ../library/libmbedtls.a
echo " CC ssl/ssl_fork_server.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/ssl_fork_server.c $(LDFLAGS) -o $@
-ssl/ssl_pthread_server: ssl/ssl_pthread_server.c ../library/libpolarssl.a
+ssl/ssl_pthread_server: ssl/ssl_pthread_server.c ../library/libmbedtls.a
echo " CC ssl/ssl_pthread_server.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/ssl_pthread_server.c $(LDFLAGS) -o $@ -lpthread
-ssl/ssl_mail_client: ssl/ssl_mail_client.c ../library/libpolarssl.a
+ssl/ssl_mail_client: ssl/ssl_mail_client.c ../library/libmbedtls.a
echo " CC ssl/ssl_mail_client.c"
$(CC) $(CFLAGS) $(OFLAGS) ssl/ssl_mail_client.c $(LDFLAGS) -o $@
-test/ssl_cert_test: test/ssl_cert_test.c ../library/libpolarssl.a
+test/ssl_cert_test: test/ssl_cert_test.c ../library/libmbedtls.a
echo " CC test/ssl_cert_test.c"
$(CC) $(CFLAGS) $(OFLAGS) test/ssl_cert_test.c $(LDFLAGS) -o $@
-test/benchmark: test/benchmark.c ../library/libpolarssl.a
+test/benchmark: test/benchmark.c ../library/libmbedtls.a
echo " CC test/benchmark.c"
$(CC) $(CFLAGS) $(OFLAGS) test/benchmark.c $(LDFLAGS) -o $@
-test/selftest: test/selftest.c ../library/libpolarssl.a
+test/selftest: test/selftest.c ../library/libmbedtls.a
echo " CC test/selftest.c"
$(CC) $(CFLAGS) $(OFLAGS) test/selftest.c $(LDFLAGS) -o $@
-test/ssl_test: test/ssl_test.c ../library/libpolarssl.a
+test/ssl_test: test/ssl_test.c ../library/libmbedtls.a
echo " CC test/ssl_test.c"
$(CC) $(CFLAGS) $(OFLAGS) test/ssl_test.c $(LDFLAGS) -o $@
+<<<<<<< HEAD
test/udp_proxy: test/udp_proxy.c ../library/libpolarssl.a
echo " CC test/udp_proxy.c"
$(CC) $(CFLAGS) $(OFLAGS) test/udp_proxy.c $(LDFLAGS) -o $@
test/o_p_test: test/o_p_test.c ../library/libpolarssl.a
+=======
+test/o_p_test: test/o_p_test.c ../library/libmbedtls.a
+>>>>>>> development
echo " CC test/o_p_test.c"
$(CC) $(CFLAGS) $(OFLAGS) test/o_p_test.c $(LDFLAGS) -o $@ -lssl -lcrypto
-util/pem2der: util/pem2der.c ../library/libpolarssl.a
+util/pem2der: util/pem2der.c ../library/libmbedtls.a
echo " CC util/pem2der.c"
$(CC) $(CFLAGS) $(OFLAGS) util/pem2der.c $(LDFLAGS) -o $@
-util/strerror: util/strerror.c ../library/libpolarssl.a
+util/strerror: util/strerror.c ../library/libmbedtls.a
echo " CC util/strerror.c"
$(CC) $(CFLAGS) $(OFLAGS) util/strerror.c $(LDFLAGS) -o $@
-x509/cert_app: x509/cert_app.c ../library/libpolarssl.a
+x509/cert_app: x509/cert_app.c ../library/libmbedtls.a
echo " CC x509/cert_app.c"
$(CC) $(CFLAGS) $(OFLAGS) x509/cert_app.c $(LDFLAGS) -o $@
-x509/crl_app: x509/crl_app.c ../library/libpolarssl.a
+x509/crl_app: x509/crl_app.c ../library/libmbedtls.a
echo " CC x509/crl_app.c"
$(CC) $(CFLAGS) $(OFLAGS) x509/crl_app.c $(LDFLAGS) -o $@
-x509/cert_req: x509/cert_req.c ../library/libpolarssl.a
+x509/cert_req: x509/cert_req.c ../library/libmbedtls.a
echo " CC x509/cert_req.c"
$(CC) $(CFLAGS) $(OFLAGS) x509/cert_req.c $(LDFLAGS) -o $@
diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt
index 9bac94a..f5a0caa 100644
--- a/programs/aes/CMakeLists.txt
+++ b/programs/aes/CMakeLists.txt
@@ -1,8 +1,8 @@
add_executable(aescrypt2 aescrypt2.c)
-target_link_libraries(aescrypt2 polarssl)
+target_link_libraries(aescrypt2 mbedtls)
add_executable(crypt_and_hash crypt_and_hash.c)
-target_link_libraries(crypt_and_hash polarssl)
+target_link_libraries(crypt_and_hash mbedtls)
install(TARGETS aescrypt2 crypt_and_hash
DESTINATION "bin"
diff --git a/programs/aes/aescrypt2.c b/programs/aes/aescrypt2.c
index a82e457..1f34748 100644
--- a/programs/aes/aescrypt2.c
+++ b/programs/aes/aescrypt2.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#if defined(_WIN32)
#include <windows.h>
#if !defined(_WIN32_WCE)
@@ -58,7 +65,7 @@
{
((void) argc);
((void) argv);
- printf("POLARSSL_AES_C and/or POLARSSL_SHA256_C not defined.\n");
+ polarssl_printf("POLARSSL_AES_C and/or POLARSSL_SHA256_C not defined.\n");
return( 0 );
}
#else
@@ -98,10 +105,10 @@
*/
if( argc != 5 )
{
- printf( USAGE );
+ polarssl_printf( USAGE );
#if defined(_WIN32)
- printf( "\n Press Enter to exit this program.\n" );
+ polarssl_printf( "\n Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
@@ -109,28 +116,32 @@
}
mode = atoi( argv[1] );
+ memset(IV, 0, sizeof(IV));
+ memset(key, 0, sizeof(key));
+ memset(digest, 0, sizeof(digest));
+ memset(buffer, 0, sizeof(buffer));
if( mode != MODE_ENCRYPT && mode != MODE_DECRYPT )
{
- fprintf( stderr, "invalide operation mode\n" );
+ polarssl_fprintf( stderr, "invalide operation mode\n" );
goto exit;
}
if( strcmp( argv[2], argv[3] ) == 0 )
{
- fprintf( stderr, "input and output filenames must differ\n" );
+ polarssl_fprintf( stderr, "input and output filenames must differ\n" );
goto exit;
}
if( ( fin = fopen( argv[2], "rb" ) ) == NULL )
{
- fprintf( stderr, "fopen(%s,rb) failed\n", argv[2] );
+ polarssl_fprintf( stderr, "fopen(%s,rb) failed\n", argv[2] );
goto exit;
}
if( ( fout = fopen( argv[3], "wb+" ) ) == NULL )
{
- fprintf( stderr, "fopen(%s,wb+) failed\n", argv[3] );
+ polarssl_fprintf( stderr, "fopen(%s,wb+) failed\n", argv[3] );
goto exit;
}
@@ -183,7 +194,7 @@
if( li_size.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR )
{
- fprintf( stderr, "SetFilePointer(0,FILE_END) failed\n" );
+ polarssl_fprintf( stderr, "SetFilePointer(0,FILE_END) failed\n" );
goto exit;
}
@@ -199,7 +210,7 @@
if( fseek( fin, 0, SEEK_SET ) < 0 )
{
- fprintf( stderr, "fseek(0,SEEK_SET) failed\n" );
+ polarssl_fprintf( stderr, "fseek(0,SEEK_SET) failed\n" );
goto exit;
}
@@ -235,7 +246,7 @@
*/
if( fwrite( IV, 1, 16, fout ) != 16 )
{
- fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
+ polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
goto exit;
}
@@ -268,7 +279,7 @@
if( fread( buffer, 1, n, fin ) != (size_t) n )
{
- fprintf( stderr, "fread(%d bytes) failed\n", n );
+ polarssl_fprintf( stderr, "fread(%d bytes) failed\n", n );
goto exit;
}
@@ -280,7 +291,7 @@
if( fwrite( buffer, 1, 16, fout ) != 16 )
{
- fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
+ polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
goto exit;
}
@@ -294,7 +305,7 @@
if( fwrite( digest, 1, 32, fout ) != 32 )
{
- fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
+ polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
goto exit;
}
}
@@ -314,13 +325,13 @@
*/
if( filesize < 48 )
{
- fprintf( stderr, "File too short to be encrypted.\n" );
+ polarssl_fprintf( stderr, "File too short to be encrypted.\n" );
goto exit;
}
if( ( filesize & 0x0F ) != 0 )
{
- fprintf( stderr, "File size not a multiple of 16.\n" );
+ polarssl_fprintf( stderr, "File size not a multiple of 16.\n" );
goto exit;
}
@@ -334,7 +345,7 @@
*/
if( fread( buffer, 1, 16, fin ) != 16 )
{
- fprintf( stderr, "fread(%d bytes) failed\n", 16 );
+ polarssl_fprintf( stderr, "fread(%d bytes) failed\n", 16 );
goto exit;
}
@@ -367,7 +378,7 @@
{
if( fread( buffer, 1, 16, fin ) != 16 )
{
- fprintf( stderr, "fread(%d bytes) failed\n", 16 );
+ polarssl_fprintf( stderr, "fread(%d bytes) failed\n", 16 );
goto exit;
}
@@ -386,7 +397,7 @@
if( fwrite( buffer, 1, n, fout ) != (size_t) n )
{
- fprintf( stderr, "fwrite(%d bytes) failed\n", n );
+ polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", n );
goto exit;
}
}
@@ -398,7 +409,7 @@
if( fread( buffer, 1, 32, fin ) != 32 )
{
- fprintf( stderr, "fread(%d bytes) failed\n", 32 );
+ polarssl_fprintf( stderr, "fread(%d bytes) failed\n", 32 );
goto exit;
}
@@ -409,7 +420,7 @@
if( diff != 0 )
{
- fprintf( stderr, "HMAC check failed: wrong key, "
+ polarssl_fprintf( stderr, "HMAC check failed: wrong key, "
"or file corrupted.\n" );
goto exit;
}
diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c
index a904bde..7ad07b4 100644
--- a/programs/aes/crypt_and_hash.c
+++ b/programs/aes/crypt_and_hash.c
@@ -4,7 +4,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,6 +27,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#if defined(_WIN32)
#include <windows.h>
#if !defined(_WIN32_WCE)
@@ -60,7 +67,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_CIPHER_C and/or POLARSSL_MD_C not defined.\n");
+ polarssl_printf("POLARSSL_CIPHER_C and/or POLARSSL_MD_C not defined.\n");
return( 0 );
}
#else
@@ -102,28 +109,28 @@
{
const int *list;
- printf( USAGE );
+ polarssl_printf( USAGE );
- printf( "Available ciphers:\n" );
+ polarssl_printf( "Available ciphers:\n" );
list = cipher_list();
while( *list )
{
cipher_info = cipher_info_from_type( *list );
- printf( " %s\n", cipher_info->name );
+ polarssl_printf( " %s\n", cipher_info->name );
list++;
}
- printf( "\nAvailable message digests:\n" );
+ polarssl_printf( "\nAvailable message digests:\n" );
list = md_list();
while( *list )
{
md_info = md_info_from_type( *list );
- printf( " %s\n", md_info->name );
+ polarssl_printf( " %s\n", md_info->name );
list++;
}
#if defined(_WIN32)
- printf( "\n Press Enter to exit this program.\n" );
+ polarssl_printf( "\n Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
@@ -134,25 +141,25 @@
if( mode != MODE_ENCRYPT && mode != MODE_DECRYPT )
{
- fprintf( stderr, "invalid operation mode\n" );
+ polarssl_fprintf( stderr, "invalid operation mode\n" );
goto exit;
}
if( strcmp( argv[2], argv[3] ) == 0 )
{
- fprintf( stderr, "input and output filenames must differ\n" );
+ polarssl_fprintf( stderr, "input and output filenames must differ\n" );
goto exit;
}
if( ( fin = fopen( argv[2], "rb" ) ) == NULL )
{
- fprintf( stderr, "fopen(%s,rb) failed\n", argv[2] );
+ polarssl_fprintf( stderr, "fopen(%s,rb) failed\n", argv[2] );
goto exit;
}
if( ( fout = fopen( argv[3], "wb+" ) ) == NULL )
{
- fprintf( stderr, "fopen(%s,wb+) failed\n", argv[3] );
+ polarssl_fprintf( stderr, "fopen(%s,wb+) failed\n", argv[3] );
goto exit;
}
@@ -162,19 +169,19 @@
cipher_info = cipher_info_from_string( argv[4] );
if( cipher_info == NULL )
{
- fprintf( stderr, "Cipher '%s' not found\n", argv[4] );
+ polarssl_fprintf( stderr, "Cipher '%s' not found\n", argv[4] );
goto exit;
}
if( ( ret = cipher_init_ctx( &cipher_ctx, cipher_info) ) != 0 )
{
- fprintf( stderr, "cipher_init_ctx failed\n" );
+ polarssl_fprintf( stderr, "cipher_init_ctx failed\n" );
goto exit;
}
md_info = md_info_from_string( argv[5] );
if( md_info == NULL )
{
- fprintf( stderr, "Message Digest '%s' not found\n", argv[5] );
+ polarssl_fprintf( stderr, "Message Digest '%s' not found\n", argv[5] );
goto exit;
}
md_init_ctx( &md_ctx, md_info);
@@ -228,7 +235,7 @@
if( li_size.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR )
{
- fprintf( stderr, "SetFilePointer(0,FILE_END) failed\n" );
+ polarssl_fprintf( stderr, "SetFilePointer(0,FILE_END) failed\n" );
goto exit;
}
@@ -244,7 +251,7 @@
if( fseek( fin, 0, SEEK_SET ) < 0 )
{
- fprintf( stderr, "fseek(0,SEEK_SET) failed\n" );
+ polarssl_fprintf( stderr, "fseek(0,SEEK_SET) failed\n" );
goto exit;
}
@@ -280,7 +287,7 @@
*/
if( fwrite( IV, 1, 16, fout ) != 16 )
{
- fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
+ polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", 16 );
goto exit;
}
@@ -305,17 +312,17 @@
if( cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
POLARSSL_ENCRYPT ) != 0 )
{
- fprintf( stderr, "cipher_setkey() returned error\n");
+ polarssl_fprintf( stderr, "cipher_setkey() returned error\n");
goto exit;
}
if( cipher_set_iv( &cipher_ctx, IV, 16 ) != 0 )
{
- fprintf( stderr, "cipher_set_iv() returned error\n");
+ polarssl_fprintf( stderr, "cipher_set_iv() returned error\n");
goto exit;
}
if( cipher_reset( &cipher_ctx ) != 0 )
{
- fprintf( stderr, "cipher_reset() returned error\n");
+ polarssl_fprintf( stderr, "cipher_reset() returned error\n");
goto exit;
}
@@ -331,13 +338,13 @@
if( fread( buffer, 1, ilen, fin ) != ilen )
{
- fprintf( stderr, "fread(%ld bytes) failed\n", (long) ilen );
+ polarssl_fprintf( stderr, "fread(%ld bytes) failed\n", (long) ilen );
goto exit;
}
if( cipher_update( &cipher_ctx, buffer, ilen, output, &olen ) != 0 )
{
- fprintf( stderr, "cipher_update() returned error\n");
+ polarssl_fprintf( stderr, "cipher_update() returned error\n");
goto exit;
}
@@ -345,21 +352,21 @@
if( fwrite( output, 1, olen, fout ) != olen )
{
- fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
+ polarssl_fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
goto exit;
}
}
if( cipher_finish( &cipher_ctx, output, &olen ) != 0 )
{
- fprintf( stderr, "cipher_finish() returned error\n" );
+ polarssl_fprintf( stderr, "cipher_finish() returned error\n" );
goto exit;
}
md_hmac_update( &md_ctx, output, olen );
if( fwrite( output, 1, olen, fout ) != olen )
{
- fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
+ polarssl_fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
goto exit;
}
@@ -370,7 +377,7 @@
if( fwrite( digest, 1, md_get_size( md_info ), fout ) != md_get_size( md_info ) )
{
- fprintf( stderr, "fwrite(%d bytes) failed\n", md_get_size( md_info ) );
+ polarssl_fprintf( stderr, "fwrite(%d bytes) failed\n", md_get_size( md_info ) );
goto exit;
}
}
@@ -388,14 +395,14 @@
*/
if( filesize < 16 + md_get_size( md_info ) )
{
- fprintf( stderr, "File too short to be encrypted.\n" );
+ polarssl_fprintf( stderr, "File too short to be encrypted.\n" );
goto exit;
}
if( ( ( filesize - md_get_size( md_info ) ) %
cipher_get_block_size( &cipher_ctx ) ) != 0 )
{
- fprintf( stderr, "File content not a multiple of the block size (%d).\n",
+ polarssl_fprintf( stderr, "File content not a multiple of the block size (%d).\n",
cipher_get_block_size( &cipher_ctx ));
goto exit;
}
@@ -410,7 +417,7 @@
*/
if( fread( buffer, 1, 16, fin ) != 16 )
{
- fprintf( stderr, "fread(%d bytes) failed\n", 16 );
+ polarssl_fprintf( stderr, "fread(%d bytes) failed\n", 16 );
goto exit;
}
@@ -437,19 +444,19 @@
if( cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
POLARSSL_DECRYPT ) != 0 )
{
- fprintf( stderr, "cipher_setkey() returned error\n" );
+ polarssl_fprintf( stderr, "cipher_setkey() returned error\n" );
goto exit;
}
if( cipher_set_iv( &cipher_ctx, IV, 16 ) != 0 )
{
- fprintf( stderr, "cipher_set_iv() returned error\n" );
+ polarssl_fprintf( stderr, "cipher_set_iv() returned error\n" );
goto exit;
}
if( cipher_reset( &cipher_ctx ) != 0 )
{
- fprintf( stderr, "cipher_reset() returned error\n" );
+ polarssl_fprintf( stderr, "cipher_reset() returned error\n" );
goto exit;
}
@@ -463,7 +470,7 @@
if( fread( buffer, 1, cipher_get_block_size( &cipher_ctx ), fin ) !=
(size_t) cipher_get_block_size( &cipher_ctx ) )
{
- fprintf( stderr, "fread(%d bytes) failed\n",
+ polarssl_fprintf( stderr, "fread(%d bytes) failed\n",
cipher_get_block_size( &cipher_ctx ) );
goto exit;
}
@@ -473,13 +480,13 @@
cipher_get_block_size( &cipher_ctx ),
output, &olen ) != 0 )
{
- fprintf( stderr, "cipher_update() returned error\n" );
+ polarssl_fprintf( stderr, "cipher_update() returned error\n" );
goto exit;
}
if( fwrite( output, 1, olen, fout ) != olen )
{
- fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
+ polarssl_fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
goto exit;
}
}
@@ -491,7 +498,7 @@
if( fread( buffer, 1, md_get_size( md_info ), fin ) != md_get_size( md_info ) )
{
- fprintf( stderr, "fread(%d bytes) failed\n", md_get_size( md_info ) );
+ polarssl_fprintf( stderr, "fread(%d bytes) failed\n", md_get_size( md_info ) );
goto exit;
}
@@ -502,7 +509,7 @@
if( diff != 0 )
{
- fprintf( stderr, "HMAC check failed: wrong key, "
+ polarssl_fprintf( stderr, "HMAC check failed: wrong key, "
"or file corrupted.\n" );
goto exit;
}
@@ -514,7 +521,7 @@
if( fwrite( output, 1, olen, fout ) != olen )
{
- fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
+ polarssl_fprintf( stderr, "fwrite(%ld bytes) failed\n", (long) olen );
goto exit;
}
}
diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt
index 870b8a0..f7a7689 100644
--- a/programs/hash/CMakeLists.txt
+++ b/programs/hash/CMakeLists.txt
@@ -1,17 +1,17 @@
add_executable(hello hello.c)
-target_link_libraries(hello polarssl)
+target_link_libraries(hello mbedtls)
add_executable(generic_sum generic_sum.c)
-target_link_libraries(generic_sum polarssl)
+target_link_libraries(generic_sum mbedtls)
add_executable(md5sum md5sum.c)
-target_link_libraries(md5sum polarssl)
+target_link_libraries(md5sum mbedtls)
add_executable(sha1sum sha1sum.c)
-target_link_libraries(sha1sum polarssl)
+target_link_libraries(sha1sum mbedtls)
add_executable(sha2sum sha2sum.c)
-target_link_libraries(sha2sum polarssl)
+target_link_libraries(sha2sum mbedtls)
install(TARGETS hello md5sum sha1sum sha2sum generic_sum
DESTINATION "bin"
diff --git a/programs/hash/generic_sum.c b/programs/hash/generic_sum.c
index 34814d5..20ff252 100644
--- a/programs/hash/generic_sum.c
+++ b/programs/hash/generic_sum.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -37,7 +44,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_MD_C not defined.\n");
+ polarssl_printf("POLARSSL_MD_C not defined.\n");
return( 0 );
}
#else
@@ -46,10 +53,10 @@
int ret = md_file( md_info, filename, sum );
if( ret == 1 )
- fprintf( stderr, "failed to open: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to open: %s\n", filename );
if( ret == 2 )
- fprintf( stderr, "failed to read: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to read: %s\n", filename );
return( ret );
}
@@ -63,9 +70,9 @@
return( 1 );
for( i = 0; i < md_info->size; i++ )
- printf( "%02x", sum[i] );
+ polarssl_printf( "%02x", sum[i] );
- printf( " %s\n", filename );
+ polarssl_printf( " %s\n", filename );
return( 0 );
}
@@ -82,7 +89,7 @@
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
- printf( "failed to open: %s\n", filename );
+ polarssl_printf( "failed to open: %s\n", filename );
return( 1 );
}
@@ -99,13 +106,13 @@
if( n < (size_t) 2 * md_info->size + 4 )
{
- printf("No '%s' hash found on line.\n", md_info->name);
+ polarssl_printf("No '%s' hash found on line.\n", md_info->name);
continue;
}
if( line[2 * md_info->size] != ' ' || line[2 * md_info->size + 1] != ' ' )
{
- printf("No '%s' hash found on line.\n", md_info->name);
+ polarssl_printf("No '%s' hash found on line.\n", md_info->name);
continue;
}
@@ -133,7 +140,7 @@
if( diff != 0 )
{
nb_err2++;
- fprintf( stderr, "wrong checksum: %s\n", line + 66 );
+ polarssl_fprintf( stderr, "wrong checksum: %s\n", line + 66 );
}
n = sizeof( line );
@@ -141,13 +148,13 @@
if( nb_err1 != 0 )
{
- printf( "WARNING: %d (out of %d) input files could "
+ polarssl_printf( "WARNING: %d (out of %d) input files could "
"not be read\n", nb_err1, nb_tot1 );
}
if( nb_err2 != 0 )
{
- printf( "WARNING: %d (out of %d) computed checksums did "
+ polarssl_printf( "WARNING: %d (out of %d) computed checksums did "
"not match\n", nb_err2, nb_tot2 );
}
@@ -168,20 +175,20 @@
{
const int *list;
- printf( "print mode: generic_sum <md> <file> <file> ...\n" );
- printf( "check mode: generic_sum <md> -c <checksum file>\n" );
+ polarssl_printf( "print mode: generic_sum <md> <file> <file> ...\n" );
+ polarssl_printf( "check mode: generic_sum <md> -c <checksum file>\n" );
- printf( "\nAvailable message digests:\n" );
+ polarssl_printf( "\nAvailable message digests:\n" );
list = md_list();
while( *list )
{
md_info = md_info_from_type( *list );
- printf( " %s\n", md_info->name );
+ polarssl_printf( " %s\n", md_info->name );
list++;
}
#if defined(_WIN32)
- printf( "\n Press Enter to exit this program.\n" );
+ polarssl_printf( "\n Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
@@ -194,12 +201,12 @@
md_info = md_info_from_string( argv[1] );
if( md_info == NULL )
{
- fprintf( stderr, "Message Digest '%s' not found\n", argv[1] );
+ polarssl_fprintf( stderr, "Message Digest '%s' not found\n", argv[1] );
return( 1 );
}
if( md_init_ctx( &md_ctx, md_info) )
{
- fprintf( stderr, "Failed to initialize context.\n" );
+ polarssl_fprintf( stderr, "Failed to initialize context.\n" );
return( 1 );
}
diff --git a/programs/hash/hello.c b/programs/hash/hello.c
index 743b66a..7c0546e 100644
--- a/programs/hash/hello.c
+++ b/programs/hash/hello.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <stdio.h>
#include "polarssl/md5.h"
@@ -36,7 +42,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_MD5_C not defined.\n");
+ polarssl_printf("POLARSSL_MD5_C not defined.\n");
return( 0 );
}
#else
@@ -49,17 +55,17 @@
((void) argc);
((void) argv);
- printf( "\n MD5('%s') = ", str );
+ polarssl_printf( "\n MD5('%s') = ", str );
md5( (unsigned char *) str, 13, digest );
for( i = 0; i < 16; i++ )
- printf( "%02x", digest[i] );
+ polarssl_printf( "%02x", digest[i] );
- printf( "\n\n" );
+ polarssl_printf( "\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/hash/md5sum.c b/programs/hash/md5sum.c
index 49dddd4..58c2d0c 100644
--- a/programs/hash/md5sum.c
+++ b/programs/hash/md5sum.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -37,7 +44,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_MD5_C and/or POLARSSL_FS_IO not defined.\n");
+ polarssl_printf("POLARSSL_MD5_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
@@ -46,10 +53,10 @@
int ret = md5_file( filename, sum );
if( ret == 1 )
- fprintf( stderr, "failed to open: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to open: %s\n", filename );
if( ret == 2 )
- fprintf( stderr, "failed to read: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to read: %s\n", filename );
return( ret );
}
@@ -63,9 +70,9 @@
return( 1 );
for( i = 0; i < 16; i++ )
- printf( "%02x", sum[i] );
+ polarssl_printf( "%02x", sum[i] );
- printf( " %s\n", filename );
+ polarssl_printf( " %s\n", filename );
return( 0 );
}
@@ -82,7 +89,7 @@
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
- printf( "failed to open: %s\n", filename );
+ polarssl_printf( "failed to open: %s\n", filename );
return( 1 );
}
@@ -127,7 +134,7 @@
if( diff != 0 )
{
nb_err2++;
- fprintf( stderr, "wrong checksum: %s\n", line + 34 );
+ polarssl_fprintf( stderr, "wrong checksum: %s\n", line + 34 );
}
n = sizeof( line );
@@ -137,13 +144,13 @@
if( nb_err1 != 0 )
{
- printf( "WARNING: %d (out of %d) input files could "
+ polarssl_printf( "WARNING: %d (out of %d) input files could "
"not be read\n", nb_err1, nb_tot1 );
}
if( nb_err2 != 0 )
{
- printf( "WARNING: %d (out of %d) computed checksums did "
+ polarssl_printf( "WARNING: %d (out of %d) computed checksums did "
"not match\n", nb_err2, nb_tot2 );
}
@@ -156,11 +163,11 @@
if( argc == 1 )
{
- printf( "print mode: md5sum <file> <file> ...\n" );
- printf( "check mode: md5sum -c <checksum file>\n" );
+ polarssl_printf( "print mode: md5sum <file> <file> ...\n" );
+ polarssl_printf( "check mode: md5sum -c <checksum file>\n" );
#if defined(_WIN32)
- printf( "\n Press Enter to exit this program.\n" );
+ polarssl_printf( "\n Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
diff --git a/programs/hash/sha1sum.c b/programs/hash/sha1sum.c
index 1fc1b00..3eafc4f 100644
--- a/programs/hash/sha1sum.c
+++ b/programs/hash/sha1sum.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -37,7 +44,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
+ polarssl_printf("POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
@@ -46,10 +53,10 @@
int ret = sha1_file( filename, sum );
if( ret == 1 )
- fprintf( stderr, "failed to open: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to open: %s\n", filename );
if( ret == 2 )
- fprintf( stderr, "failed to read: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to read: %s\n", filename );
return( ret );
}
@@ -63,9 +70,9 @@
return( 1 );
for( i = 0; i < 20; i++ )
- printf( "%02x", sum[i] );
+ polarssl_printf( "%02x", sum[i] );
- printf( " %s\n", filename );
+ polarssl_printf( " %s\n", filename );
return( 0 );
}
@@ -82,7 +89,7 @@
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
- printf( "failed to open: %s\n", filename );
+ polarssl_printf( "failed to open: %s\n", filename );
return( 1 );
}
@@ -127,7 +134,7 @@
if( diff != 0 )
{
nb_err2++;
- fprintf( stderr, "wrong checksum: %s\n", line + 42 );
+ polarssl_fprintf( stderr, "wrong checksum: %s\n", line + 42 );
}
n = sizeof( line );
@@ -137,13 +144,13 @@
if( nb_err1 != 0 )
{
- printf( "WARNING: %d (out of %d) input files could "
+ polarssl_printf( "WARNING: %d (out of %d) input files could "
"not be read\n", nb_err1, nb_tot1 );
}
if( nb_err2 != 0 )
{
- printf( "WARNING: %d (out of %d) computed checksums did "
+ polarssl_printf( "WARNING: %d (out of %d) computed checksums did "
"not match\n", nb_err2, nb_tot2 );
}
@@ -156,11 +163,11 @@
if( argc == 1 )
{
- printf( "print mode: sha1sum <file> <file> ...\n" );
- printf( "check mode: sha1sum -c <checksum file>\n" );
+ polarssl_printf( "print mode: sha1sum <file> <file> ...\n" );
+ polarssl_printf( "check mode: sha1sum -c <checksum file>\n" );
#if defined(_WIN32)
- printf( "\n Press Enter to exit this program.\n" );
+ polarssl_printf( "\n Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
diff --git a/programs/hash/sha2sum.c b/programs/hash/sha2sum.c
index 72e17c9..3fc1baa 100644
--- a/programs/hash/sha2sum.c
+++ b/programs/hash/sha2sum.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -37,7 +44,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_SHA256_C and/or POLARSSL_FS_IO not defined.\n");
+ polarssl_printf("POLARSSL_SHA256_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
@@ -46,10 +53,10 @@
int ret = sha256_file( filename, sum, 0 );
if( ret == 1 )
- fprintf( stderr, "failed to open: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to open: %s\n", filename );
if( ret == 2 )
- fprintf( stderr, "failed to read: %s\n", filename );
+ polarssl_fprintf( stderr, "failed to read: %s\n", filename );
return( ret );
}
@@ -63,9 +70,9 @@
return( 1 );
for( i = 0; i < 32; i++ )
- printf( "%02x", sum[i] );
+ polarssl_printf( "%02x", sum[i] );
- printf( " %s\n", filename );
+ polarssl_printf( " %s\n", filename );
return( 0 );
}
@@ -82,7 +89,7 @@
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
- printf( "failed to open: %s\n", filename );
+ polarssl_printf( "failed to open: %s\n", filename );
return( 1 );
}
@@ -127,7 +134,7 @@
if( diff != 0 )
{
nb_err2++;
- fprintf( stderr, "wrong checksum: %s\n", line + 66 );
+ polarssl_fprintf( stderr, "wrong checksum: %s\n", line + 66 );
}
n = sizeof( line );
@@ -137,13 +144,13 @@
if( nb_err1 != 0 )
{
- printf( "WARNING: %d (out of %d) input files could "
+ polarssl_printf( "WARNING: %d (out of %d) input files could "
"not be read\n", nb_err1, nb_tot1 );
}
if( nb_err2 != 0 )
{
- printf( "WARNING: %d (out of %d) computed checksums did "
+ polarssl_printf( "WARNING: %d (out of %d) computed checksums did "
"not match\n", nb_err2, nb_tot2 );
}
@@ -156,11 +163,11 @@
if( argc == 1 )
{
- printf( "print mode: sha256sum <file> <file> ...\n" );
- printf( "check mode: sha256sum -c <checksum file>\n" );
+ polarssl_printf( "print mode: sha256sum <file> <file> ...\n" );
+ polarssl_printf( "check mode: sha256sum -c <checksum file>\n" );
#if defined(_WIN32)
- printf( "\n Press Enter to exit this program.\n" );
+ polarssl_printf( "\n Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif
diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt
index 291ff99..8dc7def 100644
--- a/programs/pkey/CMakeLists.txt
+++ b/programs/pkey/CMakeLists.txt
@@ -1,59 +1,59 @@
add_executable(dh_client dh_client.c)
-target_link_libraries(dh_client polarssl)
+target_link_libraries(dh_client mbedtls)
add_executable(dh_genprime dh_genprime.c)
-target_link_libraries(dh_genprime polarssl)
+target_link_libraries(dh_genprime mbedtls)
add_executable(dh_server dh_server.c)
-target_link_libraries(dh_server polarssl)
+target_link_libraries(dh_server mbedtls)
add_executable(ecdsa ecdsa.c)
-target_link_libraries(ecdsa polarssl)
+target_link_libraries(ecdsa mbedtls)
add_executable(gen_key gen_key.c)
-target_link_libraries(gen_key polarssl)
+target_link_libraries(gen_key mbedtls)
add_executable(key_app key_app.c)
-target_link_libraries(key_app polarssl)
+target_link_libraries(key_app mbedtls)
add_executable(key_app_writer key_app_writer.c)
-target_link_libraries(key_app_writer polarssl)
+target_link_libraries(key_app_writer mbedtls)
add_executable(mpi_demo mpi_demo.c)
-target_link_libraries(mpi_demo polarssl)
+target_link_libraries(mpi_demo mbedtls)
add_executable(rsa_genkey rsa_genkey.c)
-target_link_libraries(rsa_genkey polarssl)
+target_link_libraries(rsa_genkey mbedtls)
add_executable(rsa_sign rsa_sign.c)
-target_link_libraries(rsa_sign polarssl)
+target_link_libraries(rsa_sign mbedtls)
add_executable(rsa_verify rsa_verify.c)
-target_link_libraries(rsa_verify polarssl)
+target_link_libraries(rsa_verify mbedtls)
add_executable(rsa_sign_pss rsa_sign_pss.c)
-target_link_libraries(rsa_sign_pss polarssl)
+target_link_libraries(rsa_sign_pss mbedtls)
add_executable(rsa_verify_pss rsa_verify_pss.c)
-target_link_libraries(rsa_verify_pss polarssl)
+target_link_libraries(rsa_verify_pss mbedtls)
add_executable(rsa_encrypt rsa_encrypt.c)
-target_link_libraries(rsa_encrypt polarssl)
+target_link_libraries(rsa_encrypt mbedtls)
add_executable(rsa_decrypt rsa_decrypt.c)
-target_link_libraries(rsa_decrypt polarssl)
+target_link_libraries(rsa_decrypt mbedtls)
add_executable(pk_sign pk_sign.c)
-target_link_libraries(pk_sign polarssl)
+target_link_libraries(pk_sign mbedtls)
add_executable(pk_verify pk_verify.c)
-target_link_libraries(pk_verify polarssl)
+target_link_libraries(pk_verify mbedtls)
add_executable(pk_encrypt pk_encrypt.c)
-target_link_libraries(pk_encrypt polarssl)
+target_link_libraries(pk_encrypt mbedtls)
add_executable(pk_decrypt pk_decrypt.c)
-target_link_libraries(pk_decrypt polarssl)
+target_link_libraries(pk_decrypt mbedtls)
install(TARGETS dh_client dh_genprime dh_server key_app mpi_demo rsa_genkey rsa_sign rsa_verify rsa_encrypt rsa_decrypt pk_encrypt pk_decrypt pk_sign pk_verify gen_key
DESTINATION "bin"
diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c
index 02511c6..a34bafa 100644
--- a/programs/pkey/dh_client.c
+++ b/programs/pkey/dh_client.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -49,7 +55,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 +91,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 +99,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 +122,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 +133,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, NET_PROTO_TCP ) ) != 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 +172,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 +180,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 +195,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 +203,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 +212,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 +261,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 +270,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 +290,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..720232f 100644
--- a/programs/pkey/dh_genprime.c
+++ b/programs/pkey/dh_genprime.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2012, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <stdio.h>
#include "polarssl/bignum.h"
@@ -47,7 +53,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 +76,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 +109,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 +161,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 3259e09..f21e578 100644
--- a/programs/pkey/dh_server.c
+++ b/programs/pkey/dh_server.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -49,7 +55,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 +92,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 +100,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 +129,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 +140,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 +154,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 +163,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, NET_PROTO_TCP ) ) != 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 +189,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 +204,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 +215,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 +230,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 +264,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 +273,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 +291,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..b533673 100644
--- a/programs/pkey/ecdsa.c
+++ b/programs/pkey/ecdsa.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
#include "polarssl/ecdsa.h"
@@ -54,7 +60,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 +71,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 +86,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 +117,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 +129,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 +137,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 +166,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 +190,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 +210,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..2d981ab 100644
--- a/programs/pkey/gen_key.c
+++ b/programs/pkey/gen_key.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -49,7 +55,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 +210,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 +280,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 +290,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 +303,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 +326,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 +339,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 +374,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 +382,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 +403,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 +414,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..04bad87 100644
--- a/programs/pkey/key_app.c
+++ b/programs/pkey/key_app.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -41,7 +47,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 +100,7 @@
if( argc == 0 )
{
usage:
- printf( USAGE );
+ polarssl_printf( USAGE );
goto exit;
}
@@ -133,7 +139,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 +147,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 +170,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 +214,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 +223,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 +257,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 +268,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..c9830c2 100644
--- a/programs/pkey/key_app_writer.c
+++ b/programs/pkey/key_app_writer.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -40,7 +46,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 +207,7 @@
{
usage:
ret = 1;
- printf( USAGE );
+ polarssl_printf( USAGE );
goto exit;
}
@@ -258,13 +264,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 +279,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 +287,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 +324,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 +332,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 +340,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 +370,7 @@
}
else
#endif
- printf("key type not supported yet\n");
+ polarssl_printf("key type not supported yet\n");
}
else
goto usage;
@@ -384,16 +390,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..b5ae13e 100644
--- a/programs/pkey/mpi_demo.c
+++ b/programs/pkey/mpi_demo.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <stdio.h>
#include "polarssl/bignum.h"
@@ -36,7 +42,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 +62,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 +79,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..8644698 100644
--- a/programs/pkey/pk_decrypt.c
+++ b/programs/pkey/pk_decrypt.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -42,7 +48,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 +72,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 +89,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 +111,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 +126,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 +148,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..663c2ee 100644
--- a/programs/pkey/pk_encrypt.c
+++ b/programs/pkey/pk_encrypt.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -42,7 +49,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 +71,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 +88,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 +114,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 +131,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 +149,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..981591d 100644
--- a/programs/pkey/pk_sign.c
+++ b/programs/pkey/pk_sign.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -49,7 +55,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 +80,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 +114,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 +138,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 +159,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..0ce45f6 100644
--- a/programs/pkey/pk_verify.c
+++ b/programs/pkey/pk_verify.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -46,7 +52,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 +72,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 +98,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 +111,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 +136,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..8df5f00 100644
--- a/programs/pkey/rsa_decrypt.c
+++ b/programs/pkey/rsa_decrypt.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -41,7 +47,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 +71,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 +88,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 +113,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 +128,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 +142,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 +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_encrypt.c b/programs/pkey/rsa_encrypt.c
index 69ffbcd..58817e3 100644
--- a/programs/pkey/rsa_encrypt.c
+++ b/programs/pkey/rsa_encrypt.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -41,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_ENTROPY_C and/or POLARSSL_FS_IO and/or "
"POLARSSL_CTR_DRBG_C not defined.\n");
return( 0 );
@@ -63,16 +70,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 +87,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 +107,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 +117,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 +126,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 +143,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..ff31598 100644
--- a/programs/pkey/rsa_genkey.c
+++ b/programs/pkey/rsa_genkey.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <stdio.h>
#include "polarssl/entropy.h"
@@ -45,7 +51,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 +70,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 +78,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 +90,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 +107,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 +130,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 +146,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 +161,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..e4f4970 100644
--- a/programs/pkey/rsa_sign.c
+++ b/programs/pkey/rsa_sign.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -39,7 +46,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 +64,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 +95,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 +103,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 +115,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 +139,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..e022db2 100644
--- a/programs/pkey/rsa_sign_pss.c
+++ b/programs/pkey/rsa_sign_pss.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -49,7 +55,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 +80,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 +124,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 +148,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 +168,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..6ff16e4 100644
--- a/programs/pkey/rsa_verify.c
+++ b/programs/pkey/rsa_verify.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -39,7 +45,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 +62,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 +86,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 +103,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 +117,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 +125,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..3ffdfbe 100644
--- a/programs/pkey/rsa_verify_pss.c
+++ b/programs/pkey/rsa_verify_pss.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -47,7 +53,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 +73,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 +109,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 +122,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 +146,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
diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt
index ae02bd1..30933d8 100644
--- a/programs/random/CMakeLists.txt
+++ b/programs/random/CMakeLists.txt
@@ -1,11 +1,11 @@
add_executable(gen_random_havege gen_random_havege.c)
-target_link_libraries(gen_random_havege polarssl)
+target_link_libraries(gen_random_havege mbedtls)
add_executable(gen_random_ctr_drbg gen_random_ctr_drbg.c)
-target_link_libraries(gen_random_ctr_drbg polarssl)
+target_link_libraries(gen_random_ctr_drbg mbedtls)
add_executable(gen_entropy gen_entropy.c)
-target_link_libraries(gen_entropy polarssl)
+target_link_libraries(gen_entropy mbedtls)
install(TARGETS gen_random_havege gen_random_ctr_drbg gen_entropy
DESTINATION "bin"
diff --git a/programs/random/gen_entropy.c b/programs/random/gen_entropy.c
index 38bd423..29e7e2f 100644
--- a/programs/random/gen_entropy.c
+++ b/programs/random/gen_entropy.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include "polarssl/entropy.h"
#include <stdio.h>
@@ -36,7 +43,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_ENTROPY_C not defined.\n");
+ polarssl_printf("POLARSSL_ENTROPY_C not defined.\n");
return( 0 );
}
#else
@@ -49,13 +56,13 @@
if( argc < 2 )
{
- fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
+ polarssl_fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
return( 1 );
}
if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
{
- printf( "failed to open '%s' for writing.\n", argv[0] );
+ polarssl_printf( "failed to open '%s' for writing.\n", argv[1] );
return( 1 );
}
@@ -66,20 +73,21 @@
ret = entropy_func( &entropy, buf, sizeof( buf ) );
if( ret != 0 )
{
- printf("failed!\n");
+ polarssl_printf("failed!\n");
goto cleanup;
}
fwrite( buf, 1, sizeof( buf ), f );
- printf( "Generating 32Mb of data in file '%s'... %04.1f" \
- "%% done\r", argv[1], (100 * (float) (i + 1)) / k );
+ polarssl_printf( "Generating %ldkb of data in file '%s'... %04.1f" \
+ "%% done\r", (long)(sizeof(buf) * k / 1024), argv[1], (100 * (float) (i + 1)) / k );
fflush( stdout );
}
ret = 0;
cleanup:
+ printf( "\n" );
fclose( f );
entropy_free( &entropy );
diff --git a/programs/random/gen_random_ctr_drbg.c b/programs/random/gen_random_ctr_drbg.c
index 6751607..c21e094 100644
--- a/programs/random/gen_random_ctr_drbg.c
+++ b/programs/random/gen_random_ctr_drbg.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
@@ -37,7 +44,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_CTR_DRBG_C or POLARSSL_ENTROPY_C not defined.\n");
+ polarssl_printf("POLARSSL_CTR_DRBG_C or POLARSSL_ENTROPY_C not defined.\n");
return( 0 );
}
#else
@@ -51,13 +58,13 @@
if( argc < 2 )
{
- fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
+ polarssl_fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
return( 1 );
}
if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
{
- printf( "failed to open '%s' for writing.\n", argv[0] );
+ polarssl_printf( "failed to open '%s' for writing.\n", argv[1] );
return( 1 );
}
@@ -65,7 +72,7 @@
ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy, (const unsigned char *) "RANDOM_GEN", 10 );
if( ret != 0 )
{
- printf( "failed in ctr_drbg_init: %d\n", ret );
+ polarssl_printf( "failed in ctr_drbg_init: %d\n", ret );
goto cleanup;
}
ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_OFF );
@@ -75,17 +82,17 @@
if( ret == POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR )
{
- printf( "Failed to open seedfile. Generating one.\n" );
+ polarssl_printf( "Failed to open seedfile. Generating one.\n" );
ret = ctr_drbg_write_seed_file( &ctr_drbg, "seedfile" );
if( ret != 0 )
{
- printf( "failed in ctr_drbg_write_seed_file: %d\n", ret );
+ polarssl_printf( "failed in ctr_drbg_write_seed_file: %d\n", ret );
goto cleanup;
}
}
else if( ret != 0 )
{
- printf( "failed in ctr_drbg_update_seed_file: %d\n", ret );
+ polarssl_printf( "failed in ctr_drbg_update_seed_file: %d\n", ret );
goto cleanup;
}
#endif
@@ -95,21 +102,21 @@
ret = ctr_drbg_random( &ctr_drbg, buf, sizeof( buf ) );
if( ret != 0 )
{
- printf("failed!\n");
+ polarssl_printf("failed!\n");
goto cleanup;
}
fwrite( buf, 1, sizeof( buf ), f );
- printf( "Generating 32Mb of data in file '%s'... %04.1f" \
- "%% done\r", argv[1], (100 * (float) (i + 1)) / k );
+ polarssl_printf( "Generating %ldkb of data in file '%s'... %04.1f" \
+ "%% done\r", (long)(sizeof(buf) * k / 1024), argv[1], (100 * (float) (i + 1)) / k );
fflush( stdout );
}
ret = 0;
cleanup:
- printf("\n");
+ polarssl_printf("\n");
fclose( f );
ctr_drbg_free( &ctr_drbg );
diff --git a/programs/random/gen_random_havege.c b/programs/random/gen_random_havege.c
index eba93dd..5336fc4 100644
--- a/programs/random/gen_random_havege.c
+++ b/programs/random/gen_random_havege.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include "polarssl/havege.h"
#include <time.h>
@@ -37,7 +44,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_HAVEGE_C not defined.\n");
+ polarssl_printf("POLARSSL_HAVEGE_C not defined.\n");
return( 0 );
}
#else
@@ -51,13 +58,13 @@
if( argc < 2 )
{
- fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
+ polarssl_fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
return( 1 );
}
if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
{
- printf( "failed to open '%s' for writing.\n", argv[0] );
+ polarssl_printf( "failed to open '%s' for writing.\n", argv[1] );
return( 1 );
}
@@ -69,7 +76,7 @@
{
if( havege_random( &hs, buf, sizeof( buf ) ) != 0 )
{
- printf( "Failed to get random from source.\n" );
+ polarssl_printf( "Failed to get random from source.\n" );
ret = 1;
goto exit;
@@ -77,15 +84,15 @@
fwrite( buf, sizeof( buf ), 1, f );
- printf( "Generating 32Mb of data in file '%s'... %04.1f" \
- "%% done\r", argv[1], (100 * (float) (i + 1)) / k );
+ polarssl_printf( "Generating %ldkb of data in file '%s'... %04.1f" \
+ "%% done\r", (long)(sizeof(buf) * k / 1024), argv[1], (100 * (float) (i + 1)) / k );
fflush( stdout );
}
if( t == time( NULL ) )
t--;
- printf(" \n ");
+ polarssl_printf(" \n ");
exit:
havege_free( &hs );
diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt
index 9872869..a608687 100644
--- a/programs/ssl/CMakeLists.txt
+++ b/programs/ssl/CMakeLists.txt
@@ -2,7 +2,7 @@
find_package(Threads)
set(libs
- polarssl
+ mbedtls
)
set(targets
diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c
index b0e66d4..d0bc7f5 100644
--- a/programs/ssl/ssl_client1.c
+++ b/programs/ssl/ssl_client1.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -46,7 +53,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_CLI_C and/or "
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C "
@@ -65,7 +72,7 @@
{
((void) level);
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
@@ -93,7 +100,7 @@
memset( &ssl, 0, sizeof( ssl_context ) );
x509_crt_init( &cacert );
- printf( "\n . Seeding the random number generator..." );
+ polarssl_printf( "\n . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
@@ -101,16 +108,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( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 0. Initialize certificates
*/
- printf( " . Loading the CA root certificate ..." );
+ polarssl_printf( " . Loading the CA root certificate ..." );
fflush( stdout );
#if defined(POLARSSL_CERTS_C)
@@ -118,46 +125,46 @@
strlen( test_ca_list ) );
#else
ret = 1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
#endif
if( ret < 0 )
{
- printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok (%d skipped)\n", ret );
+ polarssl_printf( " ok (%d skipped)\n", ret );
/*
* 1. Start the connection
*/
- printf( " . Connecting to tcp/%s/%4d...", SERVER_NAME,
+ polarssl_printf( " . Connecting to tcp/%s/%4d...", SERVER_NAME,
SERVER_PORT );
fflush( stdout );
if( ( ret = net_connect( &server_fd, SERVER_NAME,
SERVER_PORT, NET_PROTO_TCP ) ) != 0 )
{
- printf( " failed\n ! net_connect returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! net_connect returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 2. Setup stuff
*/
- printf( " . Setting up the SSL/TLS structure..." );
+ polarssl_printf( " . Setting up the SSL/TLS structure..." );
fflush( stdout );
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_init returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_init returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
/* OPTIONAL is not optimal for security,
@@ -178,51 +185,51 @@
/*
* 4. Handshake
*/
- printf( " . Performing the SSL/TLS handshake..." );
+ polarssl_printf( " . Performing the SSL/TLS handshake..." );
fflush( stdout );
while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_handshake returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_handshake returned -0x%x\n\n", -ret );
goto exit;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 5. Verify the server certificate
*/
- printf( " . Verifying peer X.509 certificate..." );
+ polarssl_printf( " . Verifying peer X.509 certificate..." );
/* In real life, we may want to bail out when ret != 0 */
if( ( ret = ssl_get_verify_result( &ssl ) ) != 0 )
{
- printf( " failed\n" );
+ polarssl_printf( " failed\n" );
if( ( ret & BADCERT_EXPIRED ) != 0 )
- printf( " ! server certificate has expired\n" );
+ polarssl_printf( " ! server certificate has expired\n" );
if( ( ret & BADCERT_REVOKED ) != 0 )
- printf( " ! server certificate has been revoked\n" );
+ polarssl_printf( " ! server certificate has been revoked\n" );
if( ( ret & BADCERT_CN_MISMATCH ) != 0 )
- printf( " ! CN mismatch (expected CN=%s)\n", "PolarSSL Server 1" );
+ polarssl_printf( " ! CN mismatch (expected CN=%s)\n", "PolarSSL Server 1" );
if( ( ret & BADCERT_NOT_TRUSTED ) != 0 )
- printf( " ! self-signed or not signed by a trusted CA\n" );
+ polarssl_printf( " ! self-signed or not signed by a trusted CA\n" );
- printf( "\n" );
+ polarssl_printf( "\n" );
}
else
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 3. Write the GET request
*/
- printf( " > Write to server:" );
+ polarssl_printf( " > Write to server:" );
fflush( stdout );
len = sprintf( (char *) buf, GET_REQUEST );
@@ -231,18 +238,18 @@
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_write returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto exit;
}
}
len = ret;
- printf( " %d bytes written\n\n%s", len, (char *) buf );
+ polarssl_printf( " %d bytes written\n\n%s", len, (char *) buf );
/*
* 7. Read the HTTP response
*/
- printf( " < Read from server:" );
+ polarssl_printf( " < Read from server:" );
fflush( stdout );
do
@@ -259,18 +266,18 @@
if( ret < 0 )
{
- printf( "failed\n ! ssl_read returned %d\n\n", ret );
+ polarssl_printf( "failed\n ! ssl_read returned %d\n\n", ret );
break;
}
if( ret == 0 )
{
- printf( "\n\nEOF\n\n" );
+ polarssl_printf( "\n\nEOF\n\n" );
break;
}
len = ret;
- printf( " %d bytes read\n\n%s", len, (char *) buf );
+ polarssl_printf( " %d bytes read\n\n%s", len, (char *) buf );
}
while( 1 );
@@ -283,7 +290,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf("Last error was: %d - %s\n\n", ret, error_buf );
+ polarssl_printf("Last error was: %d - %s\n\n", ret, error_buf );
}
#endif
@@ -298,7 +305,7 @@
memset( &ssl, 0, sizeof( ssl ) );
#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/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 6f529fa..3af8034 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#if !defined(POLARSSL_ENTROPY_C) || \
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
!defined(POLARSSL_NET_C) || !defined(POLARSSL_CTR_DRBG_C)
@@ -35,7 +42,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_ENTROPY_C and/or "
+ polarssl_printf("POLARSSL_ENTROPY_C and/or "
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
"POLARSSL_NET_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
return( 0 );
@@ -155,7 +162,7 @@
{
((void) level);
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
@@ -206,33 +213,33 @@
char buf[1024];
((void) data);
- printf( "\nVerify requested for (Depth %d):\n", depth );
+ polarssl_printf( "\nVerify requested for (Depth %d):\n", depth );
x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
- printf( "%s", buf );
+ polarssl_printf( "%s", buf );
if( ( (*flags) & BADCERT_EXPIRED ) != 0 )
- printf( " ! server certificate has expired\n" );
+ polarssl_printf( " ! server certificate has expired\n" );
if( ( (*flags) & BADCERT_REVOKED ) != 0 )
- printf( " ! server certificate has been revoked\n" );
+ polarssl_printf( " ! server certificate has been revoked\n" );
if( ( (*flags) & BADCERT_CN_MISMATCH ) != 0 )
- printf( " ! CN mismatch\n" );
+ polarssl_printf( " ! CN mismatch\n" );
if( ( (*flags) & BADCERT_NOT_TRUSTED ) != 0 )
- printf( " ! self-signed or not signed by a trusted CA\n" );
+ polarssl_printf( " ! self-signed or not signed by a trusted CA\n" );
if( ( (*flags) & BADCRL_NOT_TRUSTED ) != 0 )
- printf( " ! CRL not trusted\n" );
+ polarssl_printf( " ! CRL not trusted\n" );
if( ( (*flags) & BADCRL_EXPIRED ) != 0 )
- printf( " ! CRL expired\n" );
+ polarssl_printf( " ! CRL expired\n" );
if( ( (*flags) & BADCERT_OTHER ) != 0 )
- printf( " ! other (unknown) flag\n" );
+ polarssl_printf( " ! other (unknown) flag\n" );
if ( ( *flags ) == 0 )
- printf( " This certificate has no flags\n" );
+ polarssl_printf( " This certificate has no flags\n" );
return( 0 );
}
@@ -363,7 +370,7 @@
"\n" \
USAGE_DTLS \
"\n" \
- " auth_mode=%%s default: \"optional\"\n" \
+ " auth_mode=%%s default: \"required\"\n" \
" options: none, optional, required\n" \
USAGE_IO \
"\n" \
@@ -388,8 +395,6 @@
" arc4=%%d default: 0 (disabled)\n" \
" force_version=%%s default: \"\" (none)\n" \
" options: ssl3, tls1, tls1_1, tls1_2, dtls1, dtls1_2\n" \
- " auth_mode=%%s default: \"required\"\n" \
- " options: none, optional, required\n" \
"\n" \
" force_ciphersuite=<name> default: all enabled\n"\
" acceptable ciphersuite names:\n"
@@ -440,19 +445,19 @@
if( ret == 0 )
ret = 1;
- printf( USAGE );
+ polarssl_printf( USAGE );
list = ssl_list_ciphersuites();
while( *list )
{
- printf(" %-42s", ssl_get_ciphersuite_name( *list ) );
+ polarssl_printf(" %-42s", ssl_get_ciphersuite_name( *list ) );
list++;
if( !*list )
break;
- 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;
}
@@ -789,14 +794,14 @@
if( opt.max_version != -1 &&
ciphersuite_info->min_minor_ver > opt.max_version )
{
- printf("forced ciphersuite not allowed with this protocol version\n");
+ polarssl_printf("forced ciphersuite not allowed with this protocol version\n");
ret = 2;
goto usage;
}
if( opt.min_version != -1 &&
ciphersuite_info->max_minor_ver < opt.min_version )
{
- printf("forced ciphersuite not allowed with this protocol version\n");
+ polarssl_printf("forced ciphersuite not allowed with this protocol version\n");
ret = 2;
goto usage;
}
@@ -829,7 +834,7 @@
if( strlen( opt.psk ) % 2 != 0 )
{
- printf("pre-shared key not valid hex\n");
+ polarssl_printf("pre-shared key not valid hex\n");
goto exit;
}
@@ -846,7 +851,7 @@
c -= 'A' - 10;
else
{
- printf("pre-shared key not valid hex\n");
+ polarssl_printf("pre-shared key not valid hex\n");
goto exit;
}
psk[ j / 2 ] = c << 4;
@@ -860,7 +865,7 @@
c -= 'A' - 10;
else
{
- printf("pre-shared key not valid hex\n");
+ polarssl_printf("pre-shared key not valid hex\n");
goto exit;
}
psk[ j / 2 ] |= c;
@@ -891,7 +896,7 @@
/*
* 0. Initialize the RNG and the session data
*/
- printf( "\n . Seeding the random number generator..." );
+ polarssl_printf( "\n . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
@@ -899,17 +904,17 @@
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
- printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret );
+ polarssl_printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
#if defined(POLARSSL_X509_CRT_PARSE_C)
/*
* 1.1. Load the trusted CA
*/
- printf( " . Loading the CA root certificate ..." );
+ polarssl_printf( " . Loading the CA root certificate ..." );
fflush( stdout );
#if defined(POLARSSL_FS_IO)
@@ -931,23 +936,23 @@
#else
{
ret = 1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
}
#endif
if( ret < 0 )
{
- printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok (%d skipped)\n", ret );
+ polarssl_printf( " ok (%d skipped)\n", ret );
/*
* 1.2. Load own certificate and private key
*
* (can be skipped if client authentication is not required)
*/
- printf( " . Loading the client cert. and key..." );
+ polarssl_printf( " . Loading the client cert. and key..." );
fflush( stdout );
#if defined(POLARSSL_FS_IO)
@@ -964,12 +969,12 @@
#else
{
ret = 1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
}
#endif
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
goto exit;
}
@@ -987,16 +992,16 @@
#else
{
ret = 1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
}
#endif
if( ret != 0 )
{
- printf( " failed\n ! pk_parse_key returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! pk_parse_key returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
#endif /* POLARSSL_X509_CRT_PARSE_C */
/*
@@ -1005,7 +1010,7 @@
if( opt.server_addr == NULL)
opt.server_addr = opt.server_name;
- printf( " . Connecting to %s/%s/%-4d...",
+ polarssl_printf( " . Connecting to %s/%s/%-4d...",
opt.transport == SSL_TRANSPORT_STREAM ? "tcp" : "udp",
opt.server_addr, opt.server_port );
fflush( stdout );
@@ -1014,7 +1019,7 @@
opt.transport == SSL_TRANSPORT_STREAM ?
NET_PROTO_TCP : NET_PROTO_UDP ) ) != 0 )
{
- printf( " failed\n ! net_connect returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! net_connect returned -0x%x\n\n", -ret );
goto exit;
}
@@ -1024,21 +1029,21 @@
ret = net_set_block( server_fd );
if( ret != 0 )
{
- printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 3. Setup stuff
*/
- printf( " . Setting up the SSL/TLS structure..." );
+ polarssl_printf( " . Setting up the SSL/TLS structure..." );
fflush( stdout );
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_init returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_init returned -0x%x\n\n", -ret );
goto exit;
}
@@ -1064,7 +1069,7 @@
#if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
if( ( ret = ssl_set_max_frag_len( &ssl, opt.mfl_code ) ) != 0 )
{
- printf( " failed\n ! ssl_set_max_frag_len returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_max_frag_len returned %d\n\n", ret );
goto exit;
}
#endif
@@ -1095,7 +1100,7 @@
if( opt.alpn_string != NULL )
if( ( ret = ssl_set_alpn_protocols( &ssl, alpn_list ) ) != 0 )
{
- printf( " failed\n ! ssl_set_alpn_protocols returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_alpn_protocols returned %d\n\n", ret );
goto exit;
}
#endif
@@ -1118,7 +1123,7 @@
#if defined(POLARSSL_SSL_SESSION_TICKETS)
if( ( ret = ssl_set_session_tickets( &ssl, opt.tickets ) ) != 0 )
{
- printf( " failed\n ! ssl_set_session_tickets returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_session_tickets returned %d\n\n", ret );
goto exit;
}
#endif
@@ -1146,7 +1151,7 @@
{
if( ( ret = ssl_set_own_cert( &ssl, &clicert, &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;
}
}
@@ -1157,7 +1162,7 @@
(const unsigned char *) opt.psk_identity,
strlen( opt.psk_identity ) ) ) != 0 )
{
- printf( " failed\n ! ssl_set_psk returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_psk returned %d\n\n", ret );
goto exit;
}
#endif
@@ -1165,7 +1170,7 @@
#if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
if( ( ret = ssl_set_hostname( &ssl, opt.server_name ) ) != 0 )
{
- printf( " failed\n ! ssl_set_hostname returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_hostname returned %d\n\n", ret );
goto exit;
}
#endif
@@ -1195,33 +1200,33 @@
ssl_set_fallback( &ssl, opt.fallback );
#endif
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 4. Handshake
*/
- printf( " . Performing the SSL/TLS handshake..." );
+ polarssl_printf( " . Performing the SSL/TLS handshake..." );
fflush( stdout );
while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_handshake returned -0x%x\n", -ret );
+ polarssl_printf( " failed\n ! ssl_handshake returned -0x%x\n", -ret );
if( ret == POLARSSL_ERR_X509_CERT_VERIFY_FAILED )
- printf(
+ polarssl_printf(
" Unable to verify the server's certificate. "
"Either it is invalid,\n"
" or you didn't set ca_file or ca_path "
"to an appropriate value.\n"
" Alternatively, you may want to use "
"auth_mode=optional for testing purposes.\n" );
- printf( "\n" );
+ polarssl_printf( "\n" );
goto exit;
}
}
- printf( " ok\n [ Protocol is %s ]\n [ Ciphersuite is %s ]\n",
+ polarssl_printf( " ok\n [ Protocol is %s ]\n [ Ciphersuite is %s ]\n",
ssl_get_version( &ssl ), ssl_get_ciphersuite( &ssl ) );
if( ( ret = ssl_get_record_expansion( &ssl ) ) >= 0 )
@@ -1233,58 +1238,58 @@
if( opt.alpn_string != NULL )
{
const char *alp = ssl_get_alpn_protocol( &ssl );
- printf( " [ Application Layer Protocol is %s ]\n",
+ polarssl_printf( " [ Application Layer Protocol is %s ]\n",
alp ? alp : "(none)" );
}
#endif
if( opt.reconnect != 0 )
{
- printf(" . Saving session for reuse..." );
+ polarssl_printf(" . Saving session for reuse..." );
fflush( stdout );
if( ( ret = ssl_get_session( &ssl, &saved_session ) ) != 0 )
{
- printf( " failed\n ! ssl_get_session returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_get_session returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
#if defined(POLARSSL_X509_CRT_PARSE_C)
/*
* 5. Verify the server certificate
*/
- printf( " . Verifying peer X.509 certificate..." );
+ polarssl_printf( " . Verifying peer X.509 certificate..." );
if( ( ret = ssl_get_verify_result( &ssl ) ) != 0 )
{
- printf( " failed\n" );
+ polarssl_printf( " failed\n" );
if( ( ret & BADCERT_EXPIRED ) != 0 )
- printf( " ! server certificate has expired\n" );
+ polarssl_printf( " ! server certificate has expired\n" );
if( ( ret & BADCERT_REVOKED ) != 0 )
- printf( " ! server certificate has been revoked\n" );
+ polarssl_printf( " ! server certificate has been revoked\n" );
if( ( ret & BADCERT_CN_MISMATCH ) != 0 )
- printf( " ! CN mismatch (expected CN=%s)\n", opt.server_name );
+ polarssl_printf( " ! CN mismatch (expected CN=%s)\n", opt.server_name );
if( ( ret & BADCERT_NOT_TRUSTED ) != 0 )
- printf( " ! self-signed or not signed by a trusted CA\n" );
+ polarssl_printf( " ! self-signed or not signed by a trusted CA\n" );
- printf( "\n" );
+ polarssl_printf( "\n" );
}
else
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
if( ssl_get_peer_cert( &ssl ) != NULL )
{
- printf( " . Peer certificate information ...\n" );
+ polarssl_printf( " . Peer certificate information ...\n" );
x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
ssl_get_peer_cert( &ssl ) );
- printf( "%s\n", buf );
+ polarssl_printf( "%s\n", buf );
}
#endif /* POLARSSL_X509_CRT_PARSE_C */
@@ -1295,18 +1300,18 @@
* Perform renegotiation (this must be done when the server is waiting
* for input from our side).
*/
- printf( " . Performing renegotiation..." );
+ polarssl_printf( " . Performing renegotiation..." );
fflush( stdout );
while( ( ret = ssl_renegotiate( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_renegotiate returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_renegotiate returned %d\n\n", ret );
goto exit;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
#endif /* POLARSSL_SSL_RENEGOTIATION */
@@ -1315,7 +1320,7 @@
*/
retry_left = opt.max_resend;
send_request:
- printf( " > Write to server:" );
+ polarssl_printf( " > Write to server:" );
fflush( stdout );
len = snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST,
@@ -1354,7 +1359,7 @@
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret );
goto exit;
}
}
@@ -1377,12 +1382,12 @@
}
buf[written] = '\0';
- printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );
+ polarssl_printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );
/*
* 7. Read the HTTP response
*/
- printf( " < Read from server:" );
+ polarssl_printf( " < Read from server:" );
fflush( stdout );
/*
@@ -1449,25 +1454,25 @@
switch( ret )
{
case POLARSSL_ERR_NET_TIMEOUT:
- printf( " timeout\n" );
+ polarssl_printf( " timeout\n" );
if( retry_left-- > 0 )
goto send_request;
goto exit;
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
- printf( " connection was closed gracefully\n" );
+ polarssl_printf( " connection was closed gracefully\n" );
ret = 0;
goto close_notify;
default:
- printf( " ssl_read returned -0x%x\n", -ret );
+ polarssl_printf( " ssl_read returned -0x%x\n", -ret );
goto exit;
}
}
len = ret;
buf[len] = '\0';
- printf( " %d bytes read\n\n%s", len, (char *) buf );
+ polarssl_printf( " %d bytes read\n\n%s", len, (char *) buf );
ret = 0;
}
@@ -1481,14 +1486,14 @@
* 8. Done, cleanly close the connection
*/
close_notify:
- printf( " . Closing the connection..." );
+ polarssl_printf( " . Closing the connection..." );
/* No error checking, the connection might be closed already */
do ret = ssl_close_notify( &ssl );
while( ret == POLARSSL_ERR_NET_WANT_WRITE );
ret = 0;
- printf( " done\n" );
+ polarssl_printf( " done\n" );
/*
* 9. Reconnect?
@@ -1505,18 +1510,18 @@
m_sleep( 1000 * opt.reco_delay );
#endif
- printf( " . Reconnecting with saved session..." );
+ polarssl_printf( " . Reconnecting with saved session..." );
fflush( stdout );
if( ( ret = ssl_session_reset( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_session_reset returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_session_reset returned -0x%x\n\n", -ret );
goto exit;
}
if( ( ret = ssl_set_session( &ssl, &saved_session ) ) != 0 )
{
- printf( " failed\n ! ssl_set_session returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_session returned %d\n\n", ret );
goto exit;
}
@@ -1524,7 +1529,7 @@
opt.transport == SSL_TRANSPORT_STREAM ?
NET_PROTO_TCP : NET_PROTO_UDP ) ) != 0 )
{
- printf( " failed\n ! net_connect returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! net_connect returned -0x%x\n\n", -ret );
goto exit;
}
@@ -1544,12 +1549,12 @@
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_handshake returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_handshake returned -0x%x\n\n", -ret );
goto exit;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
goto send_request;
}
@@ -1563,7 +1568,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf("Last error was: -0x%X - %s\n\n", -ret, error_buf );
+ polarssl_printf("Last error was: -0x%X - %s\n\n", -ret, error_buf );
}
#endif
@@ -1581,7 +1586,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/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c
index 3efe6a4..6424311 100644
--- a/programs/ssl/ssl_fork_server.c
+++ b/programs/ssl/ssl_fork_server.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#if defined(_WIN32)
#include <windows.h>
#endif
@@ -62,7 +69,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
+ polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C and/or "
@@ -75,7 +82,7 @@
((void) argc);
((void) argv);
- printf("_WIN32 defined. This application requires fork() and signals "
+ polarssl_printf("_WIN32 defined. This application requires fork() and signals "
"to work correctly.\n");
return( 0 );
}
@@ -87,7 +94,7 @@
{
if( level < DEBUG_LEVEL )
{
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
}
@@ -120,23 +127,23 @@
/*
* 0. Initial seeding of the RNG
*/
- printf( "\n . Initial seeding of the random generator..." );
+ polarssl_printf( "\n . Initial seeding of the random 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" );
+ polarssl_printf( " ok\n" );
/*
* 1. Load the certificates and private RSA key
*/
- printf( " . Loading the server cert. and key..." );
+ polarssl_printf( " . Loading the server cert. and key..." );
fflush( stdout );
/*
@@ -148,7 +155,7 @@
strlen( test_srv_crt ) );
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@@ -156,7 +163,7 @@
strlen( test_ca_list ) );
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@@ -164,25 +171,25 @@
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
- printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 2. Setup the listening TCP socket
*/
- printf( " . Bind on https://localhost:4433/ ..." );
+ polarssl_printf( " . Bind on https://localhost:4433/ ..." );
fflush( stdout );
if( ( ret = net_bind( &listen_fd, NULL, 4433, NET_PROTO_TCP ) ) != 0 )
{
- printf( " failed\n ! net_bind returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! net_bind returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
while( 1 )
{
@@ -192,16 +199,16 @@
client_fd = -1;
memset( &ssl, 0, sizeof( ssl ) );
- printf( " . Waiting for a remote connection ..." );
+ polarssl_printf( " . Waiting for a remote connection ..." );
fflush( stdout );
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;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 3.5. Forking server thread
@@ -209,16 +216,16 @@
pid = fork();
- printf( " . Forking to handle connection ..." );
+ polarssl_printf( " . Forking to handle connection ..." );
fflush( stdout );
if( pid < 0 )
{
- printf(" failed\n ! fork returned %d\n\n", pid );
+ polarssl_printf(" failed\n ! fork returned %d\n\n", pid );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
if( pid != 0 )
{
@@ -226,7 +233,7 @@
(const unsigned char *) "parent",
6 ) ) != 0 )
{
- printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
+ polarssl_printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
goto exit;
}
@@ -239,24 +246,24 @@
/*
* 4. Setup stuff
*/
- printf( " . Setting up the SSL data...." );
+ polarssl_printf( " . Setting up the SSL data...." );
fflush( stdout );
if( ( ret = ctr_drbg_reseed( &ctr_drbg,
(const unsigned char *) "child",
5 ) ) != 0 )
{
- printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
+ polarssl_printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
goto exit;
}
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_init returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_init returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
ssl_set_endpoint( &ssl, SSL_IS_SERVER );
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
@@ -275,31 +282,31 @@
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;
}
/*
* 5. Handshake
*/
- printf( " . Performing the SSL/TLS handshake..." );
+ polarssl_printf( " . Performing the SSL/TLS handshake..." );
fflush( stdout );
while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
goto exit;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 6. Read the HTTP Request
*/
- printf( " < Read from client:" );
+ polarssl_printf( " < Read from client:" );
fflush( stdout );
do
@@ -316,15 +323,15 @@
switch( ret )
{
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
- printf( " connection was closed gracefully\n" );
+ polarssl_printf( " connection was closed gracefully\n" );
break;
case POLARSSL_ERR_NET_CONN_RESET:
- printf( " connection was reset by peer\n" );
+ polarssl_printf( " connection was reset by peer\n" );
break;
default:
- printf( " ssl_read returned %d\n", ret );
+ polarssl_printf( " ssl_read returned %d\n", ret );
break;
}
@@ -332,14 +339,14 @@
}
len = ret;
- printf( " %d bytes read\n\n%s", len, (char *) buf );
+ polarssl_printf( " %d bytes read\n\n%s", len, (char *) buf );
}
while( 0 );
/*
* 7. Write the 200 Response
*/
- printf( " > Write to client:" );
+ polarssl_printf( " > Write to client:" );
fflush( stdout );
len = sprintf( (char *) buf, HTTP_RESPONSE,
@@ -351,18 +358,18 @@
{
if( ret == POLARSSL_ERR_NET_CONN_RESET )
{
- printf( " failed\n ! peer closed the connection\n\n" );
+ polarssl_printf( " failed\n ! peer closed the connection\n\n" );
goto exit;
}
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_write returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto exit;
}
}
len = ret;
- printf( " %d bytes written\n\n%s\n", len, (char *) buf );
+ polarssl_printf( " %d bytes written\n\n%s\n", len, (char *) buf );
m_sleep( 1000 );
}
@@ -383,7 +390,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/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c
index 66fefe4..7259d65 100644
--- a/programs/ssl/ssl_mail_client.c
+++ b/programs/ssl/ssl_mail_client.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2012, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -70,7 +77,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_CLI_C and/or "
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C "
@@ -120,7 +127,7 @@
{
if( level < opt.debug_level )
{
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
}
@@ -134,7 +141,7 @@
/*
* 4. Handshake
*/
- printf( " . Performing the SSL/TLS handshake..." );
+ polarssl_printf( " . Performing the SSL/TLS handshake..." );
fflush( stdout );
while( ( ret = ssl_handshake( ssl ) ) != 0 )
@@ -144,45 +151,45 @@
#if defined(POLARSSL_ERROR_C)
polarssl_strerror( ret, (char *) buf, 1024 );
#endif
- printf( " failed\n ! ssl_handshake returned %d: %s\n\n", ret, buf );
+ polarssl_printf( " failed\n ! ssl_handshake returned %d: %s\n\n", ret, buf );
return( -1 );
}
}
- printf( " ok\n [ Ciphersuite is %s ]\n",
+ polarssl_printf( " ok\n [ Ciphersuite is %s ]\n",
ssl_get_ciphersuite( ssl ) );
/*
* 5. Verify the server certificate
*/
- printf( " . Verifying peer X.509 certificate..." );
+ polarssl_printf( " . Verifying peer X.509 certificate..." );
/* In real life, we may want to bail out when ret != 0 */
if( ( ret = ssl_get_verify_result( ssl ) ) != 0 )
{
- printf( " failed\n" );
+ polarssl_printf( " failed\n" );
if( ( ret & BADCERT_EXPIRED ) != 0 )
- printf( " ! server certificate has expired\n" );
+ polarssl_printf( " ! server certificate has expired\n" );
if( ( ret & BADCERT_REVOKED ) != 0 )
- printf( " ! server certificate has been revoked\n" );
+ polarssl_printf( " ! server certificate has been revoked\n" );
if( ( ret & BADCERT_CN_MISMATCH ) != 0 )
- printf( " ! CN mismatch (expected CN=%s)\n", opt->server_name );
+ polarssl_printf( " ! CN mismatch (expected CN=%s)\n", opt->server_name );
if( ( ret & BADCERT_NOT_TRUSTED ) != 0 )
- printf( " ! self-signed or not signed by a trusted CA\n" );
+ polarssl_printf( " ! self-signed or not signed by a trusted CA\n" );
- printf( "\n" );
+ polarssl_printf( "\n" );
}
else
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
- printf( " . Peer certificate information ...\n" );
+ polarssl_printf( " . Peer certificate information ...\n" );
x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
ssl_get_peer_cert( ssl ) );
- printf( "%s\n", buf );
+ polarssl_printf( "%s\n", buf );
return( 0 );
}
@@ -191,12 +198,12 @@
{
int ret;
- printf("\n%s", buf);
+ polarssl_printf("\n%s", buf);
while( len && ( ret = ssl_write( ssl, buf, len ) ) <= 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_write returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
return -1;
}
}
@@ -211,12 +218,12 @@
char code[4];
size_t i, idx = 0;
- printf("\n%s", buf);
+ polarssl_printf("\n%s", buf);
while( len && ( ret = ssl_write( ssl, buf, len ) ) <= 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_write returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
return -1;
}
}
@@ -235,11 +242,11 @@
if( ret <= 0 )
{
- printf( "failed\n ! ssl_read returned %d\n\n", ret );
+ polarssl_printf( "failed\n ! ssl_read returned %d\n\n", ret );
return -1;
}
- printf("\n%s", data);
+ polarssl_printf("\n%s", data);
len = ret;
for( i = 0; i < len; i++ )
{
@@ -269,10 +276,10 @@
char code[4];
size_t i, idx = 0;
- printf("\n%s", buf);
+ polarssl_printf("\n%s", buf);
if( len && ( ret = write( sock_fd, buf, len ) ) <= 0 )
{
- printf( " failed\n ! ssl_write returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
return -1;
}
@@ -284,12 +291,12 @@
if( ret <= 0 )
{
- printf( "failed\n ! read returned %d\n\n", ret );
+ polarssl_printf( "failed\n ! read returned %d\n\n", ret );
return -1;
}
data[len] = '\0';
- printf("\n%s", data);
+ polarssl_printf("\n%s", data);
len = ret;
for( i = 0; i < len; i++ )
{
@@ -380,15 +387,15 @@
if( argc == 0 )
{
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;
}
@@ -471,7 +478,7 @@
/*
* 0. Initialize the RNG and the session data
*/
- printf( "\n . Seeding the random number generator..." );
+ polarssl_printf( "\n . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
@@ -479,16 +486,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( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.1. Load the trusted CA
*/
- printf( " . Loading the CA root certificate ..." );
+ polarssl_printf( " . Loading the CA root certificate ..." );
fflush( stdout );
#if defined(POLARSSL_FS_IO)
@@ -502,23 +509,23 @@
#else
{
ret = 1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
}
#endif
if( ret < 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
- printf( " ok (%d skipped)\n", ret );
+ polarssl_printf( " ok (%d skipped)\n", ret );
/*
* 1.2. Load own certificate and private key
*
* (can be skipped if client authentication is not required)
*/
- printf( " . Loading the client cert. and key..." );
+ polarssl_printf( " . Loading the client cert. and key..." );
fflush( stdout );
#if defined(POLARSSL_FS_IO)
@@ -532,12 +539,12 @@
#else
{
ret = -1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
}
#endif
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@@ -552,46 +559,46 @@
#else
{
ret = -1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
}
#endif
if( ret != 0 )
{
- printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 2. Start the connection
*/
- printf( " . Connecting to tcp/%s/%-4d...", opt.server_name,
+ polarssl_printf( " . Connecting to tcp/%s/%-4d...", opt.server_name,
opt.server_port );
fflush( stdout );
if( ( ret = net_connect( &server_fd, opt.server_name,
opt.server_port, NET_PROTO_TCP ) ) != 0 )
{
- printf( " failed\n ! net_connect returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! net_connect returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 3. Setup stuff
*/
- printf( " . Setting up the SSL/TLS structure..." );
+ polarssl_printf( " . Setting up the SSL/TLS structure..." );
fflush( stdout );
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_init returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_init returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
/* OPTIONAL is not optimal for security,
@@ -614,14 +621,14 @@
ssl_set_ca_chain( &ssl, &cacert, NULL, opt.server_name );
if( ( ret = ssl_set_own_cert( &ssl, &clicert, &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;
}
#if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
if( ( ret = ssl_set_hostname( &ssl, opt.server_name ) ) != 0 )
{
- printf( " failed\n ! ssl_set_hostname returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_hostname returned %d\n\n", ret );
goto exit;
}
#endif
@@ -631,19 +638,19 @@
if( do_handshake( &ssl, &opt ) != 0 )
goto exit;
- printf( " > Get header from server:" );
+ polarssl_printf( " > Get header from server:" );
fflush( stdout );
ret = write_ssl_and_get_response( &ssl, buf, 0 );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write EHLO to server:" );
+ polarssl_printf( " > Write EHLO to server:" );
fflush( stdout );
gethostname( hostname, 32 );
@@ -651,25 +658,25 @@
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
}
else
{
- printf( " > Get header from server:" );
+ polarssl_printf( " > Get header from server:" );
fflush( stdout );
ret = write_and_get_response( server_fd, buf, 0 );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write EHLO to server:" );
+ polarssl_printf( " > Write EHLO to server:" );
fflush( stdout );
gethostname( hostname, 32 );
@@ -677,13 +684,13 @@
ret = write_and_get_response( server_fd, buf, len );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write STARTTLS to server:" );
+ polarssl_printf( " > Write STARTTLS to server:" );
fflush( stdout );
gethostname( hostname, 32 );
@@ -691,11 +698,11 @@
ret = write_and_get_response( server_fd, buf, len );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
if( do_handshake( &ssl, &opt ) != 0 )
goto exit;
@@ -704,20 +711,20 @@
#if defined(POLARSSL_BASE64_C)
if( opt.authentication )
{
- printf( " > Write AUTH LOGIN to server:" );
+ polarssl_printf( " > Write AUTH LOGIN to server:" );
fflush( stdout );
len = sprintf( (char *) buf, "AUTH LOGIN\r\n" );
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 200 || ret > 399 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write username to server: %s", opt.user_name );
+ polarssl_printf( " > Write username to server: %s", opt.user_name );
fflush( stdout );
n = sizeof( buf );
@@ -725,81 +732,81 @@
strlen( opt.user_name ) );
if( ret != 0 ) {
- printf( " failed\n ! base64_encode returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! base64_encode returned %d\n\n", ret );
goto exit;
}
len = sprintf( (char *) buf, "%s\r\n", base );
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 300 || ret > 399 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write password to server: %s", opt.user_pwd );
+ polarssl_printf( " > Write password to server: %s", opt.user_pwd );
fflush( stdout );
ret = base64_encode( base, &n, (const unsigned char *) opt.user_pwd,
strlen( opt.user_pwd ) );
if( ret != 0 ) {
- printf( " failed\n ! base64_encode returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! base64_encode returned %d\n\n", ret );
goto exit;
}
len = sprintf( (char *) buf, "%s\r\n", base );
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 200 || ret > 399 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
}
#endif
- printf( " > Write MAIL FROM to server:" );
+ polarssl_printf( " > Write MAIL FROM to server:" );
fflush( stdout );
len = sprintf( (char *) buf, "MAIL FROM:<%s>\r\n", opt.mail_from );
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write RCPT TO to server:" );
+ polarssl_printf( " > Write RCPT TO to server:" );
fflush( stdout );
len = sprintf( (char *) buf, "RCPT TO:<%s>\r\n", opt.mail_to );
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write DATA to server:" );
+ polarssl_printf( " > Write DATA to server:" );
fflush( stdout );
len = sprintf( (char *) buf, "DATA\r\n" );
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 300 || ret > 399 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
- printf( " > Write content to server:" );
+ polarssl_printf( " > Write content to server:" );
fflush( stdout );
len = sprintf( (char *) buf, "From: %s\r\nSubject: mbed TLS Test mail\r\n\r\n"
@@ -813,11 +820,11 @@
ret = write_ssl_and_get_response( &ssl, buf, len );
if( ret < 200 || ret > 299 )
{
- printf( " failed\n ! server responded with %d\n\n", ret );
+ polarssl_printf( " failed\n ! server responded with %d\n\n", ret );
goto exit;
}
- printf(" ok\n" );
+ polarssl_printf(" ok\n" );
ssl_close_notify( &ssl );
@@ -833,7 +840,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/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c
index a4a6352..d642a24 100644
--- a/programs/ssl/ssl_pthread_server.c
+++ b/programs/ssl/ssl_pthread_server.c
@@ -4,7 +4,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,6 +27,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#if defined(_WIN32)
#include <windows.h>
#endif
@@ -48,7 +55,7 @@
#endif
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
-#include "polarssl/memory.h"
+#include "polarssl/memory_buffer_alloc.h"
#endif
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
@@ -62,7 +69,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
+ polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C and/or "
@@ -86,7 +93,7 @@
polarssl_mutex_lock( &debug_mutex );
if( level < DEBUG_LEVEL )
{
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
polarssl_mutex_unlock( &debug_mutex );
@@ -131,8 +138,8 @@
memset( &ctr_drbg, 0, sizeof( ctr_drbg_context ) );
snprintf( pers, sizeof(pers), "SSL Pthread Thread %d", thread_id );
- printf( " [ #%d ] Client FD %d\n", thread_id, client_fd );
- printf( " [ #%d ] Seeding the random number generator...\n", thread_id );
+ polarssl_printf( " [ #%d ] Client FD %d\n", thread_id, client_fd );
+ polarssl_printf( " [ #%d ] Seeding the random number generator...\n", thread_id );
/* entropy_func() is thread-safe if POLARSSL_THREADING_C is set
*/
@@ -140,21 +147,21 @@
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
- printf( " [ #%d ] failed: ctr_drbg_init returned -0x%04x\n",
+ polarssl_printf( " [ #%d ] failed: ctr_drbg_init returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
- printf( " [ #%d ] ok\n", thread_id );
+ polarssl_printf( " [ #%d ] ok\n", thread_id );
/*
* 4. Setup stuff
*/
- printf( " [ #%d ] Setting up the SSL data....\n", thread_id );
+ polarssl_printf( " [ #%d ] Setting up the SSL data....\n", thread_id );
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " [ #%d ] failed: ssl_init returned -0x%04x\n",
+ polarssl_printf( " [ #%d ] failed: ssl_init returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
@@ -181,38 +188,38 @@
ssl_set_ca_chain( &ssl, thread_info->ca_chain, NULL, NULL );
if( ( ret = ssl_set_own_cert( &ssl, thread_info->server_cert, thread_info->server_key ) ) != 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 thread_exit;
}
- printf( " [ #%d ] ok\n", thread_id );
+ polarssl_printf( " [ #%d ] ok\n", thread_id );
ssl_set_bio( &ssl, net_recv, &client_fd,
net_send, &client_fd );
- printf( " [ #%d ] ok\n", thread_id );
+ polarssl_printf( " [ #%d ] ok\n", thread_id );
/*
* 5. Handshake
*/
- printf( " [ #%d ] Performing the SSL/TLS handshake\n", thread_id );
+ polarssl_printf( " [ #%d ] Performing the SSL/TLS handshake\n", thread_id );
while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " [ #%d ] failed: ssl_handshake returned -0x%04x\n",
+ polarssl_printf( " [ #%d ] failed: ssl_handshake returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
}
- printf( " [ #%d ] ok\n", thread_id );
+ polarssl_printf( " [ #%d ] ok\n", thread_id );
/*
* 6. Read the HTTP Request
*/
- printf( " [ #%d ] < Read from client\n", thread_id );
+ polarssl_printf( " [ #%d ] < Read from client\n", thread_id );
do
{
@@ -228,24 +235,24 @@
switch( ret )
{
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
- printf( " [ #%d ] connection was closed gracefully\n",
+ polarssl_printf( " [ #%d ] connection was closed gracefully\n",
thread_id );
goto thread_exit;
case POLARSSL_ERR_NET_CONN_RESET:
- printf( " [ #%d ] connection was reset by peer\n",
+ polarssl_printf( " [ #%d ] connection was reset by peer\n",
thread_id );
goto thread_exit;
default:
- printf( " [ #%d ] ssl_read returned -0x%04x\n",
+ polarssl_printf( " [ #%d ] ssl_read returned -0x%04x\n",
thread_id, -ret );
goto thread_exit;
}
}
len = ret;
- printf( " [ #%d ] %d bytes read\n=====\n%s\n=====\n",
+ polarssl_printf( " [ #%d ] %d bytes read\n=====\n%s\n=====\n",
thread_id, len, (char *) buf );
if( ret > 0 )
@@ -256,7 +263,7 @@
/*
* 7. Write the 200 Response
*/
- printf( " [ #%d ] > Write to client:\n", thread_id );
+ polarssl_printf( " [ #%d ] > Write to client:\n", thread_id );
len = sprintf( (char *) buf, HTTP_RESPONSE,
ssl_get_ciphersuite( &ssl ) );
@@ -265,37 +272,37 @@
{
if( ret == POLARSSL_ERR_NET_CONN_RESET )
{
- printf( " [ #%d ] failed: peer closed the connection\n",
+ polarssl_printf( " [ #%d ] failed: peer closed the connection\n",
thread_id );
goto thread_exit;
}
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " [ #%d ] failed: ssl_write returned -0x%04x\n",
+ polarssl_printf( " [ #%d ] failed: ssl_write returned -0x%04x\n",
thread_id, ret );
goto thread_exit;
}
}
len = ret;
- printf( " [ #%d ] %d bytes written\n=====\n%s\n=====\n",
+ polarssl_printf( " [ #%d ] %d bytes written\n=====\n%s\n=====\n",
thread_id, len, (char *) buf );
- printf( " [ #%d ] . Closing the connection...", thread_id );
+ polarssl_printf( " [ #%d ] . Closing the connection...", thread_id );
while( ( ret = ssl_close_notify( &ssl ) ) < 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " [ #%d ] failed: ssl_close_notify returned -0x%04x\n",
+ polarssl_printf( " [ #%d ] failed: ssl_close_notify returned -0x%04x\n",
thread_id, ret );
goto thread_exit;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
ret = 0;
@@ -306,7 +313,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf(" [ #%d ] Last error was: -0x%04x - %s\n\n",
+ polarssl_printf(" [ #%d ] Last error was: -0x%04x - %s\n\n",
thread_id, -ret, error_buf );
}
#endif
@@ -334,7 +341,7 @@
if( threads[i].data.thread_complete == 1 )
{
- printf( " [ main ] Cleaning up thread %d\n", i );
+ polarssl_printf( " [ main ] Cleaning up thread %d\n", i );
pthread_join(threads[i].thread, NULL );
memset( &threads[i], 0, sizeof(pthread_info_t) );
break;
@@ -400,7 +407,7 @@
/*
* 1. Load the certificates and private RSA key
*/
- printf( "\n . Loading the server cert. and key..." );
+ polarssl_printf( "\n . Loading the server cert. and key..." );
fflush( stdout );
x509_crt_init( &srvcert );
@@ -414,7 +421,7 @@
strlen( test_srv_crt ) );
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@@ -422,7 +429,7 @@
strlen( test_ca_list ) );
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@@ -431,7 +438,7 @@
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
- printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
@@ -439,21 +446,21 @@
base_info.server_cert = &srvcert;
base_info.server_key = &pkey;
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 2. Setup the listening TCP socket
*/
- printf( " . Bind on https://localhost:4433/ ..." );
+ polarssl_printf( " . Bind on https://localhost:4433/ ..." );
fflush( stdout );
if( ( ret = net_bind( &listen_fd, NULL, 4433, NET_PROTO_TCP ) ) != 0 )
{
- printf( " failed\n ! net_bind returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! net_bind returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
reset:
#ifdef POLARSSL_ERROR_C
@@ -461,7 +468,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf( " [ main ] Last error was: -0x%04x - %s\n", -ret, error_buf );
+ polarssl_printf( " [ main ] Last error was: -0x%04x - %s\n", -ret, error_buf );
}
#endif
@@ -470,20 +477,20 @@
*/
client_fd = -1;
- printf( " [ main ] Waiting for a remote connection\n" );
+ polarssl_printf( " [ main ] Waiting for a remote connection\n" );
if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 )
{
- printf( " [ main ] failed: net_accept returned -0x%04x\n", ret );
+ polarssl_printf( " [ main ] failed: net_accept returned -0x%04x\n", ret );
goto exit;
}
- printf( " [ main ] ok\n" );
- printf( " [ main ] Creating a new thread\n" );
+ polarssl_printf( " [ main ] ok\n" );
+ polarssl_printf( " [ main ] Creating a new thread\n" );
if( ( ret = thread_create( client_fd ) ) != 0 )
{
- printf( " [ main ] failed: thread_create returned %d\n", ret );
+ polarssl_printf( " [ main ] failed: thread_create returned %d\n", ret );
net_close( client_fd );
goto reset;
}
@@ -506,7 +513,7 @@
#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/ssl/ssl_server.c b/programs/ssl/ssl_server.c
index 22b2a0b..f590bad 100644
--- a/programs/ssl/ssl_server.c
+++ b/programs/ssl/ssl_server.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#if defined(_WIN32)
#include <windows.h>
#endif
@@ -57,7 +64,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
+ polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_CTR_DRBG_C and/or POLARSSL_X509_CRT_PARSE_C "
@@ -77,7 +84,7 @@
{
((void) level);
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
@@ -116,7 +123,7 @@
/*
* 1. Load the certificates and private RSA key
*/
- printf( "\n . Loading the server cert. and key..." );
+ polarssl_printf( "\n . Loading the server cert. and key..." );
fflush( stdout );
/*
@@ -128,7 +135,7 @@
strlen( test_srv_crt ) );
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@@ -136,7 +143,7 @@
strlen( test_ca_list ) );
if( ret != 0 )
{
- printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret );
goto exit;
}
@@ -144,51 +151,51 @@
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
{
- printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 2. Setup the listening TCP socket
*/
- printf( " . Bind on https://localhost:4433/ ..." );
+ polarssl_printf( " . Bind on https://localhost:4433/ ..." );
fflush( stdout );
if( ( ret = net_bind( &listen_fd, NULL, 4433, NET_PROTO_TCP ) ) != 0 )
{
- printf( " failed\n ! net_bind returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! net_bind returned %d\n\n", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 3. Seed the RNG
*/
- printf( " . Seeding the random number generator..." );
+ polarssl_printf( " . 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" );
+ polarssl_printf( " ok\n" );
/*
* 4. Setup stuff
*/
- printf( " . Setting up the SSL data...." );
+ polarssl_printf( " . Setting up the SSL data...." );
fflush( stdout );
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_init returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_init returned %d\n\n", ret );
goto exit;
}
@@ -211,11 +218,11 @@
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;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
reset:
#ifdef POLARSSL_ERROR_C
@@ -223,7 +230,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf("Last error was: %d - %s\n\n", ret, error_buf );
+ polarssl_printf("Last error was: %d - %s\n\n", ret, error_buf );
}
#endif
@@ -237,41 +244,41 @@
*/
client_fd = -1;
- printf( " . Waiting for a remote connection ..." );
+ polarssl_printf( " . Waiting for a remote connection ..." );
fflush( stdout );
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;
}
ssl_set_bio( &ssl, net_recv, &client_fd,
net_send, &client_fd );
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 5. Handshake
*/
- printf( " . Performing the SSL/TLS handshake..." );
+ polarssl_printf( " . Performing the SSL/TLS handshake..." );
fflush( stdout );
while( ( ret = ssl_handshake( &ssl ) ) != 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
goto reset;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 6. Read the HTTP Request
*/
- printf( " < Read from client:" );
+ polarssl_printf( " < Read from client:" );
fflush( stdout );
do
@@ -288,15 +295,15 @@
switch( ret )
{
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
- printf( " connection was closed gracefully\n" );
+ polarssl_printf( " connection was closed gracefully\n" );
break;
case POLARSSL_ERR_NET_CONN_RESET:
- printf( " connection was reset by peer\n" );
+ polarssl_printf( " connection was reset by peer\n" );
break;
default:
- printf( " ssl_read returned -0x%x\n", -ret );
+ polarssl_printf( " ssl_read returned -0x%x\n", -ret );
break;
}
@@ -304,7 +311,7 @@
}
len = ret;
- printf( " %d bytes read\n\n%s", len, (char *) buf );
+ polarssl_printf( " %d bytes read\n\n%s", len, (char *) buf );
if( ret > 0 )
break;
@@ -314,7 +321,7 @@
/*
* 7. Write the 200 Response
*/
- printf( " > Write to client:" );
+ polarssl_printf( " > Write to client:" );
fflush( stdout );
len = sprintf( (char *) buf, HTTP_RESPONSE,
@@ -324,33 +331,33 @@
{
if( ret == POLARSSL_ERR_NET_CONN_RESET )
{
- printf( " failed\n ! peer closed the connection\n\n" );
+ polarssl_printf( " failed\n ! peer closed the connection\n\n" );
goto reset;
}
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_write returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto exit;
}
}
len = ret;
- printf( " %d bytes written\n\n%s\n", len, (char *) buf );
+ polarssl_printf( " %d bytes written\n\n%s\n", len, (char *) buf );
- printf( " . Closing the connection..." );
+ polarssl_printf( " . Closing the connection..." );
while( ( ret = ssl_close_notify( &ssl ) ) < 0 )
{
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_close_notify returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_close_notify returned %d\n\n", ret );
goto reset;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
ret = 0;
goto reset;
@@ -362,7 +369,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf("Last error was: %d - %s\n\n", ret, error_buf );
+ polarssl_printf("Last error was: %d - %s\n\n", ret, error_buf );
}
#endif
@@ -379,7 +386,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/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index bd01c1b..f4f92b1 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -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
+
#if !defined(POLARSSL_ENTROPY_C) || \
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
!defined(POLARSSL_NET_C) || !defined(POLARSSL_CTR_DRBG_C)
@@ -35,7 +44,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_ENTROPY_C and/or "
+ polarssl_printf("POLARSSL_ENTROPY_C and/or "
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
"POLARSSL_NET_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
return( 0 );
@@ -46,13 +55,6 @@
#define POLARSSL_SNI
#endif
-#if defined(POLARSSL_PLATFORM_C)
-#include "polarssl/platform.h"
-#else
-#define polarssl_malloc malloc
-#define polarssl_free free
-#endif
-
#if defined(_WIN32)
#include <windows.h>
#endif
@@ -83,7 +85,7 @@
#endif
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
-#include "polarssl/memory.h"
+#include "polarssl/memory_buffer_alloc.h"
#endif
#define DFL_SERVER_ADDR NULL
@@ -207,7 +209,7 @@
{
((void) level);
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
@@ -773,19 +775,19 @@
if( ret == 0 )
ret = 1;
- printf( USAGE );
+ polarssl_printf( USAGE );
list = ssl_list_ciphersuites();
while( *list )
{
- printf(" %-42s", ssl_get_ciphersuite_name( *list ) );
+ polarssl_printf(" %-42s", ssl_get_ciphersuite_name( *list ) );
list++;
if( !*list )
break;
- 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;
}
@@ -1145,14 +1147,14 @@
if( opt.max_version != -1 &&
ciphersuite_info->min_minor_ver > opt.max_version )
{
- printf("forced ciphersuite not allowed with this protocol version\n");
+ polarssl_printf("forced ciphersuite not allowed with this protocol version\n");
ret = 2;
goto usage;
}
if( opt.min_version != -1 &&
ciphersuite_info->max_minor_ver < opt.min_version )
{
- printf("forced ciphersuite not allowed with this protocol version\n");
+ polarssl_printf("forced ciphersuite not allowed with this protocol version\n");
ret = 2;
goto usage;
}
@@ -1194,7 +1196,7 @@
if( i != 4 )
{
- printf( "too few values for version_suites\n" );
+ polarssl_printf( "too few values for version_suites\n" );
ret = 1;
goto exit;
}
@@ -1208,7 +1210,7 @@
if( version_suites[i][0] == 0 )
{
- printf( "unknown ciphersuite: '%s'\n", name[i] );
+ polarssl_printf( "unknown ciphersuite: '%s'\n", name[i] );
ret = 2;
goto usage;
}
@@ -1221,7 +1223,7 @@
*/
if( unhexify( psk, opt.psk, &psk_len ) != 0 )
{
- printf( "pre-shared key not valid hex\n" );
+ polarssl_printf( "pre-shared key not valid hex\n" );
goto exit;
}
@@ -1229,7 +1231,7 @@
{
if( ( psk_info = psk_parse( opt.psk_list ) ) == NULL )
{
- printf( "psk_list invalid" );
+ polarssl_printf( "psk_list invalid" );
goto exit;
}
}
@@ -1258,7 +1260,7 @@
/*
* 0. Initialize the RNG and the session data
*/
- printf( "\n . Seeding the random number generator..." );
+ polarssl_printf( "\n . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
@@ -1266,17 +1268,17 @@
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
- printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret );
+ polarssl_printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
#if defined(POLARSSL_X509_CRT_PARSE_C)
/*
* 1.1. Load the trusted CA
*/
- printf( " . Loading the CA root certificate ..." );
+ polarssl_printf( " . Loading the CA root certificate ..." );
fflush( stdout );
#if defined(POLARSSL_FS_IO)
@@ -1298,21 +1300,21 @@
#else
{
ret = 1;
- printf("POLARSSL_CERTS_C not defined.");
+ polarssl_printf("POLARSSL_CERTS_C not defined.");
}
#endif
if( ret < 0 )
{
- printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok (%d skipped)\n", ret );
+ polarssl_printf( " ok (%d skipped)\n", ret );
/*
* 1.2. Load own certificate and private key
*/
- printf( " . Loading the server cert. and key..." );
+ polarssl_printf( " . Loading the server cert. and key..." );
fflush( stdout );
#if defined(POLARSSL_FS_IO)
@@ -1321,7 +1323,7 @@
key_cert_init++;
if( ( ret = x509_crt_parse_file( &srvcert, opt.crt_file ) ) != 0 )
{
- printf( " failed\n ! x509_crt_parse_file returned -0x%x\n\n",
+ polarssl_printf( " failed\n ! x509_crt_parse_file returned -0x%x\n\n",
-ret );
goto exit;
}
@@ -1331,13 +1333,13 @@
key_cert_init++;
if( ( ret = pk_parse_keyfile( &pkey, opt.key_file, "" ) ) != 0 )
{
- printf( " failed\n ! pk_parse_keyfile returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%x\n\n", -ret );
goto exit;
}
}
if( key_cert_init == 1 )
{
- printf( " failed\n ! crt_file without key_file or vice-versa\n\n" );
+ polarssl_printf( " failed\n ! crt_file without key_file or vice-versa\n\n" );
goto exit;
}
@@ -1346,7 +1348,7 @@
key_cert_init2++;
if( ( ret = x509_crt_parse_file( &srvcert2, opt.crt_file2 ) ) != 0 )
{
- printf( " failed\n ! x509_crt_parse_file(2) returned -0x%x\n\n",
+ polarssl_printf( " failed\n ! x509_crt_parse_file(2) returned -0x%x\n\n",
-ret );
goto exit;
}
@@ -1356,14 +1358,14 @@
key_cert_init2++;
if( ( ret = pk_parse_keyfile( &pkey2, opt.key_file2, "" ) ) != 0 )
{
- printf( " failed\n ! pk_parse_keyfile(2) returned -0x%x\n\n",
+ polarssl_printf( " failed\n ! pk_parse_keyfile(2) returned -0x%x\n\n",
-ret );
goto exit;
}
}
if( key_cert_init2 == 1 )
{
- printf( " failed\n ! crt_file2 without key_file2 or vice-versa\n\n" );
+ polarssl_printf( " failed\n ! crt_file2 without key_file2 or vice-versa\n\n" );
goto exit;
}
#endif
@@ -1375,7 +1377,7 @@
strcmp( opt.key_file2, "none" ) != 0 )
{
#if !defined(POLARSSL_CERTS_C)
- printf( "Not certificated or key provided, and \n"
+ polarssl_printf( "Not certificated or key provided, and \n"
"POLARSSL_CERTS_C not defined!\n" );
goto exit;
#else
@@ -1384,14 +1386,14 @@
(const unsigned char *) test_srv_crt_rsa,
strlen( test_srv_crt_rsa ) ) ) != 0 )
{
- printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
goto exit;
}
if( ( ret = pk_parse_key( &pkey,
(const unsigned char *) test_srv_key_rsa,
strlen( test_srv_key_rsa ), NULL, 0 ) ) != 0 )
{
- printf( " failed\n ! pk_parse_key returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! pk_parse_key returned -0x%x\n\n", -ret );
goto exit;
}
key_cert_init = 2;
@@ -1401,14 +1403,14 @@
(const unsigned char *) test_srv_crt_ec,
strlen( test_srv_crt_ec ) ) ) != 0 )
{
- printf( " failed\n ! x509_crt_parse2 returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crt_parse2 returned -0x%x\n\n", -ret );
goto exit;
}
if( ( ret = pk_parse_key( &pkey2,
(const unsigned char *) test_srv_key_ec,
strlen( test_srv_key_ec ), NULL, 0 ) ) != 0 )
{
- printf( " failed\n ! pk_parse_key2 returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! pk_parse_key2 returned -0x%x\n\n", -ret );
goto exit;
}
key_cert_init2 = 2;
@@ -1416,46 +1418,46 @@
#endif /* POLARSSL_CERTS_C */
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
#endif /* POLARSSL_X509_CRT_PARSE_C */
#if defined(POLARSSL_DHM_C) && defined(POLARSSL_FS_IO)
if( opt.dhm_file != NULL )
{
- printf( " . Loading DHM parameters..." );
+ polarssl_printf( " . Loading DHM parameters..." );
fflush( stdout );
if( ( ret = dhm_parse_dhmfile( &dhm, opt.dhm_file ) ) != 0 )
{
- printf( " failed\n ! dhm_parse_dhmfile returned -0x%04X\n\n",
+ polarssl_printf( " failed\n ! dhm_parse_dhmfile returned -0x%04X\n\n",
-ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
#endif
#if defined(POLARSSL_SNI)
if( opt.sni != NULL )
{
- printf( " . Setting up SNI information..." );
+ polarssl_printf( " . Setting up SNI information..." );
fflush( stdout );
if( ( sni_info = sni_parse( opt.sni ) ) == NULL )
{
- printf( " failed\n" );
+ polarssl_printf( " failed\n" );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
#endif /* POLARSSL_SNI */
/*
* 2. Setup the listening TCP socket
*/
- printf( " . Bind on %s://%s:%-4d/ ...",
+ polarssl_printf( " . Bind on %s://%s:%-4d/ ...",
opt.transport == SSL_TRANSPORT_STREAM ? "tcp" : "udp",
opt.server_addr ? opt.server_addr : "*",
opt.server_port );
@@ -1465,21 +1467,21 @@
opt.transport == SSL_TRANSPORT_STREAM ?
NET_PROTO_TCP : NET_PROTO_UDP ) ) != 0 )
{
- printf( " failed\n ! net_bind returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! net_bind returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 3. Setup stuff
*/
- printf( " . Setting up the SSL/TLS structure..." );
+ polarssl_printf( " . Setting up the SSL/TLS structure..." );
fflush( stdout );
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_init returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_init returned -0x%x\n\n", -ret );
goto exit;
}
@@ -1500,7 +1502,7 @@
#if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
if( ( ret = ssl_set_max_frag_len( &ssl, opt.mfl_code ) ) != 0 )
{
- printf( " failed\n ! ssl_set_max_frag_len returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_max_frag_len returned %d\n\n", ret );
goto exit;
};
#endif
@@ -1524,7 +1526,7 @@
if( opt.alpn_string != NULL )
if( ( ret = ssl_set_alpn_protocols( &ssl, alpn_list ) ) != 0 )
{
- printf( " failed\n ! ssl_set_alpn_protocols returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_alpn_protocols returned %d\n\n", ret );
goto exit;
}
#endif
@@ -1546,7 +1548,7 @@
#if defined(POLARSSL_SSL_SESSION_TICKETS)
if( ( ret = ssl_set_session_tickets( &ssl, opt.tickets ) ) != 0 )
{
- printf( " failed\n ! ssl_set_session_tickets returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_session_tickets returned %d\n\n", ret );
goto exit;
}
@@ -1640,13 +1642,13 @@
if( key_cert_init )
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;
}
if( key_cert_init2 )
if( ( ret = ssl_set_own_cert( &ssl, &srvcert2, &pkey2 ) ) != 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;
}
#endif
@@ -1664,7 +1666,7 @@
strlen( opt.psk_identity ) );
if( ret != 0 )
{
- printf( " failed\n ssl_set_psk returned -0x%04X\n\n", - ret );
+ polarssl_printf( " failed\n ssl_set_psk returned -0x%04X\n\n", - ret );
goto exit;
}
}
@@ -1687,7 +1689,7 @@
if( ret != 0 )
{
- printf( " failed\n ssl_set_dh_param returned -0x%04X\n\n", - ret );
+ polarssl_printf( " failed\n ssl_set_dh_param returned -0x%04X\n\n", - ret );
goto exit;
}
#endif
@@ -1712,7 +1714,7 @@
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
reset:
#if !defined(_WIN32)
@@ -1729,7 +1731,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf("Last error was: %d - %s\n\n", ret, error_buf );
+ polarssl_printf("Last error was: %d - %s\n\n", ret, error_buf );
}
#endif
@@ -1743,7 +1745,7 @@
*/
client_fd = -1;
- printf( " . Waiting for a remote connection ..." );
+ polarssl_printf( " . Waiting for a remote connection ..." );
fflush( stdout );
if( ( ret = net_accept( listen_fd, &client_fd, client_ip ) ) != 0 )
@@ -1751,13 +1753,13 @@
#if !defined(_WIN32)
if( received_sigterm )
{
- printf( " interrupted by signal\n" );
+ polarssl_printf( " interrupted by signal\n" );
ret = 0;
goto exit;
}
#endif
- printf( " failed\n ! net_accept returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! net_accept returned -0x%x\n\n", -ret );
goto exit;
}
@@ -1767,7 +1769,7 @@
ret = net_set_block( client_fd );
if( ret != 0 )
{
- printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", -ret );
goto exit;
}
@@ -1795,7 +1797,7 @@
}
#endif /* POLARSSL_SSL_DTLS_HELLO_VERIFY */
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* With UDP, bind_fd is hijacked by client_fd, so bind a new one
@@ -1822,7 +1824,7 @@
/*
* 4. Handshake
*/
- printf( " . Performing the SSL/TLS handshake..." );
+ polarssl_printf( " . Performing the SSL/TLS handshake..." );
fflush( stdout );
do ret = ssl_handshake( &ssl );
@@ -1831,31 +1833,31 @@
if( ret == POLARSSL_ERR_SSL_HELLO_VERIFY_REQUIRED )
{
- printf( " hello verification requested\n" );
+ polarssl_printf( " hello verification requested\n" );
ret = 0;
goto reset;
}
else if( ret != 0 )
{
- printf( " failed\n ! ssl_handshake returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! ssl_handshake returned -0x%x\n\n", -ret );
goto reset;
}
else /* ret == 0 */
{
- printf( " ok\n [ Protocol is %s ]\n [ Ciphersuite is %s ]\n",
+ polarssl_printf( " ok\n [ Protocol is %s ]\n [ Ciphersuite is %s ]\n",
ssl_get_version( &ssl ), ssl_get_ciphersuite( &ssl ) );
}
if( ( ret = ssl_get_record_expansion( &ssl ) ) >= 0 )
- printf( " [ Record expansion is %d ]\n", ret );
+ polarssl_printf( " [ Record expansion is %d ]\n", ret );
else
- printf( " [ Record expansion is unknown (compression) ]\n" );
+ polarssl_printf( " [ Record expansion is unknown (compression) ]\n" );
#if defined(POLARSSL_SSL_ALPN)
if( opt.alpn_string != NULL )
{
const char *alp = ssl_get_alpn_protocol( &ssl );
- printf( " [ Application Layer Protocol is %s ]\n",
+ polarssl_printf( " [ Application Layer Protocol is %s ]\n",
alp ? alp : "(none)" );
}
#endif
@@ -1864,35 +1866,35 @@
/*
* 5. Verify the server certificate
*/
- printf( " . Verifying peer X.509 certificate..." );
+ polarssl_printf( " . Verifying peer X.509 certificate..." );
if( ( ret = ssl_get_verify_result( &ssl ) ) != 0 )
{
- printf( " failed\n" );
+ polarssl_printf( " failed\n" );
if( !ssl_get_peer_cert( &ssl ) )
- printf( " ! no client certificate sent\n" );
+ polarssl_printf( " ! no client certificate sent\n" );
if( ( ret & BADCERT_EXPIRED ) != 0 )
- printf( " ! client certificate has expired\n" );
+ polarssl_printf( " ! client certificate has expired\n" );
if( ( ret & BADCERT_REVOKED ) != 0 )
- printf( " ! client certificate has been revoked\n" );
+ polarssl_printf( " ! client certificate has been revoked\n" );
if( ( ret & BADCERT_NOT_TRUSTED ) != 0 )
- printf( " ! self-signed or not signed by a trusted CA\n" );
+ polarssl_printf( " ! self-signed or not signed by a trusted CA\n" );
- printf( "\n" );
+ polarssl_printf( "\n" );
}
else
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
if( ssl_get_peer_cert( &ssl ) )
{
- printf( " . Peer certificate information ...\n" );
+ polarssl_printf( " . Peer certificate information ...\n" );
x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
ssl_get_peer_cert( &ssl ) );
- printf( "%s\n", buf );
+ polarssl_printf( "%s\n", buf );
}
#endif /* POLARSSL_X509_CRT_PARSE_C */
@@ -1904,7 +1906,7 @@
/*
* 6. Read the HTTP Request
*/
- printf( " < Read from client:" );
+ polarssl_printf( " < Read from client:" );
fflush( stdout );
/*
@@ -1928,17 +1930,17 @@
switch( ret )
{
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
- printf( " connection was closed gracefully\n" );
+ polarssl_printf( " connection was closed gracefully\n" );
goto close_notify;
case 0:
case POLARSSL_ERR_NET_CONN_RESET:
- printf( " connection was reset by peer\n" );
+ polarssl_printf( " connection was reset by peer\n" );
ret = POLARSSL_ERR_NET_CONN_RESET;
goto reset;
default:
- printf( " ssl_read returned -0x%x\n", -ret );
+ polarssl_printf( " ssl_read returned -0x%x\n", -ret );
goto reset;
}
}
@@ -2041,7 +2043,7 @@
#if defined(POLARSSL_SSL_RENEGOTIATION)
if( opt.renegotiate && exchanges_left == opt.exchanges )
{
- printf( " . Requestion renegotiation..." );
+ polarssl_printf( " . Requestion renegotiation..." );
fflush( stdout );
while( ( ret = ssl_renegotiate( &ssl ) ) != 0 )
@@ -2049,19 +2051,19 @@
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_renegotiate returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_renegotiate returned %d\n\n", ret );
goto reset;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
#endif /* POLARSSL_SSL_RENEGOTIATION */
/*
* 7. Write the 200 Response
*/
- printf( " > Write to client:" );
+ polarssl_printf( " > Write to client:" );
fflush( stdout );
len = sprintf( (char *) buf, HTTP_RESPONSE,
@@ -2076,14 +2078,14 @@
{
if( ret == POLARSSL_ERR_NET_CONN_RESET )
{
- printf( " failed\n ! peer closed the connection\n\n" );
+ polarssl_printf( " failed\n ! peer closed the connection\n\n" );
goto reset;
}
if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_write returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto reset;
}
}
@@ -2107,6 +2109,7 @@
buf[written] = '\0';
printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );
+ polarssl_printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );
ret = 0;
/*
@@ -2119,14 +2122,15 @@
* 8. Done, cleanly close the connection
*/
close_notify:
- printf( " . Closing the connection..." );
+ polarssl_printf( " . Closing the connection..." );
/* No error checking, the connection might be closed already */
do ret = ssl_close_notify( &ssl );
while( ret == POLARSSL_ERR_NET_WANT_WRITE );
ret = 0;
- printf( " done\n" );
+ polarssl_printf( " done\n" );
+
goto reset;
/*
@@ -2138,7 +2142,7 @@
{
char error_buf[100];
polarssl_strerror( ret, error_buf, 100 );
- printf("Last error was: -0x%X - %s\n\n", -ret, error_buf );
+ polarssl_printf("Last error was: -0x%X - %s\n\n", -ret, error_buf );
}
#endif
@@ -2189,7 +2193,7 @@
printf( " done.\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/CMakeLists.txt b/programs/test/CMakeLists.txt
index 5e72210..2dbc3bc 100644
--- a/programs/test/CMakeLists.txt
+++ b/programs/test/CMakeLists.txt
@@ -1,7 +1,7 @@
FIND_PACKAGE(OpenSSL)
set(libs
- polarssl
+ mbedtls
)
if(USE_PKCS11_HELPER_LIBRARY)
diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
index 239d968..cc83746 100644
--- a/programs/test/benchmark.c
+++ b/programs/test/benchmark.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -68,7 +74,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 +106,7 @@
do { \
unsigned long i, j, tsc; \
\
- printf( HEADER_FORMAT, TITLE ); \
+ polarssl_printf( HEADER_FORMAT, TITLE ); \
fflush( stdout ); \
\
set_alarm( 1 ); \
@@ -115,17 +121,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 +139,7 @@
unsigned long i; \
int ret; \
\
- printf( HEADER_FORMAT, TITLE ); \
+ polarssl_printf( HEADER_FORMAT, TITLE ); \
fflush( stdout ); \
set_alarm( 3 ); \
\
@@ -148,7 +154,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 +231,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 +637,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..b904a9f 100644
--- a/programs/test/o_p_test.c
+++ b/programs/test/o_p_test.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2011-2012 ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@@ -51,7 +57,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 +88,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 +97,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 +137,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 +155,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 aa4410d..d2f70d2 100644
--- a/programs/test/selftest.c
+++ b/programs/test/selftest.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -57,7 +63,7 @@
#include "polarssl/timing.h"
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
-#include "polarssl/memory.h"
+#include "polarssl/memory_buffer_alloc.h"
#endif
int main( int argc, char *argv[] )
@@ -72,7 +78,7 @@
else
{
v = 1;
- printf( "\n" );
+ polarssl_printf( "\n" );
}
#if defined(POLARSSL_SELF_TEST)
@@ -215,7 +221,7 @@
#endif
#else
- printf( " POLARSSL_SELF_TEST not defined.\n" );
+ polarssl_printf( " POLARSSL_SELF_TEST not defined.\n" );
#endif
if( v != 0 )
@@ -234,9 +240,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..037c474 100644
--- a/programs/test/ssl_cert_test.c
+++ b/programs/test/ssl_cert_test.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -36,7 +42,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 +99,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 +109,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 +151,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 +176,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 +230,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 +259,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 8c43d95..23e0d3c 100644
--- a/programs/test/ssl_test.c
+++ b/programs/test/ssl_test.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -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, NET_PROTO_TCP ) ) != 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, NET_PROTO_TCP ) ) != 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
diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt
index aedd94f..f302de7 100644
--- a/programs/util/CMakeLists.txt
+++ b/programs/util/CMakeLists.txt
@@ -1,5 +1,5 @@
set(libs
- polarssl
+ mbedtls
)
add_executable(strerror strerror.c)
diff --git a/programs/util/pem2der.c b/programs/util/pem2der.c
index 1ba478b..74f7a3e 100644
--- a/programs/util/pem2der.c
+++ b/programs/util/pem2der.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,14 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_malloc malloc
+#define polarssl_free free
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -42,7 +50,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_BASE64_C and/or POLARSSL_FS_IO not defined.\n");
+ polarssl_printf("POLARSSL_BASE64_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
@@ -121,7 +129,7 @@
*n = (size_t) size;
if( *n + 1 == 0 ||
- ( *buf = (unsigned char *) malloc( *n + 1 ) ) == NULL )
+ ( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
{
fclose( f );
return( -1 );
@@ -188,7 +196,7 @@
if( argc == 0 )
{
usage:
- printf( USAGE );
+ polarssl_printf( USAGE );
goto exit;
}
@@ -214,7 +222,7 @@
/*
* 1.1. Load the PEM file
*/
- printf( "\n . Loading the PEM file ..." );
+ polarssl_printf( "\n . Loading the PEM file ..." );
fflush( stdout );
ret = load_file( opt.filename, &pem_buffer, &pem_size );
@@ -224,16 +232,16 @@
#ifdef POLARSSL_ERROR_C
polarssl_strerror( ret, buf, 1024 );
#endif
- printf( " failed\n ! load_file returned %d - %s\n\n", ret, buf );
+ polarssl_printf( " failed\n ! load_file returned %d - %s\n\n", ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.2. Convert from PEM to DER
*/
- printf( " . Converting from PEM to DER ..." );
+ polarssl_printf( " . Converting from PEM to DER ..." );
fflush( stdout );
if( ( ret = convert_pem_to_der( pem_buffer, pem_size, der_buffer, &der_size ) ) != 0 )
@@ -241,16 +249,16 @@
#ifdef POLARSSL_ERROR_C
polarssl_strerror( ret, buf, 1024 );
#endif
- printf( " failed\n ! convert_pem_to_der %d - %s\n\n", ret, buf );
+ polarssl_printf( " failed\n ! convert_pem_to_der %d - %s\n\n", ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.3. Write the DER file
*/
- printf( " . Writing the DER file ..." );
+ polarssl_printf( " . Writing the DER file ..." );
fflush( stdout );
ret = write_file( opt.output_file, der_buffer, der_size );
@@ -260,17 +268,17 @@
#ifdef POLARSSL_ERROR_C
polarssl_strerror( ret, buf, 1024 );
#endif
- printf( " failed\n ! write_file returned %d - %s\n\n", ret, buf );
+ polarssl_printf( " failed\n ! write_file returned %d - %s\n\n", ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
exit:
free( pem_buffer );
#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/util/strerror.c b/programs/util/strerror.c
index 79eec18..c5598fc 100644
--- a/programs/util/strerror.c
+++ b/programs/util/strerror.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2012, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -42,7 +48,7 @@
((void) argc);
((void) argv);
- printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERROR_DUMMY not defined.\n");
+ polarssl_printf("POLARSSL_ERROR_C and/or POLARSSL_ERROR_STRERROR_DUMMY not defined.\n");
return( 0 );
}
#else
@@ -53,7 +59,7 @@
if( argc != 2 )
{
- printf( USAGE );
+ polarssl_printf( USAGE );
return( 0 );
}
@@ -63,7 +69,7 @@
val = strtol( argv[1], &end, 16 );
if( *end != '\0' )
{
- printf( USAGE );
+ polarssl_printf( USAGE );
return( 0 );
}
}
@@ -74,11 +80,11 @@
{
char error_buf[200];
polarssl_strerror( val, error_buf, 200 );
- printf("Last error was: -0x%04x - %s\n\n", (int) -val, error_buf );
+ polarssl_printf("Last error was: -0x%04x - %s\n\n", (int) -val, error_buf );
}
#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/wince_main.c b/programs/wince_main.c
index c3c8d4a..8bf249b 100644
--- a/programs/wince_main.c
+++ b/programs/wince_main.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt
index fe46da5..4e39e45 100644
--- a/programs/x509/CMakeLists.txt
+++ b/programs/x509/CMakeLists.txt
@@ -1,5 +1,5 @@
set(libs
- polarssl
+ mbedtls
)
if(USE_PKCS11_HELPER_LIBRARY)
diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c
index 7b2034a..3eb7d6d 100644
--- a/programs/x509/cert_app.c
+++ b/programs/x509/cert_app.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,13 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#define polarssl_fprintf fprintf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -46,7 +53,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_CLI_C and/or "
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_X509_CRT_PARSE_C and/or POLARSSL_FS_IO and/or "
@@ -89,7 +96,7 @@
{
if( level < opt.debug_level )
{
- fprintf( (FILE *) ctx, "%s", str );
+ polarssl_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
}
@@ -99,33 +106,33 @@
char buf[1024];
((void) data);
- printf( "\nVerify requested for (Depth %d):\n", depth );
+ polarssl_printf( "\nVerify requested for (Depth %d):\n", depth );
x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
- printf( "%s", buf );
+ polarssl_printf( "%s", buf );
if( ( (*flags) & BADCERT_EXPIRED ) != 0 )
- printf( " ! server certificate has expired\n" );
+ polarssl_printf( " ! server certificate has expired\n" );
if( ( (*flags) & BADCERT_REVOKED ) != 0 )
- printf( " ! server certificate has been revoked\n" );
+ polarssl_printf( " ! server certificate has been revoked\n" );
if( ( (*flags) & BADCERT_CN_MISMATCH ) != 0 )
- printf( " ! CN mismatch\n" );
+ polarssl_printf( " ! CN mismatch\n" );
if( ( (*flags) & BADCERT_NOT_TRUSTED ) != 0 )
- printf( " ! self-signed or not signed by a trusted CA\n" );
+ polarssl_printf( " ! self-signed or not signed by a trusted CA\n" );
if( ( (*flags) & BADCRL_NOT_TRUSTED ) != 0 )
- printf( " ! CRL not trusted\n" );
+ polarssl_printf( " ! CRL not trusted\n" );
if( ( (*flags) & BADCRL_EXPIRED ) != 0 )
- printf( " ! CRL expired\n" );
+ polarssl_printf( " ! CRL expired\n" );
if( ( (*flags) & BADCERT_OTHER ) != 0 )
- printf( " ! other (unknown) flag\n" );
+ polarssl_printf( " ! other (unknown) flag\n" );
if ( ( *flags ) == 0 )
- printf( " This certificate has no flags\n" );
+ polarssl_printf( " This certificate has no flags\n" );
return( 0 );
}
@@ -184,7 +191,7 @@
if( argc == 0 )
{
usage:
- printf( USAGE );
+ polarssl_printf( USAGE );
ret = 2;
goto exit;
}
@@ -256,7 +263,7 @@
/*
* 1.1. Load the trusted CA
*/
- printf( " . Loading the CA root certificate ..." );
+ polarssl_printf( " . Loading the CA root certificate ..." );
fflush( stdout );
if( strlen( opt.ca_path ) )
@@ -272,18 +279,18 @@
if( ret < 0 )
{
- printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crt_parse returned -0x%x\n\n", -ret );
goto exit;
}
- printf( " ok (%d skipped)\n", ret );
+ polarssl_printf( " ok (%d skipped)\n", ret );
#if defined(POLARSSL_X509_CRL_PARSE_C)
if( strlen( opt.crl_file ) )
{
if( ( ret = x509_crl_parse_file( &cacrl, opt.crl_file ) ) != 0 )
{
- printf( " failed\n ! x509_crl_parse returned -0x%x\n\n", -ret );
+ polarssl_printf( " failed\n ! x509_crl_parse returned -0x%x\n\n", -ret );
goto exit;
}
@@ -300,43 +307,43 @@
/*
* 1.1. Load the certificate(s)
*/
- printf( "\n . Loading the certificate(s) ..." );
+ polarssl_printf( "\n . Loading the certificate(s) ..." );
fflush( stdout );
ret = x509_crt_parse_file( &crt, opt.filename );
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 );
x509_crt_free( &crt );
goto exit;
}
if( opt.permissive == 0 && ret > 0 )
{
- printf( " failed\n ! x509_crt_parse failed to parse %d certificates\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_parse failed to parse %d certificates\n\n", ret );
x509_crt_free( &crt );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.2 Print the certificate(s)
*/
while( cur != NULL )
{
- printf( " . Peer certificate information ...\n" );
+ polarssl_printf( " . Peer certificate information ...\n" );
ret = x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
cur );
if( ret == -1 )
{
- printf( " failed\n ! x509_crt_info returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_info returned %d\n\n", ret );
x509_crt_free( &crt );
goto exit;
}
- printf( "%s\n", buf );
+ polarssl_printf( "%s\n", buf );
cur = cur->next;
}
@@ -346,29 +353,29 @@
*/
if( verify )
{
- printf( " . Verifying X.509 certificate..." );
+ polarssl_printf( " . Verifying X.509 certificate..." );
if( ( ret = x509_crt_verify( &crt, &cacert, &cacrl, NULL, &flags,
my_verify, NULL ) ) != 0 )
{
- printf( " failed\n" );
+ polarssl_printf( " failed\n" );
if( ( ret & BADCERT_EXPIRED ) != 0 )
- printf( " ! server certificate has expired\n" );
+ polarssl_printf( " ! server certificate has expired\n" );
if( ( ret & BADCERT_REVOKED ) != 0 )
- printf( " ! server certificate has been revoked\n" );
+ polarssl_printf( " ! server certificate has been revoked\n" );
if( ( ret & BADCERT_CN_MISMATCH ) != 0 )
- printf( " ! CN mismatch (expected CN=%s)\n", opt.server_name );
+ polarssl_printf( " ! CN mismatch (expected CN=%s)\n", opt.server_name );
if( ( ret & BADCERT_NOT_TRUSTED ) != 0 )
- printf( " ! self-signed or not signed by a trusted CA\n" );
+ polarssl_printf( " ! self-signed or not signed by a trusted CA\n" );
- printf( "\n" );
+ polarssl_printf( "\n" );
}
else
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
x509_crt_free( &crt );
@@ -378,7 +385,7 @@
/*
* 1. Initialize the RNG and the session data
*/
- printf( "\n . Seeding the random number generator..." );
+ polarssl_printf( "\n . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
@@ -386,23 +393,23 @@
(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" );
+ polarssl_printf( " ok\n" );
/*
* 2. Start the connection
*/
- printf( " . SSL connection to tcp/%s/%-4d...", opt.server_name,
+ polarssl_printf( " . SSL connection to tcp/%s/%-4d...", opt.server_name,
opt.server_port );
fflush( stdout );
if( ( ret = net_connect( &server_fd, opt.server_name,
opt.server_port, NET_PROTO_TCP ) ) != 0 )
{
- printf( " failed\n ! net_connect returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! net_connect returned %d\n\n", ret );
goto exit;
}
@@ -411,7 +418,7 @@
*/
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
- printf( " failed\n ! ssl_init returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_init returned %d\n\n", ret );
goto exit;
}
@@ -432,14 +439,14 @@
if( ( ret = ssl_set_own_cert( &ssl, &clicert, &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;
}
#if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
if( ( ret = ssl_set_hostname( &ssl, opt.server_name ) ) != 0 )
{
- printf( " failed\n ! ssl_set_hostname returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_set_hostname returned %d\n\n", ret );
goto exit;
}
#endif
@@ -451,28 +458,28 @@
{
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
{
- printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! ssl_handshake returned %d\n\n", ret );
ssl_free( &ssl );
goto exit;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 5. Print the certificate
*/
- printf( " . Peer certificate information ...\n" );
+ polarssl_printf( " . Peer certificate information ...\n" );
ret = x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
ssl.session->peer_cert );
if( ret == -1 )
{
- printf( " failed\n ! x509_crt_info returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crt_info returned %d\n\n", ret );
ssl_free( &ssl );
goto exit;
}
- printf( "%s\n", buf );
+ polarssl_printf( "%s\n", buf );
ssl_close_notify( &ssl );
ssl_free( &ssl );
@@ -494,7 +501,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/x509/cert_req.c b/programs/x509/cert_req.c
index 54f1462..3b67f65 100644
--- a/programs/x509/cert_req.c
+++ b/programs/x509/cert_req.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -43,7 +49,7 @@
((void) argc);
((void) argv);
- printf( "POLARSSL_X509_CSR_WRITE_C and/or POLARSSL_FS_IO and/or "
+ polarssl_printf( "POLARSSL_X509_CSR_WRITE_C and/or POLARSSL_FS_IO and/or "
"POLARSSL_PK_PARSE_C and/or "
"POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C "
"not defined.\n");
@@ -150,7 +156,7 @@
if( argc == 0 )
{
usage:
- printf( USAGE );
+ polarssl_printf( USAGE );
ret = 1;
goto exit;
}
@@ -251,7 +257,7 @@
/*
* 0. Seed the PRNG
*/
- printf( " . Seeding the random number generator..." );
+ polarssl_printf( " . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
@@ -259,58 +265,58 @@
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
{
- printf( " failed\n ! ctr_drbg_init returned %d", ret );
+ polarssl_printf( " failed\n ! ctr_drbg_init returned %d", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.0. Check the subject name for validity
*/
- printf( " . Checking subjet name..." );
+ polarssl_printf( " . Checking subjet name..." );
fflush( stdout );
if( ( ret = x509write_csr_set_subject_name( &req, opt.subject_name ) ) != 0 )
{
- printf( " failed\n ! x509write_csr_set_subject_name returned %d", ret );
+ polarssl_printf( " failed\n ! x509write_csr_set_subject_name returned %d", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.1. Load the key
*/
- printf( " . Loading the private key ..." );
+ polarssl_printf( " . Loading the private key ..." );
fflush( stdout );
ret = pk_parse_keyfile( &key, opt.filename, NULL );
if( ret != 0 )
{
- printf( " failed\n ! pk_parse_keyfile returned %d", ret );
+ polarssl_printf( " failed\n ! pk_parse_keyfile returned %d", ret );
goto exit;
}
x509write_csr_set_key( &req, &key );
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.2. Writing the request
*/
- printf( " . Writing the certificate request ..." );
+ polarssl_printf( " . Writing the certificate request ..." );
fflush( stdout );
if( ( ret = write_certificate_request( &req, opt.output_file,
ctr_drbg_random, &ctr_drbg ) ) != 0 )
{
- printf( " failed\n ! write_certifcate_request %d", ret );
+ polarssl_printf( " failed\n ! write_certifcate_request %d", ret );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
exit:
@@ -318,9 +324,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
}
@@ -330,7 +336,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/x509/cert_write.c b/programs/x509/cert_write.c
index 5c7dd86..eed12cf 100644
--- a/programs/x509/cert_write.c
+++ b/programs/x509/cert_write.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -39,7 +45,7 @@
((void) argc);
((void) argv);
- printf( "POLARSSL_X509_CRT_WRITE_C and/or POLARSSL_X509_CRT_PARSE_C and/or "
+ polarssl_printf( "POLARSSL_X509_CRT_WRITE_C and/or POLARSSL_X509_CRT_PARSE_C and/or "
"POLARSSL_FS_IO and/or "
"POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C and/or "
"POLARSSL_ERROR_C not defined.\n");
@@ -216,7 +222,7 @@
if( argc == 0 )
{
usage:
- printf( USAGE );
+ polarssl_printf( USAGE );
ret = 1;
goto exit;
}
@@ -358,12 +364,12 @@
goto usage;
}
- printf("\n");
+ polarssl_printf("\n");
/*
* 0. Seed the PRNG
*/
- printf( " . Seeding the random number generator..." );
+ polarssl_printf( " . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
@@ -372,25 +378,25 @@
strlen( pers ) ) ) != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! ctr_drbg_init returned %d - %s\n", ret, buf );
+ polarssl_printf( " failed\n ! ctr_drbg_init returned %d - %s\n", ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
// Parse serial to MPI
//
- printf( " . Reading serial number..." );
+ polarssl_printf( " . Reading serial number..." );
fflush( stdout );
if( ( ret = mpi_read_string( &serial, 10, opt.serial ) ) != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! mpi_read_string returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! mpi_read_string returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
// Parse issuer certificate if present
//
@@ -399,13 +405,13 @@
/*
* 1.0.a. Load the certificates
*/
- printf( " . Loading the issuer certificate ..." );
+ polarssl_printf( " . Loading the issuer certificate ..." );
fflush( stdout );
if( ( ret = x509_crt_parse_file( &issuer_crt, opt.issuer_crt ) ) != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509_crt_parse_file returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509_crt_parse_file returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
@@ -414,13 +420,13 @@
if( ret < 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509_dn_gets returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509_dn_gets returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
opt.issuer_name = issuer_name;
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
#if defined(POLARSSL_X509_CSR_PARSE_C)
@@ -431,13 +437,13 @@
/*
* 1.0.b. Load the CSR
*/
- printf( " . Loading the certificate request ..." );
+ polarssl_printf( " . Loading the certificate request ..." );
fflush( stdout );
if( ( ret = x509_csr_parse_file( &csr, opt.request_file ) ) != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509_csr_parse_file returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509_csr_parse_file returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
@@ -446,14 +452,14 @@
if( ret < 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509_dn_gets returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509_dn_gets returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
opt.subject_name = subject_name;
subject_key = &csr.pk;
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
#endif /* POLARSSL_X509_CSR_PARSE_C */
@@ -462,7 +468,7 @@
*/
if( !opt.selfsign && !strlen( opt.request_file ) )
{
- printf( " . Loading the subject key ..." );
+ polarssl_printf( " . Loading the subject key ..." );
fflush( stdout );
ret = pk_parse_keyfile( &loaded_subject_key, opt.subject_key,
@@ -470,14 +476,14 @@
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! pk_parse_keyfile returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
- printf( " . Loading the issuer key ..." );
+ polarssl_printf( " . Loading the issuer key ..." );
fflush( stdout );
ret = pk_parse_keyfile( &loaded_issuer_key, opt.issuer_key,
@@ -485,7 +491,7 @@
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! pk_parse_keyfile returned -x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! pk_parse_keyfile returned -x%02x - %s\n\n", -ret, buf );
goto exit;
}
@@ -499,13 +505,13 @@
mpi_cmp_mpi( &pk_rsa( issuer_crt.pk )->E,
&pk_rsa( *issuer_key )->E ) != 0 )
{
- printf( " failed\n ! issuer_key does not match issuer certificate\n\n" );
+ polarssl_printf( " failed\n ! issuer_key does not match issuer certificate\n\n" );
ret = -1;
goto exit;
}
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
if( opt.selfsign )
{
@@ -522,25 +528,25 @@
if( ( ret = x509write_crt_set_subject_name( &crt, opt.subject_name ) ) != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_subject_name returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_subject_name returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
if( ( ret = x509write_crt_set_issuer_name( &crt, opt.issuer_name ) ) != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_issuer_name returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_issuer_name returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " . Setting certificate values ..." );
+ polarssl_printf( " . Setting certificate values ..." );
fflush( stdout );
ret = x509write_crt_set_serial( &crt, &serial );
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_serial returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_serial returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
@@ -548,13 +554,13 @@
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_validity returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_validity returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
- printf( " . Adding the Basic Constraints extension ..." );
+ polarssl_printf( " . Adding the Basic Constraints extension ..." );
fflush( stdout );
ret = x509write_crt_set_basic_constraints( &crt, opt.is_ca,
@@ -562,87 +568,87 @@
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_basic_contraints returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_basic_contraints returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
#if defined(POLARSSL_SHA1_C)
- printf( " . Adding the Subject Key Identifier ..." );
+ polarssl_printf( " . Adding the Subject Key Identifier ..." );
fflush( stdout );
ret = x509write_crt_set_subject_key_identifier( &crt );
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_subject_key_identifier returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_subject_key_identifier returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
- printf( " . Adding the Authority Key Identifier ..." );
+ polarssl_printf( " . Adding the Authority Key Identifier ..." );
fflush( stdout );
ret = x509write_crt_set_authority_key_identifier( &crt );
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_authority_key_identifier returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_authority_key_identifier returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
#endif /* POLARSSL_SHA1_C */
if( opt.key_usage )
{
- printf( " . Adding the Key Usage extension ..." );
+ polarssl_printf( " . Adding the Key Usage extension ..." );
fflush( stdout );
ret = x509write_crt_set_key_usage( &crt, opt.key_usage );
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_key_usage returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_key_usage returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
if( opt.ns_cert_type )
{
- printf( " . Adding the NS Cert Type extension ..." );
+ polarssl_printf( " . Adding the NS Cert Type extension ..." );
fflush( stdout );
ret = x509write_crt_set_ns_cert_type( &crt, opt.ns_cert_type );
if( ret != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! x509write_crt_set_ns_cert_type returned -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! x509write_crt_set_ns_cert_type returned -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
}
/*
* 1.2. Writing the request
*/
- printf( " . Writing the certificate..." );
+ polarssl_printf( " . Writing the certificate..." );
fflush( stdout );
if( ( ret = write_certificate( &crt, opt.output_file,
ctr_drbg_random, &ctr_drbg ) ) != 0 )
{
polarssl_strerror( ret, buf, 1024 );
- printf( " failed\n ! write_certifcate -0x%02x - %s\n\n", -ret, buf );
+ polarssl_printf( " failed\n ! write_certifcate -0x%02x - %s\n\n", -ret, buf );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
exit:
x509write_crt_free( &crt );
@@ -653,7 +659,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/x509/crl_app.c b/programs/x509/crl_app.c
index 4d91452..4370227 100644
--- a/programs/x509/crl_app.c
+++ b/programs/x509/crl_app.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -39,7 +45,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_X509_CRL_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
@@ -78,7 +84,7 @@
if( argc == 0 )
{
usage:
- printf( USAGE );
+ polarssl_printf( USAGE );
goto exit;
}
@@ -100,39 +106,39 @@
/*
* 1.1. Load the CRL
*/
- printf( "\n . Loading the CRL ..." );
+ polarssl_printf( "\n . Loading the CRL ..." );
fflush( stdout );
ret = x509_crl_parse_file( &crl, opt.filename );
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 );
x509_crl_free( &crl );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.2 Print the CRL
*/
- printf( " . CRL information ...\n" );
+ polarssl_printf( " . CRL information ...\n" );
ret = x509_crl_info( (char *) buf, sizeof( buf ) - 1, " ", &crl );
if( ret == -1 )
{
- printf( " failed\n ! x509_crl_info returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_crl_info returned %d\n\n", ret );
x509_crl_free( &crl );
goto exit;
}
- printf( "%s\n", buf );
+ polarssl_printf( "%s\n", buf );
exit:
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/x509/req_app.c b/programs/x509/req_app.c
index ced2d3e..a4be7e6 100644
--- a/programs/x509/req_app.c
+++ b/programs/x509/req_app.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
*
- * This file is part of mbed TLS (https://www.polarssl.org)
+ * This file is part of mbed TLS (https://polarssl.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,6 +26,12 @@
#include POLARSSL_CONFIG_FILE
#endif
+#if defined(POLARSSL_PLATFORM_C)
+#include "polarssl/platform.h"
+#else
+#define polarssl_printf printf
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -39,7 +45,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_X509_CSR_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
@@ -78,7 +84,7 @@
if( argc == 0 )
{
usage:
- printf( USAGE );
+ polarssl_printf( USAGE );
goto exit;
}
@@ -100,39 +106,39 @@
/*
* 1.1. Load the CSR
*/
- printf( "\n . Loading the CSR ..." );
+ polarssl_printf( "\n . Loading the CSR ..." );
fflush( stdout );
ret = x509_csr_parse_file( &csr, opt.filename );
if( ret != 0 )
{
- printf( " failed\n ! x509_csr_parse_file returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_csr_parse_file returned %d\n\n", ret );
x509_csr_free( &csr );
goto exit;
}
- printf( " ok\n" );
+ polarssl_printf( " ok\n" );
/*
* 1.2 Print the CSR
*/
- printf( " . CSR information ...\n" );
+ polarssl_printf( " . CSR information ...\n" );
ret = x509_csr_info( (char *) buf, sizeof( buf ) - 1, " ", &csr );
if( ret == -1 )
{
- printf( " failed\n ! x509_csr_info returned %d\n\n", ret );
+ polarssl_printf( " failed\n ! x509_csr_info returned %d\n\n", ret );
x509_csr_free( &csr );
goto exit;
}
- printf( "%s\n", buf );
+ polarssl_printf( "%s\n", buf );
exit:
x509_csr_free( &csr );
#if defined(_WIN32)
- printf( " + Press Enter to exit this program.\n" );
+ polarssl_printf( " + Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif