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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/bn_mp_lshd.c b/bn_mp_lshd.c
index b8da2b6..ba36576 100644
--- a/bn_mp_lshd.c
+++ b/bn_mp_lshd.c
@@ -8,6 +8,7 @@ mp_err mp_lshd(mp_int *a, int b)
{
int x;
mp_err res;
+ mp_digit *top, *bottom;
/* if its less than zero return */
if (b <= 0) {
@@ -25,32 +26,29 @@ mp_err mp_lshd(mp_int *a, int b)
}
}
- {
- mp_digit *top, *bottom;
+ /* increment the used by the shift amount then copy upwards */
+ a->used += b;
- /* increment the used by the shift amount then copy upwards */
- a->used += b;
+ /* top */
+ top = a->dp + a->used - 1;
- /* top */
- top = a->dp + a->used - 1;
+ /* base */
+ bottom = (a->dp + a->used - 1) - b;
- /* base */
- bottom = (a->dp + a->used - 1) - b;
-
- /* much like mp_rshd this is implemented using a sliding window
- * except the window goes the otherway around. Copying from
- * the bottom to the top. see bn_mp_rshd.c for more info.
- */
- for (x = a->used - 1; x >= b; x--) {
- *top-- = *bottom--;
- }
+ /* much like mp_rshd this is implemented using a sliding window
+ * except the window goes the otherway around. Copying from
+ * the bottom to the top. see bn_mp_rshd.c for more info.
+ */
+ for (x = a->used - 1; x >= b; x--) {
+ *top-- = *bottom--;
+ }
- /* zero the lower digits */
- top = a->dp;
- for (x = 0; x < b; x++) {
- *top++ = 0;
- }
+ /* zero the lower digits */
+ top = a->dp;
+ for (x = 0; x < b; x++) {
+ *top++ = 0;
}
+
return MP_OKAY;
}
#endif
diff --git a/bn_mp_rshd.c b/bn_mp_rshd.c
index 2bbf597..1ab9ba4 100644
--- a/bn_mp_rshd.c
+++ b/bn_mp_rshd.c
@@ -7,6 +7,7 @@
void mp_rshd(mp_int *a, int b)
{
int x;
+ mp_digit *bottom, *top;
/* if b <= 0 then ignore it */
if (b <= 0) {
@@ -19,35 +20,31 @@ void mp_rshd(mp_int *a, int b)
return;
}
- {
- mp_digit *bottom, *top;
+ /* shift the digits down */
- /* shift the digits down */
+ /* bottom */
+ bottom = a->dp;
- /* bottom */
- bottom = a->dp;
+ /* top [offset into digits] */
+ top = a->dp + b;
- /* top [offset into digits] */
- top = a->dp + b;
+ /* this is implemented as a sliding window where
+ * the window is b-digits long and digits from
+ * the top of the window are copied to the bottom
+ *
+ * e.g.
- /* this is implemented as a sliding window where
- * the window is b-digits long and digits from
- * the top of the window are copied to the bottom
- *
- * e.g.
-
- b-2 | b-1 | b0 | b1 | b2 | ... | bb | ---->
- /\ | ---->
- \-------------------/ ---->
- */
- for (x = 0; x < (a->used - b); x++) {
- *bottom++ = *top++;
- }
+ b-2 | b-1 | b0 | b1 | b2 | ... | bb | ---->
+ /\ | ---->
+ \-------------------/ ---->
+ */
+ for (x = 0; x < (a->used - b); x++) {
+ *bottom++ = *top++;
+ }
- /* zero the top digits */
- for (; x < a->used; x++) {
- *bottom++ = 0;
- }
+ /* zero the top digits */
+ for (; x < a->used; x++) {
+ *bottom++ = 0;
}
/* remove excess digits */