diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-09-15 14:44:00 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-09-15 14:44:00 (GMT) |
commit | 30f7e69b182d1267056ee2628a860891f6555aa3 (patch) | |
tree | 4598f9d64ea232476fcf18bbef6bd413444c0c07 /libtommath/bn_mp_rand.c | |
parent | b167e2845e3a2d5b2ffe3a877cb19c3f430aeacf (diff) | |
download | tcl-30f7e69b182d1267056ee2628a860891f6555aa3.zip tcl-30f7e69b182d1267056ee2628a860891f6555aa3.tar.gz tcl-30f7e69b182d1267056ee2628a860891f6555aa3.tar.bz2 |
re-format everything through astyle. Taken from libtom/libtommath (pull request [https://github.com/libtom/libtommath/pull/85|85])
Diffstat (limited to 'libtommath/bn_mp_rand.c')
-rw-r--r-- | libtommath/bn_mp_rand.c | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/libtommath/bn_mp_rand.c b/libtommath/bn_mp_rand.c index 93e255a..92a9a97 100644 --- a/libtommath/bn_mp_rand.c +++ b/libtommath/bn_mp_rand.c @@ -16,13 +16,13 @@ */ #if MP_GEN_RANDOM_MAX == 0xffffffff - #define MP_GEN_RANDOM_SHIFT 32 +#define MP_GEN_RANDOM_SHIFT 32 #elif MP_GEN_RANDOM_MAX == 32767 - /* SHRT_MAX */ - #define MP_GEN_RANDOM_SHIFT 15 +/* SHRT_MAX */ +#define MP_GEN_RANDOM_SHIFT 15 #elif MP_GEN_RANDOM_MAX == 2147483647 - /* INT_MAX */ - #define MP_GEN_RANDOM_SHIFT 31 +/* INT_MAX */ +#define MP_GEN_RANDOM_SHIFT 31 #elif !defined(MP_GEN_RANDOM_SHIFT) #error Thou shalt define their own valid MP_GEN_RANDOM_SHIFT #endif @@ -30,48 +30,47 @@ /* makes a pseudo-random int of a given size */ static mp_digit s_gen_random(void) { - mp_digit d = 0, msk = 0; - do { - d <<= MP_GEN_RANDOM_SHIFT; - d |= ((mp_digit) MP_GEN_RANDOM()); - msk <<= MP_GEN_RANDOM_SHIFT; - msk |= (MP_MASK & MP_GEN_RANDOM_MAX); - } while ((MP_MASK & msk) != MP_MASK); - d &= MP_MASK; - return d; + mp_digit d = 0, msk = 0; + do { + d <<= MP_GEN_RANDOM_SHIFT; + d |= ((mp_digit) MP_GEN_RANDOM()); + msk <<= MP_GEN_RANDOM_SHIFT; + msk |= (MP_MASK & MP_GEN_RANDOM_MAX); + } while ((MP_MASK & msk) != MP_MASK); + d &= MP_MASK; + return d; } -int -mp_rand (mp_int * a, int digits) +int mp_rand(mp_int *a, int digits) { - int res; - mp_digit d; + int res; + mp_digit d; - mp_zero (a); - if (digits <= 0) { - return MP_OKAY; - } + mp_zero(a); + if (digits <= 0) { + return MP_OKAY; + } - /* first place a random non-zero digit */ - do { - d = s_gen_random(); - } while (d == 0); + /* first place a random non-zero digit */ + do { + d = s_gen_random(); + } while (d == 0); - if ((res = mp_add_d (a, d, a)) != MP_OKAY) { - return res; - } - - while (--digits > 0) { - if ((res = mp_lshd (a, 1)) != MP_OKAY) { + if ((res = mp_add_d(a, d, a)) != MP_OKAY) { return res; - } + } - if ((res = mp_add_d (a, s_gen_random(), a)) != MP_OKAY) { - return res; - } - } + while (--digits > 0) { + if ((res = mp_lshd(a, 1)) != MP_OKAY) { + return res; + } + + if ((res = mp_add_d(a, s_gen_random(), a)) != MP_OKAY) { + return res; + } + } - return MP_OKAY; + return MP_OKAY; } #endif |