/src/wolfssl-fastmath/wolfcrypt/src/fp_mul_comba_4.i
Line | Count | Source |
1 | | /* fp_mul_comba_4.i |
2 | | * |
3 | | * Copyright (C) 2006-2025 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 3 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_MUL4 |
25 | | int fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C) |
26 | 5.63M | { |
27 | 5.63M | fp_digit c0, c1, c2; |
28 | | #ifndef WOLFSSL_SMALL_STACK |
29 | | fp_digit at[8]; |
30 | | #else |
31 | 5.63M | fp_digit *at; |
32 | 5.63M | #endif |
33 | | |
34 | 5.63M | #ifdef WOLFSSL_SMALL_STACK |
35 | 5.63M | at = (fp_digit*)XMALLOC(sizeof(fp_digit) * 8, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
36 | 5.63M | if (at == NULL) |
37 | 106 | return FP_MEM; |
38 | 5.63M | #endif |
39 | | |
40 | 5.63M | XMEMCPY(at, A->dp, 4 * sizeof(fp_digit)); |
41 | 5.63M | XMEMCPY(at+4, B->dp, 4 * sizeof(fp_digit)); |
42 | 5.63M | COMBA_START; |
43 | | |
44 | 5.63M | COMBA_CLEAR; |
45 | | /* 0 */ |
46 | 5.63M | MULADD(at[0], at[4]); |
47 | 5.63M | COMBA_STORE(C->dp[0]); |
48 | | /* 1 */ |
49 | 5.63M | COMBA_FORWARD; |
50 | 5.63M | MULADD(at[0], at[5]); MULADD(at[1], at[4]); |
51 | 5.63M | COMBA_STORE(C->dp[1]); |
52 | | /* 2 */ |
53 | 5.63M | COMBA_FORWARD; |
54 | 5.63M | MULADD(at[0], at[6]); MULADD(at[1], at[5]); MULADD(at[2], at[4]); |
55 | 5.63M | COMBA_STORE(C->dp[2]); |
56 | | /* 3 */ |
57 | 5.63M | COMBA_FORWARD; |
58 | 5.63M | MULADD(at[0], at[7]); MULADD(at[1], at[6]); MULADD(at[2], at[5]); MULADD(at[3], at[4]); |
59 | 5.63M | COMBA_STORE(C->dp[3]); |
60 | | /* 4 */ |
61 | 5.63M | COMBA_FORWARD; |
62 | 5.63M | MULADD(at[1], at[7]); MULADD(at[2], at[6]); MULADD(at[3], at[5]); |
63 | 5.63M | COMBA_STORE(C->dp[4]); |
64 | | /* 5 */ |
65 | 5.63M | COMBA_FORWARD; |
66 | 5.63M | MULADD(at[2], at[7]); MULADD(at[3], at[6]); |
67 | 5.63M | COMBA_STORE(C->dp[5]); |
68 | | /* 6 */ |
69 | 5.63M | COMBA_FORWARD; |
70 | 5.63M | MULADD(at[3], at[7]); |
71 | 5.63M | COMBA_STORE(C->dp[6]); |
72 | 5.63M | COMBA_STORE2(C->dp[7]); |
73 | 5.63M | C->used = 8; |
74 | 5.63M | C->sign = A->sign ^ B->sign; |
75 | 5.63M | fp_clamp(C); |
76 | 5.63M | COMBA_FINI; |
77 | | |
78 | 5.63M | #ifdef WOLFSSL_SMALL_STACK |
79 | 5.63M | XFREE(at, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
80 | 5.63M | #endif |
81 | 5.63M | return FP_OKAY; |
82 | 5.63M | } |
83 | | #endif |