Commit 434dbcab27816a6096db70fdeb7fa4b337e2b774

Francois Perrad 2018-09-23T10:16:25

refactor without bitwise operator

diff --git a/bn_mp_tc_and.c b/bn_mp_tc_and.c
index 02e43ac..e9fe4c6 100644
--- a/bn_mp_tc_and.c
+++ b/bn_mp_tc_and.c
@@ -17,7 +17,7 @@
 int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
 {
    int res = MP_OKAY, bits;
-   int as = mp_isneg(a), bs = mp_isneg(b), s = 0;
+   int as = mp_isneg(a), bs = mp_isneg(b);
    mp_int *mx = NULL, _mx, acpy, bcpy;
 
    if ((as != MP_NO) || (bs != MP_NO)) {
@@ -62,9 +62,8 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
    }
 
    res = mp_and(a, b, c);
-   s = as & bs;
 
-   if (s && res == MP_OKAY) {
+   if ((as != MP_NO) && (bs != MP_NO) && (res == MP_OKAY)) {
       res = mp_sub(c, mx, c);
    }
 
diff --git a/bn_mp_tc_or.c b/bn_mp_tc_or.c
index 549a328..91b6b40 100644
--- a/bn_mp_tc_or.c
+++ b/bn_mp_tc_or.c
@@ -17,7 +17,7 @@
 int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
 {
    int res = MP_OKAY, bits;
-   int as = mp_isneg(a), bs = mp_isneg(b), s = 0;
+   int as = mp_isneg(a), bs = mp_isneg(b);
    mp_int *mx = NULL, _mx, acpy, bcpy;
 
    if ((as != MP_NO) || (bs != MP_NO)) {
@@ -62,9 +62,8 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
    }
 
    res = mp_or(a, b, c);
-   s = as | bs;
 
-   if (s && res == MP_OKAY) {
+   if (((as != MP_NO) || (bs != MP_NO)) && (res == MP_OKAY)) {
       res = mp_sub(c, mx, c);
    }
 
diff --git a/bn_mp_tc_xor.c b/bn_mp_tc_xor.c
index 771cfd5..50fb12d 100644
--- a/bn_mp_tc_xor.c
+++ b/bn_mp_tc_xor.c
@@ -17,7 +17,7 @@
 int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
 {
    int res = MP_OKAY, bits;
-   int as = mp_isneg(a), bs = mp_isneg(b), s = 0;
+   int as = mp_isneg(a), bs = mp_isneg(b);
    mp_int *mx = NULL, _mx, acpy, bcpy;
 
    if ((as != MP_NO) || (bs != MP_NO)) {
@@ -62,9 +62,8 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
    }
 
    res = mp_xor(a, b, c);
-   s = as ^ bs;
 
-   if (s && res == MP_OKAY) {
+   if ((as != bs) && (res == MP_OKAY)) {
       res = mp_sub(c, mx, c);
    }