Skip to content

Commit 3081629

Browse files
Fix mbedtls_ecdh_get_params with new ECDH context
The new check for matching groups in mbedtls_ecdh_get_params only worked with legacy ECDH contexts. Make it work with the new context format.
1 parent e023c80 commit 3081629

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

library/ecdh.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@
4949
typedef mbedtls_ecdh_context mbedtls_ecdh_context_mbed;
5050
#endif
5151

52+
static mbedtls_ecp_group_id mbedtls_ecdh_grp_id(
53+
const mbedtls_ecdh_context *ctx )
54+
{
55+
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
56+
return( ctx->grp.id );
57+
#else
58+
return( ctx->grp_id );
59+
#endif
60+
}
61+
5262
#if !defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT)
5363
/*
5464
* Generate public key (restartable version)
@@ -442,7 +452,7 @@ int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx,
442452
ECDH_VALIDATE_RET( side == MBEDTLS_ECDH_OURS ||
443453
side == MBEDTLS_ECDH_THEIRS );
444454

445-
if( ctx->grp.id == MBEDTLS_ECP_DP_NONE )
455+
if( mbedtls_ecdh_grp_id( ctx ) == MBEDTLS_ECP_DP_NONE )
446456
{
447457
/* This is the first call to get_params(). Set up the context
448458
* for use with the group. */
@@ -454,7 +464,7 @@ int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx,
454464
/* This is not the first call to get_params(). Check that the
455465
* current key's group is the same as the context's, which was set
456466
* from the first key's group. */
457-
if( ctx->grp.id != key->grp.id )
467+
if( mbedtls_ecdh_grp_id( ctx ) != key->grp.id )
458468
return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
459469
}
460470

0 commit comments

Comments
 (0)