- Removed dependency of tests on rand()

- Added pseudo-random helper function
This commit is contained in:
Paul Bakker
2011-03-13 15:45:42 +00:00
parent 9dcc32236b
commit 997bbd10d8
4 changed files with 65 additions and 25 deletions

View File

@@ -1,14 +1,5 @@
BEGIN_HEADER
#include <polarssl/dhm.h>
static int myrand( void *r )
{
if ( r != NULL )
r = NULL;
return( rand() );
}
END_HEADER
BEGIN_CASE
@@ -26,6 +17,7 @@ dhm_do_dhm:x_size:radix_P:input_P:radix_G:input_G
int sec_srv_len = 1000;
int sec_cli_len = 1000;
int x_size;
rnd_pseudo_info rnd_info;
memset( &ctx_srv, 0x00, sizeof( dhm_context ) );
memset( &ctx_cli, 0x00, sizeof( dhm_context ) );
@@ -33,18 +25,19 @@ dhm_do_dhm:x_size:radix_P:input_P:radix_G:input_G
memset( pub_cli, 0x00, 1000 );
memset( sec_srv, 0x00, 1000 );
memset( sec_cli, 0x00, 1000 );
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( mpi_read_string( &ctx_srv.P, {radix_P}, {input_P} ) == 0 );
TEST_ASSERT( mpi_read_string( &ctx_srv.G, {radix_G}, {input_G} ) == 0 );
x_size = mpi_size( &ctx_srv.P );
TEST_ASSERT( dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &myrand, NULL ) == 0 );
TEST_ASSERT( dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
ske[ske_len++] = 0;
ske[ske_len++] = 0;
TEST_ASSERT( dhm_read_params( &ctx_cli, &p, ske + ske_len ) == 0 );
pub_cli_len = x_size;
TEST_ASSERT( dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len, &myrand, NULL ) == 0 );
TEST_ASSERT( dhm_make_public( &ctx_cli, x_size, pub_cli, pub_cli_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
TEST_ASSERT( dhm_read_public( &ctx_srv, pub_cli, pub_cli_len ) == 0 );