ECDH: use more precise error code

The documentation says "or another error code", so it's OK to change the
error code returned here for a more correct one.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2026-04-02 09:42:05 +02:00
parent 801f3b3f42
commit 559525cd7f
3 changed files with 3 additions and 3 deletions

View File

@ -129,7 +129,7 @@ int mbedtls_x25519_calc_secret( mbedtls_x25519_context *ctx, size_t *olen,
*olen = MBEDTLS_X25519_KEY_SIZE_BYTES;
if( blen < *olen )
return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
/* scalarmult modifies this input, let's make a copy... */
unsigned char secret[MBEDTLS_X25519_KEY_SIZE_BYTES];

View File

@ -649,7 +649,7 @@ static int ecdh_calc_secret_internal(mbedtls_ecdh_context_mbed *ctx,
size_t p_bytes = ctx->grp.pbits / 8 + ((ctx->grp.pbits % 8) != 0);
if (p_bytes > blen) {
return MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
return MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
}
*olen = p_bytes;

View File

@ -441,7 +441,7 @@ void ecdh_exchange_calc_secret(int grp_id,
/* Try again with an output buffer that's too short. */
TEST_CALLOC(buf, min_buf_size - 1);
TEST_EQUAL(MBEDTLS_ERR_ECP_BAD_INPUT_DATA,
TEST_EQUAL(MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL,
mbedtls_ecdh_calc_secret(
&ecdh, &shared_secret_length,
buf, min_buf_size - 1,