95#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
112 if (
a->alloc <
size) {
134 for (;
i <
a->alloc;
i++) {
147 if (
b->alloc <
a->used) {
159 tmpa =
a->dp +
b->used - 1;
162 tmpb =
b->dp +
b->used - 1;
166 for (
x =
b->used - 1;
x >= 0;
x--) {
171 *tmpb-- = (*tmpa-- >> 1) | (
r << (
DIGIT_BIT - 1));
178 tmpb =
b->dp +
b->used;
179 for (
x =
b->used;
x < oldused;
x++) {
262 for (
i = 0;
i <
a->used;
i++) {
271 a->alloc =
a->used = 0;
453 if (
x->alloc <
n->used + 1) {
473 for (ix = 0; ix <
x->used; ix++) {
478 for (; ix <
n->used * 2 + 1; ix++) {
486 for (ix = 0; ix <
n->used; ix++) {
522 for (
iy = 0;
iy <
n->used;
iy++) {
547 for (; ix <=
n->used * 2 + 1; ix++) {
564 for (ix = 0; ix <
n->used + 1; ix++) {
571 for (; ix < olduse; ix++) {
577 x->used =
n->used + 1;
606 int olduse,
res,
pa, ix, iz;
611 if (
c->alloc < digs) {
618 pa =
MIN(digs,
a->used +
b->used);
622 for (ix = 0; ix <=
pa; ix++) {
641 for (iz = 0; iz <
iy; ++iz) {
659 for (ix = 0; ix < digs; ix++) {
665 for (; ix < olduse; ix++) {
685 int olduse,
res,
pa, ix, iz;
690 pa =
a->used +
b->used;
698 pa =
a->used +
b->used;
700 for (ix = digs; ix <=
pa; ix++) {
718 for (iz = 0; iz <
iy; iz++) {
737 for (ix = digs; ix <=
pa; ix++) {
743 for (; ix < olduse; ix++) {
782 int olduse,
res,
pa, ix, iz;
787 pa =
a->used +
a->used;
796 for (ix = 0; ix <=
pa; ix++) {
824 for (iz = 0; iz <
iy; iz++) {
845 b->used =
a->used+
a->used;
850 for (ix = 0; ix <
pa; ix++) {
855 for (; ix < olduse; ix++) {
926 int res, ix, oldused;
930 if (
c->alloc <
a->used + 1) {
937 if (
a->sign ==
MP_NEG && (
a->used > 1 ||
a->dp[0] >=
b)) {
972 for (ix = 1; ix <
a->used; ix++) {
973 *tmpc = *tmpa++ + mu;
982 c->used =
a->used + 1;
989 *tmpc++ =
b -
a->dp[0];
1001 while (ix++ < oldused) {
1022 while (
a->used > 0 &&
a->dp[
a->used - 1] == 0) {
1037 while (next_mp !=
NULL) {
1049 if (
a->sign !=
b->sign) {
1082 }
else if (
a->dp[0] <
b) {
1096 if (
a->used >
b->used) {
1100 if (
a->used <
b->used) {
1105 tmpa =
a->dp + (
a->used - 1);
1108 tmpb =
b->dp + (
a->used - 1);
1111 for (
n = 0;
n <
a->used; ++
n, --tmpa, --tmpb) {
1112 if (*tmpa > *tmpb) {
1116 if (*tmpa < *tmpb) {
1124 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
1139 for (
x = 0;
x <
a->used &&
a->dp[
x] == 0;
x++);
1166 if (
b->alloc <
a->used) {
1185 for (
n = 0;
n <
a->used;
n++) {
1190 for (;
n <
b->used;
n++) {
1217 q =
a->dp[
a->used - 1];
1295 for (
x = 0;
x < (
a->used -
b);
x++) {
1300 for (;
x <
a->used;
x++) {
1361 tmpc =
c->dp + (
c->used - 1);
1365 for (
x =
c->used - 1;
x >= 0;
x--) {
1370 *tmpc = (*tmpc >>
D) | (
r <<
shift);
1396 if (
a->alloc <
a->used +
b) {
1409 top =
a->dp +
a->used - 1;
1418 for (
x =
a->used - 1;
x >=
b;
x--) {
1424 for (
x = 0;
x <
b;
x++) {
1474 for (
x = 0;
x <
c->used;
x++) {
1488 c->dp[(
c->used)++] =
r;
1501 int ix,
res, olduse;
1504 if (
c->alloc <
a->used + 1) {
1526 for (ix = 0; ix <
a->used; ix++) {
1541 while (ix++ < olduse) {
1546 c->used =
a->used + 1;
1591 q.used =
a->used + 2;
1647 for (
i =
n;
i >= (
t + 1);
i--) {
1654 if (
x.dp[
i] ==
y.dp[
t]) {
1677 t1.
dp[0] = (
t - 1 < 0) ? 0 :
y.dp[
t - 1];
1685 t2.
dp[0] = (
i - 2 < 0) ? 0 :
x.dp[
i - 2];
1686 t2.
dp[1] = (
i - 1 < 0) ? 0 :
x.dp[
i - 1];
1804 for (ix =
a->used - 1; ix >= 0; ix--) {
1854 if (
x->alloc <
m +
m) {
1875 for (
i = 0;
i <
m;
i++) {
1885 for (
i =
m + 1;
i <
x->used;
i++) {
1980 int err, bitbuf, bitcpy, bitcnt,
mode, digidx,
x,
y, winsize;
1992 }
else if (
x <= 36) {
1994 }
else if (
x <= 140) {
1996 }
else if (
x <= 450) {
1998 }
else if (
x <= 1303) {
2000 }
else if (
x <= 3529) {
2013 for (
x = 1<<(winsize-1);
x < (1 << winsize);
x++) {
2015 for (
y = 1<<(winsize-1);
y <
x;
y++) {
2038 }
else if (redmode == 1) {
2084 for (
x = 0;
x < (winsize - 1);
x++) {
2088 if ((
err = redux (&
M[1 << (winsize - 1)],
P, mp)) !=
MP_OKAY) {
2094 for (
x = (1 << (winsize - 1)) + 1;
x < (1 << winsize);
x++) {
2107 digidx =
X->used - 1;
2113 if (--bitcnt == 0) {
2119 buf =
X->dp[digidx--];
2132 if (
mode == 0 &&
y == 0) {
2137 if (
mode == 1 &&
y == 0) {
2148 bitbuf |= (
y << (winsize - ++bitcpy));
2151 if (bitcpy == winsize) {
2154 for (
x = 0;
x < winsize;
x++) {
2179 if (
mode == 2 && bitcpy > 0) {
2181 for (
x = 0;
x < bitcpy;
x++) {
2191 if ((bitbuf & (1 << winsize)) != 0) {
2221 for (
x = 1<<(winsize-1);
x < (1 << winsize);
x++) {
2231 int k, u_lsb, v_lsb,
res;
2264 k =
MIN(u_lsb, v_lsb);
2340 return res & 0xFFFFFFFFUL;
2362 while (cur_arg !=
NULL) {
2598 B =
MIN (
a->used,
b->used);
2622 x0.used =
y0.used =
B;
2623 x1.used =
a->used -
B;
2624 y1.used =
b->used -
B;
2628 register mp_digit *tmpa, *tmpb, *tmpx, *tmpy;
2638 for (
x = 0;
x <
B;
x++) {
2644 for (
x =
B;
x <
a->used;
x++) {
2649 for (
x =
B;
x <
b->used;
x++) {
2750 for (
x = 0;
x <
B;
x++) {
2755 for (
x =
B;
x <
a->used;
x++) {
2761 x1.used =
a->used -
B;
2861 if (
t.sign !=
b->sign) {
2881 int x,
res, oldused;
2884 if (
b->alloc <
a->used + 1) {
2904 for (
x = 0;
x <
a->used;
x++) {
2930 tmpb =
b->dp +
b->used;
2931 for (
x =
b->used;
x < oldused;
x++) {
2991 digs =
n->used * 2 + 1;
2999 if (
x->alloc < digs) {
3006 for (ix = 0; ix <
n->used; ix++) {
3033 for (
iy = 0;
iy <
n->used;
iy++) {
3095 x = (((
b + 2) & 4) << 1) +
b;
3123 int digs =
a->used +
b->used + 1;
3126 MIN(
a->used,
b->used) <=
3132 c->sign = (
c->used > 0) ? neg :
MP_ZPOS;
3158 0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
3159 0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
3160 0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
3161 0x0061, 0x0065, 0x0067, 0x006B, 0x006D, 0x0071, 0x007F, 0x0083,
3162 0x0089, 0x008B, 0x0095, 0x0097, 0x009D, 0x00A3, 0x00A7, 0x00AD,
3163 0x00B3, 0x00B5, 0x00BF, 0x00C1, 0x00C5, 0x00C7, 0x00D3, 0x00DF,
3164 0x00E3, 0x00E5, 0x00E9, 0x00EF, 0x00F1, 0x00FB, 0x0101, 0x0107,
3165 0x010D, 0x010F, 0x0115, 0x0119, 0x011B, 0x0125, 0x0133, 0x0137,
3167 0x0139, 0x013D, 0x014B, 0x0151, 0x015B, 0x015D, 0x0161, 0x0167,
3168 0x016F, 0x0175, 0x017B, 0x017F, 0x0185, 0x018D, 0x0191, 0x0199,
3169 0x01A3, 0x01A5, 0x01AF, 0x01B1, 0x01B7, 0x01BB, 0x01C1, 0x01C9,
3170 0x01CD, 0x01CF, 0x01D3, 0x01DF, 0x01E7, 0x01EB, 0x01F3, 0x01F7,
3171 0x01FD, 0x0209, 0x020B, 0x021D, 0x0223, 0x022D, 0x0233, 0x0239,
3172 0x023B, 0x0241, 0x024B, 0x0251, 0x0257, 0x0259, 0x025F, 0x0265,
3173 0x0269, 0x026B, 0x0277, 0x0281, 0x0283, 0x0287, 0x028D, 0x0293,
3174 0x0295, 0x02A1, 0x02A5, 0x02AB, 0x02B3, 0x02BD, 0x02C5, 0x02CF,
3176 0x02D7, 0x02DD, 0x02E3, 0x02E7, 0x02EF, 0x02F5, 0x02F9, 0x0301,
3177 0x0305, 0x0313, 0x031D, 0x0329, 0x032B, 0x0335, 0x0337, 0x033B,
3178 0x033D, 0x0347, 0x0355, 0x0359, 0x035B, 0x035F, 0x036D, 0x0371,
3179 0x0373, 0x0377, 0x038B, 0x038F, 0x0397, 0x03A1, 0x03A9, 0x03AD,
3180 0x03B3, 0x03B9, 0x03C7, 0x03CB, 0x03D1, 0x03D7, 0x03DF, 0x03E5,
3181 0x03F1, 0x03F5, 0x03FB, 0x03FD, 0x0407, 0x0409, 0x040F, 0x0419,
3182 0x041B, 0x0425, 0x0427, 0x042D, 0x043F, 0x0443, 0x0445, 0x0449,
3183 0x044F, 0x0455, 0x045D, 0x0463, 0x0469, 0x047F, 0x0481, 0x048B,
3185 0x0493, 0x049D, 0x04A3, 0x04A9, 0x04B1, 0x04BD, 0x04C1, 0x04C7,
3186 0x04CD, 0x04CF, 0x04D5, 0x04E1, 0x04EB, 0x04FD, 0x04FF, 0x0503,
3187 0x0509, 0x050B, 0x0511, 0x0515, 0x0517, 0x051B, 0x0527, 0x0529,
3188 0x052F, 0x0551, 0x0557, 0x055D, 0x0565, 0x0577, 0x0581, 0x058F,
3189 0x0593, 0x0595, 0x0599, 0x059F, 0x05A7, 0x05AB, 0x05AD, 0x05B3,
3190 0x05BF, 0x05C9, 0x05CB, 0x05CF, 0x05D1, 0x05D5, 0x05DB, 0x05E7,
3191 0x05F3, 0x05FB, 0x0607, 0x060D, 0x0611, 0x0617, 0x061F, 0x0623,
3192 0x062B, 0x062F, 0x063D, 0x0641, 0x0647, 0x0649, 0x064D, 0x0653
3349 for (ix = 0; ix <
t; ix++) {
3368static const struct {
3414 unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
3415 int res,
err, bsize, maskOR_msb_offset;
3418 if (
size <= 1 ||
t <= 0) {
3437 maskAND = ((
size&7) == 0) ? 0xFF : (0xFF >> (8 - (
size & 7)));
3441 maskOR_msb_offset = ((
size & 7) == 1) ? 1 : 0;
3443 maskOR_msb |= 1 << ((
size - 2) & 7);
3445 maskAND &= ~(1 << ((
size - 2) & 7));
3456 if (
cb(tmp, bsize, dat) != bsize) {
3463 tmp[0] |= 1 << ((
size - 1) & 7);
3466 tmp[maskOR_msb_offset] |= maskOR_msb;
3467 tmp[bsize-1] |= maskOR_lsb;
3537 int res, um =
m->used;
3683 a->used = (
a->dp[0] != 0) ? 1 : 0;
3694 for (
x = 0;
x < 8;
x++) {
3701 a->dp[0] |= (
b >> 28) & 15;
3717 if (
a->alloc !=
a->used &&
a->used > 0) {
3811 int res, ix, oldused;
3814 if (
c->alloc <
a->used + 1) {
3836 if ((
a->used == 1 &&
a->dp[0] <=
b) ||
a->used == 0) {
3838 *tmpc++ =
b - *tmpa;
3853 *tmpc = *tmpa++ -
b;
3858 for (ix = 1; ix <
a->used; ix++) {
3859 *tmpc = *tmpa++ - mu;
3866 while (ix++ < oldused) {
3886 b[
x++] = (
unsigned char) (
t.dp[0] & 255);
3902 return (
size / 8 + ((
size & 7) != 0 ? 1 : 0));
3933 if (
a->used >
b->used) {
3944 if (
c->alloc <
max + 1) {
3955 register mp_digit u, *tmpa, *tmpb, *tmpc;
3971 for (
i = 0;
i <
min;
i++) {
3973 *tmpc = *tmpa++ + *tmpb++ +
u;
3986 for (;
i <
max;
i++) {
3988 *tmpc =
x->dp[
i] +
u;
4002 for (
i =
c->used;
i < olduse;
i++) {
4015 int err, bitbuf, bitcpy, bitcnt,
mode, digidx,
x,
y, winsize;
4021 }
else if (
x <= 36) {
4023 }
else if (
x <= 140) {
4025 }
else if (
x <= 450) {
4027 }
else if (
x <= 1303) {
4029 }
else if (
x <= 3529) {
4042 for (
x = 1<<(winsize-1);
x < (1 << winsize);
x++) {
4044 for (
y = 1<<(winsize-1);
y <
x;
y++) {
4079 for (
x = 0;
x < (winsize - 1);
x++) {
4081 &
M[1 << (winsize - 1)])) !=
MP_OKAY) {
4092 for (
x = (1 << (winsize - 1)) + 1;
x < (1 << winsize);
x++) {
4111 digidx =
X->used - 1;
4117 if (--bitcnt == 0) {
4123 buf =
X->dp[digidx--];
4136 if (
mode == 0 &&
y == 0) {
4141 if (
mode == 1 &&
y == 0) {
4152 bitbuf |= (
y << (winsize - ++bitcpy));
4155 if (bitcpy == winsize) {
4158 for (
x = 0;
x < winsize;
x++) {
4183 if (
mode == 2 && bitcpy > 0) {
4185 for (
x = 0;
x < bitcpy;
x++) {
4194 if ((bitbuf & (1 << winsize)) != 0) {
4212 for (
x = 1<<(winsize-1);
x < (1 << winsize);
x++) {
4233 MIN (
a->used,
b->used) <
4245 for (ix = 0; ix <
pa; ix++) {
4250 pb =
MIN (
b->used, digs - ix);
4263 for (
iy = 0;
iy < pb;
iy++) {
4276 if (ix +
iy < digs) {
4309 t.used =
a->used +
b->used + 1;
4313 for (ix = 0; ix <
pa; ix++) {
4321 tmpt = &(
t.dp[digs]);
4324 tmpy =
b->dp + (digs - ix);
4326 for (
iy = digs - ix;
iy < pb;
iy++) {
4363 for (ix = 0; ix <
pa; ix++) {
4379 tmpt =
t.dp + (2*ix + 1);