X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=bigint%2Fbigint.c;h=c69d42ec7d22d389b67324deebc92c7ea443aa86;hp=6db0389d693490bdc818b4688e88b29370c6e4f7;hb=cc6b183296a5852449e3324737e2a2dece788786;hpb=06d9213f132d05f61b65acc51de6f7ad1b42f48a diff --git a/bigint/bigint.c b/bigint/bigint.c index 6db0389..c69d42e 100644 --- a/bigint/bigint.c +++ b/bigint/bigint.c @@ -291,26 +291,34 @@ int8_t bigint_cmp_u(const bigint_t* a, const bigint_t* b){ void bigint_add_s(bigint_t* dest, const bigint_t* a, const bigint_t* b){ uint8_t s; + int8_t d = 0; s = GET_SIGN(a)?2:0; s |= GET_SIGN(b)?1:0; switch(s){ case 0: /* both positive */ + d = 1; bigint_add_u(dest, a,b); - SET_POS(dest); break; case 1: /* a positive, b negative */ + d = bigint_cmp_u(a,b); bigint_sub_u(dest, a, b); break; case 2: /* a negative, b positive */ + d = bigint_cmp_u(b,a); bigint_sub_u(dest, b, a); break; case 3: /* both negative */ + d = -1; bigint_add_u(dest, a, b); - SET_NEG(dest); break; default: /* how can this happen?*/ break; } + if(d<0){ + SET_NEG(dest); + }else{ + SET_POS(dest); + } } /******************************************************************************/