refactor without macro mp_isneg
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
diff --git a/bn_mp_get_double.c b/bn_mp_get_double.c
index 3286a6a..6a4f2a5 100644
--- a/bn_mp_get_double.c
+++ b/bn_mp_get_double.c
@@ -22,7 +22,7 @@ double mp_get_double(const mp_int *a)
for (i = a->used; i --> 0;) {
d = (d * fac) + (double)DIGIT(a, i);
}
- return (mp_isneg(a) != MP_NO) ? -d : d;
+ return (a->sign == MP_NEG) ? -d : d;
}
#endif
diff --git a/bn_mp_jacobi.c b/bn_mp_jacobi.c
index 1eb3dd4..59eacd0 100644
--- a/bn_mp_jacobi.c
+++ b/bn_mp_jacobi.c
@@ -18,7 +18,7 @@
int mp_jacobi(const mp_int *a, const mp_int *n, int *c)
{
/* if a < 0 return MP_VAL */
- if (mp_isneg(a) == MP_YES) {
+ if (a->sign == MP_NEG) {
return MP_VAL;
}
diff --git a/bn_mp_tc_and.c b/bn_mp_tc_and.c
index 9834dc6..d94a973 100644
--- a/bn_mp_tc_and.c
+++ b/bn_mp_tc_and.c
@@ -16,10 +16,10 @@
int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
{
int res = MP_OKAY, bits, abits, bbits;
- int as = mp_isneg(a), bs = mp_isneg(b);
+ int sa = a->sign, sb = b->sign;
mp_int *mx = NULL, _mx, acpy, bcpy;
- if ((as != MP_NO) || (bs != MP_NO)) {
+ if ((sa == MP_NEG) || (sb == MP_NEG)) {
abits = mp_count_bits(a);
bbits = mp_count_bits(b);
bits = MAX(abits, bbits);
@@ -34,7 +34,7 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
goto end;
}
- if (as != MP_NO) {
+ if (sa == MP_NEG) {
res = mp_init(&acpy);
if (res != MP_OKAY) {
goto end;
@@ -47,7 +47,7 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
}
a = &acpy;
}
- if (bs != MP_NO) {
+ if (sb == MP_NEG) {
res = mp_init(&bcpy);
if (res != MP_OKAY) {
goto end;
@@ -64,7 +64,7 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
res = mp_and(a, b, c);
- if ((as != MP_NO) && (bs != MP_NO) && (res == MP_OKAY)) {
+ if ((sa == MP_NEG) && (sb == MP_NEG) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c);
}
diff --git a/bn_mp_tc_div_2d.c b/bn_mp_tc_div_2d.c
index 4ff0acf..d324013 100644
--- a/bn_mp_tc_div_2d.c
+++ b/bn_mp_tc_div_2d.c
@@ -16,7 +16,7 @@
int mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
{
int res;
- if (mp_isneg(a) == MP_NO) {
+ if (a->sign == MP_ZPOS) {
return mp_div_2d(a, b, c, NULL);
}
diff --git a/bn_mp_tc_or.c b/bn_mp_tc_or.c
index 0941468..f86e42f 100644
--- a/bn_mp_tc_or.c
+++ b/bn_mp_tc_or.c
@@ -16,10 +16,10 @@
int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
{
int res = MP_OKAY, bits, abits, bbits;
- int as = mp_isneg(a), bs = mp_isneg(b);
+ int sa = a->sign, sb = b->sign;
mp_int *mx = NULL, _mx, acpy, bcpy;
- if ((as != MP_NO) || (bs != MP_NO)) {
+ if ((sa == MP_NEG) || (sb == MP_NEG)) {
abits = mp_count_bits(a);
bbits = mp_count_bits(b);
bits = MAX(abits, bbits);
@@ -34,7 +34,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
goto end;
}
- if (as != MP_NO) {
+ if (sa == MP_NEG) {
res = mp_init(&acpy);
if (res != MP_OKAY) {
goto end;
@@ -47,7 +47,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
}
a = &acpy;
}
- if (bs != MP_NO) {
+ if (sb == MP_NEG) {
res = mp_init(&bcpy);
if (res != MP_OKAY) {
goto end;
@@ -64,7 +64,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
res = mp_or(a, b, c);
- if (((as != MP_NO) || (bs != MP_NO)) && (res == MP_OKAY)) {
+ if (((sa == MP_NEG) || (sb == MP_NEG)) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c);
}
diff --git a/bn_mp_tc_xor.c b/bn_mp_tc_xor.c
index cdb1d40..79a02cb 100644
--- a/bn_mp_tc_xor.c
+++ b/bn_mp_tc_xor.c
@@ -16,10 +16,10 @@
int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
{
int res = MP_OKAY, bits, abits, bbits;
- int as = mp_isneg(a), bs = mp_isneg(b);
+ int sa = a->sign, sb = b->sign;
mp_int *mx = NULL, _mx, acpy, bcpy;
- if ((as != MP_NO) || (bs != MP_NO)) {
+ if ((sa == MP_NEG) || (sb == MP_NEG)) {
abits = mp_count_bits(a);
bbits = mp_count_bits(b);
bits = MAX(abits, bbits);
@@ -34,7 +34,7 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
goto end;
}
- if (as != MP_NO) {
+ if (sa == MP_NEG) {
res = mp_init(&acpy);
if (res != MP_OKAY) {
goto end;
@@ -47,7 +47,7 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
}
a = &acpy;
}
- if (bs != MP_NO) {
+ if (sb == MP_NEG) {
res = mp_init(&bcpy);
if (res != MP_OKAY) {
goto end;
@@ -64,7 +64,7 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
res = mp_xor(a, b, c);
- if ((as != bs) && (res == MP_OKAY)) {
+ if ((sa != sb) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c);
}
diff --git a/tommath_class.h b/tommath_class.h
index 6363042..8918d79 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -446,7 +446,6 @@
#endif
#if defined(BN_MP_GET_DOUBLE_C)
-# define BN_MP_ISNEG_C
#endif
#if defined(BN_MP_GET_INT_C)
@@ -534,7 +533,6 @@
#if defined(BN_MP_JACOBI_C)
# define BN_MP_KRONECKER_C
-# define BN_MP_ISNEG_C
# define BN_MP_CMP_D_C
#endif
@@ -1022,7 +1020,6 @@
#endif
#if defined(BN_MP_TC_AND_C)
-# define BN_MP_ISNEG_C
# define BN_MP_COUNT_BITS_C
# define BN_MP_INIT_SET_INT_C
# define BN_MP_MUL_2D_C
@@ -1034,14 +1031,12 @@
#endif
#if defined(BN_MP_TC_DIV_2D_C)
-# define BN_MP_ISNEG_C
# define BN_MP_DIV_2D_C
# define BN_MP_ADD_D_C
# define BN_MP_SUB_D_C
#endif
#if defined(BN_MP_TC_OR_C)
-# define BN_MP_ISNEG_C
# define BN_MP_COUNT_BITS_C
# define BN_MP_INIT_SET_INT_C
# define BN_MP_MUL_2D_C
@@ -1053,7 +1048,6 @@
#endif
#if defined(BN_MP_TC_XOR_C)
-# define BN_MP_ISNEG_C
# define BN_MP_COUNT_BITS_C
# define BN_MP_INIT_SET_INT_C
# define BN_MP_MUL_2D_C