mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-29 22:20:30 +00:00
Merge pull request #8863 from minosgalanakis/feature/add_ecdh_context_5016
[MBEDTLS_PRIVATE] Add a getter for the ECDH context->grp.id member.
This commit is contained in:
commit
3c4166aef3
3
ChangeLog.d/add_get_ecp_group_id.txt
Normal file
3
ChangeLog.d/add_get_ecp_group_id.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Features
|
||||||
|
* Add new accessor to expose the private group id member of
|
||||||
|
`mbedtls_ecdh_context` structure.
|
@ -141,6 +141,19 @@ typedef struct mbedtls_ecdh_context {
|
|||||||
}
|
}
|
||||||
mbedtls_ecdh_context;
|
mbedtls_ecdh_context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Return the ECP group for provided context.
|
||||||
|
*
|
||||||
|
* \note To access group specific fields, users should use
|
||||||
|
* `mbedtls_ecp_curve_info_from_grp_id` or
|
||||||
|
* `mbedtls_ecp_group_load` on the extracted `group_id`.
|
||||||
|
*
|
||||||
|
* \param ctx The ECDH context to parse. This must not be \c NULL.
|
||||||
|
*
|
||||||
|
* \return The \c mbedtls_ecp_group_id of the context.
|
||||||
|
*/
|
||||||
|
mbedtls_ecp_group_id mbedtls_ecdh_get_grp_id(mbedtls_ecdh_context *ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Check whether a given group can be used for ECDH.
|
* \brief Check whether a given group can be used for ECDH.
|
||||||
*
|
*
|
||||||
|
@ -144,6 +144,15 @@ static void ecdh_init_internal(mbedtls_ecdh_context_mbed *ctx)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mbedtls_ecp_group_id mbedtls_ecdh_get_grp_id(mbedtls_ecdh_context *ctx)
|
||||||
|
{
|
||||||
|
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
|
||||||
|
return ctx->MBEDTLS_PRIVATE(grp).id;
|
||||||
|
#else
|
||||||
|
return ctx->MBEDTLS_PRIVATE(grp_id);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize context
|
* Initialize context
|
||||||
*/
|
*/
|
||||||
|
@ -100,3 +100,19 @@ ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"12345678123456781234567812
|
|||||||
ECDH get_params with mismatched groups: their SECP256R1, our BP256R1
|
ECDH get_params with mismatched groups: their SECP256R1, our BP256R1
|
||||||
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_BP256R1_ENABLED
|
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
|
ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"1234567812345678123456781234567812345678123456781234567812345678":MBEDTLS_ECP_DP_SECP256R1:"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":1:MBEDTLS_ERR_ECP_BAD_INPUT_DATA
|
||||||
|
|
||||||
|
Context get ECP Group #1
|
||||||
|
depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||||
|
ecdh_context_grp:MBEDTLS_ECP_DP_SECP256R1
|
||||||
|
|
||||||
|
Context get ECP Group #2
|
||||||
|
depends_on:MBEDTLS_ECP_DP_SECP384R1_ENABLED
|
||||||
|
ecdh_primitive_random:MBEDTLS_ECP_DP_SECP384R1
|
||||||
|
|
||||||
|
Context get ECP Group #3
|
||||||
|
depends_on:MBEDTLS_ECP_DP_SECP521R1_ENABLED
|
||||||
|
ecdh_primitive_random:MBEDTLS_ECP_DP_SECP521R1
|
||||||
|
|
||||||
|
Context get ECP Group #4
|
||||||
|
depends_on:MBEDTLS_ECP_DP_CURVE448_ENABLED
|
||||||
|
ecdh_primitive_random:MBEDTLS_ECP_DP_CURVE448
|
||||||
|
@ -464,3 +464,20 @@ exit:
|
|||||||
mbedtls_ecp_keypair_free(&their_key);
|
mbedtls_ecp_keypair_free(&their_key);
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void ecdh_context_grp(int id)
|
||||||
|
{
|
||||||
|
mbedtls_ecdh_context srv;
|
||||||
|
|
||||||
|
mbedtls_ecdh_init(&srv);
|
||||||
|
TEST_ASSERT(mbedtls_ecdh_setup(&srv, id) == 0);
|
||||||
|
|
||||||
|
/* Test the retrieved group id matches/*/
|
||||||
|
TEST_ASSERT((int) mbedtls_ecdh_get_grp_id(&srv) == id);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
mbedtls_ecdh_free(&srv);
|
||||||
|
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user