Lines Matching +full:mu +full:- +full:side +full:- +full:b
4 * http://libtom.org/files/ltm-0.41.tar.bz2
84 #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
86 #define MP_LT -1 /* less than */
94 #define MP_MEM -2 /* out of mem */
95 #define MP_VAL -3 /* invalid input */
114 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
115 #define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
124 /* ---> Basic Manipulations <--- */
125 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
126 #define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
127 #define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
131 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) argument
133 static int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
134 static int s_mp_sqr(mp_int * a, mp_int * b);
135 static int s_mp_mul_high_digs(mp_int * a, mp_int * b, mp_int * c, int digs);
138 static int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
147 static int mp_lshd(mp_int * a, int b);
148 static void mp_set(mp_int * a, mp_digit b);
150 static void mp_exch(mp_int * a, mp_int * b);
151 static void mp_rshd(mp_int * a, int b);
153 static int mp_mod_2d(mp_int * a, int b, mp_int * c);
154 static int mp_div_2d(mp_int * a, int b, mp_int * c, mp_int * d);
155 static int mp_init_copy(mp_int * a, mp_int * b);
156 static int mp_mul_2d(mp_int * a, int b, mp_int * c);
158 static int mp_div_2(mp_int * a, mp_int * b);
159 static int mp_invmod(mp_int * a, mp_int * b, mp_int * c);
160 static int mp_invmod_slow(mp_int * a, mp_int * b, mp_int * c);
162 static int mp_copy(mp_int * a, mp_int * b);
164 static int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d);
165 static int mp_mod(mp_int * a, mp_int * b, mp_int * c);
167 static int mp_cmp_mag(mp_int * a, mp_int * b);
169 static int mp_abs(mp_int * a, mp_int * b);
171 static int mp_sqr(mp_int * a, mp_int * b);
174 static int mp_2expt(mp_int * a, int b);
175 static int mp_reduce_setup(mp_int * a, mp_int * b);
176 static int mp_reduce(mp_int * x, mp_int * m, mp_int * mu);
182 static int fast_s_mp_sqr (mp_int * a, mp_int * b);
185 static int mp_mul_d (mp_int * a, mp_digit b, mp_int * c);
200 iy = len - 1; in bn_reverse()
206 --iy; in bn_reverse()
212 static int s_mp_add (mp_int * a, mp_int * b, mp_int * c) in s_mp_add() argument
217 /* find sizes, we let |a| <= |b| which means we have to sort in s_mp_add()
220 if (a->used > b->used) { in s_mp_add()
221 min = b->used; in s_mp_add()
222 max = a->used; in s_mp_add()
225 min = a->used; in s_mp_add()
226 max = b->used; in s_mp_add()
227 x = b; in s_mp_add()
231 if (c->alloc < max + 1) { in s_mp_add()
238 olduse = c->used; in s_mp_add()
239 c->used = max + 1; in s_mp_add()
248 tmpa = a->dp; in s_mp_add()
251 tmpb = b->dp; in s_mp_add()
254 tmpc = c->dp; in s_mp_add()
259 /* Compute the sum at one digit, T[i] = A[i] + B[i] + U */ in s_mp_add()
269 /* now copy higher words if any, that is in A+B in s_mp_add()
270 * if A or B has more digits add those in in s_mp_add()
275 *tmpc = x->dp[i] + u; in s_mp_add()
289 for (i = c->used; i < olduse; i++) { in s_mp_add()
299 /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
300 static int 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()
306 max = a->used; in s_mp_sub()
309 if (c->alloc < max) { in s_mp_sub()
314 olduse = c->used; in s_mp_sub()
315 c->used = max; in s_mp_sub()
322 tmpa = a->dp; in s_mp_sub()
323 tmpb = b->dp; in s_mp_sub()
324 tmpc = c->dp; in s_mp_sub()
329 /* T[i] = A[i] - B[i] - U */ in s_mp_sub()
330 *tmpc = *tmpa++ - *tmpb++ - u; in s_mp_sub()
337 u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1)); in s_mp_sub()
343 /* now copy higher words if any, e.g. if A has more digits than B */ in s_mp_sub()
345 /* T[i] = A[i] - U */ in s_mp_sub()
346 *tmpc = *tmpa++ - u; in s_mp_sub()
349 u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1)); in s_mp_sub()
356 for (i = c->used; i < olduse; i++) { in s_mp_sub()
372 a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * MP_PREC); in mp_init()
373 if (a->dp == NULL) { in mp_init()
379 a->dp[i] = 0; in mp_init()
384 a->used = 0; in mp_init()
385 a->alloc = MP_PREC; in mp_init()
386 a->sign = MP_ZPOS; in mp_init()
398 if (a->dp != NULL) { in mp_clear()
400 for (i = 0; i < a->used; i++) { in mp_clear()
401 a->dp[i] = 0; in mp_clear()
405 XFREE(a->dp); in mp_clear()
408 a->dp = NULL; in mp_clear()
409 a->alloc = a->used = 0; in mp_clear()
410 a->sign = MP_ZPOS; in mp_clear()
416 static int mp_add (mp_int * a, mp_int * b, mp_int * c) in mp_add() argument
421 sa = a->sign; in mp_add()
422 sb = b->sign; in mp_add()
428 c->sign = sa; in mp_add()
429 res = s_mp_add (a, b, c); in mp_add()
435 if (mp_cmp_mag (a, b) == MP_LT) { in mp_add()
436 c->sign = sb; in mp_add()
437 res = s_mp_sub (b, a, c); in mp_add()
439 c->sign = sa; in mp_add()
440 res = s_mp_sub (a, b, c); in mp_add()
448 static int mp_sub (mp_int * a, mp_int * b, mp_int * c) in mp_sub() argument
452 sa = a->sign; in mp_sub()
453 sb = b->sign; in mp_sub()
460 c->sign = sa; in mp_sub()
461 res = s_mp_add (a, b, c); in mp_sub()
467 if (mp_cmp_mag (a, b) != MP_LT) { in mp_sub()
469 c->sign = sa; in mp_sub()
471 res = s_mp_sub (a, b, c); in mp_sub()
475 c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS; in mp_sub()
477 res = s_mp_sub (b, a, c); in mp_sub()
485 static int mp_mul (mp_int * a, mp_int * b, mp_int * c) in mp_mul() argument
488 neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; in mp_mul()
490 /* use Toom-Cook? */ in mp_mul()
492 if (MIN (a->used, b->used) >= TOOM_MUL_CUTOFF) { in mp_mul()
493 res = mp_toom_mul(a, b, c); in mp_mul()
498 if (MIN (a->used, b->used) >= KARATSUBA_MUL_CUTOFF) { in mp_mul()
499 res = mp_karatsuba_mul (a, b, c); in mp_mul()
510 int digs = a->used + b->used + 1; in mp_mul()
513 MIN(a->used, b->used) <= in mp_mul()
514 (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { in mp_mul()
515 res = fast_s_mp_mul_digs (a, b, c, digs); in mp_mul()
519 res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */ in mp_mul()
526 c->sign = (c->used > 0) ? neg : MP_ZPOS; in mp_mul()
531 /* d = a * b (mod c) */
532 static int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) in mp_mulmod() argument
541 if ((res = mp_mul (a, b, &t)) != MP_OKAY) { in mp_mulmod()
551 /* c = a mod b, 0 <= c < b */
552 static int mp_mod (mp_int * a, mp_int * b, mp_int * c) in mp_mod() argument
561 if ((res = mp_div (a, b, NULL, &t)) != MP_OKAY) { in mp_mod()
566 if (t.sign != b->sign) { in mp_mod()
567 res = mp_add (b, &t, c); in mp_mod()
588 if (P->sign == MP_NEG) { in mp_exptmod()
593 if (X->sign == MP_NEG) { in mp_exptmod()
678 static int mp_cmp (mp_int * a, mp_int * b) in mp_cmp() argument
681 if (a->sign != b->sign) { in mp_cmp()
682 if (a->sign == MP_NEG) { in mp_cmp()
690 if (a->sign == MP_NEG) { in mp_cmp()
692 return mp_cmp_mag(b, a); in mp_cmp()
694 return mp_cmp_mag(a, b); in mp_cmp()
700 static int mp_cmp_d(mp_int * a, mp_digit b) in mp_cmp_d() argument
703 if (a->sign == MP_NEG) { in mp_cmp_d()
708 if (a->used > 1) { in mp_cmp_d()
712 /* compare the only digit of a to b */ in mp_cmp_d()
713 if (a->dp[0] > b) { in mp_cmp_d()
715 } else if (a->dp[0] < b) { in mp_cmp_d()
725 static int mp_invmod (mp_int * a, mp_int * b, mp_int * c) in mp_invmod() argument
727 /* b cannot be negative */ in mp_invmod()
728 if (b->sign == MP_NEG || mp_iszero(b) == 1) { in mp_invmod()
734 if (mp_isodd (b) == 1) { in mp_invmod()
735 return fast_mp_invmod (a, b, c); in mp_invmod()
740 return mp_invmod_slow(a, b, c); in mp_invmod()
763 static int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c) in mp_invmod_slow() argument
765 mp_int x, y, u, v, A, B, C, D; in mp_invmod_slow() local
768 /* b cannot be negative */ in mp_invmod_slow()
769 if (b->sign == MP_NEG || mp_iszero(b) == 1) { in mp_invmod_slow()
775 &A, &B, &C, &D, NULL)) != MP_OKAY) { in mp_invmod_slow()
779 /* x = a, y = b */ in mp_invmod_slow()
780 if ((res = mp_mod(a, b, &x)) != MP_OKAY) { in mp_invmod_slow()
783 if ((res = mp_copy (b, &y)) != MP_OKAY) { in mp_invmod_slow()
793 /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */ in mp_invmod_slow()
810 /* 4.2 if A or B is odd then */ in mp_invmod_slow()
811 if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) { in mp_invmod_slow()
812 /* A = (A+y)/2, B = (B-x)/2 */ in mp_invmod_slow()
816 if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) { in mp_invmod_slow()
820 /* A = A/2, B = B/2 */ in mp_invmod_slow()
824 if ((res = mp_div_2 (&B, &B)) != MP_OKAY) { in mp_invmod_slow()
837 /* C = (C+y)/2, D = (D-x)/2 */ in mp_invmod_slow()
856 /* u = u - v, A = A - C, B = B - D */ in mp_invmod_slow()
865 if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) { in mp_invmod_slow()
869 /* v - v - u, C = C - A, D = D - B */ in mp_invmod_slow()
878 if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) { in mp_invmod_slow()
887 /* now a = C, b = D, gcd == g*v */ in mp_invmod_slow()
897 if ((res = mp_add(&C, b, &C)) != MP_OKAY) { in mp_invmod_slow()
903 while (mp_cmp_mag(&C, b) != MP_LT) { in mp_invmod_slow()
904 if ((res = mp_sub(&C, b, &C)) != MP_OKAY) { in mp_invmod_slow()
912 LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL); in mp_invmod_slow()
919 static int mp_cmp_mag (mp_int * a, mp_int * b) in mp_cmp_mag() argument
924 /* compare based on # of non-zero digits */ in mp_cmp_mag()
925 if (a->used > b->used) { in mp_cmp_mag()
929 if (a->used < b->used) { in mp_cmp_mag()
934 tmpa = a->dp + (a->used - 1); in mp_cmp_mag()
936 /* alias for b */ in mp_cmp_mag()
937 tmpb = b->dp + (a->used - 1); in mp_cmp_mag()
940 for (n = 0; n < a->used; ++n, --tmpa, --tmpb) { in mp_cmp_mag()
954 static int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c) in mp_read_unsigned_bin() argument
959 if (a->alloc < 2) { in mp_read_unsigned_bin()
969 while (c-- > 0) { in mp_read_unsigned_bin()
975 a->dp[0] |= *b++; in mp_read_unsigned_bin()
976 a->used += 1; in mp_read_unsigned_bin()
978 a->dp[0] = (*b & MP_MASK); in mp_read_unsigned_bin()
979 a->dp[1] |= ((*b++ >> 7U) & 1); in mp_read_unsigned_bin()
980 a->used += 2; in mp_read_unsigned_bin()
989 static int mp_to_unsigned_bin (mp_int * a, unsigned char *b) in mp_to_unsigned_bin() argument
1001 b[x++] = (unsigned char) (t.dp[0] & 255); in mp_to_unsigned_bin()
1003 b[x++] = (unsigned char) (t.dp[0] | ((t.dp[1] & 0x01) << 7)); in mp_to_unsigned_bin()
1010 bn_reverse (b, x); in mp_to_unsigned_bin()
1017 static int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) in mp_div_2d() argument
1025 if (b <= 0) { in mp_div_2d()
1039 if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) { in mp_div_2d()
1052 if (b >= (int)DIGIT_BIT) { in mp_div_2d()
1053 mp_rshd (c, b / DIGIT_BIT); in mp_div_2d()
1057 D = (mp_digit) (b % DIGIT_BIT); in mp_div_2d()
1062 mask = (((mp_digit)1) << D) - 1; in mp_div_2d()
1065 shift = DIGIT_BIT - D; in mp_div_2d()
1068 tmpc = c->dp + (c->used - 1); in mp_div_2d()
1072 for (x = c->used - 1; x >= 0; x--) { in mp_div_2d()
1078 --tmpc; in mp_div_2d()
1093 static int mp_init_copy (mp_int * a, mp_int * b) in mp_init_copy() argument
1100 return mp_copy (b, a); in mp_init_copy()
1110 a->sign = MP_ZPOS; in mp_zero()
1111 a->used = 0; in mp_zero()
1113 tmp = a->dp; in mp_zero()
1114 for (n = 0; n < a->alloc; n++) { in mp_zero()
1120 /* copy, b = a */
1121 static int mp_copy (mp_int * a, mp_int * b) in mp_copy() argument
1126 if (a == b) { in mp_copy()
1131 if (b->alloc < a->used) { in mp_copy()
1132 if ((res = mp_grow (b, a->used)) != MP_OKAY) { in mp_copy()
1137 /* zero b and copy the parameters over */ in mp_copy()
1144 tmpa = a->dp; in mp_copy()
1147 tmpb = b->dp; in mp_copy()
1150 for (n = 0; n < a->used; n++) { in mp_copy()
1155 for (; n < b->used; n++) { in mp_copy()
1161 b->used = a->used; in mp_copy()
1162 b->sign = a->sign; in mp_copy()
1168 static void mp_rshd (mp_int * a, int b) in mp_rshd() argument
1172 /* if b <= 0 then ignore it */ in mp_rshd()
1173 if (b <= 0) { in mp_rshd()
1177 /* if b > used then simply zero it and return */ in mp_rshd()
1178 if (a->used <= b) { in mp_rshd()
1189 bottom = a->dp; in mp_rshd()
1192 top = a->dp + b; in mp_rshd()
1195 * the window is b-digits long and digits from in mp_rshd()
1200 b-2 | b-1 | b0 | b1 | b2 | ... | bb | ----> in mp_rshd()
1201 /\ | ----> in mp_rshd()
1202 \-------------------/ ----> in mp_rshd()
1204 for (x = 0; x < (a->used - b); x++) { in mp_rshd()
1209 for (; x < a->used; x++) { in mp_rshd()
1215 a->used -= b; in mp_rshd()
1222 static void mp_exch (mp_int * a, mp_int * b) in mp_exch() argument
1227 *a = *b; in mp_exch()
1228 *b = t; in mp_exch()
1235 * trimed and the leading "used" digit will be non-zero
1244 while (a->used > 0 && a->dp[a->used - 1] == 0) { in mp_clamp()
1245 --(a->used); in mp_clamp()
1249 if (a->used == 0) { in mp_clamp()
1250 a->sign = MP_ZPOS; in mp_clamp()
1262 if (a->alloc < size) { in mp_grow()
1264 size += (MP_PREC * 2) - (size % MP_PREC); in mp_grow()
1266 /* reallocate the array a->dp in mp_grow()
1272 tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * size); in mp_grow()
1278 /* reallocation succeeded so set a->dp */ in mp_grow()
1279 a->dp = tmp; in mp_grow()
1282 i = a->alloc; in mp_grow()
1283 a->alloc = size; in mp_grow()
1284 for (; i < a->alloc; i++) { in mp_grow()
1285 a->dp[i] = 0; in mp_grow()
1293 /* b = |a|
1297 static int mp_abs (mp_int * a, mp_int * b) in mp_abs() argument
1301 /* copy a to b */ in mp_abs()
1302 if (a != b) { in mp_abs()
1303 if ((res = mp_copy (a, b)) != MP_OKAY) { in mp_abs()
1308 /* force the sign of b to positive */ in mp_abs()
1309 b->sign = MP_ZPOS; in mp_abs()
1317 static void mp_set (mp_int * a, mp_digit b) in mp_set() argument
1320 a->dp[0] = b & MP_MASK; in mp_set()
1321 a->used = (a->dp[0] != 0) ? 1 : 0; in mp_set()
1326 /* b = a/2 */
1327 static int mp_div_2(mp_int * a, mp_int * b) in mp_div_2() argument
1332 if (b->alloc < a->used) { in mp_div_2()
1333 if ((res = mp_grow (b, a->used)) != MP_OKAY) { in mp_div_2()
1338 oldused = b->used; in mp_div_2()
1339 b->used = a->used; in mp_div_2()
1344 tmpa = a->dp + b->used - 1; in mp_div_2()
1347 tmpb = b->dp + b->used - 1; in mp_div_2()
1351 for (x = b->used - 1; x >= 0; x--) { in mp_div_2()
1356 *tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1)); in mp_div_2()
1363 tmpb = b->dp + b->used; in mp_div_2()
1364 for (x = b->used; x < oldused; x++) { in mp_div_2()
1368 b->sign = a->sign; in mp_div_2()
1369 mp_clamp (b); in mp_div_2()
1376 static int mp_mul_2d (mp_int * a, int b, mp_int * c) in mp_mul_2d() argument
1388 if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) { in mp_mul_2d()
1389 if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) { in mp_mul_2d()
1395 if (b >= (int)DIGIT_BIT) { in mp_mul_2d()
1396 if ((res = mp_lshd (c, b / DIGIT_BIT)) != MP_OKAY) { in mp_mul_2d()
1402 d = (mp_digit) (b % DIGIT_BIT); in mp_mul_2d()
1408 mask = (((mp_digit)1) << d) - 1; in mp_mul_2d()
1411 shift = DIGIT_BIT - d; in mp_mul_2d()
1414 tmpc = c->dp; in mp_mul_2d()
1418 for (x = 0; x < c->used; x++) { in mp_mul_2d()
1432 c->dp[(c->used)++] = r; in mp_mul_2d()
1451 /* Oops - error! Back-track and mp_clear what we already in mp_init_multi()
1452 succeeded in init-ing, then return error. in mp_init_multi()
1462 while (n--) { in mp_init_multi()
1494 static int mp_lshd (mp_int * a, int b) in mp_lshd() argument
1499 if (b <= 0) { in mp_lshd()
1504 if (a->alloc < a->used + b) { in mp_lshd()
1505 if ((res = mp_grow (a, a->used + b)) != MP_OKAY) { in mp_lshd()
1514 a->used += b; in mp_lshd()
1517 top = a->dp + a->used - 1; in mp_lshd()
1520 bottom = a->dp + a->used - 1 - b; in mp_lshd()
1526 for (x = a->used - 1; x >= b; x--) { in mp_lshd()
1527 *top-- = *bottom--; in mp_lshd()
1531 top = a->dp; in mp_lshd()
1532 for (x = 0; x < b; x++) { in mp_lshd()
1547 if (a->used == 0) { in mp_count_bits()
1552 r = (a->used - 1) * DIGIT_BIT; in mp_count_bits()
1555 q = a->dp[a->used - 1]; in mp_count_bits()
1564 /* calc a value mod 2**b */
1565 static int mp_mod_2d (mp_int * a, int b, mp_int * c) in mp_mod_2d() argument
1569 /* if b is <= 0 then zero the int */ in mp_mod_2d()
1570 if (b <= 0) { in mp_mod_2d()
1576 if (b >= (int) (a->used * DIGIT_BIT)) { in mp_mod_2d()
1587 for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) { in mp_mod_2d()
1588 c->dp[x] = 0; in mp_mod_2d()
1591 c->dp[b / DIGIT_BIT] &= in mp_mod_2d()
1592 (mp_digit) ((((mp_digit) 1) << (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1)); in mp_mod_2d()
1600 /* slower bit-bang division... also smaller */
1601 static int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d) in mp_div() argument
1607 if (mp_iszero (b) == 1) { in mp_div()
1611 /* if a < b then q=0, r = a */ in mp_div()
1612 if (mp_cmp_mag (a, b) == MP_LT) { in mp_div()
1631 n = mp_count_bits(a) - mp_count_bits(b); in mp_div()
1633 ((res = mp_abs(b, &tb)) != MP_OKAY) || in mp_div()
1639 while (n-- >= 0) { in mp_div()
1653 n = a->sign; in mp_div()
1654 n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG); in mp_div()
1657 c->sign = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2; in mp_div()
1661 d->sign = (mp_iszero(d) == MP_YES) ? MP_ZPOS : n; in mp_div()
1671 * c*b + d == a [e.g. a/b, c=quotient, d=remainder]
1683 static int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) in mp_div() argument
1689 if (mp_iszero (b) == 1) { in mp_div()
1693 /* if a < b then q=0, r = a */ in mp_div()
1694 if (mp_cmp_mag (a, b) == MP_LT) { in mp_div()
1706 if ((res = mp_init_size (&q, a->used + 2)) != MP_OKAY) { in mp_div()
1709 q.used = a->used + 2; in mp_div()
1723 if ((res = mp_init_copy (&y, b)) != MP_OKAY) { in mp_div()
1728 neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; in mp_div()
1731 /* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */ in mp_div()
1733 if (norm < (int)(DIGIT_BIT-1)) { in mp_div()
1734 norm = (DIGIT_BIT-1) - norm; in mp_div()
1746 n = x.used - 1; in mp_div()
1747 t = y.used - 1; in mp_div()
1749 /* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */ in mp_div()
1750 if ((res = mp_lshd (&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */ in mp_div()
1755 ++(q.dp[n - t]); in mp_div()
1762 mp_rshd (&y, n - t); in mp_div()
1765 for (i = n; i >= (t + 1); i--) { in mp_div()
1770 /* step 3.1 if xi == yt then set q{i-t-1} to b-1, in mp_div()
1771 * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */ in mp_div()
1773 q.dp[i - t - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1); in mp_div()
1777 tmp |= ((mp_word) x.dp[i - 1]); in mp_div()
1781 q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK)); in mp_div()
1784 /* while (q{i-t-1} * (yt * b + y{t-1})) > in mp_div()
1785 xi * b**2 + xi-1 * b + xi-2 in mp_div()
1787 do q{i-t-1} -= 1; in mp_div()
1789 q.dp[i - t - 1] = (q.dp[i - t - 1] + 1) & MP_MASK; in mp_div()
1791 q.dp[i - t - 1] = (q.dp[i - t - 1] - 1) & MP_MASK; in mp_div()
1795 t1.dp[0] = (t - 1 < 0) ? 0 : y.dp[t - 1]; in mp_div()
1798 if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) { in mp_div()
1803 t2.dp[0] = (i - 2 < 0) ? 0 : x.dp[i - 2]; in mp_div()
1804 t2.dp[1] = (i - 1 < 0) ? 0 : x.dp[i - 1]; in mp_div()
1809 /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */ in mp_div()
1810 if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) { in mp_div()
1814 if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) { in mp_div()
1822 /* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */ in mp_div()
1827 if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) { in mp_div()
1834 q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK; in mp_div()
1843 x.sign = x.used == 0 ? MP_ZPOS : a->sign; in mp_div()
1848 c->sign = neg; in mp_div()
1877 mp_int M[TAB_SIZE], res, mu; in s_mp_exptmod() local
1913 for (x = 1<<(winsize-1); x < (1 << winsize); x++) { in s_mp_exptmod()
1915 for (y = 1<<(winsize-1); y < x; y++) { in s_mp_exptmod()
1923 /* create mu, used for Barrett reduction */ in s_mp_exptmod()
1924 if ((err = mp_init (&mu)) != MP_OKAY) { in s_mp_exptmod()
1929 if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) { in s_mp_exptmod()
1934 if ((err = mp_reduce_2k_setup_l (P, &mu)) != MP_OKAY) { in s_mp_exptmod()
1952 /* compute the value at M[1<<(winsize-1)] by squaring in s_mp_exptmod()
1953 * M[1] (winsize-1) times in s_mp_exptmod()
1955 if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) { in s_mp_exptmod()
1959 for (x = 0; x < (winsize - 1); x++) { in s_mp_exptmod()
1961 if ((err = mp_sqr (&M[1 << (winsize - 1)], in s_mp_exptmod()
1962 &M[1 << (winsize - 1)])) != MP_OKAY) { in s_mp_exptmod()
1967 if ((err = redux (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) { in s_mp_exptmod()
1972 /* create upper table, that is M[x] = M[x-1] * M[1] (mod P) in s_mp_exptmod()
1973 * for x = (2**(winsize - 1) + 1) to (2**winsize - 1) in s_mp_exptmod()
1975 for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) { in s_mp_exptmod()
1976 if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) { in s_mp_exptmod()
1979 if ((err = redux (&M[x], P, &mu)) != MP_OKAY) { in s_mp_exptmod()
1994 digidx = X->used - 1; in s_mp_exptmod()
2000 if (--bitcnt == 0) { in s_mp_exptmod()
2001 /* if digidx == -1 we are out of digits */ in s_mp_exptmod()
2002 if (digidx == -1) { in s_mp_exptmod()
2006 buf = X->dp[digidx--]; in s_mp_exptmod()
2011 y = (buf >> (mp_digit)(DIGIT_BIT - 1)) & 1; in s_mp_exptmod()
2028 if ((err = redux (&res, P, &mu)) != MP_OKAY) { in s_mp_exptmod()
2035 bitbuf |= (y << (winsize - ++bitcpy)); in s_mp_exptmod()
2045 if ((err = redux (&res, P, &mu)) != MP_OKAY) { in s_mp_exptmod()
2054 if ((err = redux (&res, P, &mu)) != MP_OKAY) { in s_mp_exptmod()
2072 if ((err = redux (&res, P, &mu)) != MP_OKAY) { in s_mp_exptmod()
2082 if ((err = redux (&res, P, &mu)) != MP_OKAY) { in s_mp_exptmod()
2092 LBL_MU:mp_clear (&mu); in s_mp_exptmod()
2095 for (x = 1<<(winsize-1); x < (1 << winsize); x++) { in s_mp_exptmod()
2102 /* computes b = a*a */
2103 static int mp_sqr (mp_int * a, mp_int * b) in mp_sqr() argument
2108 /* use Toom-Cook? */ in mp_sqr()
2109 if (a->used >= TOOM_SQR_CUTOFF) { in mp_sqr()
2110 res = mp_toom_sqr(a, b); in mp_sqr()
2115 if (a->used >= KARATSUBA_SQR_CUTOFF) { in mp_sqr()
2116 res = mp_karatsuba_sqr (a, b); in mp_sqr()
2122 if ((a->used * 2 + 1) < MP_WARRAY && in mp_sqr()
2123 a->used < in mp_sqr()
2124 (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) { in mp_sqr()
2125 res = fast_s_mp_sqr (a, b); in mp_sqr()
2129 res = s_mp_sqr (a, b); in mp_sqr()
2135 b->sign = MP_ZPOS; in mp_sqr()
2140 /* reduces a modulo n where n is of the form 2**p - d
2205 /* computes a = 2**b
2210 static int mp_2expt (mp_int * a, int b) in mp_2expt() argument
2218 if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) { in mp_2expt()
2223 a->used = b / DIGIT_BIT + 1; in mp_2expt()
2226 a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT); in mp_2expt()
2232 /* pre-calculate the value required for Barrett reduction
2233 * For a given modulus "b" it calulates the value required in "a"
2235 static int mp_reduce_setup (mp_int * a, mp_int * b) in mp_reduce_setup() argument
2239 if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) { in mp_reduce_setup()
2242 return mp_div (a, b, a, NULL); in mp_reduce_setup()
2246 /* reduces x mod m, assumes 0 < x < m**2, mu is
2250 static int mp_reduce (mp_int * x, mp_int * m, mp_int * mu) in mp_reduce() argument
2253 int res, um = m->used; in mp_reduce()
2260 /* q1 = x / b**(k-1) */ in mp_reduce()
2261 mp_rshd (&q, um - 1); in mp_reduce()
2264 if (((unsigned long) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) { in mp_reduce()
2265 if ((res = mp_mul (&q, mu, &q)) != MP_OKAY) { in mp_reduce()
2270 if ((res = s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) { in mp_reduce()
2274 if ((res = fast_s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) { in mp_reduce()
2286 /* q3 = q2 / b**(k+1) */ in mp_reduce()
2289 /* x = x mod b**(k+1), quick (no division) */ in mp_reduce()
2294 /* q = q * m mod b**(k+1), quick (no division) */ in mp_reduce()
2299 /* x = x - q */ in mp_reduce()
2304 /* If x < 0, add b**(k+1) to it */ in mp_reduce()
2329 /* multiplies |a| * |b| and only computes up to digs digits of result
2333 static int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) in s_mp_mul_digs() argument
2344 MIN (a->used, b->used) < in s_mp_mul_digs()
2345 (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { in s_mp_mul_digs()
2346 return fast_s_mp_mul_digs (a, b, c, digs); in s_mp_mul_digs()
2356 pa = a->used; in s_mp_mul_digs()
2362 pb = MIN (b->used, digs - ix); in s_mp_mul_digs()
2366 tmpx = a->dp[ix]; in s_mp_mul_digs()
2371 /* an alias for the digits of b */ in s_mp_mul_digs()
2372 tmpy = b->dp; in s_mp_mul_digs()
2404 * This is the fast column-array [comba] multiplier. It is
2408 * simple and schedulable on super-scalar processors.
2411 * digits of output so if say only a half-product is required
2418 static int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) in fast_s_mp_mul_digs() argument
2425 if (c->alloc < digs) { in fast_s_mp_mul_digs()
2432 pa = MIN(digs, a->used + b->used); in fast_s_mp_mul_digs()
2443 ty = MIN(b->used-1, ix); in fast_s_mp_mul_digs()
2444 tx = ix - ty; in fast_s_mp_mul_digs()
2447 tmpx = a->dp + tx; in fast_s_mp_mul_digs()
2448 tmpy = b->dp + ty; in fast_s_mp_mul_digs()
2451 while (tx++ < a->used && ty-- >= 0) { ... } in fast_s_mp_mul_digs()
2453 iy = MIN(a->used-tx, ty+1); in fast_s_mp_mul_digs()
2457 _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--); in fast_s_mp_mul_digs()
2469 olduse = c->used; in fast_s_mp_mul_digs()
2470 c->used = pa; in fast_s_mp_mul_digs()
2474 tmpc = c->dp; in fast_s_mp_mul_digs()
2497 size += (MP_PREC * 2) - (size % MP_PREC); in mp_init_size()
2500 a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * size); in mp_init_size()
2501 if (a->dp == NULL) { in mp_init_size()
2506 a->used = 0; in mp_init_size()
2507 a->alloc = size; in mp_init_size()
2508 a->sign = MP_ZPOS; in mp_init_size()
2512 a->dp[x] = 0; in mp_init_size()
2519 /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
2520 static int s_mp_sqr (mp_int * a, mp_int * b) in s_mp_sqr() argument
2527 pa = a->used; in s_mp_sqr()
2539 ((mp_word)a->dp[ix])*((mp_word)a->dp[ix]); in s_mp_sqr()
2547 /* left hand side of A[ix] * A[iy] */ in s_mp_sqr()
2548 tmpx = a->dp[ix]; in s_mp_sqr()
2555 r = ((mp_word)tmpx) * ((mp_word)a->dp[iy]); in s_mp_sqr()
2577 mp_exch (&t, b); in s_mp_sqr()
2583 /* multiplies |a| * |b| and does not compute the lower digs digits
2586 static int s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) in s_mp_mul_high_digs() argument
2596 if (((a->used + b->used + 1) < MP_WARRAY) in s_mp_mul_high_digs()
2597 && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { in s_mp_mul_high_digs()
2598 return fast_s_mp_mul_high_digs (a, b, c, digs); in s_mp_mul_high_digs()
2602 if ((res = mp_init_size (&t, a->used + b->used + 1)) != MP_OKAY) { in s_mp_mul_high_digs()
2605 t.used = a->used + b->used + 1; in s_mp_mul_high_digs()
2607 pa = a->used; in s_mp_mul_high_digs()
2608 pb = b->used; in s_mp_mul_high_digs()
2613 /* left hand side of A[ix] * B[iy] */ in s_mp_mul_high_digs()
2614 tmpx = a->dp[ix]; in s_mp_mul_high_digs()
2619 /* alias for where to read the right hand side from */ in s_mp_mul_high_digs()
2620 tmpy = b->dp + (digs - ix); in s_mp_mul_high_digs()
2622 for (iy = digs - ix; iy < pb; iy++) { in s_mp_mul_high_digs()
2648 mp_digit x, b; in mp_montgomery_setup() local
2654 * XA = 1 (mod 2**n) => (X(2-XA)) A = 1 (mod 2**2n) in mp_montgomery_setup()
2655 * => 2*X*A - X*X*A*A = 1 in mp_montgomery_setup()
2656 * => 2*(1) - (1) = 1 in mp_montgomery_setup()
2658 b = n->dp[0]; in mp_montgomery_setup()
2660 if ((b & 1) == 0) { in mp_montgomery_setup()
2664 x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */ in mp_montgomery_setup()
2665 x *= 2 - b * x; /* here x*a==1 mod 2**8 */ in mp_montgomery_setup()
2667 x *= 2 - b * x; /* here x*a==1 mod 2**16 */ in mp_montgomery_setup()
2670 x *= 2 - b * x; /* here x*a==1 mod 2**32 */ in mp_montgomery_setup()
2673 x *= 2 - b * x; /* here x*a==1 mod 2**64 */ in mp_montgomery_setup()
2676 /* rho = -1/m mod b */ in mp_montgomery_setup()
2677 *rho = (unsigned long)(((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK; in mp_montgomery_setup()
2685 /* computes xR**-1 == x (mod N) via Montgomery Reduction
2699 olduse = x->used; in fast_mp_montgomery_reduce()
2702 if (x->alloc < n->used + 1) { in fast_mp_montgomery_reduce()
2703 if ((res = mp_grow (x, n->used + 1)) != MP_OKAY) { in fast_mp_montgomery_reduce()
2719 tmpx = x->dp; in fast_mp_montgomery_reduce()
2721 /* copy the digits of a into W[0..a->used-1] */ in fast_mp_montgomery_reduce()
2722 for (ix = 0; ix < x->used; ix++) { in fast_mp_montgomery_reduce()
2726 /* zero the high words of W[a->used..m->used*2] */ in fast_mp_montgomery_reduce()
2727 for (; ix < n->used * 2 + 1; ix++) { in fast_mp_montgomery_reduce()
2735 for (ix = 0; ix < n->used; ix++) { in fast_mp_montgomery_reduce()
2736 /* mu = ai * m' mod b in fast_mp_montgomery_reduce()
2740 * that W[ix-1] have the carry cleared (see after the inner loop) in fast_mp_montgomery_reduce()
2742 register mp_digit mu; in fast_mp_montgomery_reduce() local
2743 mu = (mp_digit) (((W[ix] & MP_MASK) * rho) & MP_MASK); in fast_mp_montgomery_reduce()
2745 /* a = a + mu * m * b**i in fast_mp_montgomery_reduce()
2748 * by b**i is handled by offseting which columns the results in fast_mp_montgomery_reduce()
2757 * first m->used words of W[] have the carries fixed in fast_mp_montgomery_reduce()
2765 tmpn = n->dp; in fast_mp_montgomery_reduce()
2771 for (iy = 0; iy < n->used; iy++) { in fast_mp_montgomery_reduce()
2772 *_W++ += ((mp_word)mu) * ((mp_word)*tmpn++); in fast_mp_montgomery_reduce()
2796 for (; ix <= n->used * 2 + 1; ix++) { in fast_mp_montgomery_reduce()
2800 /* copy out, A = A/b**n in fast_mp_montgomery_reduce()
2802 * The result is A/b**n but instead of converting from an in fast_mp_montgomery_reduce()
2808 tmpx = x->dp; in fast_mp_montgomery_reduce()
2811 _W = W + n->used; in fast_mp_montgomery_reduce()
2813 for (ix = 0; ix < n->used + 1; ix++) { in fast_mp_montgomery_reduce()
2818 * m->used+1 we'll have to clear the digits in fast_mp_montgomery_reduce()
2826 x->used = n->used + 1; in fast_mp_montgomery_reduce()
2829 /* if A >= m then A = A - m */ in fast_mp_montgomery_reduce()
2839 /* b = a*2 */
2840 static int mp_mul_2(mp_int * a, mp_int * b) in mp_mul_2() argument
2845 if (b->alloc < a->used + 1) { in mp_mul_2()
2846 if ((res = mp_grow (b, a->used + 1)) != MP_OKAY) { in mp_mul_2()
2851 oldused = b->used; in mp_mul_2()
2852 b->used = a->used; in mp_mul_2()
2858 tmpa = a->dp; in mp_mul_2()
2861 tmpb = b->dp; in mp_mul_2()
2865 for (x = 0; x < a->used; x++) { in mp_mul_2()
2870 rr = *tmpa >> ((mp_digit)(DIGIT_BIT - 1)); in mp_mul_2()
2885 ++(b->used); in mp_mul_2()
2891 tmpb = b->dp + b->used; in mp_mul_2()
2892 for (x = b->used; x < oldused; x++) { in mp_mul_2()
2896 b->sign = a->sign; in mp_mul_2()
2904 * shifts with subtractions when the result is greater than b.
2906 * The method is slightly modified to shift B unconditionally up to just under
2907 * the leading bit of b. This saves a lot of multiple precision shifting.
2909 static int mp_montgomery_calc_normalization (mp_int * a, mp_int * b) in mp_montgomery_calc_normalization() argument
2913 /* how many bits of last digit does b use */ in mp_montgomery_calc_normalization()
2914 bits = mp_count_bits (b) % DIGIT_BIT; in mp_montgomery_calc_normalization()
2916 if (b->used > 1) { in mp_montgomery_calc_normalization()
2917 if ((res = mp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1)) != MP_OKAY) { in mp_montgomery_calc_normalization()
2926 /* now compute C = A * B mod b */ in mp_montgomery_calc_normalization()
2927 for (x = bits - 1; x < (int)DIGIT_BIT; x++) { in mp_montgomery_calc_normalization()
2931 if (mp_cmp_mag (a, b) != MP_LT) { in mp_montgomery_calc_normalization()
2932 if ((res = s_mp_sub (a, b, a)) != MP_OKAY) { in mp_montgomery_calc_normalization()
2946 * Uses a left-to-right k-ary sliding window to compute the modular exponentiation.
2995 for (x = 1<<(winsize-1); x < (1 << winsize); x++) { in mp_exptmod_fast()
2997 for (y = 1<<(winsize-1); y < x; y++) { in mp_exptmod_fast()
3019 if (((P->used * 2 + 1) < MP_WARRAY) && in mp_exptmod_fast()
3020 P->used < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) { in mp_exptmod_fast()
3035 /* setup DR reduction for moduli of the form B**k - b */ in mp_exptmod_fast()
3044 /* setup DR reduction for moduli of the form 2**k - b */ in mp_exptmod_fast()
3089 /* compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times */ in mp_exptmod_fast()
3090 if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) { in mp_exptmod_fast()
3094 for (x = 0; x < (winsize - 1); x++) { in mp_exptmod_fast()
3095 if ((err = mp_sqr (&M[1 << (winsize - 1)], &M[1 << (winsize - 1)])) != MP_OKAY) { in mp_exptmod_fast()
3098 if ((err = redux (&M[1 << (winsize - 1)], P, mp)) != MP_OKAY) { in mp_exptmod_fast()
3104 for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) { in mp_exptmod_fast()
3105 if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) { in mp_exptmod_fast()
3117 digidx = X->used - 1; in mp_exptmod_fast()
3123 if (--bitcnt == 0) { in mp_exptmod_fast()
3124 /* if digidx == -1 we are out of digits so break */ in mp_exptmod_fast()
3125 if (digidx == -1) { in mp_exptmod_fast()
3129 buf = X->dp[digidx--]; in mp_exptmod_fast()
3134 y = (mp_digit)(buf >> (DIGIT_BIT - 1)) & 1; in mp_exptmod_fast()
3158 bitbuf |= (y << (winsize - ++bitcpy)); in mp_exptmod_fast()
3231 for (x = 1<<(winsize-1); x < (1 << winsize); x++) { in mp_exptmod_fast()
3244 * (ty-tx) so that it never happens. You double all those
3250 static int fast_s_mp_sqr (mp_int * a, mp_int * b) in fast_s_mp_sqr() argument
3257 pa = a->used + a->used; in fast_s_mp_sqr()
3258 if (b->alloc < pa) { in fast_s_mp_sqr()
3259 if ((res = mp_grow (b, pa)) != MP_OKAY) { in fast_s_mp_sqr()
3275 ty = MIN(a->used-1, ix); in fast_s_mp_sqr()
3276 tx = ix - ty; in fast_s_mp_sqr()
3279 tmpx = a->dp + tx; in fast_s_mp_sqr()
3280 tmpy = a->dp + ty; in fast_s_mp_sqr()
3283 while (tx++ < a->used && ty-- >= 0) { ... } in fast_s_mp_sqr()
3285 iy = MIN(a->used-tx, ty+1); in fast_s_mp_sqr()
3291 iy = MIN(iy, (ty-tx+1)>>1); in fast_s_mp_sqr()
3295 _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--); in fast_s_mp_sqr()
3303 _W += ((mp_word)a->dp[ix>>1])*((mp_word)a->dp[ix>>1]); in fast_s_mp_sqr()
3314 olduse = b->used; in fast_s_mp_sqr()
3315 b->used = a->used+a->used; in fast_s_mp_sqr()
3319 tmpb = b->dp; in fast_s_mp_sqr()
3329 mp_clamp (b); in fast_s_mp_sqr()
3338 mp_mul_d (mp_int * a, mp_digit b, mp_int * c) in mp_mul_d() argument
3344 /* make sure c is big enough to hold a*b */ in mp_mul_d()
3345 if (c->alloc < a->used + 1) { in mp_mul_d()
3346 if ((res = mp_grow (c, a->used + 1)) != MP_OKAY) { in mp_mul_d()
3352 olduse = c->used; in mp_mul_d()
3355 c->sign = a->sign; in mp_mul_d()
3357 /* alias for a->dp [source] */ in mp_mul_d()
3358 tmpa = a->dp; in mp_mul_d()
3360 /* alias for c->dp [dest] */ in mp_mul_d()
3361 tmpc = c->dp; in mp_mul_d()
3367 for (ix = 0; ix < a->used; ix++) { in mp_mul_d()
3369 r = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b); in mp_mul_d()
3388 c->used = a->used + 1; in mp_mul_d()