Simplify fixes for unreachable code
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
cfa722324c
commit
7e1e7be8fc
2 changed files with 7 additions and 47 deletions
|
@ -77,40 +77,19 @@ size_t mbedtls_mpi_core_bitlen(const mbedtls_mpi_uint *A, size_t A_limbs)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint
|
||||
* into the storage form used by mbedtls_mpi. */
|
||||
static mbedtls_mpi_uint mpi_bigendian_to_host_c(mbedtls_mpi_uint a)
|
||||
{
|
||||
uint8_t i;
|
||||
unsigned char *a_ptr;
|
||||
mbedtls_mpi_uint tmp = 0;
|
||||
|
||||
for (i = 0, a_ptr = (unsigned char *) &a; i < ciL; i++, a_ptr++) {
|
||||
tmp <<= CHAR_BIT;
|
||||
tmp |= (mbedtls_mpi_uint) *a_ptr;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static mbedtls_mpi_uint mpi_bigendian_to_host(mbedtls_mpi_uint a)
|
||||
{
|
||||
if (MBEDTLS_IS_BIG_ENDIAN) {
|
||||
/* Nothing to do on bigendian systems. */
|
||||
return a;
|
||||
} else {
|
||||
MBEDTLS_IGNORE_UNREACHABLE_BEGIN
|
||||
switch (sizeof(mbedtls_mpi_uint)) {
|
||||
case 4:
|
||||
#if defined(MBEDTLS_HAVE_INT32)
|
||||
return (mbedtls_mpi_uint) MBEDTLS_BSWAP32((uint32_t) a);
|
||||
case 8:
|
||||
#elif defined(MBEDTLS_HAVE_INT64)
|
||||
return (mbedtls_mpi_uint) MBEDTLS_BSWAP64((uint64_t) a);
|
||||
}
|
||||
|
||||
/* Fall back to C-based reordering if we don't know the byte order
|
||||
* or we couldn't use a compiler-specific builtin. */
|
||||
return mpi_bigendian_to_host_c(a);
|
||||
MBEDTLS_IGNORE_UNREACHABLE_END
|
||||
#else
|
||||
#error "This is one of several places that need to be adapted to support a new limb size"
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -334,23 +334,4 @@ static inline void mbedtls_xor_no_simd(unsigned char *r,
|
|||
#define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
|
||||
#endif
|
||||
|
||||
/* Define macros that can be used to disable warnings about unreachable code. */
|
||||
#if defined(__clang__)
|
||||
|
||||
#define MBEDTLS_PRAGMA(x) _Pragma(#x)
|
||||
|
||||
#define MBEDTLS_IGNORE_UNREACHABLE_BEGIN \
|
||||
MBEDTLS_PRAGMA(clang diagnostic push) \
|
||||
MBEDTLS_PRAGMA(clang diagnostic ignored "-Wunreachable-code")
|
||||
|
||||
#define MBEDTLS_IGNORE_UNREACHABLE_END \
|
||||
MBEDTLS_PRAGMA(clang diagnostic pop)
|
||||
|
||||
#else
|
||||
|
||||
#define MBEDTLS_IGNORE_UNREACHABLE_BEGIN
|
||||
#define MBEDTLS_IGNORE_UNREACHABLE_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_LIBRARY_COMMON_H */
|
||||
|
|
Loading…
Reference in a new issue