mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-11 00:40:05 +00:00
Don't explicitly inline mbedtls_mpi_core_clz
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
3b29364d61
commit
914347bfa3
@ -33,6 +33,39 @@
|
|||||||
#include "bn_mul.h"
|
#include "bn_mul.h"
|
||||||
#include "constant_time_internal.h"
|
#include "constant_time_internal.h"
|
||||||
|
|
||||||
|
size_t mbedtls_mpi_core_clz(mbedtls_mpi_uint a)
|
||||||
|
{
|
||||||
|
#if defined(__has_builtin)
|
||||||
|
#if __has_builtin(__builtin_clz)
|
||||||
|
if (sizeof(mbedtls_mpi_uint) == sizeof(unsigned int)) {
|
||||||
|
return (size_t) __builtin_clz(a);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if __has_builtin(__builtin_clzl)
|
||||||
|
if (sizeof(mbedtls_mpi_uint) == sizeof(unsigned long)) {
|
||||||
|
return (size_t) __builtin_clzl(a);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if __has_builtin(__builtin_clzll)
|
||||||
|
if (sizeof(mbedtls_mpi_uint) == sizeof(unsigned long long)) {
|
||||||
|
return (size_t) __builtin_clzll(a);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
size_t j;
|
||||||
|
mbedtls_mpi_uint mask = (mbedtls_mpi_uint) 1 << (biL - 1);
|
||||||
|
|
||||||
|
for (j = 0; j < biL; j++) {
|
||||||
|
if (a & mask) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mask >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
size_t mbedtls_mpi_core_bitlen(const mbedtls_mpi_uint *A, size_t A_limbs)
|
size_t mbedtls_mpi_core_bitlen(const mbedtls_mpi_uint *A, size_t A_limbs)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -109,38 +109,7 @@
|
|||||||
* \return The number of leading zero bits in \p a, if \p a != 0.
|
* \return The number of leading zero bits in \p a, if \p a != 0.
|
||||||
* If \p a == 0, the result is undefined.
|
* If \p a == 0, the result is undefined.
|
||||||
*/
|
*/
|
||||||
static inline size_t mbedtls_mpi_core_clz(mbedtls_mpi_uint a)
|
size_t mbedtls_mpi_core_clz(mbedtls_mpi_uint a);
|
||||||
{
|
|
||||||
#if defined(__has_builtin)
|
|
||||||
#if __has_builtin(__builtin_clz)
|
|
||||||
if (sizeof(mbedtls_mpi_uint) == sizeof(unsigned int)) {
|
|
||||||
return (size_t) __builtin_clz(a);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if __has_builtin(__builtin_clzl)
|
|
||||||
if (sizeof(mbedtls_mpi_uint) == sizeof(unsigned long)) {
|
|
||||||
return (size_t) __builtin_clzl(a);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if __has_builtin(__builtin_clzll)
|
|
||||||
if (sizeof(mbedtls_mpi_uint) == sizeof(unsigned long long)) {
|
|
||||||
return (size_t) __builtin_clzll(a);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
size_t j;
|
|
||||||
mbedtls_mpi_uint mask = (mbedtls_mpi_uint) 1 << (biL - 1);
|
|
||||||
|
|
||||||
for (j = 0; j < biL; j++) {
|
|
||||||
if (a & mask) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mask >>= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return the minimum number of bits required to represent the value held
|
/** Return the minimum number of bits required to represent the value held
|
||||||
* in the MPI.
|
* in the MPI.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user