Fix build error and set version 2.7.1
[platform/upstream/nettle.git] / arm / ecc-224-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-224-modp.asm"
21         .arm
22
23 define(<RP>, <r1>)
24 define(<H>, <r0>) C Overlaps unused ecc argument
25
26 define(<T0>, <r2>)
27 define(<T1>, <r3>)
28 define(<T2>, <r4>)
29 define(<T3>, <r5>)
30 define(<T4>, <r6>)
31 define(<T5>, <r7>)
32 define(<T6>, <r8>)
33 define(<N3>, <r10>)
34 define(<L0>, <r11>)
35 define(<L1>, <r12>)
36 define(<L2>, <lr>)
37
38         C ecc_224_modp (const struct ecc_curve *ecc, mp_limb_t *rp)
39         .text
40         .align 2
41
42 PROLOGUE(nettle_ecc_224_modp)
43         push    {r4,r5,r6,r7,r8,r10,r11,lr}
44
45         add     L2, RP, #28
46         ldm     L2, {T0,T1,T2,T3,T4,T5,T6}
47         mov     H, #0
48
49         adds    T0, T0, T4
50         adcs    T1, T1, T5
51         adcs    T2, T2, T6
52         adc     H, H, #0
53
54         C This switch from adcs to sbcs takes carry into account with
55         C correct sign, but it always subtracts 1 too much. We arrange
56         C to also add B^7 + 1 below, so the effect is adding p. This
57         C addition of p also ensures that the result never is
58         C negative.
59
60         sbcs    N3, T3, T0
61         sbcs    T4, T4, T1
62         sbcs    T5, T5, T2
63         sbcs    T6, T6, H
64         mov     H, #1           C This is the B^7
65         sbc     H, #0
66         subs    T6, T6, T3
67         sbc     H, #0
68
69         C Now subtract from low half
70         ldm     RP!, {L0,L1,L2}
71
72         C Clear carry, with the sbcs, this is the 1.
73         adds    RP, #0
74
75         sbcs    T0, L0, T0
76         sbcs    T1, L1, T1
77         sbcs    T2, L2, T2
78         ldm     RP!, {T3,L0,L1,L2}
79         sbcs    T3, T3, N3
80         sbcs    T4, L0, T4
81         sbcs    T5, L1, T5
82         sbcs    T6, L2, T6
83         rsc     H, H, #0
84
85         C Now -2 <= H <= 0 is the borrow, so subtract (B^3 - 1) |H|
86         C Use (B^3 - 1) H = <H, H, H> if -1 <=H <= 0, and
87         C     (B^3 - 1) H = <1,B-1, B-1, B-2> if H = -2
88         subs    T0, T0, H
89         asr     L1, H, #1
90         sbcs    T1, T1, L1
91         eor     H, H, L1
92         sbcs    T2, T2, L1
93         sbcs    T3, T3, H
94         sbcs    T4, T4, #0
95         sbcs    T5, T5, #0
96         sbcs    T6, T6, #0
97         sbcs    H, H, H
98
99         C Final borrow, subtract (B^3 - 1) |H|
100         subs    T0, T0, H
101         sbcs    T1, T1, H
102         sbcs    T2, T2, H
103         sbcs    T3, T3, #0
104         sbcs    T4, T4, #0
105         sbcs    T5, T5, #0
106         sbcs    T6, T6, #0
107
108         stmdb   RP, {T0,T1,T2,T3,T4,T5,T6}
109
110         pop     {r4,r5,r6,r7,r8,r10,r11,pc}
111 EPILOGUE(nettle_ecc_224_modp)