Commit 5c60de2b authored by Paul Bakker's avatar Paul Bakker
Browse files

- Added preliminary test cases for DHM

parent e5c19aab
......@@ -23,3 +23,4 @@ add_test_suite(camellia)
add_test_suite(des)
add_test_suite(rsa)
add_test_suite(xtea)
add_test_suite(dhm)
Diffie-Hellman full exchange #1
dhm_do_dhm:1024:10:"23":10:"5"
Diffie-Hellman full exchange #2
dhm_do_dhm:1024:10:"93450983094850938450983409623":10:"93450983094850938450983409622"
Diffie-Hellman full exchange #2
dhm_do_dhm:1024:10:"93450983094850938450983409623982317398171298719873918739182739712938719287391879381271":10:"9345098309485093845098340962223981329819812792137312973297123912791271"
BEGIN_HEADER
#include <polarssl/dhm.h>
static int myrand( void *r )
{
if ( r != NULL )
r = NULL;
return( rand() );
}
END_HEADER
BEGIN_CASE
dhm_do_dhm:x_size:radix_P:input_P:radix_G:input_G
{
dhm_context ctx_srv;
dhm_context ctx_cli;
unsigned char ske[1000];
unsigned char *p = ske;
unsigned char pub_cli[1000];
unsigned char sec_srv[1000];
unsigned char sec_cli[1000];
int ske_len = 0;
int pub_cli_len = 0;
int sec_srv_len = 1000;
int sec_cli_len = 1000;
memset( &ctx_srv, 0x00, sizeof( dhm_context ) );
memset( &ctx_cli, 0x00, sizeof( dhm_context ) );
memset( ske, 0x00, 1000 );
memset( pub_cli, 0x00, 1000 );
memset( sec_srv, 0x00, 1000 );
memset( sec_cli, 0x00, 1000 );
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 );
int x_size = mpi_size( &ctx_srv.P );
TEST_ASSERT( dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &myrand, NULL ) == 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_read_public( &ctx_srv, pub_cli, pub_cli_len ) == 0 );
TEST_ASSERT( dhm_calc_secret( &ctx_srv, sec_srv, &sec_srv_len ) == 0 );
TEST_ASSERT( dhm_calc_secret( &ctx_cli, sec_cli, &sec_cli_len ) == 0 );
TEST_ASSERT( sec_srv_len == sec_cli_len );
TEST_ASSERT( sec_srv_len != 0 );
TEST_ASSERT( memcmp( sec_srv, sec_cli, sec_srv_len ) == 0 );
}
END_CASE
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment