]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/CyaSSL/ctaocrypt/src/fp_sqr_comba_8.i
7d7e58f3f721645f4be522efe7f6413b16f73a0b
[freertos] / FreeRTOS-Plus / Source / CyaSSL / ctaocrypt / src / fp_sqr_comba_8.i
1 /* fp_sqr_comba_8.i
2  *
3  * Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
4  *
5  * This file is part of CyaSSL.
6  *
7  * CyaSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * CyaSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20  */
21
22
23 #ifdef TFM_SQR8
24 void fp_sqr_comba8(fp_int *A, fp_int *B)
25 {
26    fp_digit *a, b[16], c0, c1, c2, sc0, sc1, sc2;
27
28    a = A->dp;
29    COMBA_START; 
30
31    /* clear carries */
32    CLEAR_CARRY;
33
34    /* output 0 */
35    SQRADD(a[0],a[0]);
36    COMBA_STORE(b[0]);
37
38    /* output 1 */
39    CARRY_FORWARD;
40    SQRADD2(a[0], a[1]); 
41    COMBA_STORE(b[1]);
42
43    /* output 2 */
44    CARRY_FORWARD;
45    SQRADD2(a[0], a[2]); SQRADD(a[1], a[1]); 
46    COMBA_STORE(b[2]);
47
48    /* output 3 */
49    CARRY_FORWARD;
50    SQRADD2(a[0], a[3]); SQRADD2(a[1], a[2]); 
51    COMBA_STORE(b[3]);
52
53    /* output 4 */
54    CARRY_FORWARD;
55    SQRADD2(a[0], a[4]); SQRADD2(a[1], a[3]); SQRADD(a[2], a[2]); 
56    COMBA_STORE(b[4]);
57
58    /* output 5 */
59    CARRY_FORWARD;
60    SQRADDSC(a[0], a[5]); SQRADDAC(a[1], a[4]); SQRADDAC(a[2], a[3]); SQRADDDB; 
61    COMBA_STORE(b[5]);
62
63    /* output 6 */
64    CARRY_FORWARD;
65    SQRADDSC(a[0], a[6]); SQRADDAC(a[1], a[5]); SQRADDAC(a[2], a[4]); SQRADDDB; SQRADD(a[3], a[3]); 
66    COMBA_STORE(b[6]);
67
68    /* output 7 */
69    CARRY_FORWARD;
70    SQRADDSC(a[0], a[7]); SQRADDAC(a[1], a[6]); SQRADDAC(a[2], a[5]); SQRADDAC(a[3], a[4]); SQRADDDB; 
71    COMBA_STORE(b[7]);
72
73    /* output 8 */
74    CARRY_FORWARD;
75    SQRADDSC(a[1], a[7]); SQRADDAC(a[2], a[6]); SQRADDAC(a[3], a[5]); SQRADDDB; SQRADD(a[4], a[4]); 
76    COMBA_STORE(b[8]);
77
78    /* output 9 */
79    CARRY_FORWARD;
80    SQRADDSC(a[2], a[7]); SQRADDAC(a[3], a[6]); SQRADDAC(a[4], a[5]); SQRADDDB; 
81    COMBA_STORE(b[9]);
82
83    /* output 10 */
84    CARRY_FORWARD;
85    SQRADD2(a[3], a[7]); SQRADD2(a[4], a[6]); SQRADD(a[5], a[5]); 
86    COMBA_STORE(b[10]);
87
88    /* output 11 */
89    CARRY_FORWARD;
90    SQRADD2(a[4], a[7]); SQRADD2(a[5], a[6]); 
91    COMBA_STORE(b[11]);
92
93    /* output 12 */
94    CARRY_FORWARD;
95    SQRADD2(a[5], a[7]); SQRADD(a[6], a[6]); 
96    COMBA_STORE(b[12]);
97
98    /* output 13 */
99    CARRY_FORWARD;
100    SQRADD2(a[6], a[7]); 
101    COMBA_STORE(b[13]);
102
103    /* output 14 */
104    CARRY_FORWARD;
105    SQRADD(a[7], a[7]); 
106    COMBA_STORE(b[14]);
107    COMBA_STORE2(b[15]);
108    COMBA_FINI;
109
110    B->used = 16;
111    B->sign = FP_ZPOS;
112    memcpy(B->dp, b, 16 * sizeof(fp_digit));
113    fp_clamp(B);
114 }
115 #endif
116
117