diff libtommath/bn_mp_kronecker.c @ 1692:1051e4eea25a

Update LibTomMath to 1.2.0 (#84) * update C files * update other files * update headers * update makefiles * remove mp_set/get_double() * use ltm 1.2.0 API * update ltm_desc * use bundled tommath if system-tommath is too old * XMALLOC etc. were changed to MP_MALLOC etc.
author Steffen Jaeckel <s@jaeckel.eu>
date Tue, 26 May 2020 17:36:47 +0200
parents f52919ffd3b1
children
line wrap: on
line diff
--- a/libtommath/bn_mp_kronecker.c	Tue May 26 23:27:26 2020 +0800
+++ b/libtommath/bn_mp_kronecker.c	Tue May 26 17:36:47 2020 +0200
@@ -1,17 +1,8 @@
 #include "tommath_private.h"
 #ifdef BN_MP_KRONECKER_C
 
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * Michael Fromberger but has been written from scratch with
- * additional optimizations in place.
- *
- * SPDX-License-Identifier: Unlicense
- */
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
 
 /*
    Kronecker symbol (a|p)
@@ -26,43 +17,41 @@
      publisher={Springer Science \& Business Media}
     }
  */
-int mp_kronecker(const mp_int *a, const mp_int *p, int *c)
+mp_err mp_kronecker(const mp_int *a, const mp_int *p, int *c)
 {
    mp_int a1, p1, r;
-
-   int e = MP_OKAY;
+   mp_err err;
    int v, k;
 
    static const int table[8] = {0, 1, 0, -1, 0, -1, 0, 1};
 
-   if (mp_iszero(p) != MP_NO) {
+   if (MP_IS_ZERO(p)) {
       if ((a->used == 1) && (a->dp[0] == 1u)) {
          *c = 1;
-         return e;
       } else {
          *c = 0;
-         return e;
       }
+      return MP_OKAY;
    }
 
-   if ((mp_iseven(a) != MP_NO) && (mp_iseven(p) != MP_NO)) {
+   if (MP_IS_EVEN(a) && MP_IS_EVEN(p)) {
       *c = 0;
-      return e;
+      return MP_OKAY;
    }
 
-   if ((e = mp_init_copy(&a1, a)) != MP_OKAY) {
-      return e;
+   if ((err = mp_init_copy(&a1, a)) != MP_OKAY) {
+      return err;
    }
-   if ((e = mp_init_copy(&p1, p)) != MP_OKAY) {
+   if ((err = mp_init_copy(&p1, p)) != MP_OKAY) {
       goto LBL_KRON_0;
    }
 
    v = mp_cnt_lsb(&p1);
-   if ((e = mp_div_2d(&p1, v, &p1, NULL)) != MP_OKAY) {
+   if ((err = mp_div_2d(&p1, v, &p1, NULL)) != MP_OKAY) {
       goto LBL_KRON_1;
    }
 
-   if ((v & 0x1) == 0) {
+   if ((v & 1) == 0) {
       k = 1;
    } else {
       k = table[a->dp[0] & 7u];
@@ -75,12 +64,12 @@
       }
    }
 
-   if ((e = mp_init(&r)) != MP_OKAY) {
+   if ((err = mp_init(&r)) != MP_OKAY) {
       goto LBL_KRON_1;
    }
 
    for (;;) {
-      if (mp_iszero(&a1) != MP_NO) {
+      if (MP_IS_ZERO(&a1)) {
          if (mp_cmp_d(&p1, 1uL) == MP_EQ) {
             *c = k;
             goto LBL_KRON;
@@ -91,11 +80,11 @@
       }
 
       v = mp_cnt_lsb(&a1);
-      if ((e = mp_div_2d(&a1, v, &a1, NULL)) != MP_OKAY) {
+      if ((err = mp_div_2d(&a1, v, &a1, NULL)) != MP_OKAY) {
          goto LBL_KRON;
       }
 
-      if ((v & 0x1) == 1) {
+      if ((v & 1) == 1) {
          k = k * table[p1.dp[0] & 7u];
       }
 
@@ -115,14 +104,14 @@
          }
       }
 
-      if ((e = mp_copy(&a1, &r)) != MP_OKAY) {
+      if ((err = mp_copy(&a1, &r)) != MP_OKAY) {
          goto LBL_KRON;
       }
       r.sign = MP_ZPOS;
-      if ((e = mp_mod(&p1, &r, &a1)) != MP_OKAY) {
+      if ((err = mp_mod(&p1, &r, &a1)) != MP_OKAY) {
          goto LBL_KRON;
       }
-      if ((e = mp_copy(&r, &p1)) != MP_OKAY) {
+      if ((err = mp_copy(&r, &p1)) != MP_OKAY) {
          goto LBL_KRON;
       }
    }
@@ -134,11 +123,7 @@
 LBL_KRON_0:
    mp_clear(&a1);
 
-   return e;
+   return err;
 }
 
 #endif
-
-/* ref:         HEAD -> master, tag: v1.1.0 */
-/* git commit:  08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
-/* commit time: 2019-01-28 20:32:32 +0100 */