mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 17:25:37 +01:00
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.
This commit is contained in:
parent
6d9b762ee0
commit
62a73511f1
@ -87,3 +87,11 @@ ecdh_exchange_calc_secret:MBEDTLS_ECP_DP_SECP256R1:"c6ef9c5d78ae012a011164acb397
|
||||
ECDH calc_secret: theirs first, SECP256R1 (RFC 5903)
|
||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
ecdh_exchange_calc_secret:MBEDTLS_ECP_DP_SECP256R1:"c6ef9c5d78ae012a011164acb397ce2088685d8f06bf9be0b283ab46476bee53":"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":1:"d6840f6b42f6edafd13116e0e12565202fef8e9ece7dce03812464d04b9442de"
|
||||
|
||||
ECDH get_params with mismatched groups: our BP256R1, their SECP256R1
|
||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_BP256R1_ENABLED
|
||||
ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"1234567812345678123456781234567812345678123456781234567812345678":MBEDTLS_ECP_DP_SECP256R1:"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":0:MBEDTLS_ERR_ECP_BAD_INPUT_DATA
|
||||
|
||||
ECDH get_params with mismatched groups: their SECP256R1, our BP256R1
|
||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_BP256R1_ENABLED
|
||||
ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"1234567812345678123456781234567812345678123456781234567812345678":MBEDTLS_ECP_DP_SECP256R1:"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":1:MBEDTLS_ERR_ECP_BAD_INPUT_DATA
|
||||
|
@ -557,3 +557,50 @@ exit:
|
||||
mbedtls_ecp_keypair_free( &their_key );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void ecdh_exchange_get_params_fail( int our_grp_id,
|
||||
data_t *our_private_key,
|
||||
int their_grp_id,
|
||||
data_t *their_point,
|
||||
int ours_first,
|
||||
int expected_ret )
|
||||
{
|
||||
rnd_pseudo_info rnd_info;
|
||||
mbedtls_ecp_keypair our_key;
|
||||
mbedtls_ecp_keypair their_key;
|
||||
mbedtls_ecdh_context ecdh;
|
||||
|
||||
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
|
||||
mbedtls_ecdh_init( &ecdh );
|
||||
mbedtls_ecp_keypair_init( &our_key );
|
||||
mbedtls_ecp_keypair_init( &their_key );
|
||||
|
||||
if( ! load_private_key( our_grp_id, our_private_key, &our_key, &rnd_info ) )
|
||||
goto exit;
|
||||
if( ! load_public_key( their_grp_id, their_point, &their_key ) )
|
||||
goto exit;
|
||||
|
||||
if( ours_first )
|
||||
{
|
||||
TEST_ASSERT( mbedtls_ecdh_get_params(
|
||||
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_get_params(
|
||||
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) ==
|
||||
expected_ret );
|
||||
}
|
||||
else
|
||||
{
|
||||
TEST_ASSERT( mbedtls_ecdh_get_params(
|
||||
&ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 );
|
||||
TEST_ASSERT( mbedtls_ecdh_get_params(
|
||||
&ecdh, &our_key, MBEDTLS_ECDH_OURS ) ==
|
||||
expected_ret );
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_ecdh_free( &ecdh );
|
||||
mbedtls_ecp_keypair_free( &our_key );
|
||||
mbedtls_ecp_keypair_free( &their_key );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
Reference in New Issue
Block a user