Revert "Merge branch 'upstream' into tizen"
[platform/upstream/nettle.git] / arm / ecc-521-modp.asm
1 C nettle, low-level cryptographics library
2 C
3 C Copyright (C) 2013, Niels Möller
4 C
5 C The nettle library is free software; you can redistribute it and/or modify
6 C it under the terms of the GNU Lesser General Public License as published by
7 C the Free Software Foundation; either version 2.1 of the License, or (at your
8 C option) any later version.
9 C
10 C The nettle library is distributed in the hope that it will be useful, but
11 C WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 C or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
13 C License for more details.
14 C
15 C You should have received a copy of the GNU Lesser General Public License
16 C along with the nettle library; see the file COPYING.LIB.  If not, write to
17 C the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 C MA 02111-1301, USA.
19
20         .file "ecc-521-modp.asm"
21         .arm
22
23 define(<HP>, <r0>)
24 define(<RP>, <r1>)
25 define(<T0>, <r2>)
26 define(<T1>, <r3>)
27 define(<T2>, <r4>)
28 define(<F0>, <r5>)
29 define(<F1>, <r6>)
30 define(<F2>, <r7>)
31 define(<F3>, <r8>)
32 define(<H>, <r12>)
33 define(<N>, <lr>)
34
35         C ecc_521_modp (const struct ecc_curve *ecc, mp_limb_t *rp)
36         .text
37 .Lc511:
38         .int 511
39
40         .align 2
41
42 PROLOGUE(nettle_ecc_521_modp)
43         push    {r4,r5,r6,r7,r8,lr}
44
45         C Use that B^17 = 2^23 (mod p)
46         ldr     F3, [RP, #+68]          C 17
47         add     HP, RP, #72             C 18
48         ldr     T0, [RP]                C 0
49         adds    T0, T0, F3, lsl #23
50         str     T0, [RP], #+4
51         mov     N, #5
52
53         C 5 iterations, reading limbs 18-20, 21-23, 24-26, 27-29, 30-32
54         C and adding to limbs          1-3,    4-6,   7-9, 19-12, 13-15
55 .Loop:
56         ldm     RP, {T0,T1,T2}          C  1+3*k --  3+3*k
57         lsr     F0, F3, #9
58         ldm     HP!, {F1,F2,F3}         C 18+3*k -- 20+3*k
59         orr     F0, F0, F1, lsl #23
60         lsr     F1, F1, #9
61         orr     F1, F1, F2, lsl #23
62         lsr     F2, F2, #9
63         orr     F2, F2, F3, lsl #23
64         adcs    T0, T0, F0
65         adcs    T1, T1, F1
66         adcs    T2, T2, F2
67         sub     N, N, #1
68         stm     RP!,{T0,T1,T2}
69         teq     N, #0
70         bne     .Loop
71
72         ldr     F0, [RP], #-64          C 16
73         ldr     F1, [HP]                C 33
74         ldr     T0, .Lc511
75
76         C Handling of high limbs
77         C F0 = rp[16] + carry in + F3 >> 9
78         adcs    F0, F0, F3, lsr #9
79         C Copy low 9 bits to H, then shift right including carry
80         and     H, F0, T0
81         rrx     F0, F0
82         lsr     F0, F0, #8
83         C Add in F1 = rp[33], with weight 2^1056 = 2^14
84         adds    F0, F0, F1, lsl #14
85         lsr     F1, F1, #18
86         adc     F1, F1, #0
87
88         ldm     RP, {T0, T1}            C 0-1
89         adds    T0, T0, F0
90         adcs    T1, T1, F1
91         stm     RP!, {T0, T1}
92
93         ldm     RP, {T0,T1,T2,F0,F1,F2,F3}      C 2-8
94         adcs    T0, T0, #0
95         adcs    T1, T1, #0
96         adcs    T2, T2, #0
97         adcs    F0, F0, #0
98         adcs    F1, F1, #0
99         adcs    F2, F2, #0
100         adcs    F3, F3, #0
101         stm     RP!, {T0,T1,T2,F0,F1,F2,F3}     C 2-8
102         ldm     RP, {T0,T1,T2,F0,F1,F2,F3}      C 9-15
103         adcs    T0, T0, #0
104         adcs    T1, T1, #0
105         adcs    T2, T2, #0
106         adcs    F0, F0, #0
107         adcs    F1, F1, #0
108         adcs    F2, F2, #0
109         adcs    F3, F3, #0
110         adcs    H, H, #0
111         stm     RP, {T0,T1,T2,F0,F1,F2,F3,H}    C 9-16
112
113         pop     {r4,r5,r6,r7,r8,pc}
114 EPILOGUE(nettle_ecc_521_modp)