refactor without inner scope
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
diff --git a/bn_mp_copy.c b/bn_mp_copy.c
index 141dd0e..e72fcf6 100644
--- a/bn_mp_copy.c
+++ b/bn_mp_copy.c
@@ -7,6 +7,7 @@
mp_err mp_copy(const mp_int *a, mp_int *b)
{
int n;
+ mp_digit *tmpa, *tmpb;
mp_err err;
/* if dst == src do nothing */
@@ -22,26 +23,22 @@ mp_err mp_copy(const mp_int *a, mp_int *b)
}
/* zero b and copy the parameters over */
- {
- mp_digit *tmpa, *tmpb;
+ /* pointer aliases */
- /* pointer aliases */
+ /* source */
+ tmpa = a->dp;
- /* source */
- tmpa = a->dp;
+ /* destination */
+ tmpb = b->dp;
- /* destination */
- tmpb = b->dp;
-
- /* copy all the digits */
- for (n = 0; n < a->used; n++) {
- *tmpb++ = *tmpa++;
- }
-
- /* clear high digits */
- MP_ZERO_DIGITS(tmpb, b->used - n);
+ /* copy all the digits */
+ for (n = 0; n < a->used; n++) {
+ *tmpb++ = *tmpa++;
}
+ /* clear high digits */
+ MP_ZERO_DIGITS(tmpb, b->used - n);
+
/* copy used count and sign */
b->used = a->used;
b->sign = a->sign;
diff --git a/bn_mp_div_2.c b/bn_mp_div_2.c
index 2561e5a..f56ea81 100644
--- a/bn_mp_div_2.c
+++ b/bn_mp_div_2.c
@@ -7,6 +7,7 @@
mp_err mp_div_2(const mp_int *a, mp_int *b)
{
int x, oldused;
+ mp_digit r, rr, *tmpa, *tmpb;
mp_err err;
/* copy */
@@ -18,31 +19,29 @@ mp_err mp_div_2(const mp_int *a, mp_int *b)
oldused = b->used;
b->used = a->used;
- {
- mp_digit r, rr, *tmpa, *tmpb;
- /* source alias */
- tmpa = a->dp + b->used - 1;
+ /* source alias */
+ tmpa = a->dp + b->used - 1;
- /* dest alias */
- tmpb = b->dp + b->used - 1;
+ /* dest alias */
+ tmpb = b->dp + b->used - 1;
- /* carry */
- r = 0;
- for (x = b->used - 1; x >= 0; x--) {
- /* get the carry for the next iteration */
- rr = *tmpa & 1u;
+ /* carry */
+ r = 0;
+ for (x = b->used - 1; x >= 0; x--) {
+ /* get the carry for the next iteration */
+ rr = *tmpa & 1u;
- /* shift the current digit, add in carry and store */
- *tmpb-- = (*tmpa-- >> 1) | (r << (MP_DIGIT_BIT - 1));
+ /* shift the current digit, add in carry and store */
+ *tmpb-- = (*tmpa-- >> 1) | (r << (MP_DIGIT_BIT - 1));
- /* forward carry to next iteration */
- r = rr;
- }
-
- /* zero excess digits */
- MP_ZERO_DIGITS(b->dp + b->used, oldused - b->used);
+ /* forward carry to next iteration */
+ r = rr;
}
+
+ /* zero excess digits */
+ MP_ZERO_DIGITS(b->dp + b->used, oldused - b->used);
+
b->sign = a->sign;
mp_clamp(b);
return MP_OKAY;