mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 18:05:40 +01:00
- Moved all examples programs to use the new entropy and CTR_DRBG
This commit is contained in:
parent
4dc6457274
commit
508ad5ab6d
@ -35,6 +35,7 @@ Changes
|
|||||||
* Changed the used random function pointer to more flexible format. Renamed
|
* Changed the used random function pointer to more flexible format. Renamed
|
||||||
havege_rand() to havege_random() to prevent mistakes. Lots of changes as
|
havege_rand() to havege_random() to prevent mistakes. Lots of changes as
|
||||||
a consequence in library code and programs
|
a consequence in library code and programs
|
||||||
|
* Moved all examples programs to use the new entropy and CTR_DRBG
|
||||||
* Added permissive certificate parsing to x509parse_crt() and
|
* Added permissive certificate parsing to x509parse_crt() and
|
||||||
x509parse_crtfile(). With permissive parsing the parsing does not stop on
|
x509parse_crtfile(). With permissive parsing the parsing does not stop on
|
||||||
encountering a parse-error
|
encountering a parse-error
|
||||||
|
@ -37,23 +37,25 @@
|
|||||||
#include "polarssl/dhm.h"
|
#include "polarssl/dhm.h"
|
||||||
#include "polarssl/rsa.h"
|
#include "polarssl/rsa.h"
|
||||||
#include "polarssl/sha1.h"
|
#include "polarssl/sha1.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
|
|
||||||
#define SERVER_NAME "localhost"
|
#define SERVER_NAME "localhost"
|
||||||
#define SERVER_PORT 11999
|
#define SERVER_PORT 11999
|
||||||
|
|
||||||
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_DHM_C) || \
|
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_DHM_C) || \
|
||||||
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_NET_C) || \
|
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_NET_C) || \
|
||||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
|
||||||
!defined(POLARSSL_FS_IO)
|
!defined(POLARSSL_FS_IO) || !defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_HAVEGE_C "
|
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
|
||||||
"and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
"and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
|
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -68,8 +70,10 @@ int main( int argc, char *argv[] )
|
|||||||
unsigned char *p, *end;
|
unsigned char *p, *end;
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
unsigned char hash[20];
|
unsigned char hash[20];
|
||||||
|
char *pers = "dh_client";
|
||||||
|
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
rsa_context rsa;
|
rsa_context rsa;
|
||||||
dhm_context dhm;
|
dhm_context dhm;
|
||||||
aes_context aes;
|
aes_context aes;
|
||||||
@ -86,7 +90,13 @@ int main( int argc, char *argv[] )
|
|||||||
printf( "\n . Seeding the random number generator" );
|
printf( "\n . Seeding the random number generator" );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 2. Read the server's public RSA key
|
* 2. Read the server's public RSA key
|
||||||
@ -207,7 +217,7 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
n = dhm.len;
|
n = dhm.len;
|
||||||
if( ( ret = dhm_make_public( &dhm, 256, buf, n,
|
if( ( ret = dhm_make_public( &dhm, 256, buf, n,
|
||||||
havege_random, &hs ) ) != 0 )
|
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! dhm_make_public returned %d\n\n", ret );
|
printf( " failed\n ! dhm_make_public returned %d\n\n", ret );
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -273,6 +283,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_HAVEGE_C &&
|
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_ENTROPY_C &&
|
||||||
POLARSSL_NET_C && POLARSSL_RSA_C && POLARSSL_SHA1_C &&
|
POLARSSL_NET_C && POLARSSL_RSA_C && POLARSSL_SHA1_C &&
|
||||||
POLARSSL_FS_IO */
|
POLARSSL_FS_IO && POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
#include "polarssl/bignum.h"
|
#include "polarssl/bignum.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: G = 4 is always a quadratic residue mod P,
|
* Note: G = 4 is always a quadratic residue mod P,
|
||||||
@ -41,15 +42,15 @@
|
|||||||
#define DH_P_SIZE 1024
|
#define DH_P_SIZE 1024
|
||||||
#define GENERATOR "4"
|
#define GENERATOR "4"
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_FS_IO)
|
!defined(POLARSSL_FS_IO) || !defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_FS_IO not defined.\n");
|
"POLARSSL_FS_IO and/or POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -59,7 +60,9 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
#if defined(POLARSSL_GENPRIME)
|
#if defined(POLARSSL_GENPRIME)
|
||||||
mpi G, P, Q;
|
mpi G, P, Q;
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
|
char *pers = "dh_genprime";
|
||||||
FILE *fout;
|
FILE *fout;
|
||||||
|
|
||||||
((void) argc);
|
((void) argc);
|
||||||
@ -71,7 +74,13 @@ int main( int argc, char *argv[] )
|
|||||||
printf( "\n . Seeding the random number generator..." );
|
printf( "\n . Seeding the random number generator..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
printf( " ok\n . Generating the modulus, please wait..." );
|
printf( " ok\n . Generating the modulus, please wait..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
@ -80,7 +89,7 @@ int main( int argc, char *argv[] )
|
|||||||
* This can take a long time...
|
* This can take a long time...
|
||||||
*/
|
*/
|
||||||
if( ( ret = mpi_gen_prime( &P, DH_P_SIZE, 1,
|
if( ( ret = mpi_gen_prime( &P, DH_P_SIZE, 1,
|
||||||
havege_random, &hs ) ) != 0 )
|
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! mpi_gen_prime returned %d\n\n", ret );
|
printf( " failed\n ! mpi_gen_prime returned %d\n\n", ret );
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -101,7 +110,7 @@ int main( int argc, char *argv[] )
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = mpi_is_prime( &Q, havege_random, &hs ) ) != 0 )
|
if( ( ret = mpi_is_prime( &Q, ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! mpi_is_prime returned %d\n\n", ret );
|
printf( " failed\n ! mpi_is_prime returned %d\n\n", ret );
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -141,4 +150,5 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_FS_IO */
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_FS_IO &&
|
||||||
|
POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -37,23 +37,25 @@
|
|||||||
#include "polarssl/dhm.h"
|
#include "polarssl/dhm.h"
|
||||||
#include "polarssl/rsa.h"
|
#include "polarssl/rsa.h"
|
||||||
#include "polarssl/sha1.h"
|
#include "polarssl/sha1.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
|
|
||||||
#define SERVER_PORT 11999
|
#define SERVER_PORT 11999
|
||||||
#define PLAINTEXT "==Hello there!=="
|
#define PLAINTEXT "==Hello there!=="
|
||||||
|
|
||||||
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_DHM_C) || \
|
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_DHM_C) || \
|
||||||
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_NET_C) || \
|
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_NET_C) || \
|
||||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
|
||||||
!defined(POLARSSL_FS_IO)
|
!defined(POLARSSL_FS_IO) || !defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_HAVEGE_C "
|
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
|
||||||
"and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
"and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
|
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO and/or "
|
||||||
|
"POLARSSL_CTR_DBRG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -69,8 +71,10 @@ int main( int argc, char *argv[] )
|
|||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
unsigned char hash[20];
|
unsigned char hash[20];
|
||||||
unsigned char buf2[2];
|
unsigned char buf2[2];
|
||||||
|
char *pers = "dh_server";
|
||||||
|
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
rsa_context rsa;
|
rsa_context rsa;
|
||||||
dhm_context dhm;
|
dhm_context dhm;
|
||||||
aes_context aes;
|
aes_context aes;
|
||||||
@ -87,7 +91,13 @@ int main( int argc, char *argv[] )
|
|||||||
printf( "\n . Seeding the random number generator" );
|
printf( "\n . Seeding the random number generator" );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 2a. Read the server's private RSA key
|
* 2a. Read the server's private RSA key
|
||||||
@ -172,7 +182,7 @@ int main( int argc, char *argv[] )
|
|||||||
memset( buf, 0, sizeof( buf ) );
|
memset( buf, 0, sizeof( buf ) );
|
||||||
|
|
||||||
if( ( ret = dhm_make_params( &dhm, 256, buf, &n,
|
if( ( ret = dhm_make_params( &dhm, 256, buf, &n,
|
||||||
havege_random, &hs ) ) != 0 )
|
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! dhm_make_params returned %d\n\n", ret );
|
printf( " failed\n ! dhm_make_params returned %d\n\n", ret );
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -276,6 +286,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_HAVEGE_C &&
|
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_ENTROPY_C &&
|
||||||
POLARSSL_NET_C && POLARSSL_RSA_C && POLARSSL_SHA1_C &&
|
POLARSSL_NET_C && POLARSSL_RSA_C && POLARSSL_SHA1_C &&
|
||||||
POLARSSL_FS_IO */
|
POLARSSL_FS_IO && POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -33,17 +33,20 @@
|
|||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
#include "polarssl/rsa.h"
|
#include "polarssl/rsa.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_RSA_C) || \
|
||||||
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_FS_IO)
|
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_FS_IO) || \
|
||||||
|
!defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||||
"POLARSSL_HAVEGE_C and/or POLARSSL_FS_IO not defined.\n");
|
"POLARSSL_ENTROPY_C and/or POLARSSL_FS_IO and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -53,11 +56,11 @@ int main( int argc, char *argv[] )
|
|||||||
int ret;
|
int ret;
|
||||||
size_t i;
|
size_t i;
|
||||||
rsa_context rsa;
|
rsa_context rsa;
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
unsigned char input[1024];
|
unsigned char input[1024];
|
||||||
unsigned char buf[512];
|
unsigned char buf[512];
|
||||||
|
char *pers = "rsa_encrypt";
|
||||||
havege_init( &hs );
|
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
@ -72,6 +75,17 @@ int main( int argc, char *argv[] )
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf( "\n . Seeding the random number generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
printf( "\n . Reading public key from rsa_pub.txt" );
|
printf( "\n . Reading public key from rsa_pub.txt" );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
@ -110,7 +124,9 @@ int main( int argc, char *argv[] )
|
|||||||
printf( "\n . Generating the RSA encrypted value" );
|
printf( "\n . Generating the RSA encrypted value" );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
if( ( ret = rsa_pkcs1_encrypt( &rsa, havege_random, &hs, RSA_PUBLIC, strlen( argv[1] ), input, buf ) ) != 0 )
|
if( ( ret = rsa_pkcs1_encrypt( &rsa, ctr_drbg_random, &ctr_drbg,
|
||||||
|
RSA_PUBLIC, strlen( argv[1] ),
|
||||||
|
input, buf ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret );
|
printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret );
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -143,5 +159,5 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_HAVEGE_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_RSA_C && POLARSSL_ENTROPY_C &&
|
||||||
POLARSSL_FS_IO */
|
POLARSSL_FS_IO && POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -31,7 +31,8 @@
|
|||||||
|
|
||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/bignum.h"
|
#include "polarssl/bignum.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
#include "polarssl/rsa.h"
|
#include "polarssl/rsa.h"
|
||||||
@ -39,17 +40,17 @@
|
|||||||
#define KEY_SIZE 1024
|
#define KEY_SIZE 1024
|
||||||
#define EXPONENT 65537
|
#define EXPONENT 65537
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_GENPRIME) || \
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_GENPRIME) || \
|
||||||
!defined(POLARSSL_FS_IO)
|
!defined(POLARSSL_FS_IO) || !defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_RSA_C and/or POLARSSL_GENPRIME and/or "
|
"POLARSSL_RSA_C and/or POLARSSL_GENPRIME and/or "
|
||||||
"POLARSSL_FS_IO not defined.\n");
|
"POLARSSL_FS_IO and/or POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -57,9 +58,11 @@ int main( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
rsa_context rsa;
|
rsa_context rsa;
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
FILE *fpub = NULL;
|
FILE *fpub = NULL;
|
||||||
FILE *fpriv = NULL;
|
FILE *fpriv = NULL;
|
||||||
|
char *pers = "rsa_genkey";
|
||||||
|
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
@ -67,14 +70,21 @@ int main( int argc, char *argv[] )
|
|||||||
printf( "\n . Seeding the random number generator..." );
|
printf( "\n . Seeding the random number generator..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
printf( " ok\n . Generating the RSA key [ %d-bit ]...", KEY_SIZE );
|
printf( " ok\n . Generating the RSA key [ %d-bit ]...", KEY_SIZE );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||||
|
|
||||||
if( ( ret = rsa_gen_key( &rsa, havege_random, &hs, KEY_SIZE, EXPONENT ) ) != 0 )
|
if( ( ret = rsa_gen_key( &rsa, ctr_drbg_random, &ctr_drbg, KEY_SIZE,
|
||||||
|
EXPONENT ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! rsa_gen_key returned %d\n\n", ret );
|
printf( " failed\n ! rsa_gen_key returned %d\n\n", ret );
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -151,5 +161,5 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_RSA_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_RSA_C &&
|
||||||
POLARSSL_GENPRIME && POLARSSL_FS_IO */
|
POLARSSL_GENPRIME && POLARSSL_FS_IO && POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
|
|
||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/md.h"
|
#include "polarssl/md.h"
|
||||||
#include "polarssl/rsa.h"
|
#include "polarssl/rsa.h"
|
||||||
#include "polarssl/sha1.h"
|
#include "polarssl/sha1.h"
|
||||||
@ -42,17 +43,19 @@
|
|||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
|
||||||
!defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO)
|
!defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO) || \
|
||||||
|
!defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_RSA_C and/or POLARSSL_SHA1_C and/or "
|
"POLARSSL_RSA_C and/or POLARSSL_SHA1_C and/or "
|
||||||
"POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
"POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -61,10 +64,12 @@ int main( int argc, char *argv[] )
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
int ret;
|
int ret;
|
||||||
rsa_context rsa;
|
rsa_context rsa;
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
unsigned char hash[20];
|
unsigned char hash[20];
|
||||||
unsigned char buf[512];
|
unsigned char buf[512];
|
||||||
char filename[512];
|
char filename[512];
|
||||||
|
char *pers = "rsa_sign_pss";
|
||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
@ -79,10 +84,20 @@ int main( int argc, char *argv[] )
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf( "\n . Seeding the random number generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
printf( "\n . Reading private key from '%s'", argv[1] );
|
printf( "\n . Reading private key from '%s'", argv[1] );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
|
||||||
rsa_init( &rsa, RSA_PKCS_V21, POLARSSL_MD_SHA1 );
|
rsa_init( &rsa, RSA_PKCS_V21, POLARSSL_MD_SHA1 );
|
||||||
|
|
||||||
if( ( ret = x509parse_keyfile( &rsa, argv[1], "" ) ) != 0 )
|
if( ( ret = x509parse_keyfile( &rsa, argv[1], "" ) ) != 0 )
|
||||||
@ -105,7 +120,8 @@ int main( int argc, char *argv[] )
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = rsa_pkcs1_sign( &rsa, havege_random, &hs, RSA_PRIVATE, SIG_RSA_SHA1,
|
if( ( ret = rsa_pkcs1_sign( &rsa, ctr_drbg_random, &ctr_drbg,
|
||||||
|
RSA_PRIVATE, SIG_RSA_SHA1,
|
||||||
20, hash, buf ) ) != 0 )
|
20, hash, buf ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! rsa_pkcs1_sign returned %d\n\n", ret );
|
printf( " failed\n ! rsa_pkcs1_sign returned %d\n\n", ret );
|
||||||
@ -143,5 +159,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_RSA_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_RSA_C &&
|
||||||
POLARSSL_SHA1_C && POLARSSL_X509_PARSE_C && POLARSSL_FS_IO */
|
POLARSSL_SHA1_C && POLARSSL_X509_PARSE_C && POLARSSL_FS_IO &&
|
||||||
|
POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -88,4 +88,4 @@ cleanup:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_HAVEGE_C && POLARSSL_ENTROPY_C */
|
#endif /* POLARSSL_CTR_DRBG_C && POLARSSL_ENTROPY_C */
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
|
|
||||||
#include "polarssl/net.h"
|
#include "polarssl/net.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/error.h"
|
#include "polarssl/error.h"
|
||||||
|
|
||||||
#define SERVER_PORT 4433
|
#define SERVER_PORT 4433
|
||||||
@ -52,17 +53,19 @@ void my_debug( void *ctx, int level, const char *str )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
||||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C)
|
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||||
|
!defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
||||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C not defined.\n");
|
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -70,7 +73,10 @@ int main( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
int ret, len, server_fd;
|
int ret, len, server_fd;
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
havege_state hs;
|
char *pers = "ssl_client1";
|
||||||
|
|
||||||
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
ssl_session ssn;
|
ssl_session ssn;
|
||||||
|
|
||||||
@ -80,14 +86,26 @@ int main( int argc, char *argv[] )
|
|||||||
/*
|
/*
|
||||||
* 0. Initialize the RNG and the session data
|
* 0. Initialize the RNG and the session data
|
||||||
*/
|
*/
|
||||||
havege_init( &hs );
|
|
||||||
memset( &ssn, 0, sizeof( ssl_session ) );
|
memset( &ssn, 0, sizeof( ssl_session ) );
|
||||||
memset( &ssl, 0, sizeof( ssl_context ) );
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
||||||
|
|
||||||
|
printf( "\n . Seeding the random number generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( " ok\n" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. Start the connection
|
* 1. Start the connection
|
||||||
*/
|
*/
|
||||||
printf( "\n . Connecting to tcp/%s/%4d...", SERVER_NAME,
|
printf( " . Connecting to tcp/%s/%4d...", SERVER_NAME,
|
||||||
SERVER_PORT );
|
SERVER_PORT );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
@ -117,7 +135,7 @@ int main( int argc, char *argv[] )
|
|||||||
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
||||||
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
||||||
|
|
||||||
ssl_set_rng( &ssl, havege_random, &hs );
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
||||||
ssl_set_dbg( &ssl, my_debug, stdout );
|
ssl_set_dbg( &ssl, my_debug, stdout );
|
||||||
ssl_set_bio( &ssl, net_recv, &server_fd,
|
ssl_set_bio( &ssl, net_recv, &server_fd,
|
||||||
net_send, &server_fd );
|
net_send, &server_fd );
|
||||||
@ -205,5 +223,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_SSL_TLS_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
|
||||||
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C */
|
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C &&
|
||||||
|
POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
#include "polarssl/net.h"
|
#include "polarssl/net.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/certs.h"
|
#include "polarssl/certs.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
#include "polarssl/error.h"
|
#include "polarssl/error.h"
|
||||||
@ -96,17 +97,19 @@ void my_debug( void *ctx, int level, const char *str )
|
|||||||
" force_ciphersuite=<name> default: all enabled\n"\
|
" force_ciphersuite=<name> default: all enabled\n"\
|
||||||
" acceptable ciphersuite names:\n"
|
" acceptable ciphersuite names:\n"
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
||||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C)
|
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||||
|
!defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
||||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C not defined.\n");
|
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -114,7 +117,10 @@ int main( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
int ret = 0, len, server_fd;
|
int ret = 0, len, server_fd;
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
havege_state hs;
|
char *pers = "ssl_client2";
|
||||||
|
|
||||||
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
ssl_session ssn;
|
ssl_session ssn;
|
||||||
x509_cert cacert;
|
x509_cert cacert;
|
||||||
@ -214,12 +220,23 @@ int main( int argc, char *argv[] )
|
|||||||
/*
|
/*
|
||||||
* 0. Initialize the RNG and the session data
|
* 0. Initialize the RNG and the session data
|
||||||
*/
|
*/
|
||||||
havege_init( &hs );
|
printf( "\n . Seeding the random number generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( " ok\n" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1.1. Load the trusted CA
|
* 1.1. Load the trusted CA
|
||||||
*/
|
*/
|
||||||
printf( "\n . Loading the CA root certificate ..." );
|
printf( " . Loading the CA root certificate ..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
#if defined(POLARSSL_FS_IO)
|
#if defined(POLARSSL_FS_IO)
|
||||||
@ -316,8 +333,6 @@ int main( int argc, char *argv[] )
|
|||||||
printf( " . Setting up the SSL/TLS structure..." );
|
printf( " . Setting up the SSL/TLS structure..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
|
||||||
|
|
||||||
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! ssl_init returned %d\n\n", ret );
|
printf( " failed\n ! ssl_init returned %d\n\n", ret );
|
||||||
@ -329,7 +344,7 @@ int main( int argc, char *argv[] )
|
|||||||
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
||||||
ssl_set_authmode( &ssl, SSL_VERIFY_OPTIONAL );
|
ssl_set_authmode( &ssl, SSL_VERIFY_OPTIONAL );
|
||||||
|
|
||||||
ssl_set_rng( &ssl, havege_random, &hs );
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
||||||
ssl_set_dbg( &ssl, my_debug, stdout );
|
ssl_set_dbg( &ssl, my_debug, stdout );
|
||||||
ssl_set_bio( &ssl, net_recv, &server_fd,
|
ssl_set_bio( &ssl, net_recv, &server_fd,
|
||||||
net_send, &server_fd );
|
net_send, &server_fd );
|
||||||
@ -478,5 +493,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_SSL_TLS_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
|
||||||
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C */
|
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C &&
|
||||||
|
POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -39,7 +39,8 @@
|
|||||||
|
|
||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/certs.h"
|
#include "polarssl/certs.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
@ -52,17 +53,18 @@
|
|||||||
"<p>Successful connection using: %s</p>\r\n"
|
"<p>Successful connection using: %s</p>\r\n"
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
|
||||||
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_SSL_TLS_C) || \
|
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_SSL_TLS_C) || \
|
||||||
!defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
|
!defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
|
||||||
!defined(POLARSSL_RSA_C)
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_HAVEGE_C "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
|
||||||
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
||||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C not defined.\n");
|
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
@ -204,8 +206,10 @@ int main( int argc, char *argv[] )
|
|||||||
int listen_fd;
|
int listen_fd;
|
||||||
int client_fd;
|
int client_fd;
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
|
char *pers = "ssl_fork_server";
|
||||||
|
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
ssl_session ssn;
|
ssl_session ssn;
|
||||||
x509_cert srvcert;
|
x509_cert srvcert;
|
||||||
@ -216,10 +220,26 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
signal( SIGCHLD, SIG_IGN );
|
signal( SIGCHLD, SIG_IGN );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 0. Initial seeding of the RNG
|
||||||
|
*/
|
||||||
|
printf( "\n . Initial seeding of the random generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( " ok\n" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. Load the certificates and private RSA key
|
* 1. Load the certificates and private RSA key
|
||||||
*/
|
*/
|
||||||
printf( "\n . Loading the server cert. and key..." );
|
printf( " . Loading the server cert. and key..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
memset( &srvcert, 0, sizeof( x509_cert ) );
|
memset( &srvcert, 0, sizeof( x509_cert ) );
|
||||||
@ -308,6 +328,13 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
if( pid != 0 )
|
if( pid != 0 )
|
||||||
{
|
{
|
||||||
|
if( ( ret = ctr_drbg_reseed( &ctr_drbg,
|
||||||
|
(unsigned char* ) "parent", 6 ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
close( client_fd );
|
close( client_fd );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -317,10 +344,15 @@ int main( int argc, char *argv[] )
|
|||||||
/*
|
/*
|
||||||
* 4. Setup stuff
|
* 4. Setup stuff
|
||||||
*/
|
*/
|
||||||
printf( " . Setting up the RNG and SSL data...." );
|
printf( " . Setting up the SSL data...." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
if( ( ret = ctr_drbg_reseed( &ctr_drbg,
|
||||||
|
(unsigned char *) "child", 5 ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
||||||
{
|
{
|
||||||
@ -333,7 +365,7 @@ int main( int argc, char *argv[] )
|
|||||||
ssl_set_endpoint( &ssl, SSL_IS_SERVER );
|
ssl_set_endpoint( &ssl, SSL_IS_SERVER );
|
||||||
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
||||||
|
|
||||||
ssl_set_rng( &ssl, havege_random, &hs );
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
||||||
ssl_set_dbg( &ssl, my_debug, stdout );
|
ssl_set_dbg( &ssl, my_debug, stdout );
|
||||||
ssl_set_bio( &ssl, net_recv, &client_fd,
|
ssl_set_bio( &ssl, net_recv, &client_fd,
|
||||||
net_send, &client_fd );
|
net_send, &client_fd );
|
||||||
@ -466,6 +498,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_CERTS_C && POLARSSL_HAVEGE_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_CERTS_C && POLARSSL_ENTROPY_C &&
|
||||||
POLARSSL_SSL_TLS_C && POLARSSL_SSL_SRV_C && POLARSSL_NET_C &&
|
POLARSSL_SSL_TLS_C && POLARSSL_SSL_SRV_C && POLARSSL_NET_C &&
|
||||||
POLARSSL_RSA_C */
|
POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -50,7 +50,8 @@
|
|||||||
#include "polarssl/error.h"
|
#include "polarssl/error.h"
|
||||||
#include "polarssl/net.h"
|
#include "polarssl/net.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/certs.h"
|
#include "polarssl/certs.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
|
|
||||||
@ -100,17 +101,19 @@ void my_debug( void *ctx, int level, const char *str )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
||||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C)
|
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||||
|
!defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
||||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C not defined.\n");
|
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -340,7 +343,10 @@ int main( int argc, char *argv[] )
|
|||||||
unsigned char base[1024];
|
unsigned char base[1024];
|
||||||
#endif
|
#endif
|
||||||
char hostname[32];
|
char hostname[32];
|
||||||
havege_state hs;
|
char *pers = "ssl_mail_client";
|
||||||
|
|
||||||
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
ssl_session ssn;
|
ssl_session ssn;
|
||||||
x509_cert cacert;
|
x509_cert cacert;
|
||||||
@ -466,12 +472,23 @@ int main( int argc, char *argv[] )
|
|||||||
/*
|
/*
|
||||||
* 0. Initialize the RNG and the session data
|
* 0. Initialize the RNG and the session data
|
||||||
*/
|
*/
|
||||||
havege_init( &hs );
|
printf( "\n . Seeding the random number generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( " ok\n" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1.1. Load the trusted CA
|
* 1.1. Load the trusted CA
|
||||||
*/
|
*/
|
||||||
printf( "\n . Loading the CA root certificate ..." );
|
printf( " . Loading the CA root certificate ..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
#if defined(POLARSSL_FS_IO)
|
#if defined(POLARSSL_FS_IO)
|
||||||
@ -568,8 +585,6 @@ int main( int argc, char *argv[] )
|
|||||||
printf( " . Setting up the SSL/TLS structure..." );
|
printf( " . Setting up the SSL/TLS structure..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
|
||||||
|
|
||||||
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! ssl_init returned %d\n\n", ret );
|
printf( " failed\n ! ssl_init returned %d\n\n", ret );
|
||||||
@ -581,7 +596,7 @@ int main( int argc, char *argv[] )
|
|||||||
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
||||||
ssl_set_authmode( &ssl, SSL_VERIFY_OPTIONAL );
|
ssl_set_authmode( &ssl, SSL_VERIFY_OPTIONAL );
|
||||||
|
|
||||||
ssl_set_rng( &ssl, havege_random, &hs );
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
||||||
ssl_set_dbg( &ssl, my_debug, stdout );
|
ssl_set_dbg( &ssl, my_debug, stdout );
|
||||||
ssl_set_bio( &ssl, net_recv, &server_fd,
|
ssl_set_bio( &ssl, net_recv, &server_fd,
|
||||||
net_send, &server_fd );
|
net_send, &server_fd );
|
||||||
@ -799,5 +814,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_SSL_TLS_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
|
||||||
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C */
|
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C **
|
||||||
|
POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -37,7 +37,8 @@
|
|||||||
|
|
||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/certs.h"
|
#include "polarssl/certs.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
@ -172,17 +173,18 @@ static int my_set_session( ssl_context *ssl )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_CERTS_C) || \
|
||||||
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_SSL_TLS_C) || \
|
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_SSL_TLS_C) || \
|
||||||
!defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
|
!defined(POLARSSL_SSL_SRV_C) || !defined(POLARSSL_NET_C) || \
|
||||||
!defined(POLARSSL_RSA_C)
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_HAVEGE_C "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_CERTS_C and/or POLARSSL_ENTROPY_C "
|
||||||
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
"and/or POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
||||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C not defined.\n");
|
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -192,8 +194,10 @@ int main( int argc, char *argv[] )
|
|||||||
int listen_fd;
|
int listen_fd;
|
||||||
int client_fd = -1;
|
int client_fd = -1;
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
|
char *pers = "ssl_server";
|
||||||
|
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
ssl_session ssn;
|
ssl_session ssn;
|
||||||
x509_cert srvcert;
|
x509_cert srvcert;
|
||||||
@ -257,12 +261,26 @@ int main( int argc, char *argv[] )
|
|||||||
printf( " ok\n" );
|
printf( " ok\n" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 4. Setup stuff
|
* 3. Seed the RNG
|
||||||
*/
|
*/
|
||||||
printf( " . Setting up the RNG and SSL data...." );
|
printf( " . Seeding the random number generator..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
havege_init( &hs );
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf( " ok\n" );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 4. Setup stuff
|
||||||
|
*/
|
||||||
|
printf( " . Setting up the SSL data...." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
if( ( ret = ssl_init( &ssl ) ) != 0 )
|
||||||
{
|
{
|
||||||
@ -273,7 +291,7 @@ int main( int argc, char *argv[] )
|
|||||||
ssl_set_endpoint( &ssl, SSL_IS_SERVER );
|
ssl_set_endpoint( &ssl, SSL_IS_SERVER );
|
||||||
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
||||||
|
|
||||||
ssl_set_rng( &ssl, havege_random, &hs );
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
||||||
ssl_set_dbg( &ssl, my_debug, stdout );
|
ssl_set_dbg( &ssl, my_debug, stdout );
|
||||||
|
|
||||||
ssl_set_scb( &ssl, my_get_session,
|
ssl_set_scb( &ssl, my_get_session,
|
||||||
@ -468,6 +486,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_CERTS_C && POLARSSL_HAVEGE_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_CERTS_C && POLARSSL_ENTROPY_C &&
|
||||||
POLARSSL_SSL_TLS_C && POLARSSL_SSL_SRV_C && POLARSSL_NET_C &&
|
POLARSSL_SSL_TLS_C && POLARSSL_SSL_SRV_C && POLARSSL_NET_C &&
|
||||||
POLARSSL_RSA_C */
|
POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
#include "polarssl/net.h"
|
#include "polarssl/net.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/timing.h"
|
#include "polarssl/timing.h"
|
||||||
#include "polarssl/certs.h"
|
#include "polarssl/certs.h"
|
||||||
|
|
||||||
@ -123,19 +124,19 @@ void my_debug( void *ctx, int level, const char *str )
|
|||||||
fprintf( stderr, "%s", str );
|
fprintf( stderr, "%s", str );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
|
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_SRV_C) || \
|
||||||
!defined(POLARSSL_SSL_CLI_C) || !defined(POLARSSL_NET_C) || \
|
!defined(POLARSSL_SSL_CLI_C) || !defined(POLARSSL_NET_C) || \
|
||||||
!defined(POLARSSL_RSA_C)
|
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_SRV_C and/or "
|
||||||
"POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
|
"POLARSSL_SSL_CLI_C and/or POLARSSL_NET_C and/or "
|
||||||
"POLARSSL_RSA_C not defined.\n");
|
"POLARSSL_RSA_C and/or POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -160,8 +161,11 @@ static int ssl_test( struct options *opt )
|
|||||||
unsigned char *read_buf = NULL;
|
unsigned char *read_buf = NULL;
|
||||||
unsigned char *write_buf = NULL;
|
unsigned char *write_buf = NULL;
|
||||||
|
|
||||||
|
char *pers = "ssl_test";
|
||||||
|
|
||||||
struct hr_time t;
|
struct hr_time t;
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
ssl_session ssn;
|
ssl_session ssn;
|
||||||
x509_cert srvcert;
|
x509_cert srvcert;
|
||||||
@ -169,7 +173,14 @@ static int ssl_test( struct options *opt )
|
|||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
havege_init( &hs );
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
get_timer( &t, 1 );
|
get_timer( &t, 1 );
|
||||||
|
|
||||||
memset( read_state, 0, sizeof( read_state ) );
|
memset( read_state, 0, sizeof( read_state ) );
|
||||||
@ -257,7 +268,7 @@ static int ssl_test( struct options *opt )
|
|||||||
|
|
||||||
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
||||||
|
|
||||||
ssl_set_rng( &ssl, havege_random, &hs );
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
||||||
ssl_set_dbg( &ssl, my_debug, opt );
|
ssl_set_dbg( &ssl, my_debug, opt );
|
||||||
ssl_set_bio( &ssl, net_recv, &client_fd,
|
ssl_set_bio( &ssl, net_recv, &client_fd,
|
||||||
net_send, &client_fd );
|
net_send, &client_fd );
|
||||||
@ -594,6 +605,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_SSL_TLS_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
|
||||||
POLARSSL_SSL_SRV_C && POLARSSL_SSL_CLI_C && POLARSSL_NET_C &&
|
POLARSSL_SSL_SRV_C && POLARSSL_SSL_CLI_C && POLARSSL_NET_C &&
|
||||||
POLARSSL_RSA_C */
|
POLARSSL_RSA_C && POLARSSL_CTR_DRBG_C */
|
||||||
|
@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
#include "polarssl/config.h"
|
#include "polarssl/config.h"
|
||||||
|
|
||||||
#include "polarssl/havege.h"
|
#include "polarssl/entropy.h"
|
||||||
|
#include "polarssl/ctr_drbg.h"
|
||||||
#include "polarssl/net.h"
|
#include "polarssl/net.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
@ -82,19 +83,21 @@ void my_debug( void *ctx, int level, const char *str )
|
|||||||
" permissive=%%d default: 0 (disabled)\n" \
|
" permissive=%%d default: 0 (disabled)\n" \
|
||||||
"\n"
|
"\n"
|
||||||
|
|
||||||
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_HAVEGE_C) || \
|
#if !defined(POLARSSL_BIGNUM_C) || !defined(POLARSSL_ENTROPY_C) || \
|
||||||
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
!defined(POLARSSL_SSL_TLS_C) || !defined(POLARSSL_SSL_CLI_C) || \
|
||||||
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
!defined(POLARSSL_NET_C) || !defined(POLARSSL_RSA_C) || \
|
||||||
!defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO)
|
!defined(POLARSSL_X509_PARSE_C) || !defined(POLARSSL_FS_IO) || \
|
||||||
|
!defined(POLARSSL_CTR_DRBG_C)
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_HAVEGE_C and/or "
|
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||||
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
"POLARSSL_SSL_TLS_C and/or POLARSSL_SSL_CLI_C and/or "
|
||||||
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
"POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||||
"POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
"POLARSSL_X509_PARSE_C and/or POLARSSL_FS_IO and/or "
|
||||||
|
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -102,13 +105,15 @@ int main( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
int ret = 0, server_fd;
|
int ret = 0, server_fd;
|
||||||
unsigned char buf[1024];
|
unsigned char buf[1024];
|
||||||
havege_state hs;
|
entropy_context entropy;
|
||||||
|
ctr_drbg_context ctr_drbg;
|
||||||
ssl_context ssl;
|
ssl_context ssl;
|
||||||
ssl_session ssn;
|
ssl_session ssn;
|
||||||
x509_cert clicert;
|
x509_cert clicert;
|
||||||
rsa_context rsa;
|
rsa_context rsa;
|
||||||
int i, j, n;
|
int i, j, n;
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
char *pers = "cert_app";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set to sane values
|
* Set to sane values
|
||||||
@ -232,7 +237,16 @@ int main( int argc, char *argv[] )
|
|||||||
/*
|
/*
|
||||||
* 1. Initialize the RNG and the session data
|
* 1. Initialize the RNG and the session data
|
||||||
*/
|
*/
|
||||||
havege_init( &hs );
|
printf( "\n . Seeding the random number generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
entropy_init( &entropy );
|
||||||
|
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||||
|
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 2. Start the connection
|
* 2. Start the connection
|
||||||
@ -260,7 +274,7 @@ int main( int argc, char *argv[] )
|
|||||||
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
|
||||||
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
ssl_set_authmode( &ssl, SSL_VERIFY_NONE );
|
||||||
|
|
||||||
ssl_set_rng( &ssl, havege_random, &hs );
|
ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
|
||||||
ssl_set_dbg( &ssl, my_debug, stdout );
|
ssl_set_dbg( &ssl, my_debug, stdout );
|
||||||
ssl_set_bio( &ssl, net_recv, &server_fd,
|
ssl_set_bio( &ssl, net_recv, &server_fd,
|
||||||
net_send, &server_fd );
|
net_send, &server_fd );
|
||||||
@ -321,6 +335,6 @@ exit:
|
|||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C && POLARSSL_HAVEGE_C && POLARSSL_SSL_TLS_C &&
|
#endif /* POLARSSL_BIGNUM_C && POLARSSL_ENTROPY_C && POLARSSL_SSL_TLS_C &&
|
||||||
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C &&
|
POLARSSL_SSL_CLI_C && POLARSSL_NET_C && POLARSSL_RSA_C &&
|
||||||
POLARSSL_X509_PARSE_C && POLARSSL_FS_IO */
|
POLARSSL_X509_PARSE_C && POLARSSL_FS_IO && POLARSSL_CTR_DRBG_C */
|
||||||
|
Loading…
Reference in New Issue
Block a user