From c30a96120f53b960db56bc05a7ce6310bb2528f5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 14 Nov 2016 21:17:31 -0800 Subject: Fix bug in bignum addition. * mpi/mpi.c (s_mp_add): It looks like this function had the same kind of bug I fixed years ago in the multiplication routines. ("fix-mult-bug" patch, originally). In the main loop, two digit-sized values are added together to produce a partial sum with carry. Unfortunately, both operands digit-sized, so the result is truncated to the digit type. The cast of one of the operands to mp_word is missing. --- mpi/mpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mpi') diff --git a/mpi/mpi.c b/mpi/mpi.c index 1e236e26..aea72585 100644 --- a/mpi/mpi.c +++ b/mpi/mpi.c @@ -4130,7 +4130,7 @@ mp_err s_mp_add(mp_int *a, mp_int *b) /* magnitude addition */ pa = DIGITS(a); pb = DIGITS(b); for(ix = 0; ix < used; ++ix) { - w += *pa + *pb++; + w += *pa + convert(mp_word, *pb++); *pa++ = ACCUM(w); w = CARRYOUT(w); } -- cgit v1.2.3