mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Bignum: move internal constants to headers
Now that the check_names script allows it, we can do so. Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
@ -63,19 +63,8 @@
|
|||||||
#define MPI_VALIDATE( cond ) \
|
#define MPI_VALIDATE( cond ) \
|
||||||
MBEDTLS_INTERNAL_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 */
|
#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 */
|
/* Implementation that should never be optimized out by the compiler */
|
||||||
static void mbedtls_mpi_zeroize( mbedtls_mpi_uint *v, size_t n )
|
static void mbedtls_mpi_zeroize( mbedtls_mpi_uint *v, size_t n )
|
||||||
{
|
{
|
||||||
@ -304,10 +293,6 @@ int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos )
|
|||||||
return( ( X->p[pos / biL] >> ( pos % biL ) ) & 0x01 );
|
return( ( X->p[pos / biL] >> ( pos % biL ) ) & 0x01 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a specific byte, without range checks. */
|
|
||||||
#define GET_BYTE( X, i ) \
|
|
||||||
( ( ( X )->p[( i ) / ciL] >> ( ( ( i ) % ciL ) * 8 ) ) & 0xff )
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a bit to a specific value of 0 or 1
|
* Set a bit to a specific value of 0 or 1
|
||||||
*/
|
*/
|
||||||
|
@ -38,20 +38,6 @@
|
|||||||
|
|
||||||
#include "bignum_core.h"
|
#include "bignum_core.h"
|
||||||
|
|
||||||
#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 ) )
|
|
||||||
/* Get a specific byte, without range checks. */
|
|
||||||
#define GET_BYTE( X, i ) \
|
|
||||||
( ( ( X )[( i ) / ciL] >> ( ( ( i ) % ciL ) * 8 ) ) & 0xff )
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Count leading zero bits in a given integer
|
* Count leading zero bits in a given integer
|
||||||
*/
|
*/
|
||||||
|
@ -122,4 +122,18 @@ int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *X,
|
|||||||
unsigned char *buf,
|
unsigned char *buf,
|
||||||
size_t buflen );
|
size_t buflen );
|
||||||
|
|
||||||
|
#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 ) )
|
||||||
|
/* Get a specific byte, without range checks. */
|
||||||
|
#define GET_BYTE( X, i ) \
|
||||||
|
( ( ( X )[( i ) / ciL] >> ( ( ( i ) % ciL ) * 8 ) ) & 0xff )
|
||||||
|
|
||||||
#endif /* MBEDTLS_BIGNUM_CORE_H */
|
#endif /* MBEDTLS_BIGNUM_CORE_H */
|
||||||
|
@ -10,17 +10,7 @@
|
|||||||
#if MBEDTLS_MPI_MAX_BITS > 792
|
#if MBEDTLS_MPI_MAX_BITS > 792
|
||||||
#define MPI_MAX_BITS_LARGER_THAN_792
|
#define MPI_MAX_BITS_LARGER_THAN_792
|
||||||
#endif
|
#endif
|
||||||
|
#
|
||||||
#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */
|
|
||||||
#define biL (ciL << 3) /* bits in limb */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 ) )
|
|
||||||
|
|
||||||
/* Check the validity of the sign bit in an MPI object. Reject representations
|
/* Check the validity of the sign bit in an MPI object. Reject representations
|
||||||
* that are not supported by the rest of the library and indicate a bug when
|
* that are not supported by the rest of the library and indicate a bug when
|
||||||
* constructing the value. */
|
* constructing the value. */
|
||||||
|
Reference in New Issue
Block a user