From 24a305ec22901ea58a28c8b82eedd4555316d944 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 18 Jul 2023 13:41:22 +0200 Subject: [PATCH] Explain why we check 65535 (not USHORT_MAX) Signed-off-by: Gilles Peskine --- include/mbedtls/bignum.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/mbedtls/bignum.h b/include/mbedtls/bignum.h index a8422b1fc..eb372cf1f 100644 --- a/include/mbedtls/bignum.h +++ b/include/mbedtls/bignum.h @@ -224,6 +224,12 @@ typedef struct mbedtls_mpi { /** Total number of limbs in \c p. */ unsigned short MBEDTLS_PRIVATE(n); + /* Make sure that MBEDTLS_MPI_MAX_LIMBS fits in n. + * Use the same limit value on all platforms so that we don't have to + * think about different behavior on the rare platforms where + * unsigned short can store values larger than the minimum required by + * the C language, which is 65535. + */ #if MBEDTLS_MPI_MAX_LIMBS > 65535 #error "MBEDTLS_MPI_MAX_LIMBS > 65535 is not supported" #endif