From: Pekka Riikonen Date: Sat, 15 Mar 2008 09:10:26 +0000 (+0200) Subject: Fixed tfm_fp_mul_2 and tfm_fp_mul_d to handle leading digit correctly. X-Git-Tag: 1.2.beta2~1 X-Git-Url: http://git.silc.fi/gitweb/?p=crypto.git;a=commitdiff_plain;h=af315d6ae4f6f57944b558b18225454f63d24104 Fixed tfm_fp_mul_2 and tfm_fp_mul_d to handle leading digit correctly. --- diff --git a/lib/silcmath/mp_tfm.c b/lib/silcmath/mp_tfm.c index 9424ad97..45a1cd81 100644 --- a/lib/silcmath/mp_tfm.c +++ b/lib/silcmath/mp_tfm.c @@ -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))) { diff --git a/lib/silcmath/tests/test_silcmp.c b/lib/silcmath/tests/test_silcmp.c index cfbd950d..894fbf83 100644 --- a/lib/silcmath/tests/test_silcmp.c +++ b/lib/silcmath/tests/test_silcmp.c @@ -79,6 +79,7 @@ const char *numor = const char *numxor = "406442100086368525205432595008864090782598685309019707370392150093114259667017507345870606014161693990793563407656070252325154011"; + int main(int argc, char **argv) { SilcBool success = FALSE; diff --git a/lib/silcmath/tfm.c b/lib/silcmath/tfm.c index 49234bca..aab79d5c 100644 --- a/lib/silcmath/tfm.c +++ b/lib/silcmath/tfm.c @@ -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; }