From 85061b97b57f6bd70d90be58b4ba1c0548035aee Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Wed, 6 Sep 2023 08:41:05 +0100 Subject: [PATCH] Improve sanity checking of MBEDTLS_HAVE_INTxx Signed-off-by: Dave Rodgman --- include/mbedtls/bignum.h | 9 +++++++++ library/bignum_core.c | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/mbedtls/bignum.h b/include/mbedtls/bignum.h index 3ba177799d..eb8446ea88 100644 --- a/include/mbedtls/bignum.h +++ b/include/mbedtls/bignum.h @@ -186,6 +186,15 @@ typedef uint64_t mbedtls_t_udbl; #endif /* !MBEDTLS_NO_UDBL_DIVISION */ #endif /* !MBEDTLS_HAVE_INT64 */ +/* + * Sanity check that exactly one of MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64 is defined, + * so that code elsewhere doesn't have to check. + */ +#if (!(defined(MBEDTLS_HAVE_INT32) || defined(MBEDTLS_HAVE_INT64))) || \ + (defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64)) +#error "Only 32-bit or 64-bit limbs are supported in bignum" +#endif + /** \typedef mbedtls_mpi_uint * \brief The type of machine digits in a bignum, called _limbs_. * diff --git a/library/bignum_core.c b/library/bignum_core.c index e719dcc69b..dbf6d1df46 100644 --- a/library/bignum_core.c +++ b/library/bignum_core.c @@ -87,8 +87,6 @@ static mbedtls_mpi_uint mpi_bigendian_to_host(mbedtls_mpi_uint a) return (mbedtls_mpi_uint) MBEDTLS_BSWAP32(a); #elif defined(MBEDTLS_HAVE_INT64) return (mbedtls_mpi_uint) MBEDTLS_BSWAP64(a); -#else -#error "This is one of several places that need to be adapted to support a new limb size" #endif } }