]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - bigint/bigint.c
some fixes, mainly at rsaes-pkcs1v15
[avr-crypto-lib.git] / bigint / bigint.c
index 6db0389d693490bdc818b4688e88b29370c6e4f7..c69d42ec7d22d389b67324deebc92c7ea443aa86 100644 (file)
@@ -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);
+       }
 }
 
 /******************************************************************************/