libtommath/mp_log_u32.c
2019-11-09 06:43:59 +01:00

38 lines
713 B
C

#include "tommath_private.h"
#ifdef MP_LOG_U32_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
{
if (a->sign == MP_NEG) {
return MP_VAL;
}
if (mp_iszero(a)) {
return MP_VAL;
}
if (base < 2u) {
return MP_VAL;
}
if (MP_HAS(S_MP_LOG_POW2) && MP_IS_2EXPT(base)) {
*c = s_mp_log_pow2(a, base);
return MP_OKAY;
}
if (MP_HAS(S_MP_LOG_D) && (a->used == 1)) {
*c = (uint32_t)s_mp_log_d(base, a->dp[0]);
return MP_OKAY;
}
if (MP_HAS(S_MP_LOG)) {
return s_mp_log(a, base, c);
}
return MP_VAL;
}
#endif