From 3c5ef71322a4e5b79eeb62db48b495a9816503b6 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Tue, 25 Jun 2013 16:37:45 +0200
Subject: [PATCH] Cleanup up non-prototyped functions (static) and
const-correctness in programs
---
programs/pkey/key_app.c | 20 +-------------------
programs/pkey/key_app_writer.c | 24 +++---------------------
programs/ssl/ssl_client1.c | 4 ++--
programs/ssl/ssl_client2.c | 8 ++++----
programs/ssl/ssl_fork_server.c | 4 ++--
programs/ssl/ssl_mail_client.c | 14 +++++++-------
programs/ssl/ssl_server.c | 4 ++--
programs/ssl/ssl_server2.c | 6 +++---
programs/test/ecp-bench.c | 10 +++++-----
programs/test/ssl_test.c | 4 ++--
programs/x509/cert_app.c | 4 ++--
programs/x509/crl_app.c | 20 +-------------------
12 files changed, 34 insertions(+), 88 deletions(-)
diff --git a/programs/pkey/key_app.c b/programs/pkey/key_app.c
index fc0269e28..051ceb511 100644
--- a/programs/pkey/key_app.c
+++ b/programs/pkey/key_app.c
@@ -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
@@ -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;
}
diff --git a/programs/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c
index 746da0c4f..7d3a77c5a 100644
--- a/programs/pkey/key_app_writer.c
+++ b/programs/pkey/key_app_writer.c
@@ -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
@@ -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;
}
diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c
index 8c990238b..184aac1f5 100644
--- a/programs/ssl/ssl_client1.c
+++ b/programs/ssl/ssl_client1.c
@@ -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
@@ -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 )
{
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 214733b65..72372acea 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -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
@@ -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
diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c
index 89f834aad..03112adcd 100644
--- a/programs/ssl/ssl_fork_server.c
+++ b/programs/ssl/ssl_fork_server.c
@@ -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
@@ -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 )
{
diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c
index 249b99c56..107f52603 100644
--- a/programs/ssl/ssl_mail_client.c
+++ b/programs/ssl/ssl_mail_client.c
@@ -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
@@ -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];
diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c
index 37846020b..bd6c38407 100644
--- a/programs/ssl/ssl_server.c
+++ b/programs/ssl/ssl_server.c
@@ -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
@@ -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 )
{
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index f788f5e6a..e6b4a1224 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -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
@@ -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
diff --git a/programs/test/ecp-bench.c b/programs/test/ecp-bench.c
index 3064cc9eb..fc9a0cfd9 100644
--- a/programs/test/ecp-bench.c
+++ b/programs/test/ecp-bench.c
@@ -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 );
diff --git a/programs/test/ssl_test.c b/programs/test/ssl_test.c
index 34fd9c269..420484b41 100644
--- a/programs/test/ssl_test.c
+++ b/programs/test/ssl_test.c
@@ -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 );
diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c
index 2c8a88d7e..d7cacdb88 100644
--- a/programs/x509/cert_app.c
+++ b/programs/x509/cert_app.c
@@ -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);
diff --git a/programs/x509/crl_app.c b/programs/x509/crl_app.c
index fb191a1b4..b98e743dd 100644
--- a/programs/x509/crl_app.c
+++ b/programs/x509/crl_app.c
@@ -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
@@ -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;
}