]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/bn/asm/x86_64-gcc.c
Copyright consolidation 06/10
[thirdparty/openssl.git] / crypto / bn / asm / x86_64-gcc.c
CommitLineData
4f22f405
RS
1/*
2 * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
41b76195 10#include "../bn_lcl.h"
93c4ba07 11#if !(defined(__GNUC__) && __GNUC__>=2)
0f113f3e 12# include "../bn_asm.c" /* kind of dirty hack for Sun Studio */
c8a0d0aa 13#else
1d97c843 14/*-
2f98abbc
AP
15 * x86_64 BIGNUM accelerator version 0.1, December 2002.
16 *
17 * Implemented by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
18 * project.
19 *
20 * Rights for redistribution and usage in source and binary forms are
21 * granted according to the OpenSSL license. Warranty of any kind is
22 * disclaimed.
23 *
24 * Q. Version 0.1? It doesn't sound like Andy, he used to assign real
25 * versions, like 1.0...
26 * A. Well, that's because this code is basically a quick-n-dirty
27 * proof-of-concept hack. As you can see it's implemented with
28 * inline assembler, which means that you're bound to GCC and that
1809e858 29 * there might be enough room for further improvement.
2f98abbc
AP
30 *
31 * Q. Why inline assembler?
1809e858
AP
32 * A. x86_64 features own ABI which I'm not familiar with. This is
33 * why I decided to let the compiler take care of subroutine
34 * prologue/epilogue as well as register allocation. For reference.
35 * Win64 implements different ABI for AMD64, different from Linux.
2f98abbc
AP
36 *
37 * Q. How much faster does it get?
1809e858
AP
38 * A. 'apps/openssl speed rsa dsa' output with no-asm:
39 *
0f113f3e
MC
40 * sign verify sign/s verify/s
41 * rsa 512 bits 0.0006s 0.0001s 1683.8 18456.2
42 * rsa 1024 bits 0.0028s 0.0002s 356.0 6407.0
43 * rsa 2048 bits 0.0172s 0.0005s 58.0 1957.8
44 * rsa 4096 bits 0.1155s 0.0018s 8.7 555.6
45 * sign verify sign/s verify/s
46 * dsa 512 bits 0.0005s 0.0006s 2100.8 1768.3
47 * dsa 1024 bits 0.0014s 0.0018s 692.3 559.2
48 * dsa 2048 bits 0.0049s 0.0061s 204.7 165.0
1809e858
AP
49 *
50 * 'apps/openssl speed rsa dsa' output with this module:
51 *
0f113f3e
MC
52 * sign verify sign/s verify/s
53 * rsa 512 bits 0.0004s 0.0000s 2767.1 33297.9
54 * rsa 1024 bits 0.0012s 0.0001s 867.4 14674.7
55 * rsa 2048 bits 0.0061s 0.0002s 164.0 5270.0
56 * rsa 4096 bits 0.0384s 0.0006s 26.1 1650.8
57 * sign verify sign/s verify/s
58 * dsa 512 bits 0.0002s 0.0003s 4442.2 3786.3
59 * dsa 1024 bits 0.0005s 0.0007s 1835.1 1497.4
60 * dsa 2048 bits 0.0016s 0.0020s 620.4 504.6
1809e858
AP
61 *
62 * For the reference. IA-32 assembler implementation performs
63 * very much like 64-bit code compiled with no-asm on the same
64 * machine.
2f98abbc
AP
65 */
66
0f113f3e
MC
67# if defined(_WIN64) || !defined(__LP64__)
68# define BN_ULONG unsigned long long
69# else
70# define BN_ULONG unsigned long
71# endif
2f98abbc 72
0f113f3e
MC
73# undef mul
74# undef mul_add
41b76195 75
1d97c843 76/*-
053fa39a 77 * "m"(a), "+m"(r) is the way to favor DirectPath ยต-code;
0f113f3e
MC
78 * "g"(0) let the compiler to decide where does it
79 * want to keep the value of zero;
2f98abbc 80 */
0f113f3e
MC
81# define mul_add(r,a,word,carry) do { \
82 register BN_ULONG high,low; \
83 asm ("mulq %3" \
84 : "=a"(low),"=d"(high) \
85 : "a"(word),"m"(a) \
86 : "cc"); \
87 asm ("addq %2,%0; adcq %3,%1" \
88 : "+r"(carry),"+d"(high)\
89 : "a"(low),"g"(0) \
90 : "cc"); \
91 asm ("addq %2,%0; adcq %3,%1" \
92 : "+m"(r),"+d"(high) \
93 : "r"(carry),"g"(0) \
94 : "cc"); \
95 carry=high; \
96 } while (0)
97
98# define mul(r,a,word,carry) do { \
99 register BN_ULONG high,low; \
100 asm ("mulq %3" \
101 : "=a"(low),"=d"(high) \
102 : "a"(word),"g"(a) \
103 : "cc"); \
104 asm ("addq %2,%0; adcq %3,%1" \
105 : "+r"(carry),"+d"(high)\
106 : "a"(low),"g"(0) \
107 : "cc"); \
108 (r)=carry, carry=high; \
109 } while (0)
c27310f9 110# undef sqr
0f113f3e
MC
111# define sqr(r0,r1,a) \
112 asm ("mulq %2" \
113 : "=a"(r0),"=d"(r1) \
114 : "a"(a) \
115 : "cc");
116
117BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num,
118 BN_ULONG w)
119{
120 BN_ULONG c1 = 0;
121
122 if (num <= 0)
123 return (c1);
124
125 while (num & ~3) {
126 mul_add(rp[0], ap[0], w, c1);
127 mul_add(rp[1], ap[1], w, c1);
128 mul_add(rp[2], ap[2], w, c1);
129 mul_add(rp[3], ap[3], w, c1);
130 ap += 4;
131 rp += 4;
132 num -= 4;
133 }
134 if (num) {
135 mul_add(rp[0], ap[0], w, c1);
136 if (--num == 0)
137 return c1;
138 mul_add(rp[1], ap[1], w, c1);
139 if (--num == 0)
140 return c1;
141 mul_add(rp[2], ap[2], w, c1);
142 return c1;
143 }
144
145 return (c1);
146}
2f98abbc 147
41b76195 148BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
0f113f3e
MC
149{
150 BN_ULONG c1 = 0;
151
152 if (num <= 0)
153 return (c1);
154
155 while (num & ~3) {
156 mul(rp[0], ap[0], w, c1);
157 mul(rp[1], ap[1], w, c1);
158 mul(rp[2], ap[2], w, c1);
159 mul(rp[3], ap[3], w, c1);
160 ap += 4;
161 rp += 4;
162 num -= 4;
163 }
164 if (num) {
165 mul(rp[0], ap[0], w, c1);
166 if (--num == 0)
167 return c1;
168 mul(rp[1], ap[1], w, c1);
169 if (--num == 0)
170 return c1;
171 mul(rp[2], ap[2], w, c1);
172 }
173 return (c1);
174}
2f98abbc 175
41b76195 176void bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n)
0f113f3e
MC
177{
178 if (n <= 0)
179 return;
180
181 while (n & ~3) {
182 sqr(r[0], r[1], a[0]);
183 sqr(r[2], r[3], a[1]);
184 sqr(r[4], r[5], a[2]);
185 sqr(r[6], r[7], a[3]);
186 a += 4;
187 r += 8;
188 n -= 4;
189 }
190 if (n) {
191 sqr(r[0], r[1], a[0]);
192 if (--n == 0)
193 return;
194 sqr(r[2], r[3], a[1]);
195 if (--n == 0)
196 return;
197 sqr(r[4], r[5], a[2]);
198 }
199}
2f98abbc
AP
200
201BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
0f113f3e
MC
202{
203 BN_ULONG ret, waste;
2f98abbc 204
0f113f3e
MC
205 asm("divq %4":"=a"(ret), "=d"(waste)
206 : "a"(l), "d"(h), "g"(d)
207 : "cc");
2f98abbc 208
0f113f3e 209 return ret;
2f98abbc
AP
210}
211
0f113f3e
MC
212BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
213 int n)
214{
215 BN_ULONG ret;
216 size_t i = 0;
217
218 if (n <= 0)
219 return 0;
220
221 asm volatile (" subq %0,%0 \n" /* clear carry */
222 " jmp 1f \n"
223 ".p2align 4 \n"
224 "1: movq (%4,%2,8),%0 \n"
225 " adcq (%5,%2,8),%0 \n"
226 " movq %0,(%3,%2,8) \n"
227 " lea 1(%2),%2 \n"
228 " loop 1b \n"
229 " sbbq %0,%0 \n":"=&r" (ret), "+c"(n),
230 "+r"(i)
231 :"r"(rp), "r"(ap), "r"(bp)
232 :"cc", "memory");
233
234 return ret & 1;
2f98abbc
AP
235}
236
0f113f3e
MC
237# ifndef SIMICS
238BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
239 int n)
240{
241 BN_ULONG ret;
242 size_t i = 0;
243
244 if (n <= 0)
245 return 0;
246
247 asm volatile (" subq %0,%0 \n" /* clear borrow */
248 " jmp 1f \n"
249 ".p2align 4 \n"
250 "1: movq (%4,%2,8),%0 \n"
251 " sbbq (%5,%2,8),%0 \n"
252 " movq %0,(%3,%2,8) \n"
253 " lea 1(%2),%2 \n"
254 " loop 1b \n"
255 " sbbq %0,%0 \n":"=&r" (ret), "+c"(n),
256 "+r"(i)
257 :"r"(rp), "r"(ap), "r"(bp)
258 :"cc", "memory");
259
260 return ret & 1;
2f98abbc 261}
0f113f3e 262# else
2f98abbc 263/* Simics 1.4<7 has buggy sbbq:-( */
0f113f3e 264# define BN_MASK2 0xffffffffffffffffL
2f98abbc 265BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
0f113f3e
MC
266{
267 BN_ULONG t1, t2;
268 int c = 0;
269
270 if (n <= 0)
271 return ((BN_ULONG)0);
272
273 for (;;) {
274 t1 = a[0];
275 t2 = b[0];
276 r[0] = (t1 - t2 - c) & BN_MASK2;
277 if (t1 != t2)
278 c = (t1 < t2);
279 if (--n <= 0)
280 break;
281
282 t1 = a[1];
283 t2 = b[1];
284 r[1] = (t1 - t2 - c) & BN_MASK2;
285 if (t1 != t2)
286 c = (t1 < t2);
287 if (--n <= 0)
288 break;
289
290 t1 = a[2];
291 t2 = b[2];
292 r[2] = (t1 - t2 - c) & BN_MASK2;
293 if (t1 != t2)
294 c = (t1 < t2);
295 if (--n <= 0)
296 break;
297
298 t1 = a[3];
299 t2 = b[3];
300 r[3] = (t1 - t2 - c) & BN_MASK2;
301 if (t1 != t2)
302 c = (t1 < t2);
303 if (--n <= 0)
304 break;
305
306 a += 4;
307 b += 4;
308 r += 4;
309 }
310 return (c);
311}
312# endif
2f98abbc
AP
313
314/* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
315/* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
316/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
0f113f3e
MC
317/*
318 * sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number
319 * c=(c2,c1,c0)
320 */
2f98abbc 321
a7a44ba5
AP
322/*
323 * Keep in mind that carrying into high part of multiplication result
324 * can not overflow, because it cannot be all-ones.
325 */
0f113f3e 326# if 0
2f98abbc 327/* original macros are kept for reference purposes */
0f113f3e
MC
328# define mul_add_c(a,b,c0,c1,c2) do { \
329 BN_ULONG ta = (a), tb = (b); \
330 BN_ULONG lo, hi; \
331 BN_UMULT_LOHI(lo,hi,ta,tb); \
332 c0 += lo; hi += (c0<lo)?1:0; \
333 c1 += hi; c2 += (c1<hi)?1:0; \
334 } while(0)
335
336# define mul_add_c2(a,b,c0,c1,c2) do { \
337 BN_ULONG ta = (a), tb = (b); \
338 BN_ULONG lo, hi, tt; \
339 BN_UMULT_LOHI(lo,hi,ta,tb); \
340 c0 += lo; tt = hi+((c0<lo)?1:0); \
341 c1 += tt; c2 += (c1<tt)?1:0; \
342 c0 += lo; hi += (c0<lo)?1:0; \
343 c1 += hi; c2 += (c1<hi)?1:0; \
344 } while(0)
345
346# define sqr_add_c(a,i,c0,c1,c2) do { \
347 BN_ULONG ta = (a)[i]; \
348 BN_ULONG lo, hi; \
349 BN_UMULT_LOHI(lo,hi,ta,ta); \
350 c0 += lo; hi += (c0<lo)?1:0; \
351 c1 += hi; c2 += (c1<hi)?1:0; \
352 } while(0)
353# else
354# define mul_add_c(a,b,c0,c1,c2) do { \
355 BN_ULONG t1,t2; \
356 asm ("mulq %3" \
357 : "=a"(t1),"=d"(t2) \
358 : "a"(a),"m"(b) \
359 : "cc"); \
360 asm ("addq %3,%0; adcq %4,%1; adcq %5,%2" \
361 : "+r"(c0),"+r"(c1),"+r"(c2) \
362 : "r"(t1),"r"(t2),"g"(0) \
363 : "cc"); \
364 } while (0)
365
366# define sqr_add_c(a,i,c0,c1,c2) do { \
367 BN_ULONG t1,t2; \
368 asm ("mulq %2" \
369 : "=a"(t1),"=d"(t2) \
370 : "a"(a[i]) \
371 : "cc"); \
372 asm ("addq %3,%0; adcq %4,%1; adcq %5,%2" \
373 : "+r"(c0),"+r"(c1),"+r"(c2) \
374 : "r"(t1),"r"(t2),"g"(0) \
375 : "cc"); \
376 } while (0)
377
378# define mul_add_c2(a,b,c0,c1,c2) do { \
379 BN_ULONG t1,t2; \
380 asm ("mulq %3" \
381 : "=a"(t1),"=d"(t2) \
382 : "a"(a),"m"(b) \
383 : "cc"); \
384 asm ("addq %3,%0; adcq %4,%1; adcq %5,%2" \
385 : "+r"(c0),"+r"(c1),"+r"(c2) \
386 : "r"(t1),"r"(t2),"g"(0) \
387 : "cc"); \
388 asm ("addq %3,%0; adcq %4,%1; adcq %5,%2" \
389 : "+r"(c0),"+r"(c1),"+r"(c2) \
390 : "r"(t1),"r"(t2),"g"(0) \
391 : "cc"); \
392 } while (0)
393# endif
394
395# define sqr_add_c2(a,i,j,c0,c1,c2) \
396 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
2f98abbc
AP
397
398void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
0f113f3e
MC
399{
400 BN_ULONG c1, c2, c3;
401
402 c1 = 0;
403 c2 = 0;
404 c3 = 0;
405 mul_add_c(a[0], b[0], c1, c2, c3);
406 r[0] = c1;
407 c1 = 0;
408 mul_add_c(a[0], b[1], c2, c3, c1);
409 mul_add_c(a[1], b[0], c2, c3, c1);
410 r[1] = c2;
411 c2 = 0;
412 mul_add_c(a[2], b[0], c3, c1, c2);
413 mul_add_c(a[1], b[1], c3, c1, c2);
414 mul_add_c(a[0], b[2], c3, c1, c2);
415 r[2] = c3;
416 c3 = 0;
417 mul_add_c(a[0], b[3], c1, c2, c3);
418 mul_add_c(a[1], b[2], c1, c2, c3);
419 mul_add_c(a[2], b[1], c1, c2, c3);
420 mul_add_c(a[3], b[0], c1, c2, c3);
421 r[3] = c1;
422 c1 = 0;
423 mul_add_c(a[4], b[0], c2, c3, c1);
424 mul_add_c(a[3], b[1], c2, c3, c1);
425 mul_add_c(a[2], b[2], c2, c3, c1);
426 mul_add_c(a[1], b[3], c2, c3, c1);
427 mul_add_c(a[0], b[4], c2, c3, c1);
428 r[4] = c2;
429 c2 = 0;
430 mul_add_c(a[0], b[5], c3, c1, c2);
431 mul_add_c(a[1], b[4], c3, c1, c2);
432 mul_add_c(a[2], b[3], c3, c1, c2);
433 mul_add_c(a[3], b[2], c3, c1, c2);
434 mul_add_c(a[4], b[1], c3, c1, c2);
435 mul_add_c(a[5], b[0], c3, c1, c2);
436 r[5] = c3;
437 c3 = 0;
438 mul_add_c(a[6], b[0], c1, c2, c3);
439 mul_add_c(a[5], b[1], c1, c2, c3);
440 mul_add_c(a[4], b[2], c1, c2, c3);
441 mul_add_c(a[3], b[3], c1, c2, c3);
442 mul_add_c(a[2], b[4], c1, c2, c3);
443 mul_add_c(a[1], b[5], c1, c2, c3);
444 mul_add_c(a[0], b[6], c1, c2, c3);
445 r[6] = c1;
446 c1 = 0;
447 mul_add_c(a[0], b[7], c2, c3, c1);
448 mul_add_c(a[1], b[6], c2, c3, c1);
449 mul_add_c(a[2], b[5], c2, c3, c1);
450 mul_add_c(a[3], b[4], c2, c3, c1);
451 mul_add_c(a[4], b[3], c2, c3, c1);
452 mul_add_c(a[5], b[2], c2, c3, c1);
453 mul_add_c(a[6], b[1], c2, c3, c1);
454 mul_add_c(a[7], b[0], c2, c3, c1);
455 r[7] = c2;
456 c2 = 0;
457 mul_add_c(a[7], b[1], c3, c1, c2);
458 mul_add_c(a[6], b[2], c3, c1, c2);
459 mul_add_c(a[5], b[3], c3, c1, c2);
460 mul_add_c(a[4], b[4], c3, c1, c2);
461 mul_add_c(a[3], b[5], c3, c1, c2);
462 mul_add_c(a[2], b[6], c3, c1, c2);
463 mul_add_c(a[1], b[7], c3, c1, c2);
464 r[8] = c3;
465 c3 = 0;
466 mul_add_c(a[2], b[7], c1, c2, c3);
467 mul_add_c(a[3], b[6], c1, c2, c3);
468 mul_add_c(a[4], b[5], c1, c2, c3);
469 mul_add_c(a[5], b[4], c1, c2, c3);
470 mul_add_c(a[6], b[3], c1, c2, c3);
471 mul_add_c(a[7], b[2], c1, c2, c3);
472 r[9] = c1;
473 c1 = 0;
474 mul_add_c(a[7], b[3], c2, c3, c1);
475 mul_add_c(a[6], b[4], c2, c3, c1);
476 mul_add_c(a[5], b[5], c2, c3, c1);
477 mul_add_c(a[4], b[6], c2, c3, c1);
478 mul_add_c(a[3], b[7], c2, c3, c1);
479 r[10] = c2;
480 c2 = 0;
481 mul_add_c(a[4], b[7], c3, c1, c2);
482 mul_add_c(a[5], b[6], c3, c1, c2);
483 mul_add_c(a[6], b[5], c3, c1, c2);
484 mul_add_c(a[7], b[4], c3, c1, c2);
485 r[11] = c3;
486 c3 = 0;
487 mul_add_c(a[7], b[5], c1, c2, c3);
488 mul_add_c(a[6], b[6], c1, c2, c3);
489 mul_add_c(a[5], b[7], c1, c2, c3);
490 r[12] = c1;
491 c1 = 0;
492 mul_add_c(a[6], b[7], c2, c3, c1);
493 mul_add_c(a[7], b[6], c2, c3, c1);
494 r[13] = c2;
495 c2 = 0;
496 mul_add_c(a[7], b[7], c3, c1, c2);
497 r[14] = c3;
498 r[15] = c1;
499}
2f98abbc
AP
500
501void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
0f113f3e
MC
502{
503 BN_ULONG c1, c2, c3;
504
505 c1 = 0;
506 c2 = 0;
507 c3 = 0;
508 mul_add_c(a[0], b[0], c1, c2, c3);
509 r[0] = c1;
510 c1 = 0;
511 mul_add_c(a[0], b[1], c2, c3, c1);
512 mul_add_c(a[1], b[0], c2, c3, c1);
513 r[1] = c2;
514 c2 = 0;
515 mul_add_c(a[2], b[0], c3, c1, c2);
516 mul_add_c(a[1], b[1], c3, c1, c2);
517 mul_add_c(a[0], b[2], c3, c1, c2);
518 r[2] = c3;
519 c3 = 0;
520 mul_add_c(a[0], b[3], c1, c2, c3);
521 mul_add_c(a[1], b[2], c1, c2, c3);
522 mul_add_c(a[2], b[1], c1, c2, c3);
523 mul_add_c(a[3], b[0], c1, c2, c3);
524 r[3] = c1;
525 c1 = 0;
526 mul_add_c(a[3], b[1], c2, c3, c1);
527 mul_add_c(a[2], b[2], c2, c3, c1);
528 mul_add_c(a[1], b[3], c2, c3, c1);
529 r[4] = c2;
530 c2 = 0;
531 mul_add_c(a[2], b[3], c3, c1, c2);
532 mul_add_c(a[3], b[2], c3, c1, c2);
533 r[5] = c3;
534 c3 = 0;
535 mul_add_c(a[3], b[3], c1, c2, c3);
536 r[6] = c1;
537 r[7] = c2;
538}
2f98abbc 539
41b76195 540void bn_sqr_comba8(BN_ULONG *r, const BN_ULONG *a)
0f113f3e
MC
541{
542 BN_ULONG c1, c2, c3;
543
544 c1 = 0;
545 c2 = 0;
546 c3 = 0;
547 sqr_add_c(a, 0, c1, c2, c3);
548 r[0] = c1;
549 c1 = 0;
550 sqr_add_c2(a, 1, 0, c2, c3, c1);
551 r[1] = c2;
552 c2 = 0;
553 sqr_add_c(a, 1, c3, c1, c2);
554 sqr_add_c2(a, 2, 0, c3, c1, c2);
555 r[2] = c3;
556 c3 = 0;
557 sqr_add_c2(a, 3, 0, c1, c2, c3);
558 sqr_add_c2(a, 2, 1, c1, c2, c3);
559 r[3] = c1;
560 c1 = 0;
561 sqr_add_c(a, 2, c2, c3, c1);
562 sqr_add_c2(a, 3, 1, c2, c3, c1);
563 sqr_add_c2(a, 4, 0, c2, c3, c1);
564 r[4] = c2;
565 c2 = 0;
566 sqr_add_c2(a, 5, 0, c3, c1, c2);
567 sqr_add_c2(a, 4, 1, c3, c1, c2);
568 sqr_add_c2(a, 3, 2, c3, c1, c2);
569 r[5] = c3;
570 c3 = 0;
571 sqr_add_c(a, 3, c1, c2, c3);
572 sqr_add_c2(a, 4, 2, c1, c2, c3);
573 sqr_add_c2(a, 5, 1, c1, c2, c3);
574 sqr_add_c2(a, 6, 0, c1, c2, c3);
575 r[6] = c1;
576 c1 = 0;
577 sqr_add_c2(a, 7, 0, c2, c3, c1);
578 sqr_add_c2(a, 6, 1, c2, c3, c1);
579 sqr_add_c2(a, 5, 2, c2, c3, c1);
580 sqr_add_c2(a, 4, 3, c2, c3, c1);
581 r[7] = c2;
582 c2 = 0;
583 sqr_add_c(a, 4, c3, c1, c2);
584 sqr_add_c2(a, 5, 3, c3, c1, c2);
585 sqr_add_c2(a, 6, 2, c3, c1, c2);
586 sqr_add_c2(a, 7, 1, c3, c1, c2);
587 r[8] = c3;
588 c3 = 0;
589 sqr_add_c2(a, 7, 2, c1, c2, c3);
590 sqr_add_c2(a, 6, 3, c1, c2, c3);
591 sqr_add_c2(a, 5, 4, c1, c2, c3);
592 r[9] = c1;
593 c1 = 0;
594 sqr_add_c(a, 5, c2, c3, c1);
595 sqr_add_c2(a, 6, 4, c2, c3, c1);
596 sqr_add_c2(a, 7, 3, c2, c3, c1);
597 r[10] = c2;
598 c2 = 0;
599 sqr_add_c2(a, 7, 4, c3, c1, c2);
600 sqr_add_c2(a, 6, 5, c3, c1, c2);
601 r[11] = c3;
602 c3 = 0;
603 sqr_add_c(a, 6, c1, c2, c3);
604 sqr_add_c2(a, 7, 5, c1, c2, c3);
605 r[12] = c1;
606 c1 = 0;
607 sqr_add_c2(a, 7, 6, c2, c3, c1);
608 r[13] = c2;
609 c2 = 0;
610 sqr_add_c(a, 7, c3, c1, c2);
611 r[14] = c3;
612 r[15] = c1;
613}
2f98abbc 614
41b76195 615void bn_sqr_comba4(BN_ULONG *r, const BN_ULONG *a)
0f113f3e
MC
616{
617 BN_ULONG c1, c2, c3;
618
619 c1 = 0;
620 c2 = 0;
621 c3 = 0;
622 sqr_add_c(a, 0, c1, c2, c3);
623 r[0] = c1;
624 c1 = 0;
625 sqr_add_c2(a, 1, 0, c2, c3, c1);
626 r[1] = c2;
627 c2 = 0;
628 sqr_add_c(a, 1, c3, c1, c2);
629 sqr_add_c2(a, 2, 0, c3, c1, c2);
630 r[2] = c3;
631 c3 = 0;
632 sqr_add_c2(a, 3, 0, c1, c2, c3);
633 sqr_add_c2(a, 2, 1, c1, c2, c3);
634 r[3] = c1;
635 c1 = 0;
636 sqr_add_c(a, 2, c2, c3, c1);
637 sqr_add_c2(a, 3, 1, c2, c3, c1);
638 r[4] = c2;
639 c2 = 0;
640 sqr_add_c2(a, 3, 2, c3, c1, c2);
641 r[5] = c3;
642 c3 = 0;
643 sqr_add_c(a, 3, c1, c2, c3);
644 r[6] = c1;
645 r[7] = c2;
646}
c8a0d0aa 647#endif