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

More fixes based on the compiler directives -Wcast-qual -Wwrite-strings
-Wmissing-prototypes -Wmissing-declarations. Not everything with regards
to -Wcast-qual has been fixed as some have unwanted consequences for the
rest of the code.
diff --git a/library/ctr_drbg.c b/library/ctr_drbg.c
index b6a774b..3182c3b 100644
--- a/library/ctr_drbg.c
+++ b/library/ctr_drbg.c
@@ -1,7 +1,7 @@
 /*
  *  CTR_DRBG implementation based on AES-256 (NIST SP 800-90)
  *
- *  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>
@@ -42,7 +42,7 @@
  * Non-public function wrapped by ctr_crbg_init(). Necessary to allow NIST
  * tests to succeed (which require known length fixed entropy)
  */
-int ctr_drbg_init_entropy_len(
+static int ctr_drbg_init_entropy_len(
                    ctr_drbg_context *ctx,
                    int (*f_entropy)(void *, unsigned char *, size_t),
                    void *p_entropy,
@@ -92,14 +92,14 @@
 {
     ctx->entropy_len = len;
 }
-    
+
 void ctr_drbg_set_reseed_interval( ctr_drbg_context *ctx, int interval )
 {
     ctx->reseed_interval = interval;
 }
-    
-int block_cipher_df( unsigned char *output,
-                     const unsigned char *data, size_t data_len )
+
+static int block_cipher_df( unsigned char *output,
+                            const unsigned char *data, size_t data_len )
 {
     unsigned char buf[CTR_DRBG_MAX_SEED_INPUT + CTR_DRBG_BLOCKSIZE + 16];
     unsigned char tmp[CTR_DRBG_SEEDLEN];
@@ -180,7 +180,7 @@
     return( 0 );
 }
 
-int ctr_drbg_update_internal( ctr_drbg_context *ctx,
+static int ctr_drbg_update_internal( ctr_drbg_context *ctx,
                               const unsigned char data[CTR_DRBG_SEEDLEN] )
 {
     unsigned char tmp[CTR_DRBG_SEEDLEN];
@@ -449,7 +449,8 @@
       0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f };
 
 int test_offset;
-int ctr_drbg_self_test_entropy( void *data, unsigned char *buf, size_t len )
+static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf,
+                                       size_t len )
 {
     unsigned char *p = data;
     memcpy( buf, p + test_offset, len );
diff --git a/library/ecp.c b/library/ecp.c
index 2a6045f..f14b0b4 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -1296,7 +1296,7 @@
     ecp_point R;
     mpi m;
     unsigned long add_c_prev, dbl_c_prev;
-    char *exponents[] =
+    const char *exponents[] =
     {
         "000000000000000000000000000000000000000000000000", /* zero */
         "000000000000000000000000000000000000000000000001", /* one */
diff --git a/library/entropy.c b/library/entropy.c
index 9662454..253ae3d 100644
--- a/library/entropy.c
+++ b/library/entropy.c
@@ -1,7 +1,7 @@
 /*
  *  Entropy accumulator implementation
  *
- *  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>
@@ -81,14 +81,14 @@
 /*
  * Entropy accumulator update
  */
-int entropy_update( entropy_context *ctx, unsigned char source_id,
-                    const unsigned char *data, size_t len )
+static int entropy_update( entropy_context *ctx, unsigned char source_id,
+                           const unsigned char *data, size_t len )
 {
     unsigned char header[2];
     unsigned char tmp[ENTROPY_BLOCK_SIZE];
     size_t use_len = len;
     const unsigned char *p = data;
-   
+
     if( use_len > ENTROPY_BLOCK_SIZE )
     {
         sha4( data, len, tmp, 0 );
@@ -102,7 +102,7 @@
 
     sha4_update( &ctx->accumulator, header, 2 );
     sha4_update( &ctx->accumulator, p, use_len );
-    
+
     return( 0 );
 }
 
diff --git a/library/gcm.c b/library/gcm.c
index 7fd9ad9..f1daaff 100644
--- a/library/gcm.c
+++ b/library/gcm.c
@@ -1,7 +1,7 @@
 /*
  *  NIST SP800-38D compliant GCM implementation
  *
- *  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>
@@ -123,7 +123,8 @@
     0x9180, 0x8da0, 0xa9c0, 0xb5e0
 };
 
-void gcm_mult( gcm_context *ctx, const unsigned char x[16], unsigned char output[16] )
+static void gcm_mult( gcm_context *ctx, const unsigned char x[16],
+                      unsigned char output[16] )
 {
     int i = 0;
     unsigned char z[16];
diff --git a/library/md_wrap.c b/library/md_wrap.c
index 5f64df7..f98550f 100644
--- a/library/md_wrap.c
+++ b/library/md_wrap.c
@@ -5,7 +5,7 @@
  *
  * \author Adriaan de Jong <dejong@fox-it.com>
  *
- *  Copyright (C) 2006-2010, 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>
@@ -76,7 +76,7 @@
     md2_finish( (md2_context *) ctx, output );
 }
 
-int md2_file_wrap( const char *path, unsigned char *output )
+static int md2_file_wrap( const char *path, unsigned char *output )
 {
 #if defined(POLARSSL_FS_IO)
     return md2_file( path, output );
@@ -246,7 +246,7 @@
     md5_finish( (md5_context *) ctx, output );
 }
 
-int md5_file_wrap( const char *path, unsigned char *output )
+static int md5_file_wrap( const char *path, unsigned char *output )
 {
 #if defined(POLARSSL_FS_IO)
     return md5_file( path, output );
diff --git a/library/oid.c b/library/oid.c
index 51851ba..a280070 100644
--- a/library/oid.c
+++ b/library/oid.c
@@ -351,7 +351,7 @@
                 const unsigned char *oid,
                 size_t len )
 {
-    const unsigned char *p = (unsigned char *) struct_set;
+    const unsigned char *p = (const unsigned char *) struct_set;
     const oid_descriptor_t *cur;
 
     if( struct_set == NULL || oid == NULL )
diff --git a/library/pem.c b/library/pem.c
index e2e3998..d2d70ab 100644
--- a/library/pem.c
+++ b/library/pem.c
@@ -178,7 +178,9 @@
 
 #endif /* POLARSSL_MD5_C && (POLARSSL_AES_C || POLARSSL_DES_C) */
 
-int pem_read_buffer( pem_context *ctx, char *header, char *footer, const unsigned char *data, const unsigned char *pwd, size_t pwdlen, size_t *use_len )
+int pem_read_buffer( pem_context *ctx, const char *header, const char *footer,
+                     const unsigned char *data, const unsigned char *pwd,
+                     size_t pwdlen, size_t *use_len )
 {
     int ret, enc;
     size_t len;
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 5625644..61a155c 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -195,9 +195,9 @@
 }
 
 #if defined(POLARSSL_ECP_C)
-int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
-                                         const unsigned char *buf,
-                                         size_t len )
+static int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
+                                                const unsigned char *buf,
+                                                size_t len )
 {
     size_t list_size;
     const unsigned char *p;
@@ -231,9 +231,9 @@
     return( 0 );
 }
 
-int ssl_parse_supported_point_formats( ssl_context *ssl,
-                                       const unsigned char *buf,
-                                       size_t len )
+static int ssl_parse_supported_point_formats( ssl_context *ssl,
+                                              const unsigned char *buf,
+                                              size_t len )
 {
     size_t list_size;
     const unsigned char *p;
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index c56ae0d..a19e4da 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -96,8 +96,9 @@
 /*
  * Key material generation
  */
-static int ssl3_prf( unsigned char *secret, size_t slen, char *label,
-                     unsigned char *random, size_t rlen,
+static int ssl3_prf( const unsigned char *secret, size_t slen,
+                     const char *label,
+                     const unsigned char *random, size_t rlen,
                      unsigned char *dstbuf, size_t dlen )
 {
     size_t i;
@@ -140,13 +141,14 @@
     return( 0 );
 }
 
-static int tls1_prf( unsigned char *secret, size_t slen, char *label,
-                     unsigned char *random, size_t rlen,
+static int tls1_prf( const unsigned char *secret, size_t slen,
+                     const char *label,
+                     const unsigned char *random, size_t rlen,
                      unsigned char *dstbuf, size_t dlen )
 {
     size_t nb, hs;
     size_t i, j, k;
-    unsigned char *S1, *S2;
+    const unsigned char *S1, *S2;
     unsigned char tmp[128];
     unsigned char h_i[20];
 
@@ -200,8 +202,9 @@
     return( 0 );
 }
 
-static int tls_prf_sha256( unsigned char *secret, size_t slen, char *label,
-                           unsigned char *random, size_t rlen,
+static int tls_prf_sha256( const unsigned char *secret, size_t slen,
+                           const char *label,
+                           const unsigned char *random, size_t rlen,
                            unsigned char *dstbuf, size_t dlen )
 {
     size_t nb;
@@ -240,8 +243,9 @@
 }
 
 #if defined(POLARSSL_SHA4_C)
-static int tls_prf_sha384( unsigned char *secret, size_t slen, char *label,
-                           unsigned char *random, size_t rlen,
+static int tls_prf_sha384( const unsigned char *secret, size_t slen,
+                           const char *label,
+                           const unsigned char *random, size_t rlen,
                            unsigned char *dstbuf, size_t dlen )
 {
     size_t nb;
@@ -280,9 +284,9 @@
 }
 #endif
 
-static void ssl_update_checksum_start(ssl_context *, unsigned char *, size_t);
-static void ssl_update_checksum_md5sha1(ssl_context *, unsigned char *, size_t);
-static void ssl_update_checksum_sha256(ssl_context *, unsigned char *, size_t);
+static void ssl_update_checksum_start(ssl_context *, const unsigned char *, size_t);
+static void ssl_update_checksum_md5sha1(ssl_context *, const unsigned char *, size_t);
+static void ssl_update_checksum_sha256(ssl_context *, const unsigned char *, size_t);
 
 static void ssl_calc_verify_ssl(ssl_context *,unsigned char *);
 static void ssl_calc_verify_tls(ssl_context *,unsigned char *);
@@ -293,7 +297,7 @@
 static void ssl_calc_finished_tls_sha256(ssl_context *,unsigned char *,int);
 
 #if defined(POLARSSL_SHA4_C)
-static void ssl_update_checksum_sha384(ssl_context *, unsigned char *, size_t);
+static void ssl_update_checksum_sha384(ssl_context *, const unsigned char *, size_t);
 static void ssl_calc_verify_tls_sha384(ssl_context *,unsigned char *);
 static void ssl_calc_finished_tls_sha384(ssl_context *,unsigned char *,int);
 #endif
@@ -2229,8 +2233,8 @@
         ssl->handshake->update_checksum = ssl_update_checksum_sha256;
 }
 
-static void ssl_update_checksum_start( ssl_context *ssl, unsigned char *buf,
-                                       size_t len )
+static void ssl_update_checksum_start( ssl_context *ssl,
+                                       const unsigned char *buf, size_t len )
 {
      md5_update( &ssl->handshake->fin_md5 , buf, len );
     sha1_update( &ssl->handshake->fin_sha1, buf, len );
@@ -2240,22 +2244,22 @@
 #endif
 }
 
-static void ssl_update_checksum_md5sha1( ssl_context *ssl, unsigned char *buf,
-                                         size_t len )
+static void ssl_update_checksum_md5sha1( ssl_context *ssl,
+                                         const unsigned char *buf, size_t len )
 {
      md5_update( &ssl->handshake->fin_md5 , buf, len );
     sha1_update( &ssl->handshake->fin_sha1, buf, len );
 }
 
-static void ssl_update_checksum_sha256( ssl_context *ssl, unsigned char *buf,
-                                        size_t len )
+static void ssl_update_checksum_sha256( ssl_context *ssl,
+                                        const unsigned char *buf, size_t len )
 {
     sha2_update( &ssl->handshake->fin_sha2, buf, len );
 }
 
 #if defined(POLARSSL_SHA4_C)
-static void ssl_update_checksum_sha384( ssl_context *ssl, unsigned char *buf,
-                                        size_t len )
+static void ssl_update_checksum_sha384( ssl_context *ssl,
+                                        const unsigned char *buf, size_t len )
 {
     sha4_update( &ssl->handshake->fin_sha4, buf, len );
 }
@@ -2382,7 +2386,7 @@
     md5_finish(  &md5, padbuf );
     sha1_finish( &sha1, padbuf + 16 );
 
-    ssl->handshake->tls_prf( session->master, 48, (char *) sender,
+    ssl->handshake->tls_prf( session->master, 48, sender,
                              padbuf, 36, buf, len );
 
     SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
@@ -2428,7 +2432,7 @@
 
     sha2_finish( &sha2, padbuf );
 
-    ssl->handshake->tls_prf( session->master, 48, (char *) sender,
+    ssl->handshake->tls_prf( session->master, 48, sender,
                              padbuf, 32, buf, len );
 
     SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
@@ -2474,7 +2478,7 @@
 
     sha4_finish( &sha4, padbuf );
 
-    ssl->handshake->tls_prf( session->master, 48, (char *) sender,
+    ssl->handshake->tls_prf( session->master, 48, sender,
                              padbuf, 48, buf, len );
 
     SSL_DEBUG_BUF( 3, "calc finished result", buf, len );
@@ -2689,7 +2693,7 @@
     return( 0 );
 }
 
-int ssl_handshake_init( ssl_context *ssl )
+static int ssl_handshake_init( ssl_context *ssl )
 {
     if( ssl->transform_negotiate )
         ssl_transform_free( ssl->transform_negotiate );
diff --git a/library/x509parse.c b/library/x509parse.c
index caa4643..13be0e6 100644
--- a/library/x509parse.c
+++ b/library/x509parse.c
@@ -1,7 +1,7 @@
 /*
  *  X.509 certificate and private key decoding
  *
- *  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>
@@ -1113,8 +1113,8 @@
 /*
  * Parse and fill a single X.509 certificate in DER format
  */
-int x509parse_crt_der_core( x509_cert *crt, const unsigned char *buf,
-                            size_t buflen )
+static int x509parse_crt_der_core( x509_cert *crt, const unsigned char *buf,
+                                   size_t buflen )
 {
     int ret;
     size_t len;
@@ -1813,7 +1813,7 @@
 /*
  * Load all data from a file into a given buffer.
  */
-int load_file( const char *path, unsigned char **buf, size_t *n )
+static int load_file( const char *path, unsigned char **buf, size_t *n )
 {
     FILE *f;
 
@@ -1994,7 +1994,7 @@
         ret = x509parse_key( rsa, buf, n, NULL, 0 );
     else
         ret = x509parse_key( rsa, buf, n,
-                (unsigned char *) pwd, strlen( pwd ) );
+                (const unsigned char *) pwd, strlen( pwd ) );
 
     memset( buf, 0, n + 1 );
     free( buf );
@@ -3101,7 +3101,7 @@
     return flags;
 }
 
-int x509_wildcard_verify( const char *cn, x509_buf *name )
+static int x509_wildcard_verify( const char *cn, x509_buf *name )
 {
     size_t i;
     size_t cn_idx = 0;
diff --git a/library/x509write.c b/library/x509write.c
index cf68b02..7aa65ce 100644
--- a/library/x509write.c
+++ b/library/x509write.c
@@ -1,7 +1,7 @@
 /*
  * X509 buffer writing functionality
  *
- *  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>
@@ -109,8 +109,8 @@
     return( len );
 }
 
-int x509_write_name( unsigned char **p, unsigned char *start, char *oid,
-                     char *name )
+static int x509_write_name( unsigned char **p, unsigned char *start, char *oid,
+                            char *name )
 {
     int ret;
     size_t string_len = 0;
@@ -141,8 +141,8 @@
     return( len );
 }
 
-int x509_write_sig( unsigned char **p, unsigned char *start, const char *oid,
-                    unsigned char *sig, size_t size )
+static int x509_write_sig( unsigned char **p, unsigned char *start,
+                           const char *oid, unsigned char *sig, size_t size )
 {
     int ret;
     size_t len = 0;
@@ -209,7 +209,7 @@
     while( cur != NULL )
     {
         ASN1_CHK_ADD( sub_len, x509_write_name( &c, tmp_buf, cur->oid, cur->name ) );
-        
+
         cur = cur->next;
     }
 
@@ -221,7 +221,7 @@
 
     ASN1_CHK_ADD( len, asn1_write_len( &c, tmp_buf, len ) );
     ASN1_CHK_ADD( len, asn1_write_tag( &c, tmp_buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
-    
+
     md( md_info_from_type( md_alg ), c, len, hash );
 
     rsa_pkcs1_sign( rsa, NULL, NULL, RSA_PRIVATE, md_alg, 0, hash, sig );
@@ -232,10 +232,10 @@
 
     c2 = buf + size - 1;
     ASN1_CHK_ADD( sig_len, x509_write_sig( &c2, buf, sig_oid, sig, rsa->len ) );
-    
+
     c2 -= len;
-    memcpy( c2, c, len ); 
-    
+    memcpy( c2, c, len );
+
     len += sig_len;
     ASN1_CHK_ADD( len, asn1_write_len( &c2, buf, len ) );
     ASN1_CHK_ADD( len, asn1_write_tag( &c2, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
diff --git a/library/xtea.c b/library/xtea.c
index f8ab014..9404927 100644
--- a/library/xtea.c
+++ b/library/xtea.c
@@ -57,7 +57,7 @@
 /*
  * XTEA key schedule
  */
-void xtea_setup( xtea_context *ctx, unsigned char key[16] )
+void xtea_setup( xtea_context *ctx, const unsigned char key[16] )
 {
     int i;
 
@@ -72,13 +72,13 @@
 /*
  * XTEA encrypt function
  */
-int xtea_crypt_ecb( xtea_context *ctx, int mode, unsigned char input[8],
-                     unsigned char output[8])
+int xtea_crypt_ecb( xtea_context *ctx, int mode,
+                    const unsigned char input[8], unsigned char output[8])
 {
     uint32_t *k, v0, v1, i;
 
     k = ctx->k;
-    
+
     GET_UINT32_BE( v0, input, 0 );
     GET_UINT32_BE( v1, input, 4 );
 
@@ -114,27 +114,24 @@
 /*
  * XTEA-CBC buffer encryption/decryption
  */
-int xtea_crypt_cbc( xtea_context *ctx,
-                    int mode,
-                    size_t length,
-                    unsigned char iv[8],
-                    unsigned char *input,
+int xtea_crypt_cbc( xtea_context *ctx, int mode, size_t length,
+                    unsigned char iv[8], const unsigned char *input,
                     unsigned char *output)
 {
     int i;
     unsigned char temp[8];
 
-    if(length % 8)
+    if( length % 8 )
         return( POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH );
 
-    if( mode == XTEA_DECRYPT ) 
+    if( mode == XTEA_DECRYPT )
     {
         while( length > 0 )
         {
             memcpy( temp, input, 8 );
             xtea_crypt_ecb( ctx, mode, input, output );
 
-            for(i = 0; i < 8; i++) 
+            for(i = 0; i < 8; i++)
                 output[i] = (unsigned char)( output[i] ^ iv[i] );
 
             memcpy( iv, temp, 8 );
@@ -143,8 +140,8 @@
             output += 8;
             length -= 8;
         }
-    } 
-    else 
+    }
+    else
     {
         while( length > 0 )
         {
@@ -153,7 +150,7 @@
 
             xtea_crypt_ecb( ctx, mode, output, output );
             memcpy( iv, output, 8 );
-            
+
             input  += 8;
             output += 8;
             length -= 8;
@@ -225,7 +222,7 @@
 
         memcpy( buf, xtea_test_pt[i], 8 );
 
-        xtea_setup( &ctx, (unsigned char *) xtea_test_key[i] );
+        xtea_setup( &ctx, xtea_test_key[i] );
         xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, buf, buf );
 
         if( memcmp( buf, xtea_test_ct[i], 8 ) != 0 )