Skip to content

Commit c4dff06

Browse files
Add test case for ecdh_get_params with mismatching group
Add a test case for doing an ECDH calculation by calling mbedtls_ecdh_get_params on both keys, with keys belonging to different groups. This should fail, but currently passes.
1 parent 552563b commit c4dff06

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tests/suites/test_suite_ecdh.data

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ ecdh_exchange_calc_secret:MBEDTLS_ECP_DP_SECP256R1:"c6ef9c5d78ae012a011164acb397
8787
ECDH calc_secret: theirs first, SECP256R1 (RFC 5903)
8888
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
8989
ecdh_exchange_calc_secret:MBEDTLS_ECP_DP_SECP256R1:"c6ef9c5d78ae012a011164acb397ce2088685d8f06bf9be0b283ab46476bee53":"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":1:"d6840f6b42f6edafd13116e0e12565202fef8e9ece7dce03812464d04b9442de"
90+
91+
ECDH get_params with mismatched groups: our BP256R1, their SECP256R1
92+
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_BP256R1_ENABLED
93+
ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"1234567812345678123456781234567812345678123456781234567812345678":MBEDTLS_ECP_DP_SECP256R1:"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":0:MBEDTLS_ERR_ECP_BAD_INPUT_DATA
94+
95+
ECDH get_params with mismatched groups: their SECP256R1, our BP256R1
96+
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_BP256R1_ENABLED
97+
ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"1234567812345678123456781234567812345678123456781234567812345678":MBEDTLS_ECP_DP_SECP256R1:"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":1:MBEDTLS_ERR_ECP_BAD_INPUT_DATA

tests/suites/test_suite_ecdh.function

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,50 @@ exit:
557557
mbedtls_ecp_keypair_free( &their_key );
558558
}
559559
/* END_CASE */
560+
561+
/* BEGIN_CASE */
562+
void ecdh_exchange_get_params_fail( int our_grp_id,
563+
data_t *our_private_key,
564+
int their_grp_id,
565+
data_t *their_point,
566+
int ours_first,
567+
int expected_ret )
568+
{
569+
rnd_pseudo_info rnd_info;
570+
mbedtls_ecp_keypair our_key;
571+
mbedtls_ecp_keypair their_key;
572+
mbedtls_ecdh_context ecdh;
573+
574+
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
575+
mbedtls_ecdh_init( &ecdh );
576+
mbedtls_ecp_keypair_init( &our_key );
577+
mbedtls_ecp_keypair_init( &their_key );
578+
579+
if( ! load_private_key( our_grp_id, our_private_key, &our_key, &rnd_info ) )
580+
goto exit;
581+
if( ! load_public_key( their_grp_id, their_point, &their_key ) )
582+
goto exit;
583+
584+
if( ours_first )
585+
{
586+
TEST_ASSERT( mbedtls_ecdh_get_params(
587+
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
588+
TEST_ASSERT( mbedtls_ecdh_get_params(
589+
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) ==
590+
expected_ret );
591+
}
592+
else
593+
{
594+
TEST_ASSERT( mbedtls_ecdh_get_params(
595+
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
596+
TEST_ASSERT( mbedtls_ecdh_get_params(
597+
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) ==
598+
expected_ret );
599+
}
600+
601+
exit:
602+
mbedtls_ecdh_free( &ecdh );
603+
mbedtls_ecp_keypair_free( &our_key );
604+
mbedtls_ecp_keypair_free( &their_key );
605+
}
606+
/* END_CASE */

0 commit comments

Comments
 (0)