1
C nettle, low-level cryptographics library
3
C Copyright (C) 2013, Niels Möller
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.
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.
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,
20
.file "ecc-256-redc.asm"
25
define(<T0>, <r0>) C Overlaps unused ecc argument
38
C ecc_256_redc (const struct ecc_curve *ecc, mp_limb_t *rp)
42
PROLOGUE(nettle_ecc_256_redc)
43
push {r4,r5,r6,r7,r8,r10,r11,lr}
45
ldm RP!, {T0,T1,T2,T3,T4,T5,T6,T7}
47
C Set <F3,F2,F1> to the high 4 limbs of (B^2-B+1)<T2,T1,T0>
60
sbcs F1, F1, T1 C Could also be rsc ?
65
C T10 T9 T8 T7 T6 T5 T4 T3
66
C + F3 F2 F1 F0 T0 T2 T1 T0
67
C --------------------------
68
C T7 T6 T5 T4 T3 T2 T1 T0
74
mov T0, T3 C FIXME: Be more clever?
83
C New F3, F2, F1, F0, also adding in carry
89
sbcs F1, F1, T1 C Could also be rsc ?
98
mov T0, T3 C FIXME: Be more clever?
107
C Final iteration, eliminate only T0, T1
108
C Set <F2, F1, F0> to the high 3 limbs of (B^2-B+1)<T1,T0>
123
C T9 T8 T7 T6 T5 T4 T3 T2
124
C + F2 F1 F0 T0 0 T1 T0 0
125
C --------------------------
126
C F2 F1 T7 T6 T5 T4 T3 T2
138
C Sum is < B^8 + p, so it's enough to fold carry once,
140
C B^7 - B^6 - B^3 + 1 = <0, B-2, B-1, B-1, B-1, 0, 0, 1>
142
C Mask from carry flag, leaving carry intact
157
stm RP, {T0,T1,T2,T3,T4,T5,T6,T7}
159
pop {r4,r5,r6,r7,r8,r10,r11,pc}
160
EPILOGUE(nettle_ecc_256_redc)