From 1dd95465f6c1bd4fe5402c80b885724e1122e569 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Tue, 26 Jul 2022 09:40:16 +0800 Subject: [PATCH] M467: Fix mbedtls_ecp_point_cmp() call with null argument Guard from null argument passed to mbedtls_ecp_point_cmp() in ECC H/W port --- .../TARGET_NUVOTON/TARGET_M460/ecp/crypto_ecc_hw.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M460/ecp/crypto_ecc_hw.c b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M460/ecp/crypto_ecc_hw.c index 42f75beaea..f7c903532e 100644 --- a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M460/ecp/crypto_ecc_hw.c +++ b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M460/ecp/crypto_ecc_hw.c @@ -181,8 +181,13 @@ int crypto_ecc_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 crypto_ecc_run_eccop(grp, R, NULL, P, NULL, NULL, ECCOP_POINT_DOUBLE, blinding); + 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 crypto_ecc_run_eccop(grp, R, NULL, P, NULL, NULL, ECCOP_POINT_DOUBLE, blinding); + } } /* Acquire ownership of ECC accelerator */