summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_rand.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-01 20:43:31 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-01 20:43:31 (GMT)
commit5753c7a42b638962406f9f7f822e48561e7a6253 (patch)
tree65742203dd83d002e9c923ddf96ddf45460e0d05 /libtommath/bn_mp_rand.c
parent6881a1a27437cae50d56f12227e9cfe10c7a49f2 (diff)
downloadtcl-5753c7a42b638962406f9f7f822e48561e7a6253.zip
tcl-5753c7a42b638962406f9f7f822e48561e7a6253.tar.gz
tcl-5753c7a42b638962406f9f7f822e48561e7a6253.tar.bz2
Lots of code cleanup, mainly [https://github.com/libtom/libtommath/pull/102|Pull request #102]
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;