diff --git a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c index c028923ed77..1840b198b2f 100644 --- a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c +++ b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c @@ -503,8 +503,13 @@ NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp, } /* NOTE: Engine doesn't support P + Q when P and Q are the same. Workaround by 2*P */ - if (mbedtls_ecp_point_cmp(P, Q) == 0) { - return internal_run_eccop(grp, R, NULL, P, NULL, NULL, ECCOP_POINT_DOUBLE); + if (eccop == ECCOP_POINT_ADD) { + if (P == NULL || Q == NULL) { + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; + } + if (mbedtls_ecp_point_cmp(P, Q) == 0) { + return internal_run_eccop(grp, R, NULL, P, NULL, NULL, ECCOP_POINT_DOUBLE); + } } int ret;