Merge remote-tracking branch 'rich/platform' into development
* rich/platform:
Remove dependency on sscanf in lib x509
Fix extra guard in memory_buffer_alloc
rebase from development
implemented macro overriding for polarssl_* library functions
fix bug introduced by the addition of snprintf and assert macro which caused tests to fail without polarssl_platform_c defined
add initial symbols to config and checks to check_config to allow use of macros to define standard functions
reformat and arrange additions to config alphabetically
add missing checks to check_config
add macro definition of assert using polarssl_exit
modify library/memory_buffer_alloc.c, benchmark.c and the tests main code to use polarssl_exit
add POLARSSL_PLATFORM_EXIT_ALT
modify scripts/* and tests/* to use polarssl_snprintf
modify programs/*.c to use polarssl_snprintf
modify library/debug.c to use polarssl_snprintf
modify library/x509*.c to use polarssl_snprintf
modify library/net.c to use polarssl_snprintf
modify oid.c to use polarssl_snprintf
add platform_set_snprintf
Conflicts:
library/memory_buffer_alloc.c
programs/pkey/pk_sign.c
programs/pkey/pk_verify.c
programs/pkey/rsa_sign_pss.c
programs/pkey/rsa_verify_pss.c
programs/ssl/ssl_client2.c
programs/ssl/ssl_pthread_server.c
programs/test/benchmark.c
programs/test/ssl_cert_test.c
diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c
index 162db1e..88561b1 100644
--- a/programs/pkey/pk_sign.c
+++ b/programs/pkey/pk_sign.c
@@ -30,6 +30,7 @@
#include "polarssl/platform.h"
#else
#include <stdio.h>
+#define polarssl_snprintf snprintf
#define polarssl_printf printf
#endif
@@ -136,7 +137,7 @@
/*
* Write the signature into <filename>-sig.txt
*/
- snprintf( filename, sizeof(filename), "%s.sig", argv[2] );
+ polarssl_snprintf( filename, sizeof(filename), "%s.sig", argv[2] );
if( ( f = fopen( filename, "wb+" ) ) == NULL )
{
diff --git a/programs/pkey/pk_verify.c b/programs/pkey/pk_verify.c
index 6f8755b..d8cd9a1 100644
--- a/programs/pkey/pk_verify.c
+++ b/programs/pkey/pk_verify.c
@@ -30,6 +30,7 @@
#include "polarssl/platform.h"
#else
#include <stdio.h>
+#define polarssl_snprintf snprintf
#define polarssl_printf printf
#endif
@@ -96,7 +97,7 @@
* Extract the signature from the text file
*/
ret = 1;
- snprintf( filename, sizeof(filename), "%s.sig", argv[2] );
+ polarssl_snprintf( filename, sizeof(filename), "%s.sig", argv[2] );
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c
index be42ad1..2433096 100644
--- a/programs/pkey/rsa_sign_pss.c
+++ b/programs/pkey/rsa_sign_pss.c
@@ -30,6 +30,7 @@
#include "polarssl/platform.h"
#else
#include <stdio.h>
+#define polarssl_snprintf snprintf
#define polarssl_printf printf
#endif
@@ -146,7 +147,7 @@
/*
* Write the signature into <filename>-sig.txt
*/
- snprintf( filename, 512, "%s.sig", argv[2] );
+ polarssl_snprintf( filename, 512, "%s.sig", argv[2] );
if( ( f = fopen( filename, "wb+" ) ) == NULL )
{
diff --git a/programs/pkey/rsa_verify_pss.c b/programs/pkey/rsa_verify_pss.c
index d679a58..65fcfbe 100644
--- a/programs/pkey/rsa_verify_pss.c
+++ b/programs/pkey/rsa_verify_pss.c
@@ -30,6 +30,7 @@
#include "polarssl/platform.h"
#else
#include <stdio.h>
+#define polarssl_snprintf snprintf
#define polarssl_printf printf
#endif
@@ -107,7 +108,7 @@
* Extract the RSA signature from the text file
*/
ret = 1;
- snprintf( filename, 512, "%s.sig", argv[2] );
+ polarssl_snprintf( filename, 512, "%s.sig", argv[2] );
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index e0ba186..e2dac43 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
+#define polarssl_snprintf snprintf
#endif
#if defined(POLARSSL_ENTROPY_C) && defined(POLARSSL_FS_IO) && \
@@ -1197,7 +1198,7 @@
polarssl_printf( " > Write to server:" );
fflush( stdout );
- len = snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST,
+ len = polarssl_snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST,
opt.request_page );
tail_len = strlen( GET_REQUEST_END );
diff --git a/programs/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c
index 091d07a..524413c 100644
--- a/programs/ssl/ssl_pthread_server.c
+++ b/programs/ssl/ssl_pthread_server.c
@@ -33,6 +33,7 @@
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
+#define polarssl_snprintf snprintf
#endif
#if defined(_WIN32)
@@ -141,7 +142,7 @@
memset( &ssl, 0, sizeof( ssl_context ) );
memset( &ctr_drbg, 0, sizeof( ctr_drbg_context ) );
- snprintf( pers, sizeof(pers), "SSL Pthread Thread %d", thread_id );
+ polarssl_snprintf( pers, sizeof(pers), "SSL Pthread Thread %d", thread_id );
polarssl_printf( " [ #%d ] Client FD %d\n", thread_id, client_fd );
polarssl_printf( " [ #%d ] Seeding the random number generator...\n", thread_id );
diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
index 2882ecf..edb7c07 100644
--- a/programs/test/benchmark.c
+++ b/programs/test/benchmark.c
@@ -30,7 +30,9 @@
#include "polarssl/platform.h"
#else
#include <stdio.h>
+#define polarssl_snprintf snprintf
#define polarssl_printf printf
+#define polarssl_exit exit
#endif
#if defined(POLARSSL_TIMING_C)
@@ -314,7 +316,7 @@
aes_init( &aes );
for( keysize = 128; keysize <= 256; keysize += 64 )
{
- snprintf( title, sizeof( title ), "AES-CBC-%d", keysize );
+ polarssl_snprintf( title, sizeof( title ), "AES-CBC-%d", keysize );
memset( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) );
@@ -332,7 +334,7 @@
gcm_context gcm;
for( keysize = 128; keysize <= 256; keysize += 64 )
{
- snprintf( title, sizeof( title ), "AES-GCM-%d", keysize );
+ polarssl_snprintf( title, sizeof( title ), "AES-GCM-%d", keysize );
memset( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) );
@@ -352,7 +354,7 @@
ccm_context ccm;
for( keysize = 128; keysize <= 256; keysize += 64 )
{
- snprintf( title, sizeof( title ), "AES-CCM-%d", keysize );
+ polarssl_snprintf( title, sizeof( title ), "AES-CCM-%d", keysize );
memset( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) );
@@ -375,7 +377,7 @@
camellia_init( &camellia );
for( keysize = 128; keysize <= 256; keysize += 64 )
{
- snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize );
+ polarssl_snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize );
memset( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) );
@@ -397,7 +399,7 @@
for( keysize = 128; keysize <= 256; keysize += 64 )
{
- snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize );
+ polarssl_snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize );
memset( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) );
@@ -428,17 +430,17 @@
ctr_drbg_context ctr_drbg;
if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
- exit(1);
+ polarssl_exit(1);
TIME_AND_TSC( "CTR_DRBG (NOPR)",
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
- exit(1) );
+ polarssl_exit(1) );
if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
- exit(1);
+ polarssl_exit(1);
ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON );
TIME_AND_TSC( "CTR_DRBG (PR)",
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
- exit(1) );
+ polarssl_exit(1) );
ctr_drbg_free( &ctr_drbg );
}
#endif
@@ -451,43 +453,43 @@
#if defined(POLARSSL_SHA1_C)
if( ( md_info = md_info_from_type( POLARSSL_MD_SHA1 ) ) == NULL )
- exit(1);
+ polarssl_exit(1);
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
- exit(1);
+ polarssl_exit(1);
TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)",
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
- exit(1) );
+ polarssl_exit(1) );
hmac_drbg_free( &hmac_drbg );
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
- exit(1);
+ polarssl_exit(1);
hmac_drbg_set_prediction_resistance( &hmac_drbg,
POLARSSL_HMAC_DRBG_PR_ON );
TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)",
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
- exit(1) );
+ polarssl_exit(1) );
hmac_drbg_free( &hmac_drbg );
#endif
#if defined(POLARSSL_SHA256_C)
if( ( md_info = md_info_from_type( POLARSSL_MD_SHA256 ) ) == NULL )
- exit(1);
+ polarssl_exit(1);
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
- exit(1);
+ polarssl_exit(1);
TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)",
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
- exit(1) );
+ polarssl_exit(1) );
hmac_drbg_free( &hmac_drbg );
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
- exit(1);
+ polarssl_exit(1);
hmac_drbg_set_prediction_resistance( &hmac_drbg,
POLARSSL_HMAC_DRBG_PR_ON );
TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)",
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
- exit(1) );
+ polarssl_exit(1) );
hmac_drbg_free( &hmac_drbg );
#endif
}
@@ -499,7 +501,7 @@
rsa_context rsa;
for( keysize = 1024; keysize <= 4096; keysize *= 2 )
{
- snprintf( title, sizeof( title ), "RSA-%d", keysize );
+ polarssl_snprintf( title, sizeof( title ), "RSA-%d", keysize );
rsa_init( &rsa, RSA_PKCS_V15, 0 );
rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 );
@@ -541,22 +543,22 @@
if( mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 ||
mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 )
{
- exit( 1 );
+ polarssl_exit( 1 );
}
dhm.len = mpi_size( &dhm.P );
dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL );
if( mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
- exit( 1 );
+ polarssl_exit( 1 );
- snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
+ polarssl_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
TIME_PUBLIC( title, "handshake",
olen = sizeof( buf );
ret |= dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len,
myrand, NULL );
ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) );
- snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] );
+ polarssl_snprintf( title, sizeof( title ), "DH-%d", dhm_sizes[i] );
TIME_PUBLIC( title, "handshake",
olen = sizeof( buf );
ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) );
@@ -582,9 +584,9 @@
ecdsa_init( &ecdsa );
if( ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
- exit( 1 );
+ polarssl_exit( 1 );
- snprintf( title, sizeof( title ), "ECDSA-%s",
+ polarssl_snprintf( title, sizeof( title ), "ECDSA-%s",
curve_info->name );
TIME_PUBLIC( title, "sign",
ret = ecdsa_write_signature( &ecdsa, buf, curve_info->size,
@@ -617,10 +619,10 @@
myrand, NULL ) != 0 ||
ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 )
{
- exit( 1 );
+ polarssl_exit( 1 );
}
- snprintf( title, sizeof( title ), "ECDHE-%s",
+ polarssl_snprintf( title, sizeof( title ), "ECDHE-%s",
curve_info->name );
TIME_PUBLIC( title, "handshake",
ret |= ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
@@ -628,7 +630,7 @@
ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
myrand, NULL ) );
- snprintf( title, sizeof( title ), "ECDH-%s",
+ polarssl_snprintf( title, sizeof( title ), "ECDH-%s",
curve_info->name );
TIME_PUBLIC( title, "handshake",
ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
diff --git a/programs/test/ssl_cert_test.c b/programs/test/ssl_cert_test.c
index 393651f..782d6f3 100644
--- a/programs/test/ssl_cert_test.c
+++ b/programs/test/ssl_cert_test.c
@@ -30,6 +30,7 @@
#include "polarssl/platform.h"
#else
#include <stdio.h>
+#define polarssl_snprintf snprintf
#define polarssl_printf printf
#endif
@@ -145,7 +146,7 @@
x509_crt_init( &clicert );
pk_init( &pk );
- snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]);
+ polarssl_snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]);
polarssl_printf( " . Loading the client certificate %s...", name );
fflush( stdout );
@@ -194,7 +195,7 @@
/*
* 1.5. Load own private key
*/
- snprintf(name, 512, "ssl/test-ca/%s", client_private_keys[i]);
+ polarssl_snprintf(name, 512, "ssl/test-ca/%s", client_private_keys[i]);
polarssl_printf( " . Loading the client private key %s...", name );
fflush( stdout );