Cleanup up non-prototyped functions (static) and const-correctness in programs
diff --git a/programs/pkey/key_app.c b/programs/pkey/key_app.c
index fc0269e..051ceb5 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 <polarssl_maintainer at polarssl.org>
@@ -56,18 +56,8 @@
     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 @@
     "    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 @@
     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 @@
             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 746da0c..7d3a77c 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 <polarssl_maintainer at polarssl.org>
@@ -73,21 +73,11 @@
 {
     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 @@
     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 @@
     "\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 @@
 
     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 @@
             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 8c99023..184aac1 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 <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 )
     {
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 214733b..72372ac 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 <polarssl_maintainer at polarssl.org>
@@ -83,7 +83,7 @@
     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 @@
 /*
  * 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 @@
 #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 89f834a..03112ad 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 <polarssl_maintainer at polarssl.org>
@@ -82,7 +82,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_mail_client.c b/programs/ssl/ssl_mail_client.c
index 249b99c..107f526 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 <polarssl_maintainer at polarssl.org>
@@ -92,7 +92,7 @@
     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 @@
     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 @@
     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 @@
     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 @@
                 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 3784602..bd6c384 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 <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 )
     {
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index f788f5e..e6b4a12 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 <polarssl_maintainer at polarssl.org>
@@ -89,7 +89,7 @@
     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 @@
 #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 3064cc9..fc9a0cf 100644
--- a/programs/test/ecp-bench.c
+++ b/programs/test/ecp-bench.c
@@ -28,8 +28,8 @@
 
 #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 @@
     "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 @@
             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 @@
     "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 34fd9c2..420484b 100644
--- a/programs/test/ssl_test.c
+++ b/programs/test/ssl_test.c
@@ -91,7 +91,7 @@
  * 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 @@
     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 2c8a88d..d7cacdb 100644
--- a/programs/x509/cert_app.c
+++ b/programs/x509/cert_app.c
@@ -67,7 +67,7 @@
     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 @@
     }
 }
 
-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 fb191a1..b98e743 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 <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 @@
     }
 
     opt.filename            = DFL_FILENAME;
-    opt.debug_level         = DFL_DEBUG_LEVEL;
 
     for( i = 1; i < argc; i++ )
     {
@@ -115,12 +103,6 @@
 
         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;
     }