1
0
mirror of http://galexander.org/git/simplesshd.git synced 2024-11-15 19:48:56 +00:00
simplesshd/dropbear/libtommath/bn_mp_reduce_is_2k_l.c

29 lines
683 B
C
Raw Normal View History

2020-12-28 21:40:37 +00:00
#include "tommath_private.h"
2014-12-10 21:56:49 +00:00
#ifdef BN_MP_REDUCE_IS_2K_L_C
2020-12-28 21:40:37 +00:00
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
2014-12-10 21:56:49 +00:00
/* determines if reduce_2k_l can be used */
2020-12-28 21:40:37 +00:00
mp_bool mp_reduce_is_2k_l(const mp_int *a)
2014-12-10 21:56:49 +00:00
{
int ix, iy;
2020-12-28 21:40:37 +00:00
2014-12-10 21:56:49 +00:00
if (a->used == 0) {
return MP_NO;
} else if (a->used == 1) {
return MP_YES;
} else if (a->used > 1) {
/* if more than half of the digits are -1 we're sold */
for (iy = ix = 0; ix < a->used; ix++) {
2020-12-28 21:40:37 +00:00
if (a->dp[ix] == MP_DIGIT_MAX) {
++iy;
}
2014-12-10 21:56:49 +00:00
}
return (iy >= (a->used/2)) ? MP_YES : MP_NO;
2020-12-28 21:40:37 +00:00
} else {
return MP_NO;
2014-12-10 21:56:49 +00:00
}
}
#endif