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-256-redc.asm"
38 define(<T0>, <r0>) C Overlaps unused modulo argument
51 C ecc_256_redc (const struct ecc_modulo *m, mp_limb_t *rp)
55 PROLOGUE(nettle_ecc_256_redc)
56 push {r4,r5,r6,r7,r8,r10,r11,lr}
58 ldm RP!, {T0,T1,T2,T3,T4,T5,T6,T7}
60 C Set <F3,F2,F1> to the high 4 limbs of (B^2-B+1)<T2,T1,T0>
73 sbcs F1, F1, T1 C Could also be rsc ?
78 C T10 T9 T8 T7 T6 T5 T4 T3
79 C + F3 F2 F1 F0 T0 T2 T1 T0
80 C --------------------------
81 C T7 T6 T5 T4 T3 T2 T1 T0
87 mov T0, T3 C FIXME: Be more clever?
96 C New F3, F2, F1, F0, also adding in carry
102 sbcs F1, F1, T1 C Could also be rsc ?
111 mov T0, T3 C FIXME: Be more clever?
120 C Final iteration, eliminate only T0, T1
121 C Set <F2, F1, F0> to the high 3 limbs of (B^2-B+1)<T1,T0>
136 C T9 T8 T7 T6 T5 T4 T3 T2
137 C + F2 F1 F0 T0 0 T1 T0 0
138 C --------------------------
139 C F2 F1 T7 T6 T5 T4 T3 T2
151 C Sum is < B^8 + p, so it's enough to fold carry once,
153 C B^7 - B^6 - B^3 + 1 = <0, B-2, B-1, B-1, B-1, 0, 0, 1>
155 C Mask from carry flag, leaving carry intact
170 stm RP, {T0,T1,T2,T3,T4,T5,T6,T7}
172 pop {r4,r5,r6,r7,r8,r10,r11,pc}
173 EPILOGUE(nettle_ecc_256_redc)