Skip to content

Commit b12dedf

Browse files
committed
Added J. Arndt's permission
1 parent 07d24da commit b12dedf

7 files changed

+396
-362
lines changed

bn_s_mp_fft.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44
/* SPDX-License-Identifier: Unlicense */
55

6-
6+
/*
7+
This file contains code from J. Arndt's book "Matters Computational"
8+
and the accompanying FXT-library with permission of the author.
9+
*/
710

811
/* base two integer logarithm */
912
static int s_highbit(int n)

bn_s_mp_toom_cook_4_mul.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44
/* SPDX-License-Identifier: Unlicense */
55

6+
/*
7+
This file contains code from J. Arndt's book "Matters Computational"
8+
and the accompanying FXT-library with permission of the author.
9+
*/
10+
611
/*
712
Bodrato, Marco, and Alberto Zanoni. "Integer and polynomial multiplication:
813
Towards optimal Toom-Cook matrices." Proceedings of the 2007 international
@@ -93,11 +98,11 @@ int s_mp_toom_cook_4_mul(const mp_int *a, const mp_int *b, mp_int *c)
9398
mp_clamp(&b3);
9499

95100

96-
/** S1 = a3 * b3 */
101+
/** S1 = a3 * b3; */
97102
if ((e = mp_mul(&a3, &b3, &S1)) != MP_OKAY) {
98103
goto LTM_ERR;
99104
}
100-
/** S2 = (8*a3 + 4*a2 + 2*a1 + a0)*(8*b3 + 4*b2 + 2*b1 + b0) */
105+
/** S2 = (8*a3 + 4*a2 + 2*a1 + a0)*(8*b3 + 4*b2 + 2*b1 + b0); */
101106
if ((e = mp_mul_2d(&a3, 3, &S2)) != MP_OKAY) {
102107
goto LTM_ERR;
103108
}
@@ -139,7 +144,7 @@ int s_mp_toom_cook_4_mul(const mp_int *a, const mp_int *b, mp_int *c)
139144
if ((e = mp_mul(&S2, &S3, &S2)) != MP_OKAY) {
140145
goto LTM_ERR;
141146
}
142-
/** S3 = (+a3 + a2 + a1 + a0)*(+b3 + b2 + b1 + b0) */
147+
/** S3 = (+a3 + a2 + a1 + a0)*(+b3 + b2 + b1 + b0); */
143148
if ((e = mp_add(&a3, &a2, &S3)) != MP_OKAY) {
144149
goto LTM_ERR;
145150
}
@@ -163,8 +168,8 @@ int s_mp_toom_cook_4_mul(const mp_int *a, const mp_int *b, mp_int *c)
163168
goto LTM_ERR;
164169
}
165170

166-
/** S4 = (-a3+a2-a1+a0)*(-b3+b2-b1+b0) */
167-
/* = (+a2-a1 + a0-a3)*(+b2-b1 + b0-b3) */
171+
/** S4 = (-a3+a2-a1+a0)*(-b3+b2-b1+b0); */
172+
/* = (+a2-a1 + a0-a3)*(+b2-b1 + b0-b3); */
168173

169174
if ((e = mp_sub(&a2, &a1, &S4)) != MP_OKAY) {
170175
goto LTM_ERR;
@@ -188,7 +193,7 @@ int s_mp_toom_cook_4_mul(const mp_int *a, const mp_int *b, mp_int *c)
188193
goto LTM_ERR;
189194
}
190195

191-
/** S5 = (+8*a0+4*a1+2*a2+a3)*(+8*b0+4*b1+2*b2+b3) */
196+
/** S5 = (+8*a0+4*a1+2*a2+a3)*(+8*b0+4*b1+2*b2+b3); */
192197
if ((e = mp_mul_2d(&a0, 3, &S5)) != MP_OKAY) {
193198
goto LTM_ERR;
194199
}
@@ -231,8 +236,8 @@ int s_mp_toom_cook_4_mul(const mp_int *a, const mp_int *b, mp_int *c)
231236
goto LTM_ERR;
232237
}
233238

234-
/** S6 = (-8*a0+4*a1-2*a2+a3)*(-8*b0+4*b1-2*b2+b3) */
235-
/* = (+4*a1-2*a2+a3-8*a0)*(+4*b1-2*b2+b3-8*b0) */
239+
/** S6 = (-8*a0+4*a1-2*a2+a3)*(-8*b0+4*b1-2*b2+b3); */
240+
/* = (+4*a1-2*a2+a3-8*a0)*(+4*b1-2*b2+b3-8*b0); */
236241
if ((e = mp_mul_2d(&a1, 2, &S6)) != MP_OKAY) {
237242
goto LTM_ERR;
238243
}
@@ -273,7 +278,7 @@ int s_mp_toom_cook_4_mul(const mp_int *a, const mp_int *b, mp_int *c)
273278
if ((e = mp_mul(&S6, &S7, &S6)) != MP_OKAY) {
274279
goto LTM_ERR;
275280
}
276-
/** S7 = a0 * b0 */
281+
/** S7 = a0 * b0; */
277282
if ((e = mp_mul(&a0, &b0, &S7)) != MP_OKAY) {
278283
goto LTM_ERR;
279284
}
@@ -444,7 +449,7 @@ int s_mp_toom_cook_4_mul(const mp_int *a, const mp_int *b, mp_int *c)
444449
goto LTM_ERR;
445450
}
446451

447-
/** S - a*b */
452+
/** S - a*b; */
448453

449454
LTM_ERR:
450455
mp_clear(&b3);

bn_s_mp_toom_cook_4_sqr.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44
/* SPDX-License-Identifier: Unlicense */
55

6+
/*
7+
This file contains code from J. Arndt's book "Matters Computational"
8+
and the accompanying FXT-library with permission of the author.
9+
*/
10+
611
/*
712
Setup and interpolation from
813
@@ -27,7 +32,7 @@ int s_mp_toom_cook_4_sqr(const mp_int *a, mp_int *c)
2732
return e;
2833
}
2934

30-
/** A = a3*x^3 + a2*x^2 + a1*x + a0; */
35+
/** A = a3*x^3 + a2*x^2 + a1*x + a0;; */
3136
if ((e = mp_init_size(&a0, B)) != MP_OKAY) {
3237
goto LTM_ERRa0;
3338
}
@@ -61,113 +66,113 @@ int s_mp_toom_cook_4_sqr(const mp_int *a, mp_int *c)
6166
}
6267
mp_clamp(&a3);
6368

64-
/** S2 = a0 * a1 */
69+
/** S2 = a0 * a1; */
6570
if ((e = mp_mul(&a0, &a1, &S2)) != MP_OKAY) {
6671
goto LTM_ERR;
6772
}
68-
/** S2 = S2 * 2 */
73+
/** S2 = S2 * 2 ; */
6974
if ((e = mp_mul_2(&S2, &S2)) != MP_OKAY) {
7075
goto LTM_ERR;
7176
}
72-
/** S6 = a0 - a2 */
77+
/** S6 = a0 - a2; */
7378
if ((e = mp_sub(&a0, &a2, &S6)) != MP_OKAY) {
7479
goto LTM_ERR;
7580
}
76-
/** S7 = a1 - a3 */
81+
/** S7 = a1 - a3; */
7782
if ((e = mp_sub(&a1, &a3, &S7)) != MP_OKAY) {
7883
goto LTM_ERR;
7984
}
80-
/** S3 = S6 + S7 */
85+
/** S3 = S6 + S7; */
8186
if ((e = mp_add(&S6, &S7, &S3)) != MP_OKAY) {
8287
goto LTM_ERR;
8388
}
84-
/** S4 = S6 - S7 */
89+
/** S4 = S6 - S7; */
8590
if ((e = mp_sub(&S6, &S7, &S4)) != MP_OKAY) {
8691
goto LTM_ERR;
8792
}
88-
/** S3 = S3 * S4 */
93+
/** S3 = S3 * S4; */
8994
if ((e = mp_mul(&S3, &S4, &S3)) != MP_OKAY) {
9095
goto LTM_ERR;
9196
}
92-
/** S5 = S6 * S7 */
97+
/** S5 = S6 * S7; */
9398
if ((e = mp_mul(&S6, &S7, &S5)) != MP_OKAY) {
9499
goto LTM_ERR;
95100
}
96-
/** S5 = S5 * 2 */
101+
/** S5 = S5 * 2 ; */
97102
if ((e = mp_mul_2(&S5, &S5)) != MP_OKAY) {
98103
goto LTM_ERR;
99104
}
100-
/** S4 = a0 + a1 */
105+
/** S4 = a0 + a1; */
101106
if ((e = mp_add(&a0, &a1, &S4)) != MP_OKAY) {
102107
goto LTM_ERR;
103108
}
104-
/** S4 = S4 + a2 */
109+
/** S4 = S4 + a2; */
105110
if ((e = mp_add(&S4, &a2, &S4)) != MP_OKAY) {
106111
goto LTM_ERR;
107112
}
108-
/** S4 = S4 + a3 */
113+
/** S4 = S4 + a3; */
109114
if ((e = mp_add(&S4, &a3, &S4)) != MP_OKAY) {
110115
goto LTM_ERR;
111116
}
112-
/** S4 = S4^2 */
117+
/** S4 = S4^2; */
113118
if ((e = mp_sqr(&S4, &S4)) != MP_OKAY) {
114119
goto LTM_ERR;
115120
}
116121

117-
/** S6 = a3 * a2 */
122+
/** S6 = a3 * a2; */
118123
if ((e = mp_mul(&a3, &a2, &S6)) != MP_OKAY) {
119124
goto LTM_ERR;
120125
}
121-
/** S6 = S6 * 2 */
126+
/** S6 = S6 * 2 ; */
122127
if ((e = mp_mul_2(&S6, &S6)) != MP_OKAY) {
123128
goto LTM_ERR;
124129
}
125-
/** T1 = S3 + S4 */
130+
/** T1 = S3 + S4; */
126131
if ((e = mp_add(&S3, &S4, &tmp)) != MP_OKAY) {
127132
goto LTM_ERR;
128133
}
129-
/** T1 = T1 + S5 */
134+
/** T1 = T1 + S5; */
130135
if ((e = mp_add(&tmp, &S5, &tmp)) != MP_OKAY) {
131136
goto LTM_ERR;
132137
}
133-
/** T1 = T1 / 2 */
138+
/** T1 = T1 / 2 ; */
134139
if ((e = mp_div_2(&tmp,&tmp)) != MP_OKAY) {
135140
goto LTM_ERR;
136141
}
137-
/** S1 = S2 + S6 */
142+
/** S1 = S2 + S6; */
138143
if ((e = mp_add(&S2, &S6, &S1)) != MP_OKAY) {
139144
goto LTM_ERR;
140145
}
141-
/** S7 = T1 - S1 */
146+
/** S7 = T1 - S1; */
142147
if ((e = mp_sub(&tmp, &S1, &S7)) != MP_OKAY) {
143148
goto LTM_ERR;
144149
}
145-
/** S4 = S1 - S5 */
150+
/** S4 = S1 - S5; */
146151
if ((e = mp_sub(&S1, &S5, &S4)) != MP_OKAY) {
147152
goto LTM_ERR;
148153
}
149-
/** S3 = S7 - S3 */
154+
/** S3 = S7 - S3; */
150155
if ((e = mp_sub(&S7, &S3, &S3)) != MP_OKAY) {
151156
goto LTM_ERR;
152157
}
153-
/** S1 = a0^2 */
158+
/** S1 = a0^2 ; */
154159
if ((e = mp_sqr(&a0, &S1)) != MP_OKAY) {
155160
goto LTM_ERR;
156161
}
157-
/** S5 = S7 - S1 */
162+
/** S5 = S7 - S1; */
158163
if ((e = mp_sub(&S7, &S1, &S5)) != MP_OKAY) {
159164
goto LTM_ERR;
160165
}
161-
/** S7 = a3^2 */
166+
/** S7 = a3^2 ; */
162167
if ((e = mp_sqr(&a3, &S7)) != MP_OKAY) {
163168
goto LTM_ERR;
164169
}
165-
/** S3 = S3 - S7 */
170+
/** S3 = S3 - S7; */
166171
if ((e = mp_sub(&S3, &S7, &S3)) != MP_OKAY) {
167172
goto LTM_ERR;
168173
}
169174

170-
/** P = S7 * x^6 + S6 * x^5 + S5 * x^4 + S4 * x^3 + S3 * x^2 + S2 * x + S1 */
175+
/** P = S7 * x^6 + S6 * x^5 + S5 * x^4 + S4 * x^3 + S3 * x^2 + S2 * x + S1; */
171176
if ((e = mp_lshd(&S7, 6 * B)) != MP_OKAY) {
172177
goto LTM_ERR;
173178
}

0 commit comments

Comments
 (0)