another proposal: use _ul and _l for the long macros
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
diff --git a/demo/test.c b/demo/test.c
index c2f5c81..a16397a 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -230,7 +230,7 @@ static int test_mp_fread_fwrite(void)
return EXIT_FAILURE;
}
- mp_set_ulong(&a, 123456uL);
+ mp_set_ul(&a, 123456uL);
tmp = tmpfile();
if ((e = mp_fwrite(&a, 64, tmp)) != MP_OKAY) {
goto LBL_ERR;
@@ -313,8 +313,8 @@ static int test_s_mp_jacobi(void)
return EXIT_FAILURE;
}
- mp_set_ulong(&a, 0uL);
- mp_set_ulong(&b, 1uL);
+ mp_set_ul(&a, 0uL);
+ mp_set_ul(&b, 1uL);
if ((err = s_mp_jacobi(&a, &b, &i)) != MP_OKAY) {
printf("Failed executing s_mp_jacobi(0 | 1) %s.\n", mp_error_to_string(err));
goto LBL_ERR;
@@ -324,10 +324,10 @@ static int test_s_mp_jacobi(void)
goto LBL_ERR;
}
for (cnt = 0; cnt < (int)(sizeof(jacobi)/sizeof(jacobi[0])); ++cnt) {
- mp_set_ulong(&b, jacobi[cnt].n);
+ mp_set_ul(&b, jacobi[cnt].n);
/* only test positive values of a */
for (n = -5; n <= 10; ++n) {
- mp_set_ulong(&a, (unsigned int)abs(n));
+ mp_set_ul(&a, (unsigned int)abs(n));
should = MP_OKAY;
if (n < 0) {
mp_neg(&a, &a);
@@ -391,8 +391,8 @@ static int test_mp_kronecker(void)
return EXIT_FAILURE;
}
- mp_set_ulong(&a, 0uL);
- mp_set_ulong(&b, 1uL);
+ mp_set_ul(&a, 0uL);
+ mp_set_ul(&b, 1uL);
if ((err = mp_kronecker(&a, &b, &i)) != MP_OKAY) {
printf("Failed executing mp_kronecker(0 | 1) %s.\n", mp_error_to_string(err));
goto LBL_ERR;
@@ -404,18 +404,18 @@ static int test_mp_kronecker(void)
for (cnt = 0; cnt < (int)(sizeof(kronecker)/sizeof(kronecker[0])); ++cnt) {
k = kronecker[cnt].n;
if (k < 0) {
- mp_set_ulong(&a, (unsigned long)(-k));
+ mp_set_ul(&a, (unsigned long)(-k));
mp_neg(&a, &a);
} else {
- mp_set_ulong(&a, (unsigned long) k);
+ mp_set_ul(&a, (unsigned long) k);
}
/* only test positive values of a */
for (m = -10; m <= 10; m++) {
if (m < 0) {
- mp_set_ulong(&b,(unsigned long)(-m));
+ mp_set_ul(&b,(unsigned long)(-m));
mp_neg(&b, &b);
} else {
- mp_set_ulong(&b, (unsigned long) m);
+ mp_set_ul(&b, (unsigned long) m);
}
if ((err = mp_kronecker(&a, &b, &i)) != MP_OKAY) {
printf("Failed executing mp_kronecker(%ld | %ld) %s.\n", kronecker[cnt].n, m, mp_error_to_string(err));
@@ -446,13 +446,13 @@ static int test_mp_complement(void)
for (i = 0; i < 1000; ++i) {
long l = rand_long();
- mp_set_ulong(&a, ulabs(l));
+ mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
mp_complement(&a, &b);
l = ~l;
- mp_set_ulong(&c, ulabs(l));
+ mp_set_ul(&c, ulabs(l));
if (l < 0)
mp_neg(&c, &c);
@@ -483,13 +483,13 @@ static int test_mp_signed_rsh(void)
int em;
l = rand_long();
- mp_set_ulong(&a, ulabs(l));
+ mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = abs(rand_int()) % 32;
- mp_set_ulong(&d, ulabs(l >> em));
+ mp_set_ul(&d, ulabs(l >> em));
if ((l >> em) < 0)
mp_neg(&d, &d);
@@ -521,16 +521,16 @@ static int test_mp_xor(void)
long l, em;
l = rand_long();
- mp_set_ulong(&a, ulabs(l));
+ mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = rand_long();
- mp_set_ulong(&b, ulabs(em));
+ mp_set_ul(&b, ulabs(em));
if (em < 0)
mp_neg(&b, &b);
- mp_set_ulong(&d, ulabs(l ^ em));
+ mp_set_ul(&d, ulabs(l ^ em));
if ((l ^ em) < 0)
mp_neg(&d, &d);
@@ -562,16 +562,16 @@ static int test_mp_or(void)
long l, em;
l = rand_long();
- mp_set_ulong(&a, ulabs(l));
+ mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = rand_long();
- mp_set_ulong(&b, ulabs(em));
+ mp_set_ul(&b, ulabs(em));
if (em < 0)
mp_neg(&b, &b);
- mp_set_ulong(&d, ulabs(l | em));
+ mp_set_ul(&d, ulabs(l | em));
if ((l | em) < 0)
mp_neg(&d, &d);
@@ -602,16 +602,16 @@ static int test_mp_and(void)
long l, em;
l = rand_long();
- mp_set_ulong(&a, ulabs(l));
+ mp_set_ul(&a, ulabs(l));
if (l < 0)
mp_neg(&a, &a);
em = rand_long();
- mp_set_ulong(&b, ulabs(em));
+ mp_set_ul(&b, ulabs(em));
if (em < 0)
mp_neg(&b, &b);
- mp_set_ulong(&d, ulabs(l & em));
+ mp_set_ul(&d, ulabs(l & em));
if ((l & em) < 0)
mp_neg(&d, &d);
@@ -744,18 +744,18 @@ static int test_mp_get_uint32(void)
for (i = 0; i < 1000; ++i) {
t = (unsigned long)rand_long() & 0xFFFFFFFFuL;
- mp_set_ulong(&a, t);
+ mp_set_ul(&a, t);
if (t != mp_get_uint32(&a)) {
printf("\nmp_get_uint32() bad result!");
goto LBL_ERR;
}
}
- mp_set_ulong(&a, 0uL);
+ mp_set_ul(&a, 0uL);
if (mp_get_uint32(&a) != 0) {
printf("\nmp_get_uint32() bad result!");
goto LBL_ERR;
}
- mp_set_ulong(&a, 0xFFFFFFFFuL);
+ mp_set_ul(&a, 0xFFFFFFFFuL);
if (mp_get_uint32(&a) != 0xFFFFFFFFuL) {
printf("\nmp_get_uint32() bad result!");
goto LBL_ERR;
@@ -768,7 +768,7 @@ LBL_ERR:
return EXIT_FAILURE;
}
-static int test_mp_get_ulong(void)
+static int test_mp_get_ul(void)
{
unsigned long s, t;
int i;
@@ -784,10 +784,10 @@ static int test_mp_get_ulong(void)
t = ~0UL;
printf(" t = 0x%lx i = %d\r", t, i);
do {
- mp_set_ulong(&a, t);
- s = mp_get_ulong(&a);
+ mp_set_ul(&a, t);
+ s = mp_get_ul(&a);
if (s != t) {
- printf("\nmp_get_ulong() bad result! 0x%lx != 0x%lx", s, t);
+ printf("\nmp_get_ul() bad result! 0x%lx != 0x%lx", s, t);
goto LBL_ERR;
}
t <<= 1;
@@ -943,8 +943,8 @@ static int test_mp_sqrtmod_prime(void)
/* r^2 = n (mod p) */
for (i = 0; i < (int)(sizeof(sqrtmod_prime)/sizeof(sqrtmod_prime[0])); ++i) {
- mp_set_ulong(&a, sqrtmod_prime[i].p);
- mp_set_ulong(&b, sqrtmod_prime[i].n);
+ mp_set_ul(&a, sqrtmod_prime[i].p);
+ mp_set_ul(&b, sqrtmod_prime[i].n);
if (mp_sqrtmod_prime(&b, &a, &c) != MP_OKAY) {
printf("Failed executing %d. mp_sqrtmod_prime\n", (i+1));
goto LBL_ERR;
@@ -2154,7 +2154,7 @@ int unit_tests(int argc, char **argv)
T(mp_fread_fwrite),
T(mp_get_uint32),
T(mp_get_uint64),
- T(mp_get_ulong),
+ T(mp_get_ul),
T(mp_ilogb),
T(mp_incr),
T(mp_invmod),
diff --git a/doc/bn.tex b/doc/bn.tex
index c9d6b56..6f5afcd 100644
--- a/doc/bn.tex
+++ b/doc/bn.tex
@@ -882,8 +882,8 @@ number == 654321
\index{mp\_set\_ulong}
\begin{alltt}
-void mp_set_slong (mp_int * a, long b);
-void mp_set_ulong (mp_int * a, unsigned long b);
+void mp_set_l (mp_int * a, long b);
+void mp_set_ul (mp_int * a, unsigned long b);
\end{alltt}
This will assign the value of the platform-dependent sized variable $b$ to the mp\_int $a$.
@@ -892,8 +892,8 @@ To retrieve the value, the following functions can be used.
\index{mp\_get\_ulong}
\begin{alltt}
-long mp_get_slong (mp_int * a);
-unsigned long mp_get_ulong (mp_int * a);
+long mp_get_l (mp_int * a);
+unsigned long mp_get_ul (mp_int * a);
\end{alltt}
This will return the least significant bits of the mp\_int $a$ that fit into a ``long''.
diff --git a/tommath.h b/tommath.h
index ba10fef..936a432 100644
--- a/tommath.h
+++ b/tommath.h
@@ -297,13 +297,13 @@ uint32_t mp_get_mag32(const mp_int *a) MP_WUR;
uint64_t mp_get_mag64(const mp_int *a) MP_WUR;
/* get integer, set integer (long) */
-#define mp_get_slong(a) (sizeof (long) == 8 ? (long)mp_get_int64(a) : (long)mp_get_int32(a))
-#define mp_set_slong(a, b) (sizeof (long) == 8 ? mp_set_int64((a), (b)) : mp_set_int32((a), (int32_t)(b)))
+#define mp_get_l(a) (sizeof (long) == 8 ? (long)mp_get_int64(a) : (long)mp_get_int32(a))
+#define mp_set_l(a, b) (sizeof (long) == 8 ? mp_set_int64((a), (b)) : mp_set_int32((a), (int32_t)(b)))
/* get integer, set integer (unsigned long) */
-#define mp_get_ulong(a) (sizeof (long) == 8 ? (unsigned long)mp_get_uint64(a) : (unsigned long)mp_get_uint32(a))
-#define mp_set_ulong(a, b) (sizeof (long) == 8 ? mp_set_uint64((a), (b)) : mp_set_uint32((a), (uint32_t)(b)))
-#define mp_get_mag_long(a) (sizeof (long) == 8 ? (unsigned long)mp_get_mag64(a) : (unsigned long)mp_get_mag32(a))
+#define mp_get_ul(a) (sizeof (long) == 8 ? (unsigned long)mp_get_uint64(a) : (unsigned long)mp_get_uint32(a))
+#define mp_set_ul(a, b) (sizeof (long) == 8 ? mp_set_uint64((a), (b)) : mp_set_uint32((a), (uint32_t)(b)))
+#define mp_get_magl(a) (sizeof (long) == 8 ? (unsigned long)mp_get_mag64(a) : (unsigned long)mp_get_mag32(a))
/* set to single unsigned digit, up to MP_DIGIT_MAX */
void mp_set(mp_int *a, mp_digit b);
@@ -311,10 +311,10 @@ mp_err mp_init_set(mp_int *a, mp_digit b) MP_WUR;
/* get integer, set integer and init with integer (deprecated) */
MP_DEPRECATED(mp_get_mag32/mp_get_uint32) unsigned long mp_get_int(const mp_int *a) MP_WUR;
-MP_DEPRECATED(mp_get_mag_long/mp_get_ulong) unsigned long mp_get_long(const mp_int *a) MP_WUR;
+MP_DEPRECATED(mp_get_magl/mp_get_ul) unsigned long mp_get_long(const mp_int *a) MP_WUR;
MP_DEPRECATED(mp_get_mag64/mp_get_uint64) unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
MP_DEPRECATED(mp_set_uint32) mp_err mp_set_int(mp_int *a, unsigned long b);
-MP_DEPRECATED(mp_set_ulong) mp_err mp_set_long(mp_int *a, unsigned long b);
+MP_DEPRECATED(mp_set_ul) mp_err mp_set_long(mp_int *a, unsigned long b);
MP_DEPRECATED(mp_set_uint64) mp_err mp_set_long_long(mp_int *a, unsigned long long b);
MP_DEPRECATED(mp_init_uint32) mp_err mp_init_set_int(mp_int *a, unsigned long b) MP_WUR;