Commit 18b78c74 authored by Rich Evans's avatar Rich Evans
Browse files

cleanup programs

Clean up the contents of programs, add more guards to includes, move all
defines to the top of the top of files, remove some unused includes
parent 3cfb3456
......@@ -29,8 +29,19 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
#endif
#if defined(POLARSSL_AES_C) && defined(POLARSSL_SHA256_C) &&\
defined(POLARSSL_FS_IO)
#include "polarssl/aes.h"
#include "polarssl/sha256.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
#if defined(_WIN32)
......@@ -43,14 +54,6 @@
#include <unistd.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "polarssl/aes.h"
#include "polarssl/sha256.h"
#define MODE_ENCRYPT 0
#define MODE_DECRYPT 1
......@@ -60,12 +63,13 @@
"\n example: aescrypt2 0 file file.aes hex:E76B2413958B00E193\n" \
"\n"
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA256_C)
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA256_C) ||\
!defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
polarssl_printf("POLARSSL_AES_C and/or POLARSSL_SHA256_C not defined.\n");
polarssl_printf("POLARSSL_AES_C and/or POLARSSL_SHA256_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
......@@ -442,4 +446,4 @@ exit:
return( ret );
}
#endif /* POLARSSL_AES_C && POLARSSL_SHA256_C */
#endif /* POLARSSL_AES_C && POLARSSL_SHA256_C && POLARSSL_FS_IO */
......@@ -30,8 +30,19 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
#endif
#if defined(POLARSSL_CIPHER_C) && defined(POLARSSL_MD_C) &&\
defined(POLARSSL_FS_IO)
#include "polarssl/cipher.h"
#include "polarssl/md.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
#if defined(_WIN32)
......@@ -44,14 +55,6 @@
#include <unistd.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "polarssl/cipher.h"
#include "polarssl/md.h"
#define MODE_ENCRYPT 0
#define MODE_DECRYPT 1
......@@ -61,13 +64,14 @@
"\n example: crypt_and_hash 0 file file.aes AES-128-CBC SHA1 hex:E76B2413958B00E193\n" \
"\n"
#if !defined(POLARSSL_CIPHER_C) || !defined(POLARSSL_MD_C)
#if !defined(POLARSSL_CIPHER_C) || !defined(POLARSSL_MD_C) ||\
!defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
polarssl_printf("POLARSSL_CIPHER_C and/or POLARSSL_MD_C not defined.\n");
polarssl_printf("POLARSSL_CIPHER_C and/or POLARSSL_MD_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
......@@ -542,4 +546,4 @@ exit:
return( ret );
}
#endif /* POLARSSL_CIPHER_C && POLARSSL_MD_C */
#endif /* POLARSSL_CIPHER_C && POLARSSL_MD_C && POLARSSL_FS_IO */
......@@ -29,22 +29,25 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdio.h>
#if defined(POLARSSL_MD_C) && defined(POLARSSL_FS_IO)
#include "polarssl/md.h"
#if !defined(POLARSSL_MD_C)
#include <stdio.h>
#include <string.h>
#endif
#if !defined(POLARSSL_MD_C) || !defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
polarssl_printf("POLARSSL_MD_C not defined.\n");
polarssl_printf("POLARSSL_MD_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
......@@ -225,4 +228,4 @@ exit:
return( ret );
}
#endif /* POLARSSL_MD_C */
#endif /* POLARSSL_MD_C && POLARSSL_FS_IO */
......@@ -29,12 +29,13 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#include <stdio.h>
#if defined(POLARSSL_MD5_C)
#include "polarssl/md5.h"
#endif
#if !defined(POLARSSL_MD5_C)
int main( int argc, char *argv[] )
......
......@@ -29,15 +29,18 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdio.h>
#if defined(POLARSSL_MD5_C) && defined(POLARSSL_FS_IO)
#include "polarssl/md5.h"
#include <stdio.h>
#include <string.h>
#endif
#if !defined(POLARSSL_MD5_C) || !defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
......
......@@ -29,15 +29,18 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdio.h>
#if defined(POLARSSL_SHA1_C) && defined(POLARSSL_FS_IO)
#include "polarssl/sha1.h"
#include <stdio.h>
#include <string.h>
#endif
#if !defined(POLARSSL_SHA1_C) || !defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
......
......@@ -29,15 +29,18 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#include <stdio.h>
#define polarssl_fprintf fprintf
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdio.h>
#if defined(POLARSSL_SHA256_C) && defined(POLARSSL_FS_IO)
#include "polarssl/sha256.h"
#include <stdio.h>
#include <string.h>
#endif
#if !defined(POLARSSL_SHA256_C) || !defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
......
......@@ -29,12 +29,14 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdio.h>
#if defined(POLARSSL_AES_C) && defined(POLARSSL_DHM_C) &&\
defined(POLARSSL_ENTROPY_C) && defined(POLARSSL_NET_C) &&\
defined(POLARSSL_RSA_C) && defined(POLARSSL_SHA256_C) &&\
defined(POLARSSL_FS_IO) && defined(POLARSSL_CTR_DRBG_C)
#include "polarssl/net.h"
#include "polarssl/aes.h"
#include "polarssl/dhm.h"
......@@ -43,6 +45,10 @@
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
#include <stdio.h>
#include <string.h>
#endif
#define SERVER_NAME "localhost"
#define SERVER_PORT 11999
......
......@@ -29,16 +29,21 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#include <stdio.h>
#include <string.h>
#if defined(POLARSSL_BIGNUM_C) && defined(POLARSSL_ENTROPY_C) &&\
defined(POLARSSL_FS_IO) && defined(POLARSSL_CTR_DRBG_C) &&\
defined(POLARSSL_GENPRIME)
#include "polarssl/bignum.h"
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
#include <stdio.h>
#include <string.h>
#endif
/*
* Note: G = 4 is always a quadratic residue mod P,
* so it is a generator of order Q (with P = 2*Q+1).
......
......@@ -29,12 +29,14 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdio.h>
#if defined(POLARSSL_AES_C) && defined(POLARSSL_DHM_C) &&\
defined(POLARSSL_ENTROPY_C) && defined(POLARSSL_NET_C) &&\
defined(POLARSSL_RSA_C) && defined(POLARSSL_SHA256_C) &&\
defined(POLARSSL_FS_IO) && defined(POLARSSL_CTR_DRBG_C)
#include "polarssl/net.h"
#include "polarssl/aes.h"
#include "polarssl/dhm.h"
......@@ -43,6 +45,10 @@
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
#include <stdio.h>
#include <string.h>
#endif
#define SERVER_PORT 11999
#define PLAINTEXT "==Hello there!=="
......
......@@ -29,15 +29,18 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#if defined(POLARSSL_ECDSA_C) &&\
defined(POLARSSL_ENTROPY_C) && defined(POLARSSL_CTR_DRBG_C)
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
#include "polarssl/ecdsa.h"
#include <string.h>
#include <stdio.h>
#endif
/*
* Uncomment to show key and signature details
......@@ -65,7 +68,6 @@ int main( int argc, char *argv[] )
return( 0 );
}
#else
#if defined(VERBOSE)
static void dump_buf( const char *title, unsigned char *buf, size_t len )
{
......
......@@ -29,17 +29,12 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#if !defined(_WIN32) && defined(POLARSSL_FS_IO)
#include <unistd.h>
#endif /* !_WIN32 && POLARSSL_FS_IO */
#if defined(POLARSSL_PK_WRITE_C) && defined(POLARSSL_FS_IO) &&\
defined(POLARSSL_ENTROPY_C) && defined(POLARSSL_CTR_DRBG_C)
#include "polarssl/error.h"
#include "polarssl/pk.h"
#include "polarssl/ecdsa.h"
......@@ -48,49 +43,12 @@
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
#if !defined(POLARSSL_PK_WRITE_C) || !defined(POLARSSL_FS_IO) || \
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_CTR_DRBG_C)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO and/or "
"POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C "
"not defined.\n" );
return( 0 );
}
#else
#define FORMAT_PEM 0
#define FORMAT_DER 1
#define DFL_TYPE POLARSSL_PK_RSA
#define DFL_RSA_KEYSIZE 4096
#define DFL_FILENAME "keyfile.key"
#define DFL_FORMAT FORMAT_PEM
#define DFL_USE_DEV_RANDOM 0
#if defined(POLARSSL_ECP_C)
#define DFL_EC_CURVE ecp_curve_list()->grp_id
#else
#define DFL_EC_CURVE 0
#endif
/*
* global options
*/
struct options
{
int type; /* the type of key to generate */
int rsa_keysize; /* length of key in bits */
int ec_curve; /* curve identifier for EC keys */
const char *filename; /* filename of the key file */
int format; /* the output format to use */
int use_dev_random; /* use /dev/random as entropy source */
} opt;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(_WIN32) && defined(POLARSSL_FS_IO)
#if !defined(_WIN32)
#include <unistd.h>
#define DEV_RANDOM_THRESHOLD 32
......@@ -127,8 +85,68 @@ int dev_random_entropy_poll( void *data, unsigned char *output,
return( 0 );
}
#endif /* !_WIN32 */
#endif
#if defined(POLARSSL_ECP_C)
#define DFL_EC_CURVE ecp_curve_list()->grp_id
#else
#define DFL_EC_CURVE 0
#endif
#if !defined(_WIN32) && defined(POLARSSL_FS_IO)
#define USAGE_DEV_RANDOM \
" use_dev_random=0|1 default: 0\n"
#else
#define USAGE_DEV_RANDOM ""
#endif /* !_WIN32 && POLARSSL_FS_IO */
#define FORMAT_PEM 0
#define FORMAT_DER 1
#define DFL_TYPE POLARSSL_PK_RSA
#define DFL_RSA_KEYSIZE 4096
#define DFL_FILENAME "keyfile.key"
#define DFL_FORMAT FORMAT_PEM
#define DFL_USE_DEV_RANDOM 0
#define USAGE \
"\n usage: gen_key param=<>...\n" \
"\n acceptable parameters:\n" \
" type=rsa|ec default: rsa\n" \
" rsa_keysize=%%d default: 4096\n" \
" ec_curve=%%s see below\n" \
" filename=%%s default: keyfile.key\n" \
" format=pem|der default: pem\n" \
USAGE_DEV_RANDOM \
"\n"
#if !defined(POLARSSL_PK_WRITE_C) || !defined(POLARSSL_FS_IO) || \
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_CTR_DRBG_C)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO and/or "
"POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C "
"not defined.\n" );
return( 0 );
}
#else
/*
* global options
*/
struct options
{
int type; /* the type of key to generate */
int rsa_keysize; /* length of key in bits */
int ec_curve; /* curve identifier for EC keys */
const char *filename; /* filename of the key file */
int format; /* the output format to use */
int use_dev_random; /* use /dev/random as entropy source */
} opt;
static int write_private_key( pk_context *key, const char *output_file )
{
int ret;
......@@ -168,24 +186,6 @@ static int write_private_key( pk_context *key, const char *output_file )
return( 0 );
}
#if !defined(_WIN32) && defined(POLARSSL_FS_IO)
#define USAGE_DEV_RANDOM \
" use_dev_random=0|1 default: 0\n"
#else
#define USAGE_DEV_RANDOM ""
#endif /* !_WIN32 && POLARSSL_FS_IO */
#define USAGE \
"\n usage: gen_key param=<>...\n" \
"\n acceptable parameters:\n" \
" type=rsa|ec default: rsa\n" \
" rsa_keysize=%%d default: 4096\n" \
" ec_curve=%%s see below\n" \
" filename=%%s default: keyfile.key\n" \
" format=pem|der default: pem\n" \
USAGE_DEV_RANDOM \
"\n"
int main( int argc, char *argv[] )
{
int ret = 0;
......
......@@ -29,17 +29,39 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#if defined(POLARSSL_BIGNUM_C) &&\
defined(POLARSSL_PK_PARSE_C) && defined(POLARSSL_FS_IO)
#include "polarssl/error.h"
#include "polarssl/rsa.h"
#include "polarssl/x509.h"
#include <string.h>
#endif
#define MODE_NONE 0
#define MODE_PRIVATE 1
#define MODE_PUBLIC 2
#define DFL_MODE MODE_NONE
#define DFL_FILENAME "keyfile.key"
#define DFL_PASSWORD ""
#define DFL_PASSWORD_FILE ""
#define DFL_DEBUG_LEVEL 0
#define USAGE \
"\n usage: key_app param=<>...\n" \
"\n acceptable parameters:\n" \
" mode=private|public default: none\n" \
" filename=%%s default: keyfile.key\n" \
" password=%%s default: \"\"\n" \
" password_file=%%s default: \"\"\n" \
"\n"
#if !defined(POLARSSL_BIGNUM_C) || \
!defined(POLARSSL_PK_PARSE_C) || !defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
......@@ -52,17 +74,6 @@ int main( int argc, char *argv[] )
return( 0 );
}
#else
#define MODE_NONE 0
#define MODE_PRIVATE 1
#define MODE_PUBLIC 2
#define DFL_MODE MODE_NONE
#define DFL_FILENAME "keyfile.key"
#define DFL_PASSWORD ""
#define DFL_PASSWORD_FILE ""
#define DFL_DEBUG_LEVEL 0
/*
* global options
*/
......@@ -74,15 +85,6 @@ struct options
const char *password_file; /* password_file for the private key */
} opt;
#define USAGE \
"\n usage: key_app param=<>...\n" \
"\n acceptable parameters:\n" \
" mode=private|public default: none\n" \
" filename=%%s default: keyfile.key\n" \
" password=%%s default: \"\"\n" \
" password_file=%%s default: \"\"\n" \
"\n"
int main( int argc, char *argv[] )
{
int ret = 0;
......
......@@ -29,27 +29,41 @@
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#include <stdio.h>
#define polarssl_printf printf
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#if defined(POLARSSL_PK_WRITE_C) && defined(POLARSSL_FS_IO)
#include "polarssl/error.h"
#include "polarssl/pk.h"
#include "polarssl/error.h"
#if !defined(POLARSSL_PK_WRITE_C) || !defined(POLARSSL_FS_IO)
int main( int argc, char *argv[] )
{
((void) argc);
((void) argv);
#include <stdio.h>
#include <string.h>
#endif
polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
return( 0 );
}
#if defined(POLARSSL_PEM_WRITE_C)
#define USAGE_OUT \
" output_file=%%s default: keyfile.pem\n" \