From 8fc1af1b7eea89e942c4af4ebcc7b8d8abfc8eff Mon Sep 17 00:00:00 2001
From: Steffen Jaeckel <s@jaeckel.eu>
Date: Wed, 15 Feb 2017 23:15:43 +0100
Subject: [PATCH] make implementation easier to read

damn you negated logic...
---
 src/pk/rsa/rsa_exptmod.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/pk/rsa/rsa_exptmod.c b/src/pk/rsa/rsa_exptmod.c
index 78858fe..714bc52 100644
--- a/src/pk/rsa/rsa_exptmod.c
+++ b/src/pk/rsa/rsa_exptmod.c
@@ -38,7 +38,7 @@ int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
    void        *rnd, *rndi /* inverse of rnd */;
    #endif
    unsigned long x;
-   int           err, no_crt;
+   int           err, has_crt_parameters;
 
    LTC_ARGCHK(in     != NULL);
    LTC_ARGCHK(out    != NULL);
@@ -100,9 +100,11 @@ int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
       }
       #endif /* LTC_RSA_BLINDING */
 
-      no_crt = (key->dP == NULL) || (mp_get_digit_count(key->dP) == 0);
+      has_crt_parameters = (key->dP != NULL) && (mp_get_digit_count(key->dP) != 0) &&
+                              (key->dQ != NULL) && (mp_get_digit_count(key->dQ) != 0) &&
+                                 (key->qP != NULL) && (mp_get_digit_count(key->qP) != 0);
 
-      if (no_crt) {
+      if (!has_crt_parameters) {
          /*
           * In case CRT optimization parameters are not provided,
           * the private key is directly used to exptmod it
@@ -133,7 +135,7 @@ int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
       #endif
 
       #ifdef LTC_RSA_CRT_HARDENING
-      if (!no_crt) {
+      if (has_crt_parameters) {
          if ((err = mp_exptmod(tmp, key->e, key->N, tmpa)) != CRYPT_OK)                              { goto error; }
          if ((err = mp_read_unsigned_bin(tmpb, (unsigned char *)in, (int)inlen)) != CRYPT_OK)        { goto error; }
          if (mp_cmp(tmpa, tmpb) != LTC_MP_EQ)                                     { err = CRYPT_ERROR; goto error; }