summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_div_d.c
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath/bn_mp_div_d.c')
-rw-r--r--libtommath/bn_mp_div_d.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c
index d0131c3..c408602 100644
--- a/libtommath/bn_mp_div_d.c
+++ b/libtommath/bn_mp_div_d.c
@@ -15,21 +15,6 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-static int s_is_power_of_two(mp_digit b, int *p)
-{
- int x;
-
- /* Gives the wrong result for b==1, but this function
- * is never called for this value anyway. */
- for (x = 1; x < DIGIT_BIT; x++) {
- if (b == (((mp_digit)1)<<x)) {
- *p = x;
- return 1;
- }
- }
- return 0;
-}
-
/* single digit division (based on routine from MPI) */
int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
{
@@ -55,7 +40,12 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
}
/* power of two ? */
- if (((b & (b-1)) == 0) && s_is_power_of_two(b, &ix)) {
+ if (((b & (b-1)) == 0)) {
+ for (ix = 1; ix < DIGIT_BIT; ix++) {
+ if (b == (((mp_digit)1)<<ix)) {
+ break;
+ }
+ }
if (d != NULL) {
*d = a->dp[0] & ((((mp_digit)1)<<ix) - 1);
}