Commit d7e1cb4a099acff58afa892bfef20b31571dfe2b

Daniel Mendler 2019-05-24T00:15:11

another proposal: use _ul and _l for the long macros

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;