Commit 5690efcc authored by Paul Bakker's avatar Paul Bakker
Browse files

- Fixed a whole bunch of dependencies on defines between files, examples and tests

parent 2c0994e9
......@@ -132,6 +132,8 @@
/**
* \def POLARSSL_DEBUG_MSG
*
* Requires: POLARSSL_DEBUG_C
*
* Enable all SSL/TLS debugging messages.
*/
#define POLARSSL_DEBUG_MSG
......@@ -139,6 +141,8 @@
/**
* \def POLARSSL_GENPRIME
*
* Requires: POLARSSL_BIGNUM_C, POLARSSL_RSA_C
*
* Enable the RSA prime-number generation code.
*/
#define POLARSSL_GENPRIME
......@@ -153,6 +157,8 @@
/**
* \def POLARSSL_PKCS1_V21
*
* Requires: POLARSSL_MD_C, POLARSSL_RSA_C
*
* Enable support for PKCS#1 v2.1 encoding.
* This enables support for RSAES-OAEP and RSASSA-PSS operations.
*/
......@@ -219,9 +225,9 @@
* Enable the Base64 module.
*
* Module: library/base64.c
* Caller: library/x509parse.c
* Caller: library/pem.c
*
* This module is required for X.509 support.
* This module is required for PEM support (required by X.509).
*/
#define POLARSSL_BASE64_C
......@@ -343,6 +349,8 @@
* Module: library/havege.c
* Caller:
*
* Requires: POLARSSL_TIMING_C
*
* This module enables the HAVEGE random number generator.
*/
#define POLARSSL_HAVEGE_C
......@@ -430,10 +438,28 @@
* Module: library/pem.c
* Caller: library/x509parse.c
*
* Requires: POLARSSL_BASE64_C
*
* This modules adds support for decoding PEM files.
*/
#define POLARSSL_PEM_C
/**
* \def POLARSSL_PKCS11_C
*
* Enable support for PKCS#11 smartcard support.
*
* Module: library/ssl_srv.c
* Caller: library/ssl_cli.c
* library/ssl_srv.c
*
* Requires: POLARSSL_SSL_TLS_C
*
* This module is required for SSL/TLS PKCS #11 smartcard support.
* Requires the presence of the PKCS#11 helper library (libpkcs11-helper)
#define POLARSSL_PKCS11_C
*/
/**
* \def POLARSSL_RSA_C
*
......@@ -445,6 +471,8 @@
* library/ssl_tls.c
* library/x509.c
*
* Requires: POLARSSL_BIGNUM_C
*
* This module is required for SSL/TLS and MD5-signed certificates.
*/
#define POLARSSL_RSA_C
......@@ -498,6 +526,8 @@
* Module: library/ssl_cli.c
* Caller:
*
* Requires: POLARSSL_SSL_TLS_C
*
* This module is required for SSL/TLS client support.
*/
#define POLARSSL_SSL_CLI_C
......@@ -510,6 +540,8 @@
* Module: library/ssl_srv.c
* Caller:
*
* Requires: POLARSSL_SSL_TLS_C
*
* This module is required for SSL/TLS server support.
*/
#define POLARSSL_SSL_SRV_C
......@@ -523,24 +555,12 @@
* Caller: library/ssl_cli.c
* library/ssl_srv.c
*
* Requires: POLARSSL_MD5_C, POLARSSL_SHA1_C, POLARSSL_X509_PARSE_C
*
* This module is required for SSL/TLS.
*/
#define POLARSSL_SSL_TLS_C
/**
* \def POLARSSL_PKCS11_C
*
* Enable support for PKCS#11 smartcard support.
*
* Module: library/ssl_srv.c
* Caller: library/ssl_cli.c
* library/ssl_srv.c
*
* This module is required for SSL/TLS PKCS #11 smartcard support.
* Requires the presence of the PKCS#11 helper library (libpkcs11-helper)
#define POLARSSL_PKCS11_C
*/
/**
* \def POLARSSL_TIMING_C
*
......@@ -574,6 +594,8 @@
* library/ssl_srv.c
* library/ssl_tls.c
*
* Requires: POLARSSL_BIGNUM_C, POLARSSL_RSA_C
*
* This module is required for X.509 certificate parsing.
*/
#define POLARSSL_X509_PARSE_C
......
......@@ -30,7 +30,7 @@
#include "polarssl/config.h"
#include "polarssl/ssl.h"
#if defined(POLARSSL_DEBUG_MSG)
#if defined(POLARSSL_DEBUG_MSG) && defined(POLARSSL_DEBUG_C)
#define SSL_DEBUG_MSG( level, args ) \
debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args );
......
......@@ -2033,6 +2033,7 @@ int mpi_self_test( int verbose )
if( verbose != 0 )
printf( "passed\n" );
#if defined(POLARSSL_GENPRIME)
MPI_CHK( mpi_inv_mod( &X, &A, &N ) );
MPI_CHK( mpi_read_string( &U, 16,
......@@ -2053,6 +2054,7 @@ int mpi_self_test( int verbose )
if( verbose != 0 )
printf( "passed\n" );
#endif
if( verbose != 0 )
printf( " MPI test #5 (simple gcd): " );
......
......@@ -1095,10 +1095,12 @@ int rsa_self_test( int verbose )
{
size_t len;
rsa_context rsa;
unsigned char sha1sum[20];
unsigned char rsa_plaintext[PT_LEN];
unsigned char rsa_decrypted[PT_LEN];
unsigned char rsa_ciphertext[KEY_LEN];
#if defined(POLARSSL_SHA1_C)
unsigned char sha1sum[20];
#endif
rsa_init( &rsa, RSA_PKCS_V15, 0 );
......@@ -1159,6 +1161,7 @@ int rsa_self_test( int verbose )
return( 1 );
}
#if defined(POLARSSL_SHA1_C)
if( verbose != 0 )
printf( "passed\n PKCS#1 data sign : " );
......@@ -1187,6 +1190,7 @@ int rsa_self_test( int verbose )
if( verbose != 0 )
printf( "passed\n\n" );
#endif /* POLARSSL_SHA1_C */
rsa_free( &rsa );
......
......@@ -322,12 +322,14 @@ static int ssl_parse_server_hello( ssl_context *ssl )
static int ssl_parse_server_key_exchange( ssl_context *ssl )
{
#if defined(POLARSSL_DHM_C)
int ret;
size_t n;
unsigned char *p, *end;
unsigned char hash[36];
md5_context md5;
sha1_context sha1;
#endif
SSL_DEBUG_MSG( 2, ( "=> parse server key exchange" ) );
......
......@@ -527,11 +527,13 @@ static int ssl_write_certificate_request( ssl_context *ssl )
static int ssl_write_server_key_exchange( ssl_context *ssl )
{
#if defined(POLARSSL_DHM_C)
int ret;
size_t n, rsa_key_len = 0;
unsigned char hash[36];
md5_context md5;
sha1_context sha1;
#endif
SSL_DEBUG_MSG( 2, ( "=> write server key exchange" ) );
......
......@@ -1124,11 +1124,12 @@ static int x509_get_sig_alg( const x509_buf *sig_oid, int *sig_alg )
int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen )
{
int ret;
size_t len, use_len;
size_t len;
unsigned char *p, *end;
x509_cert *crt;
#if defined(POLARSSL_PEM_C)
pem_context pem;
size_t use_len;
#endif
crt = chain;
......@@ -1461,10 +1462,11 @@ int x509parse_crt( x509_cert *chain, const unsigned char *buf, size_t buflen )
int x509parse_crl( x509_crl *chain, const unsigned char *buf, size_t buflen )
{
int ret;
size_t len, use_len;
size_t len;
unsigned char *p, *end;
x509_crl *crl;
#if defined(POLARSSL_PEM_C)
size_t use_len;
pem_context pem;
#endif
......@@ -1893,6 +1895,8 @@ int x509parse_key( rsa_context *rsa, const unsigned char *key, size_t keylen,
p = ( ret == 0 ) ? pem.buf : (unsigned char *) key;
#else
((void) pwd);
((void) pwdlen);
p = (unsigned char *) key;
#endif
end = p + keylen;
......@@ -3033,14 +3037,16 @@ void x509_crl_free( x509_crl *crl )
*/
int x509_self_test( int verbose )
{
#if defined(POLARSSL_MD5_C)
#if defined(POLARSSL_CERTS_C) && defined(POLARSSL_MD5_C)
int ret;
int flags;
size_t i, j;
x509_cert cacert;
x509_cert clicert;
rsa_context rsa;
#if defined(POLARSSL_DHM_C)
dhm_context dhm;
#endif
if( verbose != 0 )
printf( " X.509 certificate load: " );
......@@ -3100,6 +3106,7 @@ int x509_self_test( int verbose )
return( ret );
}
#if defined(POLARSSL_DHM_C)
if( verbose != 0 )
printf( "passed\n X.509 DHM parameter load: " );
......@@ -3116,11 +3123,14 @@ int x509_self_test( int verbose )
if( verbose != 0 )
printf( "passed\n\n" );
#endif
x509_free( &cacert );
x509_free( &clicert );
rsa_free( &rsa );
#if defined(POLARSSL_DHM_C)
dhm_free( &dhm );
#endif
return( 0 );
#else
......
......@@ -40,6 +40,8 @@
#include <stdio.h>
#include <time.h>
#include "polarssl/config.h"
#include "polarssl/aes.h"
#include "polarssl/sha2.h"
......@@ -52,9 +54,18 @@
"\n example: aescrypt2 0 file file.aes hex:E76B2413958B00E193\n" \
"\n"
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA2_C)
int main( void )
{
printf("POLARSSL_AES_C and/or POLARSSL_SHA2_C not defined.\n");
return( 0 );
}
#else
int main( int argc, char *argv[] )
{
int ret = 1, i, n;
int ret = 1;
int i, n;
int mode, lastn;
size_t keylen;
FILE *fkey, *fin = NULL, *fout = NULL;
......@@ -404,3 +415,4 @@ exit:
return( ret );
}
#endif /* POLARSSL_AES_C && POLARSSL_SHA2_C */
......@@ -41,6 +41,8 @@
#include <stdio.h>
#include <time.h>
#include "polarssl/config.h"
#include "polarssl/cipher.h"
#include "polarssl/md.h"
......@@ -53,6 +55,13 @@
"\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)
int main( void )
{
printf("POLARSSL_CIPHER_C and/or POLARSSL_MD_C not defined.\n");
return( 0 );
}
#else
int main( int argc, char *argv[] )
{
int ret = 1, i;
......@@ -463,3 +472,4 @@ exit:
return( ret );
}
#endif /* POLARSSL_CIPHER_C && POLARSSL_MD_C */
......@@ -30,8 +30,17 @@
#include <string.h>
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/md.h"
#if !defined(POLARSSL_MD_C)
int main( void )
{
printf("POLARSSL_MD_C not defined.\n");
return( 0 );
}
#else
static int generic_wrapper( const md_info_t *md_info, char *filename, unsigned char *sum )
{
int ret = md_file( md_info, filename, sum );
......@@ -201,3 +210,4 @@ exit:
return( ret );
}
#endif /* POLARSSL_MD_C */
......@@ -29,8 +29,17 @@
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/md5.h"
#if !defined(POLARSSL_MD5_C)
int main( void )
{
printf("POLARSSL_MD5_C not defined.\n");
return( 0 );
}
#else
int main( void )
{
int i;
......@@ -53,3 +62,4 @@ int main( void )
return( 0 );
}
#endif /* POLARSSL_MD5_C */
......@@ -30,8 +30,17 @@
#include <string.h>
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/md5.h"
#if !defined(POLARSSL_MD5_C) || !defined(POLARSSL_FS_IO)
int main( void )
{
printf("POLARSSL_MD5_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
static int md5_wrapper( char *filename, unsigned char *sum )
{
int ret = md5_file( filename, sum );
......@@ -159,3 +168,4 @@ int main( int argc, char *argv[] )
return( ret );
}
#endif /* POLARSSL_MD5_C && POLARSSL_FS_IO */
......@@ -30,8 +30,17 @@
#include <string.h>
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/sha1.h"
#if !defined(POLARSSL_SHA1_C) || !defined(POLARSSL_FS_IO)
int main( void )
{
printf("POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
static int sha1_wrapper( char *filename, unsigned char *sum )
{
int ret = sha1_file( filename, sum );
......@@ -159,3 +168,4 @@ int main( int argc, char *argv[] )
return( ret );
}
#endif /* POLARSSL_SHA1_C && POLARSSL_FS_IO */
......@@ -30,8 +30,17 @@
#include <string.h>
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/sha2.h"
#if !defined(POLARSSL_SHA2_C) || !defined(POLARSSL_FS_IO)
int main( void )
{
printf("POLARSSL_SHA2_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
static int sha2_wrapper( char *filename, unsigned char *sum )
{
int ret = sha2_file( filename, sum, 0 );
......@@ -159,3 +168,4 @@ int main( int argc, char *argv[] )
return( ret );
}
#endif /* POLARSSL_SHA2_C && POLARSSL_FS_IO */
......@@ -30,6 +30,8 @@
#include <string.h>
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/net.h"
#include "polarssl/aes.h"
#include "polarssl/dhm.h"
......@@ -40,6 +42,18 @@
#define SERVER_NAME "localhost"
#define SERVER_PORT 11999
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_DHM_C) || \
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_NET_C) || \
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
!defined(POLARSSL_FS_IO)
int main( void )
{
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_HAVEGE_C "
"and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
int main( void )
{
FILE *f;
......@@ -253,3 +267,6 @@ exit:
return( ret );
}
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_HAVEGE_C &&
POLARSSL_NET_C && POLARSSL_RSA_C && POLARSSL_SHA1_C &&
POLARSSL_FS_IO */
......@@ -29,8 +29,9 @@
#include <stdio.h>
#include "polarssl/bignum.h"
#include "polarssl/config.h"
#include "polarssl/bignum.h"
#include "polarssl/havege.h"
/*
......@@ -40,6 +41,15 @@
#define DH_P_SIZE 1024
#define GENERATOR "4"
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
!defined(POLARSSL_FS_IO)
int main( void )
{
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
"POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
int main( void )
{
int ret = 1;
......@@ -125,3 +135,4 @@ exit:
return( ret );
}
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_FS_IO */
......@@ -30,6 +30,8 @@
#include <string.h>
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/net.h"
#include "polarssl/aes.h"
#include "polarssl/dhm.h"
......@@ -40,6 +42,18 @@
#define SERVER_PORT 11999
#define PLAINTEXT "==Hello there!=="
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_DHM_C) || \
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_NET_C) || \
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
!defined(POLARSSL_FS_IO)
int main( void )
{
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_HAVEGE_C "
"and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
int main( void )
{
FILE *f;
......@@ -256,3 +270,6 @@ exit:
return( ret );
}
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_HAVEGE_C &&
POLARSSL_NET_C && POLARSSL_RSA_C && POLARSSL_SHA1_C &&
POLARSSL_FS_IO */
......@@ -29,8 +29,16 @@
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/bignum.h"
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_FS_IO)
int main( void )
{
printf("POLARSSL_BIGNUM_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
int main( void )
{
mpi E, P, Q, N, H, D, X, Y, Z;
......@@ -52,6 +60,7 @@ int main( void )
mpi_write_file( " P = ", &P, 10, NULL );
mpi_write_file( " Q = ", &Q, 10, NULL );
#if defined(POLARSSL_GENPRIME)
mpi_sub_int( &P, &P, 1 );
mpi_sub_int( &Q, &Q, 1 );
mpi_mul_mpi( &H, &P, &Q );
......@@ -59,7 +68,9 @@ int main( void )
mpi_write_file( " D = E^-1 mod (P-1)*(Q-1) = ",
&D, 10, NULL );
#else
printf("\nTest skipped (POLARSSL_GENPRIME not defined).\n\n");
#endif
mpi_read_string( &X, 10, "55555" );
mpi_exp_mod( &Y, &X, &E, &N, NULL );
mpi_exp_mod( &Z, &Y, &D, &N, NULL );
......@@ -81,3 +92,4 @@ int main( void )
return( 0 );
}
#endif /* POLARSSL_BIGNUM_C && POLARSSL_FS_IO */
......@@ -29,6 +29,8 @@
#include <stdio.h>
#include "polarssl/config.h"
#include "polarssl/havege.h"
#include "polarssl/bignum.h"
#include "polarssl/x509.h"
......@@ -37,6 +39,17 @@