From 6666914b76ed9a4199c12c99842a643de711f0e3 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Wed, 3 Aug 2022 12:52:26 +0200 Subject: [PATCH] Revert "Move Bignum macros to common header" This reverts commit 62c5901f0a5061a8825e19c77f88c91fea235078. Reverting commit due the macros are meant to be local and not following the naming convention. Signed-off-by: Gabor Mezei --- library/bignum.c | 16 ++++++++++++++++ library/bignum_core.h | 16 ---------------- library/bignum_new.c | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/library/bignum.c b/library/bignum.c index 391ff8776..0e7b3cea0 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -58,8 +58,24 @@ #define mbedtls_free free #endif +#define MPI_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA ) +#define MPI_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) + +#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */ +#define biL (ciL << 3) /* bits in limb */ +#define biH (ciL << 2) /* half limb size */ + #define MPI_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */ +/* + * Convert between bits/chars and number of limbs + * Divide first in order to avoid potential overflows + */ +#define BITS_TO_LIMBS(i) ( (i) / biL + ( (i) % biL != 0 ) ) +#define CHARS_TO_LIMBS(i) ( (i) / ciL + ( (i) % ciL != 0 ) ) + /* Implementation that should never be optimized out by the compiler */ static void mbedtls_mpi_zeroize( mbedtls_mpi_uint *v, size_t n ) { diff --git a/library/bignum_core.h b/library/bignum_core.h index 98a8c97c2..2248f49db 100644 --- a/library/bignum_core.h +++ b/library/bignum_core.h @@ -26,22 +26,6 @@ #include "mbedtls/bignum.h" #endif -#define MPI_VALIDATE_RET( cond ) \ - MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA ) -#define MPI_VALIDATE( cond ) \ - MBEDTLS_INTERNAL_VALIDATE( cond ) - -#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */ -#define biL (ciL << 3) /* bits in limb */ -#define biH (ciL << 2) /* half limb size */ - -/* - * Convert between bits/chars and number of limbs - * Divide first in order to avoid potential overflows - */ -#define BITS_TO_LIMBS(i) ( (i) / biL + ( (i) % biL != 0 ) ) -#define CHARS_TO_LIMBS(i) ( (i) / ciL + ( (i) % ciL != 0 ) ) - /** Count leading zero bits in a given integer. * * \param x Integer to count leading zero bits. diff --git a/library/bignum_new.c b/library/bignum_new.c index 2245650ae..d1253f8d0 100644 --- a/library/bignum_new.c +++ b/library/bignum_new.c @@ -41,6 +41,22 @@ #define mbedtls_free free #endif +#define MPI_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA ) +#define MPI_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) + +#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */ +#define biL (ciL << 3) /* bits in limb */ +#define biH (ciL << 2) /* half limb size */ + +/* + * Convert between bits/chars and number of limbs + * Divide first in order to avoid potential overflows + */ +#define BITS_TO_LIMBS(i) ( (i) / biL + ( (i) % biL != 0 ) ) +#define CHARS_TO_LIMBS(i) ( (i) / ciL + ( (i) % ciL != 0 ) ) + /* * Count leading zero bits in a given integer */