]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_apple_csp/open_ssl/bn/bn_asm.c
2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 /* crypto/bn/bn_asm.c */
20 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
21 * All rights reserved.
23 * This package is an SSL implementation written
24 * by Eric Young (eay@cryptsoft.com).
25 * The implementation was written so as to conform with Netscapes SSL.
27 * This library is free for commercial and non-commercial use as long as
28 * the following conditions are aheared to. The following conditions
29 * apply to all code found in this distribution, be it the RC4, RSA,
30 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
31 * included with this distribution is covered by the same copyright terms
32 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
34 * Copyright remains Eric Young's, and as such any Copyright notices in
35 * the code are not to be removed.
36 * If this package is used in a product, Eric Young should be given attribution
37 * as the author of the parts of the library used.
38 * This can be in the form of a textual message at program startup or
39 * in documentation (online or textual) provided with the package.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * "This product includes cryptographic software written by
52 * Eric Young (eay@cryptsoft.com)"
53 * The word 'cryptographic' can be left out if the rouines from the library
54 * being used are not cryptographic related :-).
55 * 4. If you include any Windows specific code (or a derivative thereof) from
56 * the apps directory (application code) you must include an acknowledgement:
57 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
59 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * The licence and distribution terms for any publically available version or
72 * derivative of this code cannot be changed. i.e. this code cannot simply be
73 * copied and put under another distribution licence
74 * [including the GNU Public Licence.]
78 # undef NDEBUG /* avoid conflicting definitions */
83 #include <security_utilities/simulatecrash_assert.h>
87 #if defined(BN_LLONG) || defined(BN_UMULT_HIGH)
89 BN_ULONG
bn_mul_add_words(BN_ULONG
*rp
, BN_ULONG
*ap
, int num
, BN_ULONG w
)
94 if (num
<= 0) return(c1
);
98 mul_add(rp
[0],ap
[0],w
,c1
);
99 mul_add(rp
[1],ap
[1],w
,c1
);
100 mul_add(rp
[2],ap
[2],w
,c1
);
101 mul_add(rp
[3],ap
[3],w
,c1
);
102 ap
+=4; rp
+=4; num
-=4;
106 mul_add(rp
[0],ap
[0],w
,c1
); if (--num
==0) return c1
;
107 mul_add(rp
[1],ap
[1],w
,c1
); if (--num
==0) return c1
;
108 mul_add(rp
[2],ap
[2],w
,c1
); return c1
;
114 BN_ULONG
bn_mul_words(BN_ULONG
*rp
, BN_ULONG
*ap
, int num
, BN_ULONG w
)
119 if (num
<= 0) return(c1
);
123 mul(rp
[0],ap
[0],w
,c1
);
124 mul(rp
[1],ap
[1],w
,c1
);
125 mul(rp
[2],ap
[2],w
,c1
);
126 mul(rp
[3],ap
[3],w
,c1
);
127 ap
+=4; rp
+=4; num
-=4;
131 mul(rp
[0],ap
[0],w
,c1
); if (--num
== 0) return c1
;
132 mul(rp
[1],ap
[1],w
,c1
); if (--num
== 0) return c1
;
133 mul(rp
[2],ap
[2],w
,c1
);
138 void bn_sqr_words(BN_ULONG
*r
, BN_ULONG
*a
, int n
)
152 sqr(r
[0],r
[1],a
[0]); if (--n
== 0) return;
153 sqr(r
[2],r
[3],a
[1]); if (--n
== 0) return;
158 #else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
160 BN_ULONG
bn_mul_add_words(BN_ULONG
*rp
, BN_ULONG
*ap
, int num
, BN_ULONG w
)
166 if (num
<= 0) return((BN_ULONG
)0);
173 mul_add(rp
[0],ap
[0],bl
,bh
,c
);
174 if (--num
== 0) break;
175 mul_add(rp
[1],ap
[1],bl
,bh
,c
);
176 if (--num
== 0) break;
177 mul_add(rp
[2],ap
[2],bl
,bh
,c
);
178 if (--num
== 0) break;
179 mul_add(rp
[3],ap
[3],bl
,bh
,c
);
180 if (--num
== 0) break;
187 BN_ULONG
bn_mul_words(BN_ULONG
*rp
, BN_ULONG
*ap
, int num
, BN_ULONG w
)
193 if (num
<= 0) return((BN_ULONG
)0);
200 mul(rp
[0],ap
[0],bl
,bh
,carry
);
201 if (--num
== 0) break;
202 mul(rp
[1],ap
[1],bl
,bh
,carry
);
203 if (--num
== 0) break;
204 mul(rp
[2],ap
[2],bl
,bh
,carry
);
205 if (--num
== 0) break;
206 mul(rp
[3],ap
[3],bl
,bh
,carry
);
207 if (--num
== 0) break;
214 void bn_sqr_words(BN_ULONG
*r
, BN_ULONG
*a
, int n
)
220 sqr64(r
[0],r
[1],a
[0]);
223 sqr64(r
[2],r
[3],a
[1]);
226 sqr64(r
[4],r
[5],a
[2]);
229 sqr64(r
[6],r
[7],a
[3]);
237 #endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */
239 #if defined(BN_LLONG) && defined(BN_DIV2W)
241 BN_ULONG
bn_div_words(BN_ULONG h
, BN_ULONG l
, BN_ULONG d
)
243 return((BN_ULONG
)(((((BN_ULLONG
)h
)<<BN_BITS2
)|l
)/(BN_ULLONG
)d
));
248 /* Divide h-l by d and return the result. */
249 /* I need to test this some more :-( */
250 BN_ULONG
bn_div_words(BN_ULONG h
, BN_ULONG l
, BN_ULONG d
)
252 BN_ULONG dh
,dl
,q
,ret
=0,th
,tl
,t
;
255 if (d
== 0) return(BN_MASK2
);
257 i
=BN_num_bits_word(d
);
258 if ((i
!= BN_BITS2
) && (h
> (BN_ULONG
)1<<i
))
260 #if !defined(NO_STDIO) && !defined(WIN16)
261 fprintf(stderr
,"Division would overflow (%d)\n",i
);
271 h
=(h
<<i
)|(l
>>(BN_BITS2
-i
));
274 dh
=(d
&BN_MASK2h
)>>BN_BITS4
;
278 if ((h
>>BN_BITS4
) == dh
)
291 ((l
&BN_MASK2h
)>>BN_BITS4
))))
298 tl
=(tl
<<BN_BITS4
)&BN_MASK2h
;
310 if (--count
== 0) break;
313 h
=((h
<<BN_BITS4
)|(l
>>BN_BITS4
))&BN_MASK2
;
314 l
=(l
&BN_MASK2l
)<<BN_BITS4
;
319 #endif /* !defined(BN_LLONG) && defined(BN_DIV2W) */
322 BN_ULONG
bn_add_words(BN_ULONG
*r
, BN_ULONG
*a
, BN_ULONG
*b
, int n
)
327 if (n
<= 0) return((BN_ULONG
)0);
331 ll
+=(BN_ULLONG
)a
[0]+b
[0];
332 r
[0]=(BN_ULONG
)ll
&BN_MASK2
;
336 ll
+=(BN_ULLONG
)a
[1]+b
[1];
337 r
[1]=(BN_ULONG
)ll
&BN_MASK2
;
341 ll
+=(BN_ULLONG
)a
[2]+b
[2];
342 r
[2]=(BN_ULONG
)ll
&BN_MASK2
;
346 ll
+=(BN_ULLONG
)a
[3]+b
[3];
347 r
[3]=(BN_ULONG
)ll
&BN_MASK2
;
355 return((BN_ULONG
)ll
);
357 #else /* !BN_LLONG */
358 BN_ULONG
bn_add_words(BN_ULONG
*r
, BN_ULONG
*a
, BN_ULONG
*b
, int n
)
363 if (n
<= 0) return((BN_ULONG
)0);
406 #endif /* !BN_LLONG */
408 BN_ULONG
bn_sub_words(BN_ULONG
*r
, BN_ULONG
*a
, BN_ULONG
*b
, int n
)
414 if (n
<= 0) return((BN_ULONG
)0);
419 r
[0]=(t1
-t2
-c
)&BN_MASK2
;
420 if (t1
!= t2
) c
=(t1
< t2
);
424 r
[1]=(t1
-t2
-c
)&BN_MASK2
;
425 if (t1
!= t2
) c
=(t1
< t2
);
429 r
[2]=(t1
-t2
-c
)&BN_MASK2
;
430 if (t1
!= t2
) c
=(t1
< t2
);
434 r
[3]=(t1
-t2
-c
)&BN_MASK2
;
435 if (t1
!= t2
) c
=(t1
< t2
);
452 /* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */
453 /* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */
454 /* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
455 /* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
458 #define mul_add_c(a,b,c0,c1,c2) \
460 t1=(BN_ULONG)Lw(t); \
461 t2=(BN_ULONG)Hw(t); \
462 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
463 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
465 #define mul_add_c2(a,b,c0,c1,c2) \
469 t1=(BN_ULONG)Lw(tt); \
470 t2=(BN_ULONG)Hw(tt); \
471 c0=(c0+t1)&BN_MASK2; \
472 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
473 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
475 #define sqr_add_c(a,i,c0,c1,c2) \
476 t=(BN_ULLONG)a[i]*a[i]; \
477 t1=(BN_ULONG)Lw(t); \
478 t2=(BN_ULONG)Hw(t); \
479 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
480 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
482 #define sqr_add_c2(a,i,j,c0,c1,c2) \
483 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
485 #elif defined(BN_UMULT_HIGH)
487 #define mul_add_c(a,b,c0,c1,c2) { \
488 BN_ULONG ta=(a),tb=(b); \
490 t2 = BN_UMULT_HIGH(ta,tb); \
491 c0 += t1; t2 += (c0<t1)?1:0; \
492 c1 += t2; c2 += (c1<t2)?1:0; \
495 #define mul_add_c2(a,b,c0,c1,c2) { \
496 BN_ULONG ta=(a),tb=(b),t0; \
497 t1 = BN_UMULT_HIGH(ta,tb); \
499 t2 = t1+t1; c2 += (t2<t1)?1:0; \
500 t1 = t0+t0; t2 += (t1<t0)?1:0; \
501 c0 += t1; t2 += (c0<t1)?1:0; \
502 c1 += t2; c2 += (c1<t2)?1:0; \
505 #define sqr_add_c(a,i,c0,c1,c2) { \
506 BN_ULONG ta=(a)[i]; \
508 t2 = BN_UMULT_HIGH(ta,ta); \
509 c0 += t1; t2 += (c0<t1)?1:0; \
510 c1 += t2; c2 += (c1<t2)?1:0; \
513 #define sqr_add_c2(a,i,j,c0,c1,c2) \
514 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
516 #else /* !BN_LLONG */
517 #define mul_add_c(a,b,c0,c1,c2) \
518 t1=LBITS(a); t2=HBITS(a); \
519 bl=LBITS(b); bh=HBITS(b); \
520 mul64(t1,t2,bl,bh); \
521 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
522 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
524 #define mul_add_c2(a,b,c0,c1,c2) \
525 t1=LBITS(a); t2=HBITS(a); \
526 bl=LBITS(b); bh=HBITS(b); \
527 mul64(t1,t2,bl,bh); \
528 if (t2 & BN_TBIT) c2++; \
529 t2=(t2+t2)&BN_MASK2; \
530 if (t1 & BN_TBIT) t2++; \
531 t1=(t1+t1)&BN_MASK2; \
532 c0=(c0+t1)&BN_MASK2; \
533 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
534 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
536 #define sqr_add_c(a,i,c0,c1,c2) \
537 sqr64(t1,t2,(a)[i]); \
538 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
539 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
541 #define sqr_add_c2(a,i,j,c0,c1,c2) \
542 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
543 #endif /* !BN_LLONG */
545 void bn_mul_comba8(BN_ULONG
*r
, BN_ULONG
*a
, BN_ULONG
*b
)
558 mul_add_c(a
[0],b
[0],c1
,c2
,c3
);
561 mul_add_c(a
[0],b
[1],c2
,c3
,c1
);
562 mul_add_c(a
[1],b
[0],c2
,c3
,c1
);
565 mul_add_c(a
[2],b
[0],c3
,c1
,c2
);
566 mul_add_c(a
[1],b
[1],c3
,c1
,c2
);
567 mul_add_c(a
[0],b
[2],c3
,c1
,c2
);
570 mul_add_c(a
[0],b
[3],c1
,c2
,c3
);
571 mul_add_c(a
[1],b
[2],c1
,c2
,c3
);
572 mul_add_c(a
[2],b
[1],c1
,c2
,c3
);
573 mul_add_c(a
[3],b
[0],c1
,c2
,c3
);
576 mul_add_c(a
[4],b
[0],c2
,c3
,c1
);
577 mul_add_c(a
[3],b
[1],c2
,c3
,c1
);
578 mul_add_c(a
[2],b
[2],c2
,c3
,c1
);
579 mul_add_c(a
[1],b
[3],c2
,c3
,c1
);
580 mul_add_c(a
[0],b
[4],c2
,c3
,c1
);
583 mul_add_c(a
[0],b
[5],c3
,c1
,c2
);
584 mul_add_c(a
[1],b
[4],c3
,c1
,c2
);
585 mul_add_c(a
[2],b
[3],c3
,c1
,c2
);
586 mul_add_c(a
[3],b
[2],c3
,c1
,c2
);
587 mul_add_c(a
[4],b
[1],c3
,c1
,c2
);
588 mul_add_c(a
[5],b
[0],c3
,c1
,c2
);
591 mul_add_c(a
[6],b
[0],c1
,c2
,c3
);
592 mul_add_c(a
[5],b
[1],c1
,c2
,c3
);
593 mul_add_c(a
[4],b
[2],c1
,c2
,c3
);
594 mul_add_c(a
[3],b
[3],c1
,c2
,c3
);
595 mul_add_c(a
[2],b
[4],c1
,c2
,c3
);
596 mul_add_c(a
[1],b
[5],c1
,c2
,c3
);
597 mul_add_c(a
[0],b
[6],c1
,c2
,c3
);
600 mul_add_c(a
[0],b
[7],c2
,c3
,c1
);
601 mul_add_c(a
[1],b
[6],c2
,c3
,c1
);
602 mul_add_c(a
[2],b
[5],c2
,c3
,c1
);
603 mul_add_c(a
[3],b
[4],c2
,c3
,c1
);
604 mul_add_c(a
[4],b
[3],c2
,c3
,c1
);
605 mul_add_c(a
[5],b
[2],c2
,c3
,c1
);
606 mul_add_c(a
[6],b
[1],c2
,c3
,c1
);
607 mul_add_c(a
[7],b
[0],c2
,c3
,c1
);
610 mul_add_c(a
[7],b
[1],c3
,c1
,c2
);
611 mul_add_c(a
[6],b
[2],c3
,c1
,c2
);
612 mul_add_c(a
[5],b
[3],c3
,c1
,c2
);
613 mul_add_c(a
[4],b
[4],c3
,c1
,c2
);
614 mul_add_c(a
[3],b
[5],c3
,c1
,c2
);
615 mul_add_c(a
[2],b
[6],c3
,c1
,c2
);
616 mul_add_c(a
[1],b
[7],c3
,c1
,c2
);
619 mul_add_c(a
[2],b
[7],c1
,c2
,c3
);
620 mul_add_c(a
[3],b
[6],c1
,c2
,c3
);
621 mul_add_c(a
[4],b
[5],c1
,c2
,c3
);
622 mul_add_c(a
[5],b
[4],c1
,c2
,c3
);
623 mul_add_c(a
[6],b
[3],c1
,c2
,c3
);
624 mul_add_c(a
[7],b
[2],c1
,c2
,c3
);
627 mul_add_c(a
[7],b
[3],c2
,c3
,c1
);
628 mul_add_c(a
[6],b
[4],c2
,c3
,c1
);
629 mul_add_c(a
[5],b
[5],c2
,c3
,c1
);
630 mul_add_c(a
[4],b
[6],c2
,c3
,c1
);
631 mul_add_c(a
[3],b
[7],c2
,c3
,c1
);
634 mul_add_c(a
[4],b
[7],c3
,c1
,c2
);
635 mul_add_c(a
[5],b
[6],c3
,c1
,c2
);
636 mul_add_c(a
[6],b
[5],c3
,c1
,c2
);
637 mul_add_c(a
[7],b
[4],c3
,c1
,c2
);
640 mul_add_c(a
[7],b
[5],c1
,c2
,c3
);
641 mul_add_c(a
[6],b
[6],c1
,c2
,c3
);
642 mul_add_c(a
[5],b
[7],c1
,c2
,c3
);
645 mul_add_c(a
[6],b
[7],c2
,c3
,c1
);
646 mul_add_c(a
[7],b
[6],c2
,c3
,c1
);
649 mul_add_c(a
[7],b
[7],c3
,c1
,c2
);
654 void bn_mul_comba4(BN_ULONG
*r
, BN_ULONG
*a
, BN_ULONG
*b
)
667 mul_add_c(a
[0],b
[0],c1
,c2
,c3
);
670 mul_add_c(a
[0],b
[1],c2
,c3
,c1
);
671 mul_add_c(a
[1],b
[0],c2
,c3
,c1
);
674 mul_add_c(a
[2],b
[0],c3
,c1
,c2
);
675 mul_add_c(a
[1],b
[1],c3
,c1
,c2
);
676 mul_add_c(a
[0],b
[2],c3
,c1
,c2
);
679 mul_add_c(a
[0],b
[3],c1
,c2
,c3
);
680 mul_add_c(a
[1],b
[2],c1
,c2
,c3
);
681 mul_add_c(a
[2],b
[1],c1
,c2
,c3
);
682 mul_add_c(a
[3],b
[0],c1
,c2
,c3
);
685 mul_add_c(a
[3],b
[1],c2
,c3
,c1
);
686 mul_add_c(a
[2],b
[2],c2
,c3
,c1
);
687 mul_add_c(a
[1],b
[3],c2
,c3
,c1
);
690 mul_add_c(a
[2],b
[3],c3
,c1
,c2
);
691 mul_add_c(a
[3],b
[2],c3
,c1
,c2
);
694 mul_add_c(a
[3],b
[3],c1
,c2
,c3
);
699 void bn_sqr_comba8(BN_ULONG
*r
, BN_ULONG
*a
)
712 sqr_add_c(a
,0,c1
,c2
,c3
);
715 sqr_add_c2(a
,1,0,c2
,c3
,c1
);
718 sqr_add_c(a
,1,c3
,c1
,c2
);
719 sqr_add_c2(a
,2,0,c3
,c1
,c2
);
722 sqr_add_c2(a
,3,0,c1
,c2
,c3
);
723 sqr_add_c2(a
,2,1,c1
,c2
,c3
);
726 sqr_add_c(a
,2,c2
,c3
,c1
);
727 sqr_add_c2(a
,3,1,c2
,c3
,c1
);
728 sqr_add_c2(a
,4,0,c2
,c3
,c1
);
731 sqr_add_c2(a
,5,0,c3
,c1
,c2
);
732 sqr_add_c2(a
,4,1,c3
,c1
,c2
);
733 sqr_add_c2(a
,3,2,c3
,c1
,c2
);
736 sqr_add_c(a
,3,c1
,c2
,c3
);
737 sqr_add_c2(a
,4,2,c1
,c2
,c3
);
738 sqr_add_c2(a
,5,1,c1
,c2
,c3
);
739 sqr_add_c2(a
,6,0,c1
,c2
,c3
);
742 sqr_add_c2(a
,7,0,c2
,c3
,c1
);
743 sqr_add_c2(a
,6,1,c2
,c3
,c1
);
744 sqr_add_c2(a
,5,2,c2
,c3
,c1
);
745 sqr_add_c2(a
,4,3,c2
,c3
,c1
);
748 sqr_add_c(a
,4,c3
,c1
,c2
);
749 sqr_add_c2(a
,5,3,c3
,c1
,c2
);
750 sqr_add_c2(a
,6,2,c3
,c1
,c2
);
751 sqr_add_c2(a
,7,1,c3
,c1
,c2
);
754 sqr_add_c2(a
,7,2,c1
,c2
,c3
);
755 sqr_add_c2(a
,6,3,c1
,c2
,c3
);
756 sqr_add_c2(a
,5,4,c1
,c2
,c3
);
759 sqr_add_c(a
,5,c2
,c3
,c1
);
760 sqr_add_c2(a
,6,4,c2
,c3
,c1
);
761 sqr_add_c2(a
,7,3,c2
,c3
,c1
);
764 sqr_add_c2(a
,7,4,c3
,c1
,c2
);
765 sqr_add_c2(a
,6,5,c3
,c1
,c2
);
768 sqr_add_c(a
,6,c1
,c2
,c3
);
769 sqr_add_c2(a
,7,5,c1
,c2
,c3
);
772 sqr_add_c2(a
,7,6,c2
,c3
,c1
);
775 sqr_add_c(a
,7,c3
,c1
,c2
);
780 void bn_sqr_comba4(BN_ULONG
*r
, BN_ULONG
*a
)
793 sqr_add_c(a
,0,c1
,c2
,c3
);
796 sqr_add_c2(a
,1,0,c2
,c3
,c1
);
799 sqr_add_c(a
,1,c3
,c1
,c2
);
800 sqr_add_c2(a
,2,0,c3
,c1
,c2
);
803 sqr_add_c2(a
,3,0,c1
,c2
,c3
);
804 sqr_add_c2(a
,2,1,c1
,c2
,c3
);
807 sqr_add_c(a
,2,c2
,c3
,c1
);
808 sqr_add_c2(a
,3,1,c2
,c3
,c1
);
811 sqr_add_c2(a
,3,2,c3
,c1
,c2
);
814 sqr_add_c(a
,3,c1
,c2
,c3
);
818 #else /* !BN_MUL_COMBA */
820 /* hmm... is it faster just to do a multiply? */
822 void bn_sqr_comba4(BN_ULONG
*r
, BN_ULONG
*a
)
825 bn_sqr_normal(r
,a
,4,t
);
829 void bn_sqr_comba8(BN_ULONG
*r
, BN_ULONG
*a
)
832 bn_sqr_normal(r
,a
,8,t
);
835 void bn_mul_comba4(BN_ULONG
*r
, BN_ULONG
*a
, BN_ULONG
*b
)
837 r
[4]=bn_mul_words( &(r
[0]),a
,4,b
[0]);
838 r
[5]=bn_mul_add_words(&(r
[1]),a
,4,b
[1]);
839 r
[6]=bn_mul_add_words(&(r
[2]),a
,4,b
[2]);
840 r
[7]=bn_mul_add_words(&(r
[3]),a
,4,b
[3]);
843 void bn_mul_comba8(BN_ULONG
*r
, BN_ULONG
*a
, BN_ULONG
*b
)
845 r
[ 8]=bn_mul_words( &(r
[0]),a
,8,b
[0]);
846 r
[ 9]=bn_mul_add_words(&(r
[1]),a
,8,b
[1]);
847 r
[10]=bn_mul_add_words(&(r
[2]),a
,8,b
[2]);
848 r
[11]=bn_mul_add_words(&(r
[3]),a
,8,b
[3]);
849 r
[12]=bn_mul_add_words(&(r
[4]),a
,8,b
[4]);
850 r
[13]=bn_mul_add_words(&(r
[5]),a
,8,b
[5]);
851 r
[14]=bn_mul_add_words(&(r
[6]),a
,8,b
[6]);
852 r
[15]=bn_mul_add_words(&(r
[7]),a
,8,b
[7]);
855 #endif /* !BN_MUL_COMBA */