1 /* fp_mul_comba_8.i
2 *
3 * Copyright (C) 2006-2021 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL 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 * wolfSSL 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23
24 #ifdef TFM_MUL8
fp_mul_comba8(fp_int * A,fp_int * B,fp_int * C)25 int fp_mul_comba8(fp_int *A, fp_int *B, fp_int *C)
26 {
27 fp_digit c0, c1, c2;
28 #ifndef WOLFSSL_SMALL_STACK
29 fp_digit at[16];
30 #else
31 fp_digit *at;
32 #endif
33
34 #ifdef WOLFSSL_SMALL_STACK
35 at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
36 if (at == NULL)
37 return FP_MEM;
38 #endif
39
40 XMEMCPY(at, A->dp, 8 * sizeof(fp_digit));
41 XMEMCPY(at+8, B->dp, 8 * sizeof(fp_digit));
42 COMBA_START;
43
44 COMBA_CLEAR;
45 /* 0 */
46 MULADD(at[0], at[8]);
47 COMBA_STORE(C->dp[0]);
48 /* 1 */
49 COMBA_FORWARD;
50 MULADD(at[0], at[9]); MULADD(at[1], at[8]);
51 COMBA_STORE(C->dp[1]);
52 /* 2 */
53 COMBA_FORWARD;
54 MULADD(at[0], at[10]); MULADD(at[1], at[9]); MULADD(at[2], at[8]);
55 COMBA_STORE(C->dp[2]);
56 /* 3 */
57 COMBA_FORWARD;
58 MULADD(at[0], at[11]); MULADD(at[1], at[10]); MULADD(at[2], at[9]); MULADD(at[3], at[8]);
59 COMBA_STORE(C->dp[3]);
60 /* 4 */
61 COMBA_FORWARD;
62 MULADD(at[0], at[12]); MULADD(at[1], at[11]); MULADD(at[2], at[10]); MULADD(at[3], at[9]); MULADD(at[4], at[8]);
63 COMBA_STORE(C->dp[4]);
64 /* 5 */
65 COMBA_FORWARD;
66 MULADD(at[0], at[13]); MULADD(at[1], at[12]); MULADD(at[2], at[11]); MULADD(at[3], at[10]); MULADD(at[4], at[9]); MULADD(at[5], at[8]);
67 COMBA_STORE(C->dp[5]);
68 /* 6 */
69 COMBA_FORWARD;
70 MULADD(at[0], at[14]); MULADD(at[1], at[13]); MULADD(at[2], at[12]); MULADD(at[3], at[11]); MULADD(at[4], at[10]); MULADD(at[5], at[9]); MULADD(at[6], at[8]);
71 COMBA_STORE(C->dp[6]);
72 /* 7 */
73 COMBA_FORWARD;
74 MULADD(at[0], at[15]); MULADD(at[1], at[14]); MULADD(at[2], at[13]); MULADD(at[3], at[12]); MULADD(at[4], at[11]); MULADD(at[5], at[10]); MULADD(at[6], at[9]); MULADD(at[7], at[8]);
75 COMBA_STORE(C->dp[7]);
76 /* 8 */
77 COMBA_FORWARD;
78 MULADD(at[1], at[15]); MULADD(at[2], at[14]); MULADD(at[3], at[13]); MULADD(at[4], at[12]); MULADD(at[5], at[11]); MULADD(at[6], at[10]); MULADD(at[7], at[9]);
79 COMBA_STORE(C->dp[8]);
80 /* 9 */
81 COMBA_FORWARD;
82 MULADD(at[2], at[15]); MULADD(at[3], at[14]); MULADD(at[4], at[13]); MULADD(at[5], at[12]); MULADD(at[6], at[11]); MULADD(at[7], at[10]);
83 COMBA_STORE(C->dp[9]);
84 /* 10 */
85 COMBA_FORWARD;
86 MULADD(at[3], at[15]); MULADD(at[4], at[14]); MULADD(at[5], at[13]); MULADD(at[6], at[12]); MULADD(at[7], at[11]);
87 COMBA_STORE(C->dp[10]);
88 /* 11 */
89 COMBA_FORWARD;
90 MULADD(at[4], at[15]); MULADD(at[5], at[14]); MULADD(at[6], at[13]); MULADD(at[7], at[12]);
91 COMBA_STORE(C->dp[11]);
92 /* 12 */
93 COMBA_FORWARD;
94 MULADD(at[5], at[15]); MULADD(at[6], at[14]); MULADD(at[7], at[13]);
95 COMBA_STORE(C->dp[12]);
96 /* 13 */
97 COMBA_FORWARD;
98 MULADD(at[6], at[15]); MULADD(at[7], at[14]);
99 COMBA_STORE(C->dp[13]);
100 /* 14 */
101 COMBA_FORWARD;
102 MULADD(at[7], at[15]);
103 COMBA_STORE(C->dp[14]);
104 COMBA_STORE2(C->dp[15]);
105 C->used = 16;
106 C->sign = A->sign ^ B->sign;
107 fp_clamp(C);
108 COMBA_FINI;
109
110 #ifdef WOLFSSL_SMALL_STACK
111 XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER);
112 #endif
113 return FP_OKAY;
114 }
115 #endif
116