From 60165d7708746e5d714b63a2fb95bb047fffa17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20=C5=BDilys?= Date: Wed, 26 Jan 2022 15:33:27 -0800 Subject: [PATCH 1/2] =?UTF-8?q?Don't=20inline=20mbedtls=5Fmpi=5Fsafe=5Fcon?= =?UTF-8?q?d=5Fassign=20on=20MSVC/ARM64=20to=20avoid=20a=20compiler=20bug.?= =?UTF-8?q?=20Signed-off-by:=20Tautvydas=20=C5=BDilys=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/constant_time.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/constant_time.c b/library/constant_time.c index d8870ae7f3..4dace48961 100644 --- a/library/constant_time.c +++ b/library/constant_time.c @@ -533,6 +533,13 @@ cleanup: * about whether the assignment was made or not. * (Leaking information about the respective sizes of X and Y is ok however.) */ +#if defined(_MSC_VER) && defined(_M_ARM64) +/* + * MSVC miscompiles this function if it's inlined. See: + * https://developercommunity.visualstudio.com/t/c-compiler-miscompiles-part-of-mbedtls-library-on/1646989 + */ +__declspec(noinline) +#endif int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign ) From 40fc7da101c9e25897a7a3cf24936aa261eb58cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20=C5=BDilys?= Date: Mon, 31 Jan 2022 13:34:01 -0800 Subject: [PATCH 2/2] =?UTF-8?q?Cap=20the=20workaround=20for=20mbedtls=5Fmp?= =?UTF-8?q?i=5Fsafe=5Fcond=5Fassign=20on=20MSVC/ARM64=20to=20MSVC=20versio?= =?UTF-8?q?ns=20prior=20to=2017.1.=20Signed-off-by:=20Tautvydas=20=C5=BDil?= =?UTF-8?q?ys=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/constant_time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/constant_time.c b/library/constant_time.c index 4dace48961..0f2e46f6de 100644 --- a/library/constant_time.c +++ b/library/constant_time.c @@ -533,9 +533,9 @@ cleanup: * about whether the assignment was made or not. * (Leaking information about the respective sizes of X and Y is ok however.) */ -#if defined(_MSC_VER) && defined(_M_ARM64) +#if defined(_MSC_VER) && defined(_M_ARM64) && (_MSC_FULL_VER < 193131103) /* - * MSVC miscompiles this function if it's inlined. See: + * MSVC miscompiles this function if it's inlined prior to Visual Studio 2022 version 17.1. See: * https://developercommunity.visualstudio.com/t/c-compiler-miscompiles-part-of-mbedtls-library-on/1646989 */ __declspec(noinline)