Revert "Merge branch 'upstream' into tizen"
[platform/upstream/nettle.git] / x86_64 / 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
22 define(<RP>, <%rsi>)
23 define(<T0>, <%rdi>) C Overlaps unused ecc input
24 define(<T1>, <%rcx>)
25 define(<H0>, <%rax>)
26 define(<H1>, <%rdx>)
27 define(<H2>, <%r8>)
28 define(<F0>, <%r9>)
29 define(<F1>, <%r10>)
30 define(<F2>, <%r11>)
31
32 PROLOGUE(nettle_ecc_224_modp)
33         W64_ENTRY(2, 0)
34         mov     48(RP), H0
35         mov     56(RP), H1
36         C Set (F2,F1,F0)  <--  (H1,H0) << 32
37         mov     H0, F0
38         mov     H0, F1
39         shl     $32, F0
40         shr     $32, F1
41         mov     H1, F2
42         mov     H1, T0
43         shl     $32, T0
44         shr     $32, F2
45         or      T0, F1
46
47         xor     H2, H2
48         mov     16(RP), T0
49         mov     24(RP), T1
50         sub     F0, T0
51         sbb     F1, T1
52         sbb     F2, H0
53         sbb     $0, H1          C No further borrow
54
55         adc     32(RP), H0
56         adc     40(RP), H1
57         adc     $0, H2
58
59         C Set (F2,F1,F0)  <--  (H2,H1,H0) << 32
60         C To free registers, add in T1, T0 as soon as H0, H1 have been copied
61         mov     H0, F0
62         mov     H0, F1
63         add     T0, H0
64         mov     H1, F2
65         mov     H1, T0
66         adc     T1, H1
67         mov     H2, T1
68         adc     $0, H2
69
70         C Shift 32 bits
71         shl     $32, F0
72         shr     $32, F1
73         shl     $32, T0
74         shr     $32, F2
75         shl     $32, T1
76         or      T0, F1
77         or      T1, F2
78
79         mov     (RP), T0
80         mov     8(RP), T1
81         sub     F0, T0
82         sbb     F1, T1
83         sbb     F2, H0
84         sbb     $0, H1
85         sbb     $0, H2
86
87         C We now have H2, H1, H0, T1, T0, with 33 bits left to reduce
88         C Set F0       <-- (H2, H1) >> 32
89         C Set (F2,F1)  <-- (H2, H1 & 0xffffffff00000000)
90         C H1  <--  H1 & 0xffffffff
91
92         mov     H1, F0
93         mov     H1, F1
94         mov     H2, F2
95         movl    XREG(H1), XREG(H1)      C Clears high 32 bits
96         sub     H1, F1                  C Clears low 32 bits
97         shr     $32, F0
98         shl     $32, H2
99         or      H2, F0
100
101         sub     F0, T0
102         sbb     $0, F1
103         sbb     $0, F2
104         add     F1, T1
105         adc     F2, H0
106         adc     $0, H1
107
108         mov     T0, (RP)
109         mov     T1, 8(RP)
110         mov     H0, 16(RP)
111         mov     H1, 24(RP)
112
113         W64_EXIT(2, 0)
114         ret
115 EPILOGUE(nettle_ecc_224_modp)