modify programs/*.c to use polarssl_snprintf

This commit is contained in:
Rich Evans 2015-01-30 11:11:57 +00:00
parent 2387c7d105
commit 783d9d1c3e
8 changed files with 27 additions and 19 deletions

View File

@ -29,6 +29,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#endif #endif
@ -133,7 +134,7 @@ int main( int argc, char *argv[] )
/* /*
* Write the signature into <filename>-sig.txt * 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 ) if( ( f = fopen( filename, "wb+" ) ) == NULL )
{ {

View File

@ -29,6 +29,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#endif #endif
@ -94,7 +95,7 @@ int main( int argc, char *argv[] )
* Extract the signature from the text file * Extract the signature from the text file
*/ */
ret = 1; 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 ) if( ( f = fopen( filename, "rb" ) ) == NULL )
{ {

View File

@ -29,6 +29,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#endif #endif
@ -143,7 +144,7 @@ int main( int argc, char *argv[] )
/* /*
* Write the signature into <filename>-sig.txt * 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 ) if( ( f = fopen( filename, "wb+" ) ) == NULL )
{ {

View File

@ -29,6 +29,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#endif #endif
@ -105,7 +106,7 @@ int main( int argc, char *argv[] )
* Extract the RSA signature from the text file * Extract the RSA signature from the text file
*/ */
ret = 1; ret = 1;
snprintf( filename, 512, "%s.sig", argv[2] ); polarssl_snprintf( filename, 512, "%s.sig", argv[2] );
if( ( f = fopen( filename, "rb" ) ) == NULL ) if( ( f = fopen( filename, "rb" ) ) == NULL )
{ {

View File

@ -29,6 +29,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#define polarssl_fprintf fprintf #define polarssl_fprintf fprintf
#endif #endif
@ -1197,7 +1198,7 @@ send_request:
polarssl_printf( " > Write to server:" ); polarssl_printf( " > Write to server:" );
fflush( stdout ); fflush( stdout );
len = snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST, len = polarssl_snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST,
opt.request_page ); opt.request_page );
tail_len = strlen( GET_REQUEST_END ); tail_len = strlen( GET_REQUEST_END );

View File

@ -30,6 +30,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#define polarssl_fprintf fprintf #define polarssl_fprintf fprintf
#endif #endif
@ -137,7 +138,7 @@ static void *handle_ssl_connection( void *data )
memset( &ssl, 0, sizeof( ssl_context ) ); memset( &ssl, 0, sizeof( ssl_context ) );
memset( &ctr_drbg, 0, sizeof( ctr_drbg_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 ] Client FD %d\n", thread_id, client_fd );
polarssl_printf( " [ #%d ] Seeding the random number generator...\n", thread_id ); polarssl_printf( " [ #%d ] Seeding the random number generator...\n", thread_id );

View File

@ -29,6 +29,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#endif #endif
@ -313,7 +314,7 @@ int main( int argc, char *argv[] )
aes_init( &aes ); aes_init( &aes );
for( keysize = 128; keysize <= 256; keysize += 64 ) 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( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) ); memset( tmp, 0, sizeof( tmp ) );
@ -331,7 +332,7 @@ int main( int argc, char *argv[] )
gcm_context gcm; gcm_context gcm;
for( keysize = 128; keysize <= 256; keysize += 64 ) 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( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) ); memset( tmp, 0, sizeof( tmp ) );
@ -351,7 +352,7 @@ int main( int argc, char *argv[] )
ccm_context ccm; ccm_context ccm;
for( keysize = 128; keysize <= 256; keysize += 64 ) 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( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) ); memset( tmp, 0, sizeof( tmp ) );
@ -374,7 +375,7 @@ int main( int argc, char *argv[] )
camellia_init( &camellia ); camellia_init( &camellia );
for( keysize = 128; keysize <= 256; keysize += 64 ) 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( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) ); memset( tmp, 0, sizeof( tmp ) );
@ -396,7 +397,7 @@ int main( int argc, char *argv[] )
for( keysize = 128; keysize <= 256; keysize += 64 ) 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( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) ); memset( tmp, 0, sizeof( tmp ) );
@ -498,7 +499,7 @@ int main( int argc, char *argv[] )
rsa_context rsa; rsa_context rsa;
for( keysize = 1024; keysize <= 4096; keysize *= 2 ) 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_init( &rsa, RSA_PKCS_V15, 0 );
rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 ); rsa_gen_key( &rsa, myrand, NULL, keysize, 65537 );
@ -549,14 +550,14 @@ int main( int argc, char *argv[] )
if( mpi_copy( &dhm.GY, &dhm.GX ) != 0 ) if( mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
exit( 1 ); 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", TIME_PUBLIC( title, "handshake",
olen = sizeof( buf ); olen = sizeof( buf );
ret |= dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, ret |= dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len,
myrand, NULL ); myrand, NULL );
ret |= dhm_calc_secret( &dhm, buf, &olen, 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", TIME_PUBLIC( title, "handshake",
olen = sizeof( buf ); olen = sizeof( buf );
ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) ); ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL ) );
@ -584,7 +585,7 @@ int main( int argc, char *argv[] )
if( ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 ) if( ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
exit( 1 ); exit( 1 );
snprintf( title, sizeof( title ), "ECDSA-%s", polarssl_snprintf( title, sizeof( title ), "ECDSA-%s",
curve_info->name ); curve_info->name );
TIME_PUBLIC( title, "sign", TIME_PUBLIC( title, "sign",
ret = ecdsa_write_signature( &ecdsa, buf, curve_info->size, ret = ecdsa_write_signature( &ecdsa, buf, curve_info->size,
@ -620,7 +621,7 @@ int main( int argc, char *argv[] )
exit( 1 ); exit( 1 );
} }
snprintf( title, sizeof( title ), "ECDHE-%s", polarssl_snprintf( title, sizeof( title ), "ECDHE-%s",
curve_info->name ); curve_info->name );
TIME_PUBLIC( title, "handshake", TIME_PUBLIC( title, "handshake",
ret |= ecdh_make_public( &ecdh, &olen, buf, sizeof( buf), ret |= ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
@ -628,7 +629,7 @@ int main( int argc, char *argv[] )
ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
myrand, NULL ) ); myrand, NULL ) );
snprintf( title, sizeof( title ), "ECDH-%s", polarssl_snprintf( title, sizeof( title ), "ECDH-%s",
curve_info->name ); curve_info->name );
TIME_PUBLIC( title, "handshake", TIME_PUBLIC( title, "handshake",
ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ), ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),

View File

@ -29,6 +29,7 @@
#if defined(POLARSSL_PLATFORM_C) #if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h" #include "polarssl/platform.h"
#else #else
#define polarssl_snprintf snprintf
#define polarssl_printf printf #define polarssl_printf printf
#endif #endif
@ -149,7 +150,7 @@ int main( int argc, char *argv[] )
x509_crt_init( &clicert ); x509_crt_init( &clicert );
pk_init( &pk ); 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 ); polarssl_printf( " . Loading the client certificate %s...", name );
fflush( stdout ); fflush( stdout );
@ -198,7 +199,7 @@ int main( int argc, char *argv[] )
/* /*
* 1.5. Load own private key * 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 ); polarssl_printf( " . Loading the client private key %s...", name );
fflush( stdout ); fflush( stdout );