Fixed tfm_fp_mul_2 and tfm_fp_mul_d to handle leading digit correctly.
authorPekka Riikonen <priikone@silcnet.org>
Sat, 15 Mar 2008 09:10:26 +0000 (11:10 +0200)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 15 Mar 2008 09:10:26 +0000 (11:10 +0200)
lib/silcmath/mp_tfm.c
lib/silcmath/tests/test_silcmp.c
lib/silcmath/tfm.c

index 9424ad97e7618a1e7ef605fe29fef1cce4531148..45a1cd8176a58c3bb39bcbc1f302c698a8811da4 100644 (file)
@@ -293,7 +293,7 @@ SilcBool silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp)
 }
 
 SilcBool silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp,
-                    SilcMPInt *mod)
+                        SilcMPInt *mod)
 {
   int ret;
   if ((ret = tfm_fp_exptmod(mp1, exp, mod, dst))) {
index cfbd950d14d12104a7a7a2a71df2018844c559d5..894fbf83b8044d7187eccbe80e26dd85715e963f 100644 (file)
@@ -79,6 +79,7 @@ const char *numor =
 const char *numxor =
 "406442100086368525205432595008864090782598685309019707370392150093114259667017507345870606014161693990793563407656070252325154011";
 
+
 int main(int argc, char **argv)
 {
   SilcBool success = FALSE;
index 49234bca01e556b7d32929049a8176da1d6beb59..aab79d5c97e2c0ffacb019c8d5afb255ec8ff908 100644 (file)
@@ -2156,7 +2156,7 @@ int tfm_fp_mul_2(tfm_fp_int * a, tfm_fp_int * b)
 {
   int     x, oldused;
 
-  if (b->alloc < a->used + 1)
+  if (b->alloc <= a->used + 1)
     if (tfm_fp_grow(b, a->used + 1))
       return TFM_FP_MEM;
 
@@ -2191,7 +2191,7 @@ int tfm_fp_mul_2(tfm_fp_int * a, tfm_fp_int * b)
     }
 
     /* new leading digit? */
-    if (r != 0 && b->used != (b->alloc-1)) {
+    if (r != 0) {
       /* add a MSB which is always 1 at this point */
       *tmpb = 1;
       ++(b->used);
@@ -5672,7 +5672,7 @@ int tfm_fp_mul_d(tfm_fp_int *a, tfm_fp_digit b, tfm_fp_int *c)
    tfm_fp_word  w;
    int      x, oldused;
 
-   if (c->alloc < a->used + 1)
+   if (c->alloc <= a->used + 1)
      if (tfm_fp_grow(c, a->used + 1))
        return TFM_FP_MEM;
 
@@ -5685,7 +5685,7 @@ int tfm_fp_mul_d(tfm_fp_int *a, tfm_fp_digit b, tfm_fp_int *c)
        c->dp[x]  = (tfm_fp_digit)w;
        w         = w >> DIGIT_BIT;
    }
-   if (w != 0 && (a->used != a->alloc)) {
+   if (w != 0) {
       c->dp[c->used++] = w;
       ++x;
    }