Lines Matching refs:b

130 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)  argument
132 static int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
133 static int s_mp_sqr(mp_int * a, mp_int * b);
134 static int s_mp_mul_high_digs(mp_int * a, mp_int * b, mp_int * c, int digs);
136 static int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
144 static int mp_lshd(mp_int * a, int b);
145 static void mp_set(mp_int * a, mp_digit b);
147 static void mp_exch(mp_int * a, mp_int * b);
148 static void mp_rshd(mp_int * a, int b);
150 static int mp_mod_2d(mp_int * a, int b, mp_int * c);
151 static int mp_div_2d(mp_int * a, int b, mp_int * c, mp_int * d);
152 static int mp_init_copy(mp_int * a, mp_int * b);
153 static int mp_mul_2d(mp_int * a, int b, mp_int * c);
155 static int mp_div_2(mp_int * a, mp_int * b);
156 static int mp_invmod(mp_int * a, mp_int * b, mp_int * c);
157 static int mp_invmod_slow(mp_int * a, mp_int * b, mp_int * c);
159 static int mp_copy(mp_int * a, mp_int * b);
161 static int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d);
162 static int mp_mod(mp_int * a, mp_int * b, mp_int * c);
164 static int mp_cmp_mag(mp_int * a, mp_int * b);
166 static int mp_abs(mp_int * a, mp_int * b);
168 static int mp_sqr(mp_int * a, mp_int * b);
171 static int mp_2expt(mp_int * a, int b);
172 static int mp_reduce_setup(mp_int * a, mp_int * b);
179 static int fast_s_mp_sqr (mp_int * a, mp_int * b);
182 static int mp_mul_d (mp_int * a, mp_digit b, mp_int * c);
211 s_mp_add (mp_int * a, mp_int * b, mp_int * c) in s_mp_add() argument
219 if (a->used > b->used) { in s_mp_add()
220 min = b->used; in s_mp_add()
225 max = b->used; in s_mp_add()
226 x = b; in s_mp_add()
250 tmpb = b->dp; in s_mp_add()
300 s_mp_sub (mp_int * a, mp_int * b, mp_int * c) in s_mp_sub() argument
305 min = b->used; in s_mp_sub()
323 tmpb = b->dp; in s_mp_sub()
419 mp_add (mp_int * a, mp_int * b, mp_int * c) in mp_add() argument
425 sb = b->sign; in mp_add()
432 res = s_mp_add (a, b, c); in mp_add()
438 if (mp_cmp_mag (a, b) == MP_LT) { in mp_add()
440 res = s_mp_sub (b, a, c); in mp_add()
443 res = s_mp_sub (a, b, c); in mp_add()
452 mp_sub (mp_int * a, mp_int * b, mp_int * c) in mp_sub() argument
457 sb = b->sign; in mp_sub()
465 res = s_mp_add (a, b, c); in mp_sub()
471 if (mp_cmp_mag (a, b) != MP_LT) { in mp_sub()
475 res = s_mp_sub (a, b, c); in mp_sub()
481 res = s_mp_sub (b, a, c); in mp_sub()
490 mp_mul (mp_int * a, mp_int * b, mp_int * c) in mp_mul() argument
493 neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; in mp_mul()
497 if (MIN (a->used, b->used) >= TOOM_MUL_CUTOFF) { in mp_mul()
498 res = mp_toom_mul(a, b, c); in mp_mul()
503 if (MIN (a->used, b->used) >= KARATSUBA_MUL_CUTOFF) { in mp_mul()
504 res = mp_karatsuba_mul (a, b, c); in mp_mul()
515 int digs = a->used + b->used + 1; in mp_mul()
518 MIN(a->used, b->used) <= in mp_mul()
520 res = fast_s_mp_mul_digs (a, b, c, digs); in mp_mul()
524 res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */ in mp_mul()
538 mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) in mp_mulmod() argument
547 if ((res = mp_mul (a, b, &t)) != MP_OKAY) { in mp_mulmod()
559 mp_mod (mp_int * a, mp_int * b, mp_int * c) in mp_mod() argument
568 if ((res = mp_div (a, b, NULL, &t)) != MP_OKAY) { in mp_mod()
573 if (t.sign != b->sign) { in mp_mod()
574 res = mp_add (b, &t, c); in mp_mod()
683 mp_cmp (mp_int * a, mp_int * b) in mp_cmp() argument
686 if (a->sign != b->sign) { in mp_cmp()
697 return mp_cmp_mag(b, a); in mp_cmp()
699 return mp_cmp_mag(a, b); in mp_cmp()
706 mp_cmp_d(mp_int * a, mp_digit b) in mp_cmp_d() argument
719 if (a->dp[0] > b) { in mp_cmp_d()
721 } else if (a->dp[0] < b) { in mp_cmp_d()
732 mp_invmod (mp_int * a, mp_int * b, mp_int * c) in mp_invmod() argument
735 if (b->sign == MP_NEG || mp_iszero(b) == 1) { in mp_invmod()
741 if (mp_isodd (b) == 1) { in mp_invmod()
742 return fast_mp_invmod (a, b, c); in mp_invmod()
747 return mp_invmod_slow(a, b, c); in mp_invmod()
772 mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c) in mp_invmod_slow() argument
778 if (b->sign == MP_NEG || mp_iszero(b) == 1) { in mp_invmod_slow()
789 if ((res = mp_mod(a, b, &x)) != MP_OKAY) { in mp_invmod_slow()
792 if ((res = mp_copy (b, &y)) != MP_OKAY) { in mp_invmod_slow()
906 if ((res = mp_add(&C, b, &C)) != MP_OKAY) { in mp_invmod_slow()
912 while (mp_cmp_mag(&C, b) != MP_LT) { in mp_invmod_slow()
913 if ((res = mp_sub(&C, b, &C)) != MP_OKAY) { in mp_invmod_slow()
929 mp_cmp_mag (mp_int * a, mp_int * b) in mp_cmp_mag() argument
935 if (a->used > b->used) { in mp_cmp_mag()
939 if (a->used < b->used) { in mp_cmp_mag()
947 tmpb = b->dp + (a->used - 1); in mp_cmp_mag()
965 mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c) in mp_read_unsigned_bin() argument
986 a->dp[0] |= *b++; in mp_read_unsigned_bin()
989 a->dp[0] = (*b & MP_MASK); in mp_read_unsigned_bin()
990 a->dp[1] |= ((*b++ >> 7U) & 1); in mp_read_unsigned_bin()
1001 mp_to_unsigned_bin (mp_int * a, unsigned char *b) in mp_to_unsigned_bin() argument
1013 b[x++] = (unsigned char) (t.dp[0] & 255); in mp_to_unsigned_bin()
1015 b[x++] = (unsigned char) (t.dp[0] | ((t.dp[1] & 0x01) << 7)); in mp_to_unsigned_bin()
1022 bn_reverse (b, x); in mp_to_unsigned_bin()
1030 mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) in mp_div_2d() argument
1038 if (b <= 0) { in mp_div_2d()
1052 if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) { in mp_div_2d()
1065 if (b >= (int)DIGIT_BIT) { in mp_div_2d()
1066 mp_rshd (c, b / DIGIT_BIT); in mp_div_2d()
1070 D = (mp_digit) (b % DIGIT_BIT); in mp_div_2d()
1107 mp_init_copy (mp_int * a, mp_int * b) in mp_init_copy() argument
1114 return mp_copy (b, a); in mp_init_copy()
1137 mp_copy (mp_int * a, mp_int * b) in mp_copy() argument
1142 if (a == b) { in mp_copy()
1147 if (b->alloc < a->used) { in mp_copy()
1148 if ((res = mp_grow (b, a->used)) != MP_OKAY) { in mp_copy()
1163 tmpb = b->dp; in mp_copy()
1171 for (; n < b->used; n++) { in mp_copy()
1177 b->used = a->used; in mp_copy()
1178 b->sign = a->sign; in mp_copy()
1185 mp_rshd (mp_int * a, int b) in mp_rshd() argument
1190 if (b <= 0) { in mp_rshd()
1195 if (a->used <= b) { in mp_rshd()
1209 top = a->dp + b; in mp_rshd()
1221 for (x = 0; x < (a->used - b); x++) { in mp_rshd()
1232 a->used -= b; in mp_rshd()
1240 mp_exch (mp_int * a, mp_int * b) in mp_exch() argument
1245 *a = *b; in mp_exch()
1246 *b = t; in mp_exch()
1318 mp_abs (mp_int * a, mp_int * b) in mp_abs() argument
1323 if (a != b) { in mp_abs()
1324 if ((res = mp_copy (a, b)) != MP_OKAY) { in mp_abs()
1330 b->sign = MP_ZPOS; in mp_abs()
1339 mp_set (mp_int * a, mp_digit b) in mp_set() argument
1342 a->dp[0] = b & MP_MASK; in mp_set()
1350 mp_div_2(mp_int * a, mp_int * b) in mp_div_2() argument
1355 if (b->alloc < a->used) { in mp_div_2()
1356 if ((res = mp_grow (b, a->used)) != MP_OKAY) { in mp_div_2()
1361 oldused = b->used; in mp_div_2()
1362 b->used = a->used; in mp_div_2()
1367 tmpa = a->dp + b->used - 1; in mp_div_2()
1370 tmpb = b->dp + b->used - 1; in mp_div_2()
1374 for (x = b->used - 1; x >= 0; x--) { in mp_div_2()
1386 tmpb = b->dp + b->used; in mp_div_2()
1387 for (x = b->used; x < oldused; x++) { in mp_div_2()
1391 b->sign = a->sign; in mp_div_2()
1392 mp_clamp (b); in mp_div_2()
1400 mp_mul_2d (mp_int * a, int b, mp_int * c) in mp_mul_2d() argument
1412 if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) { in mp_mul_2d()
1413 if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) { in mp_mul_2d()
1419 if (b >= (int)DIGIT_BIT) { in mp_mul_2d()
1420 if ((res = mp_lshd (c, b / DIGIT_BIT)) != MP_OKAY) { in mp_mul_2d()
1426 d = (mp_digit) (b % DIGIT_BIT); in mp_mul_2d()
1522 mp_lshd (mp_int * a, int b) in mp_lshd() argument
1527 if (b <= 0) { in mp_lshd()
1532 if (a->alloc < a->used + b) { in mp_lshd()
1533 if ((res = mp_grow (a, a->used + b)) != MP_OKAY) { in mp_lshd()
1542 a->used += b; in mp_lshd()
1548 bottom = a->dp + a->used - 1 - b; in mp_lshd()
1554 for (x = a->used - 1; x >= b; x--) { in mp_lshd()
1560 for (x = 0; x < b; x++) { in mp_lshd()
1595 mp_mod_2d (mp_int * a, int b, mp_int * c) in mp_mod_2d() argument
1600 if (b <= 0) { in mp_mod_2d()
1606 if (b >= (int) (a->used * DIGIT_BIT)) { in mp_mod_2d()
1617 for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) { in mp_mod_2d()
1621 c->dp[b / DIGIT_BIT] &= in mp_mod_2d()
1622 (mp_digit) ((((mp_digit) 1) << (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1)); in mp_mod_2d()
1632 mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d) in mp_div() argument
1638 if (mp_iszero (b) == 1) { in mp_div()
1643 if (mp_cmp_mag (a, b) == MP_LT) { in mp_div()
1662 n = mp_count_bits(a) - mp_count_bits(b); in mp_div()
1664 ((res = mp_abs(b, &tb)) != MP_OKAY) || in mp_div()
1685 n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG); in mp_div()
1715 mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) in mp_div() argument
1721 if (mp_iszero (b) == 1) { in mp_div()
1726 if (mp_cmp_mag (a, b) == MP_LT) { in mp_div()
1755 if ((res = mp_init_copy (&y, b)) != MP_OKAY) { in mp_div()
1760 neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; in mp_div()
2137 mp_sqr (mp_int * a, mp_int * b) in mp_sqr() argument
2144 res = mp_toom_sqr(a, b); in mp_sqr()
2150 res = mp_karatsuba_sqr (a, b); in mp_sqr()
2159 res = fast_s_mp_sqr (a, b); in mp_sqr()
2163 res = s_mp_sqr (a, b); in mp_sqr()
2169 b->sign = MP_ZPOS; in mp_sqr()
2247 mp_2expt (mp_int * a, int b) in mp_2expt() argument
2255 if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) { in mp_2expt()
2260 a->used = b / DIGIT_BIT + 1; in mp_2expt()
2263 a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT); in mp_2expt()
2273 mp_reduce_setup (mp_int * a, mp_int * b) in mp_reduce_setup() argument
2277 if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) { in mp_reduce_setup()
2280 return mp_div (a, b, a, NULL); in mp_reduce_setup()
2373 s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) in s_mp_mul_digs() argument
2383 MIN (a->used, b->used) < in s_mp_mul_digs()
2385 return fast_s_mp_mul_digs (a, b, c, digs); in s_mp_mul_digs()
2400 pb = MIN (b->used, digs - ix); in s_mp_mul_digs()
2410 tmpy = b->dp; in s_mp_mul_digs()
2456 fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) in fast_s_mp_mul_digs() argument
2470 pa = MIN(digs, a->used + b->used); in fast_s_mp_mul_digs()
2480 ty = MIN(b->used-1, ix); in fast_s_mp_mul_digs()
2485 tmpy = b->dp + ty; in fast_s_mp_mul_digs()
2558 s_mp_sqr (mp_int * a, mp_int * b) in s_mp_sqr() argument
2615 mp_exch (&t, b); in s_mp_sqr()
2625 s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) in s_mp_mul_high_digs() argument
2635 if (((a->used + b->used + 1) < MP_WARRAY) in s_mp_mul_high_digs()
2636 && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { in s_mp_mul_high_digs()
2637 return fast_s_mp_mul_high_digs (a, b, c, digs); in s_mp_mul_high_digs()
2641 if ((res = mp_init_size (&t, a->used + b->used + 1)) != MP_OKAY) { in s_mp_mul_high_digs()
2644 t.used = a->used + b->used + 1; in s_mp_mul_high_digs()
2647 pb = b->used; in s_mp_mul_high_digs()
2659 tmpy = b->dp + (digs - ix); in s_mp_mul_high_digs()
2687 mp_digit x, b; in mp_montgomery_setup() local
2697 b = n->dp[0]; in mp_montgomery_setup()
2699 if ((b & 1) == 0) { in mp_montgomery_setup()
2703 x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ in mp_montgomery_setup()
2704 x *= 2 - b * x; /* here x*a==1 mod 2**8 */ in mp_montgomery_setup()
2706 x *= 2 - b * x; /* here x*a==1 mod 2**16 */ in mp_montgomery_setup()
2709 x *= 2 - b * x; /* here x*a==1 mod 2**32 */ in mp_montgomery_setup()
2712 x *= 2 - b * x; /* here x*a==1 mod 2**64 */ in mp_montgomery_setup()
2881 mp_mul_2(mp_int * a, mp_int * b) in mp_mul_2() argument
2886 if (b->alloc < a->used + 1) { in mp_mul_2()
2887 if ((res = mp_grow (b, a->used + 1)) != MP_OKAY) { in mp_mul_2()
2892 oldused = b->used; in mp_mul_2()
2893 b->used = a->used; in mp_mul_2()
2902 tmpb = b->dp; in mp_mul_2()
2926 ++(b->used); in mp_mul_2()
2932 tmpb = b->dp + b->used; in mp_mul_2()
2933 for (x = b->used; x < oldused; x++) { in mp_mul_2()
2937 b->sign = a->sign; in mp_mul_2()
2951 mp_montgomery_calc_normalization (mp_int * a, mp_int * b) in mp_montgomery_calc_normalization() argument
2956 bits = mp_count_bits (b) % DIGIT_BIT; in mp_montgomery_calc_normalization()
2958 if (b->used > 1) { in mp_montgomery_calc_normalization()
2959 if ((res = mp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1)) != MP_OKAY) { in mp_montgomery_calc_normalization()
2973 if (mp_cmp_mag (a, b) != MP_LT) { in mp_montgomery_calc_normalization()
2974 if ((res = s_mp_sub (a, b, a)) != MP_OKAY) { in mp_montgomery_calc_normalization()
3294 fast_s_mp_sqr (mp_int * a, mp_int * b) in fast_s_mp_sqr() argument
3302 if (b->alloc < pa) { in fast_s_mp_sqr()
3303 if ((res = mp_grow (b, pa)) != MP_OKAY) { in fast_s_mp_sqr()
3358 olduse = b->used; in fast_s_mp_sqr()
3359 b->used = a->used+a->used; in fast_s_mp_sqr()
3363 tmpb = b->dp; in fast_s_mp_sqr()
3373 mp_clamp (b); in fast_s_mp_sqr()
3382 mp_mul_d (mp_int * a, mp_digit b, mp_int * c) in mp_mul_d() argument
3413 r = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b); in mp_mul_d()