Cleanup up non-prototyped functions (static) and const-correctness in programs

This commit is contained in:
Paul Bakker 2013-06-25 16:37:45 +02:00
parent b6c5d2e1a6
commit 3c5ef71322
12 changed files with 34 additions and 88 deletions

View file

@ -1,7 +1,7 @@
/*
* Key reading application
*
* Copyright (C) 2006-2012, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -56,18 +56,8 @@ struct options
const char *filename; /* filename of the key file */
const char *password; /* password for the private key */
const char *password_file; /* password_file for the private key */
int debug_level; /* level of debugging */
} opt;
void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
}
#define USAGE \
"\n usage: key_app param=<>...\n" \
"\n acceptable parameters:\n" \
@ -75,7 +65,6 @@ void my_debug( void *ctx, int level, const char *str )
" filename=%%s default: keyfile.key\n" \
" password=%%s default: \"\"\n" \
" password_file=%%s default: \"\"\n" \
" debug_level=%%d default: 0 (disabled)\n" \
"\n"
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
@ -115,7 +104,6 @@ int main( int argc, char *argv[] )
opt.filename = DFL_FILENAME;
opt.password = DFL_PASSWORD;
opt.password_file = DFL_PASSWORD_FILE;
opt.debug_level = DFL_DEBUG_LEVEL;
for( i = 1; i < argc; i++ )
{
@ -139,12 +127,6 @@ int main( int argc, char *argv[] )
opt.password = q;
else if( strcmp( p, "password_file" ) == 0 )
opt.password_file = q;
else if( strcmp( p, "debug_level" ) == 0 )
{
opt.debug_level = atoi( q );
if( opt.debug_level < 0 || opt.debug_level > 65535 )
goto usage;
}
else
goto usage;
}

View file

@ -1,7 +1,7 @@
/*
* Key reading application
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -73,21 +73,11 @@ struct options
{
int mode; /* the mode to run the application in */
const char *filename; /* filename of the key file */
int debug_level; /* level of debugging */
int output_mode; /* the output mode to use */
const char *output_file; /* where to store the constructed key file */
} opt;
void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
}
void write_public_key( rsa_context *rsa, const char *output_file )
static void write_public_key( rsa_context *rsa, const char *output_file )
{
FILE *f;
unsigned char output_buf[16000];
@ -124,7 +114,7 @@ void write_public_key( rsa_context *rsa, const char *output_file )
fclose(f);
}
void write_private_key( rsa_context *rsa, const char *output_file )
static void write_private_key( rsa_context *rsa, const char *output_file )
{
FILE *f;
unsigned char output_buf[16000];
@ -165,7 +155,6 @@ void write_private_key( rsa_context *rsa, const char *output_file )
"\n acceptable parameters:\n" \
" mode=private|public default: none\n" \
" filename=%%s default: keyfile.key\n" \
" debug_level=%%d default: 0 (disabled)\n" \
" output_mode=private|public default: none\n" \
" output_file=%%s defeult: keyfile.pem\n" \
"\n"
@ -193,7 +182,6 @@ int main( int argc, char *argv[] )
opt.mode = DFL_MODE;
opt.filename = DFL_FILENAME;
opt.debug_level = DFL_DEBUG_LEVEL;
opt.output_mode = DFL_OUTPUT_MODE;
opt.output_file = DFL_OUTPUT_FILENAME;
@ -226,12 +214,6 @@ int main( int argc, char *argv[] )
opt.filename = q;
else if( strcmp( p, "output_file" ) == 0 )
opt.output_file = q;
else if( strcmp( p, "debug_level" ) == 0 )
{
opt.debug_level = atoi( q );
if( opt.debug_level < 0 || opt.debug_level > 65535 )
goto usage;
}
else
goto usage;
}

View file

@ -1,7 +1,7 @@
/*
* SSL client demonstration program
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -45,7 +45,7 @@
#define DEBUG_LEVEL 1
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < DEBUG_LEVEL )
{

View file

@ -1,7 +1,7 @@
/*
* SSL client with certificate authentication
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -83,7 +83,7 @@ struct options
int auth_mode; /* verify mode for connection */
} opt;
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
@ -96,7 +96,7 @@ void my_debug( void *ctx, int level, const char *str )
/*
* Enabled if debug_level > 1 in code below
*/
int my_verify( void *data, x509_cert *crt, int depth, int *flags )
static int my_verify( void *data, x509_cert *crt, int depth, int *flags )
{
char buf[1024];
((void) data);
@ -595,7 +595,7 @@ int main( int argc, char *argv[] )
#endif
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
ssl_set_psk( &ssl, psk, psk_len, (unsigned char *) opt.psk_identity,
ssl_set_psk( &ssl, psk, psk_len, (const unsigned char *) opt.psk_identity,
strlen( opt.psk_identity ) );
#endif

View file

@ -1,7 +1,7 @@
/*
* SSL server demonstration program using fork() for handling multiple clients
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -82,7 +82,7 @@ int main( int argc, char *argv[] )
#define DEBUG_LEVEL 0
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < DEBUG_LEVEL )
{

View file

@ -1,7 +1,7 @@
/*
* SSL client for SMTP servers
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2012, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -92,7 +92,7 @@ struct options
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
} opt;
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
@ -118,7 +118,7 @@ int main( int argc, char *argv[] )
return( 0 );
}
#else
int do_handshake( ssl_context *ssl, struct options *opt )
static int do_handshake( ssl_context *ssl, struct options *opt )
{
int ret;
unsigned char buf[1024];
@ -179,7 +179,7 @@ int do_handshake( ssl_context *ssl, struct options *opt )
return( 0 );
}
int write_ssl_data( ssl_context *ssl, unsigned char *buf, size_t len )
static int write_ssl_data( ssl_context *ssl, unsigned char *buf, size_t len )
{
int ret;
@ -196,7 +196,7 @@ int write_ssl_data( ssl_context *ssl, unsigned char *buf, size_t len )
return( 0 );
}
int write_ssl_and_get_response( ssl_context *ssl, unsigned char *buf, size_t len )
static int write_ssl_and_get_response( ssl_context *ssl, unsigned char *buf, size_t len )
{
int ret;
unsigned char data[128];
@ -247,14 +247,14 @@ int write_ssl_and_get_response( ssl_context *ssl, unsigned char *buf, size_t len
code[3] = '\0';
return atoi( code );
}
idx = 0;
}
}
while( 1 );
}
int write_and_get_response( int sock_fd, unsigned char *buf, size_t len )
static int write_and_get_response( int sock_fd, unsigned char *buf, size_t len )
{
int ret;
unsigned char data[128];

View file

@ -1,7 +1,7 @@
/*
* SSL server demonstration program
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -56,7 +56,7 @@
#define DEBUG_LEVEL 0
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < DEBUG_LEVEL )
{

View file

@ -1,7 +1,7 @@
/*
* SSL client with options
*
* Copyright (C) 2006-2012, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -89,7 +89,7 @@ struct options
int auth_mode; /* verify mode for connection */
} opt;
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
@ -514,7 +514,7 @@ int main( int argc, char *argv[] )
#endif
#if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED)
ssl_set_psk( &ssl, psk, psk_len, (unsigned char *) opt.psk_identity,
ssl_set_psk( &ssl, psk, psk_len, (const unsigned char *) opt.psk_identity,
strlen( opt.psk_identity ) );
#endif

View file

@ -28,8 +28,8 @@ int main( int argc, char *argv[] )
#else
void dhm_bench_case( const char *s, const char *p,
const char *g, const char *x )
static void dhm_bench_case( const char *s, const char *p,
const char *g, const char *x )
{
unsigned long i;
mpi P, G, X, R, C;
@ -132,7 +132,7 @@ void dhm_bench_case( const char *s, const char *p,
"F98E0273FC5C08A4EA70D6DC09A1855AFB402E02BD9F261E" \
"863717A552F4A83D4DD5060CB70E2D4D7FFAEE912C2C4408"
void dhm_bench( void )
static void dhm_bench( void )
{
dhm_bench_case( "1024", POLARSSL_DHM_RFC5114_MODP_1024_P,
MODP_1024_G, MODP_1024_X );
@ -144,7 +144,7 @@ void dhm_bench( void )
MODP_3072_G, MODP_3072_X );
}
void ecp_bench_case( size_t dp, char *s, char *m )
static void ecp_bench_case( size_t dp, const char *s, const char *m )
{
unsigned long i;
ecp_group grp;
@ -181,7 +181,7 @@ void ecp_bench_case( size_t dp, char *s, char *m )
"017F540D09F24EC6B102E8E4A9F14B850442D98C68FB29A6B09B9B9D40E2A750" \
"7F3D2D6C5B6536B607EF2BCEA4797BB3A68F0D745410EB5CFFC7FF7FB17381544E"
void ecp_bench( void )
static void ecp_bench( void )
{
ecp_bench_case( 0, "192", ECP_192_M );
ecp_bench_case( 1, "224", ECP_224_M );

View file

@ -91,7 +91,7 @@ struct options
* Although this PRNG has good statistical properties (eg. passes
* DIEHARD), it is not cryptographically secure.
*/
unsigned long int lcppm5( unsigned long int *state )
static unsigned long int lcppm5( unsigned long int *state )
{
unsigned long int u, v;
@ -108,7 +108,7 @@ unsigned long int lcppm5( unsigned long int *state )
return( u );
}
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < ((struct options *) ctx)->debug_level )
fprintf( stderr, "%s", str );

View file

@ -67,7 +67,7 @@ struct options
int permissive; /* permissive parsing */
} opt;
void my_debug( void *ctx, int level, const char *str )
static void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
@ -76,7 +76,7 @@ void my_debug( void *ctx, int level, const char *str )
}
}
int my_verify( void *data, x509_cert *crt, int depth, int *flags )
static int my_verify( void *data, x509_cert *crt, int depth, int *flags )
{
char buf[1024];
((void) data);

View file

@ -1,7 +1,7 @@
/*
* CRL reading application
*
* Copyright (C) 2006-2011, Brainspark B.V.
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
@ -44,23 +44,12 @@
struct options
{
const char *filename; /* filename of the certificate file */
int debug_level; /* level of debugging */
} opt;
void my_debug( void *ctx, int level, const char *str )
{
if( level < opt.debug_level )
{
fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
}
#define USAGE \
"\n usage: crl_app param=<>...\n" \
"\n acceptable parameters:\n" \
" filename=%%s default: crl.pem\n" \
" debug_level=%%d default: 0 (disabled)\n" \
"\n"
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
@ -96,7 +85,6 @@ int main( int argc, char *argv[] )
}
opt.filename = DFL_FILENAME;
opt.debug_level = DFL_DEBUG_LEVEL;
for( i = 1; i < argc; i++ )
{
@ -115,12 +103,6 @@ int main( int argc, char *argv[] )
if( strcmp( p, "filename" ) == 0 )
opt.filename = q;
else if( strcmp( p, "debug_level" ) == 0 )
{
opt.debug_level = atoi( q );
if( opt.debug_level < 0 || opt.debug_level > 65535 )
goto usage;
}
else
goto usage;
}