b6074a2e05e996df730236ac3c0aa31f76ee38af
[platform/upstream/nettle.git] / arm / ecc-192-modp.asm
1 C arm/ecc-192-modp.asm
2
3 ifelse(<
4    Copyright (C) 2013 Niels Möller
5
6    This file is part of GNU Nettle.
7
8    GNU Nettle is free software: you can redistribute it and/or
9    modify it under the terms of either:
10
11      * the GNU Lesser General Public License as published by the Free
12        Software Foundation; either version 3 of the License, or (at your
13        option) any later version.
14
15    or
16
17      * the GNU General Public License as published by the Free
18        Software Foundation; either version 2 of the License, or (at your
19        option) any later version.
20
21    or both in parallel, as here.
22
23    GNU Nettle is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26    General Public License for more details.
27
28    You should have received copies of the GNU General Public License and
29    the GNU Lesser General Public License along with this program.  If
30    not, see http://www.gnu.org/licenses/.
31 >) 
32
33         .file "ecc-192-modp.asm"
34         .arm
35
36 define(<HP>, <r0>) C Overlaps unused modulo argument
37 define(<RP>, <r1>)
38
39 define(<T0>, <r2>)
40 define(<T1>, <r3>)
41 define(<T2>, <r4>)
42 define(<T3>, <r5>)
43 define(<T4>, <r6>)
44 define(<T5>, <r7>)
45 define(<T6>, <r8>)
46 define(<T7>, <r10>)
47 define(<H0>, <T0>) C Overlaps T0 and T1
48 define(<H1>, <T1>)
49 define(<C2>, <HP>)
50 define(<C4>, <r12>)
51
52         C ecc_192_modp (const struct ecc_modulo *m, mp_limb_t *rp)
53         .text
54         .align 2
55
56 PROLOGUE(nettle_ecc_192_modp)
57         push    {r4,r5,r6,r7,r8,r10}
58         C Reduce two words at a time
59         add     HP, RP, #48
60         add     RP, RP, #8
61         ldmdb   HP!, {H0,H1}
62         ldm     RP, {T2,T3,T4,T5,T6,T7}
63         mov     C4, #0
64         adds    T4, T4, H0
65         adcs    T5, T5, H1
66         adcs    T6, T6, H0
67         adcs    T7, T7, H1
68         C Need to add carry to T2 and T4, do T4 later.
69         adc     C4, C4, #0
70
71         ldmdb   HP!, {H0,H1}
72         mov     C2, #0
73         adcs    T2, T2, H0
74         adcs    T3, T3, H1
75         adcs    T4, T4, H0
76         adcs    T5, T5, H1
77         C Need to add carry to T0 and T2, do T2 later
78         adc     C2, C2, #0
79
80         ldmdb   RP!, {T0, T1}
81         adcs    T0, T0, T6
82         adcs    T1, T1, T7
83         adcs    T2, T2, T6
84         adcs    T3, T3, T7
85         adc     C4, C4, #0
86
87         adds    T2, T2, C2
88         adcs    T3, T3, #0
89         adcs    T4, T4, C4
90         adcs    T5, T5, #0
91         mov     C2, #0
92         adc     C2, C2, #0
93
94         C Add in final carry
95         adcs    T0, T0, #0
96         adcs    T1, T1, #0
97         adcs    T2, T2, C2
98         adcs    T3, T3, #0
99         adcs    T4, T4, #0
100         adc     T5, T5, #0
101
102         stm     RP, {T0,T1,T2,T3,T4,T5}
103
104         pop     {r4,r5,r6,r7,r8,r10}
105         bx      lr
106 EPILOGUE(nettle_ecc_192_modp)