@@ -45,22 +45,29 @@ mp_err s_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
4545 B = B >> 1 ;
4646
4747 /* init copy all the temps */
48- if (mp_init_size (& x0 , B ) != MP_OKAY )
48+ if (mp_init_size (& x0 , B ) != MP_OKAY ) {
4949 goto LBL_ERR ;
50- if (mp_init_size (& x1 , a -> used - B ) != MP_OKAY )
50+ }
51+ if (mp_init_size (& x1 , a -> used - B ) != MP_OKAY ) {
5152 goto X0 ;
52- if (mp_init_size (& y0 , B ) != MP_OKAY )
53+ }
54+ if (mp_init_size (& y0 , B ) != MP_OKAY ) {
5355 goto X1 ;
54- if (mp_init_size (& y1 , b -> used - B ) != MP_OKAY )
56+ }
57+ if (mp_init_size (& y1 , b -> used - B ) != MP_OKAY ) {
5558 goto Y0 ;
59+ }
5660
5761 /* init temps */
58- if (mp_init_size (& t1 , B * 2 ) != MP_OKAY )
62+ if (mp_init_size (& t1 , B * 2 ) != MP_OKAY ) {
5963 goto Y1 ;
60- if (mp_init_size (& x0y0 , B * 2 ) != MP_OKAY )
64+ }
65+ if (mp_init_size (& x0y0 , B * 2 ) != MP_OKAY ) {
6166 goto T1 ;
62- if (mp_init_size (& x1y1 , B * 2 ) != MP_OKAY )
67+ }
68+ if (mp_init_size (& x1y1 , B * 2 ) != MP_OKAY ) {
6369 goto X0Y0 ;
70+ }
6471
6572 /* now shift the digits */
6673 x0 .used = y0 .used = B ;
@@ -103,35 +110,46 @@ mp_err s_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
103110
104111 /* now calc the products x0y0 and x1y1 */
105112 /* after this x0 is no longer required, free temp [x0==t2]! */
106- if (mp_mul (& x0 , & y0 , & x0y0 ) != MP_OKAY )
113+ if (mp_mul (& x0 , & y0 , & x0y0 ) != MP_OKAY ) {
107114 goto X1Y1 ; /* x0y0 = x0*y0 */
108- if (mp_mul (& x1 , & y1 , & x1y1 ) != MP_OKAY )
115+ }
116+ if (mp_mul (& x1 , & y1 , & x1y1 ) != MP_OKAY ) {
109117 goto X1Y1 ; /* x1y1 = x1*y1 */
118+ }
110119
111120 /* now calc x1+x0 and y1+y0 */
112- if (s_mp_add (& x1 , & x0 , & t1 ) != MP_OKAY )
121+ if (s_mp_add (& x1 , & x0 , & t1 ) != MP_OKAY ) {
113122 goto X1Y1 ; /* t1 = x1 - x0 */
114- if (s_mp_add (& y1 , & y0 , & x0 ) != MP_OKAY )
123+ }
124+ if (s_mp_add (& y1 , & y0 , & x0 ) != MP_OKAY ) {
115125 goto X1Y1 ; /* t2 = y1 - y0 */
116- if (mp_mul (& t1 , & x0 , & t1 ) != MP_OKAY )
126+ }
127+ if (mp_mul (& t1 , & x0 , & t1 ) != MP_OKAY ) {
117128 goto X1Y1 ; /* t1 = (x1 + x0) * (y1 + y0) */
129+ }
118130
119131 /* add x0y0 */
120- if (mp_add (& x0y0 , & x1y1 , & x0 ) != MP_OKAY )
132+ if (mp_add (& x0y0 , & x1y1 , & x0 ) != MP_OKAY ) {
121133 goto X1Y1 ; /* t2 = x0y0 + x1y1 */
122- if (s_mp_sub (& t1 , & x0 , & t1 ) != MP_OKAY )
134+ }
135+ if (s_mp_sub (& t1 , & x0 , & t1 ) != MP_OKAY ) {
123136 goto X1Y1 ; /* t1 = (x1+x0)*(y1+y0) - (x1y1 + x0y0) */
137+ }
124138
125139 /* shift by B */
126- if (mp_lshd (& t1 , B ) != MP_OKAY )
140+ if (mp_lshd (& t1 , B ) != MP_OKAY ) {
127141 goto X1Y1 ; /* t1 = (x0y0 + x1y1 - (x1-x0)*(y1-y0))<<B */
128- if (mp_lshd (& x1y1 , B * 2 ) != MP_OKAY )
142+ }
143+ if (mp_lshd (& x1y1 , B * 2 ) != MP_OKAY ) {
129144 goto X1Y1 ; /* x1y1 = x1y1 << 2*B */
145+ }
130146
131- if (mp_add (& x0y0 , & t1 , & t1 ) != MP_OKAY )
147+ if (mp_add (& x0y0 , & t1 , & t1 ) != MP_OKAY ) {
132148 goto X1Y1 ; /* t1 = x0y0 + t1 */
133- if (mp_add (& t1 , & x1y1 , c ) != MP_OKAY )
149+ }
150+ if (mp_add (& t1 , & x1y1 , c ) != MP_OKAY ) {
134151 goto X1Y1 ; /* t1 = x0y0 + t1 + x1y1 */
152+ }
135153
136154 /* Algorithm succeeded set the return code to MP_OKAY */
137155 err = MP_OKAY ;
0 commit comments