summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_prime_random_ex.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-15 14:44:00 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-15 14:44:00 (GMT)
commit30f7e69b182d1267056ee2628a860891f6555aa3 (patch)
tree4598f9d64ea232476fcf18bbef6bd413444c0c07 /libtommath/bn_mp_prime_random_ex.c
parentb167e2845e3a2d5b2ffe3a877cb19c3f430aeacf (diff)
downloadtcl-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_prime_random_ex.c')
-rw-r--r--libtommath/bn_mp_prime_random_ex.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/libtommath/bn_mp_prime_random_ex.c b/libtommath/bn_mp_prime_random_ex.c
index cf5272e..d3d6f3d 100644
--- a/libtommath/bn_mp_prime_random_ex.c
+++ b/libtommath/bn_mp_prime_random_ex.c
@@ -18,7 +18,7 @@
/* makes a truly random prime of a given size (bits),
*
* Flags are as follows:
- *
+ *
* LTM_PRIME_BBS - make prime congruent to 3 mod 4
* LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
* LTM_PRIME_2MSB_ON - make the 2nd highest bit one
@@ -62,7 +62,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
if ((flags & LTM_PRIME_2MSB_ON) != 0) {
maskOR_msb |= 0x80 >> ((9 - size) & 7);
- }
+ }
/* get the maskOR_lsb */
maskOR_lsb = 1;
@@ -76,7 +76,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
err = MP_VAL;
goto error;
}
-
+
/* work over the MSbyte */
tmp[0] &= maskAND;
tmp[0] |= 1 << ((size - 1) & 7);
@@ -86,28 +86,42 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
tmp[bsize-1] |= maskOR_lsb;
/* read it in */
- if ((err = mp_read_unsigned_bin(a, tmp, bsize)) != MP_OKAY) { goto error; }
+ if ((err = mp_read_unsigned_bin(a, tmp, bsize)) != MP_OKAY) {
+ goto error;
+ }
/* is it prime? */
- if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY) { goto error; }
- if (res == MP_NO) {
+ if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY) {
+ goto error;
+ }
+ if (res == MP_NO) {
continue;
}
if ((flags & LTM_PRIME_SAFE) != 0) {
/* see if (a-1)/2 is prime */
- if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) { goto error; }
- if ((err = mp_div_2(a, a)) != MP_OKAY) { goto error; }
-
+ if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) {
+ goto error;
+ }
+ if ((err = mp_div_2(a, a)) != MP_OKAY) {
+ goto error;
+ }
+
/* is it prime? */
- if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY) { goto error; }
+ if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY) {
+ goto error;
+ }
}
} while (res == MP_NO);
if ((flags & LTM_PRIME_SAFE) != 0) {
/* restore a to the original value */
- if ((err = mp_mul_2(a, a)) != MP_OKAY) { goto error; }
- if ((err = mp_add_d(a, 1, a)) != MP_OKAY) { goto error; }
+ if ((err = mp_mul_2(a, a)) != MP_OKAY) {
+ goto error;
+ }
+ if ((err = mp_add_d(a, 1, a)) != MP_OKAY) {
+ goto error;
+ }
}
err = MP_OKAY;