summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath/bn_mp_rand.c')
-rw-r--r--libtommath/bn_mp_rand.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libtommath/bn_mp_rand.c b/libtommath/bn_mp_rand.c
index 92a9a97..2ed665e 100644
--- a/libtommath/bn_mp_rand.c
+++ b/libtommath/bn_mp_rand.c
@@ -15,7 +15,10 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-#if MP_GEN_RANDOM_MAX == 0xffffffff
+#if defined(MP_8BIT) || defined(MP_16BIT)
+#define MP_GEN_RANDOM_SHIFT DIGIT_BIT
+#else
+#if MP_GEN_RANDOM_MAX == 0xffffffffu
#define MP_GEN_RANDOM_SHIFT 32
#elif MP_GEN_RANDOM_MAX == 32767
/* SHRT_MAX */
@@ -26,6 +29,7 @@
#elif !defined(MP_GEN_RANDOM_SHIFT)
#error Thou shalt define their own valid MP_GEN_RANDOM_SHIFT
#endif
+#endif
/* makes a pseudo-random int of a given size */
static mp_digit s_gen_random(void)
@@ -54,7 +58,7 @@ int mp_rand(mp_int *a, int digits)
/* first place a random non-zero digit */
do {
d = s_gen_random();
- } while (d == 0);
+ } while (d == 0u);
if ((res = mp_add_d(a, d, a)) != MP_OKAY) {
return res;