4 Copyright (C) 2013 Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
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.
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.
21 or both in parallel, as here.
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.
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/.
33 .file "ecc-384-modp.asm"
49 C ecc_384_modp (const struct ecc_modulo *m, mp_limb_t *rp)
53 PROLOGUE(nettle_ecc_384_modp)
54 push {r4,r5,r6,r7,r8,r10,lr}
57 ldm RP, {T0, T1, T2, T3} C 20-23
59 C First get top 4 limbs, which need folding twice, as
73 C F2 F1 F0 Always fits
95 ldm RP, {T0, T1, T2, T3} C 12-15
101 adcs F4, F4, #0 C Do F4 later
103 C Add to low part, keeping carry (positive or negative) in H
105 ldm RP, {T0, T1, T2, T3} C 0-3
119 stm RP!, {T0,T1,T2,T3} C 0-3
122 ldm RP, {T0,T1,T2,T3} C 4-7
124 C First, propagate carry
126 asr H, #31 C Sign extend
140 ldr F0, [RP, #+48] C 16
148 ldr F1, [RP, #+52] C 17-18
157 ldr F3, [RP, #+60] C 19
164 stm RP!, {T0,T1,T2,T3}
167 C Fold high limbs, we need to add in
169 C F4 F4 0 -F4 F4 H H 0 -H H
171 C We always have F4 >= 0, but we can have H < 0.
172 C Sign extension gets tricky when F4 = 0 and H < 0.
175 ldm RP, {T0,T1,T2,T3} C 0-3
181 C Define S = H >> 31 (asr), we then have
189 C And we get underflow in S - H iff H > 0
194 subs F1, H, F0 C 0,C=1 -H,C=0 0,C=1
195 sbc F2, F2, F2 C 0 -1 0
196 sbc F3, F0, #0 C 0 H-1 -1
202 adc H, H, F0 C 0+cy H+cy -2+cy
204 stm RP!, {T0,T1,T2,T3} C 0-3
205 ldm RP, {T0,T1,T2,T3} C 4-7
229 stm RP!, {T0,T1,T2,T3} C 4-7
230 ldm RP, {T0,T1,T2,T3} C 8-11
238 stm RP, {T0,T1,T2,T3} C 8-11
240 C Final (unlikely) carry
242 ldm RP, {T0,T1,T2,T3} C 0-3
256 stm RP!, {T0,T1,T2,T3} C 0-3
257 ldm RP, {T0,T1,T2,T3} C 4-7
262 stm RP!, {T0,T1,T2,T3} C 4-7
263 ldm RP, {T0,T1,T2,T3} C 8-11
268 stm RP!, {T0,T1,T2,T3} C 8-11
269 pop {r4,r5,r6,r7,r8,r10,pc}
270 EPILOGUE(nettle_ecc_384_modp)