Apply %restore_fcommon macro for Address Sanitizer
[platform/upstream/nettle.git] / x86_64 / ecc-25519-modp.asm
1 C x86_64/ecc-25519-modp.asm
2
3 ifelse(<
4    Copyright (C) 2014 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-25519-modp.asm"
34
35 define(<RP>, <%rsi>)
36 define(<U0>, <%rdi>)    C Overlaps unused modulo input
37 define(<U1>, <%rcx>)
38 define(<U2>, <%r8>)
39 define(<U3>, <%r9>)
40 define(<T0>, <%r10>)
41 define(<T1>, <%r11>)
42 define(<M>, <%rbx>)
43
44 PROLOGUE(nettle_ecc_25519_modp)
45         W64_ENTRY(2, 0)
46         push    %rbx
47
48         C First fold the limbs affecting bit 255
49         mov     56(RP), %rax
50         mov     $38, M
51         mul     M
52         mov     24(RP), U3
53         xor     T0, T0
54         add     %rax, U3
55         adc     %rdx, T0
56
57         mov     40(RP), %rax    C Do this early as possible
58         mul     M
59         
60         add     U3, U3
61         adc     T0, T0
62         shr     U3              C Undo shift, clear high bit
63
64         C Fold the high limb again, together with RP[5]
65         imul    $19, T0
66
67         mov     (RP), U0
68         mov     8(RP), U1
69         mov     16(RP), U2
70         add     T0, U0
71         adc     %rax, U1
72         mov     32(RP), %rax
73         adc     %rdx, U2
74         adc     $0, U3
75
76         C Fold final two limbs, RP[4] and RP[6]
77         mul     M
78         mov     %rax, T0
79         mov     48(RP), %rax
80         mov     %rdx, T1
81         mul     M
82         add     T0, U0
83         mov     U0, (RP)
84         adc     T1, U1
85         mov     U1, 8(RP)
86         adc     %rax, U2
87         mov     U2, 16(RP)
88         adc     %rdx, U3
89         mov     U3, 24(RP)
90
91         pop     %rbx
92         W64_EXIT(2, 0)
93         ret
94 EPILOGUE(nettle_ecc_25519_modp)