mbedtls/tests/suites/test_suite_dhm.function

55 lines
1.7 KiB
Plaintext
Raw Normal View History

2009-07-08 21:47:36 +02:00
BEGIN_HEADER
#include <polarssl/dhm.h>
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];
2011-04-24 17:53:29 +02:00
size_t ske_len = 0;
size_t pub_cli_len = 0;
size_t sec_srv_len = 1000;
size_t sec_cli_len = 1000;
int x_size;
rnd_pseudo_info rnd_info;
2009-07-08 21:47:36 +02:00
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 );
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
2009-07-08 21:47:36 +02:00
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 );
2009-07-08 21:47:36 +02:00
TEST_ASSERT( dhm_make_params( &ctx_srv, x_size, ske, &ske_len, &rnd_pseudo_rand, &rnd_info ) == 0 );
2009-07-08 21:47:36 +02:00
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, &rnd_pseudo_rand, &rnd_info ) == 0 );
2009-07-08 21:47:36 +02:00
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 );
2011-02-20 17:34:26 +01:00
dhm_free( &ctx_srv );
dhm_free( &ctx_cli );
2009-07-08 21:47:36 +02:00
}
END_CASE