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
"sha256-compress.asm"
34 define
(<T1
>, <r1
>) C Overlap INPUT
35 define
(<COUNT
>, <r0
>) C Overlap STATE
45 define
(<SHIFT
>, <r10
>)
46 define
(<ILEFT
>, <r11
>)
49 ldr W
, [sp, #
+eval
(4*$1)]
50 ldr T0
, [sp, #
+eval
(4*(($1 + 14) % 16))]
52 eor T1
, T1
, T0
, ror #
19
53 eor T1
, T1
, T0
, lsr #
10
55 ldr T0
, [sp, #
+eval
(4*(($1 + 9) % 16))]
57 ldr T0
, [sp, #
+eval
(4*(($1 + 1) % 16))]
59 eor T1
, T1
, T0
, ror #
18
60 eor T1
, T1
, T0
, lsr #
3
62 str W
, [sp, #
+eval
(4*$1)]
65 C ROUND
(A
,B
,C
,D
,E
,F
,G
,H
)
67 C H
+= S1
(E
) + Choice
(E
,F
,G
) + K
+ W
69 C H
+= S0
(A
) + Majority
(A
,B
,C
)
73 C S1
(E
) = E
<<<26 ^ E
<<<21 ^ E
<<<7
74 C S0
(A
) = A
<<<30 ^ A
<<<19 ^ A
<<<10
75 C Choice
(E
, F
, G
) = G^
(E
&(F^G
))
76 C Majority
(A
,B
,C
) = (A
&B
) + (C
&(A^B
))
80 eor T0
, T0
, $5, ror #
11
81 eor T0
, T0
, $5, ror #
25
92 eor T0
, T0
, $1, ror #
13
93 eor T0
, T0
, $1, ror #
22
107 C _nettle_sha256_compress
(uint32_t
*state
, const uint8_t
*input
, const uint32_t
*k
)
112 PROLOGUE
(_nettle_sha256_compress
)
113 push {r4,r5,r6,r7,r8,r10,r11,r14}
115 str STATE
, [sp, +#
64]
117 C Load data up front
, since we don
't have enough registers
118 C to load and shift on-the-fly
119 ands SHIFT, INPUT, #3
120 and INPUT, INPUT, $-4
122 addne INPUT, INPUT, #4
127 uadd8 T0, T0, I1 C Sets APSR.GE bits
132 ldm INPUT!, {I1,I2,I3,I4}
145 subs ILEFT, ILEFT, #1
146 stm DST!, {I0,I1,I2,I3}
150 ldm STATE, {SA,SB,SC,SD,SE,SF,SG,SH}
155 NOEXPN(COUNT) ROUND(SA,SB,SC,SD,SE,SF,SG,SH)
156 NOEXPN(COUNT) ROUND(SH,SA,SB,SC,SD,SE,SF,SG)
157 NOEXPN(COUNT) ROUND(SG,SH,SA,SB,SC,SD,SE,SF)
158 NOEXPN(COUNT) ROUND(SF,SG,SH,SA,SB,SC,SD,SE)
159 NOEXPN(COUNT) ROUND(SE,SF,SG,SH,SA,SB,SC,SD)
160 NOEXPN(COUNT) ROUND(SD,SE,SF,SG,SH,SA,SB,SC)
161 NOEXPN(COUNT) ROUND(SC,SD,SE,SF,SG,SH,SA,SB)
162 NOEXPN(COUNT) ROUND(SB,SC,SD,SE,SF,SG,SH,SA)
169 EXPN( 0) ROUND(SA,SB,SC,SD,SE,SF,SG,SH)
170 EXPN( 1) ROUND(SH,SA,SB,SC,SD,SE,SF,SG)
171 EXPN( 2) ROUND(SG,SH,SA,SB,SC,SD,SE,SF)
172 EXPN( 3) ROUND(SF,SG,SH,SA,SB,SC,SD,SE)
173 EXPN( 4) ROUND(SE,SF,SG,SH,SA,SB,SC,SD)
174 EXPN( 5) ROUND(SD,SE,SF,SG,SH,SA,SB,SC)
175 EXPN( 6) ROUND(SC,SD,SE,SF,SG,SH,SA,SB)
176 EXPN( 7) ROUND(SB,SC,SD,SE,SF,SG,SH,SA)
177 EXPN( 8) ROUND(SA,SB,SC,SD,SE,SF,SG,SH)
178 EXPN( 9) ROUND(SH,SA,SB,SC,SD,SE,SF,SG)
179 EXPN(10) ROUND(SG,SH,SA,SB,SC,SD,SE,SF)
180 EXPN(11) ROUND(SF,SG,SH,SA,SB,SC,SD,SE)
181 EXPN(12) ROUND(SE,SF,SG,SH,SA,SB,SC,SD)
182 EXPN(13) ROUND(SD,SE,SF,SG,SH,SA,SB,SC)
183 EXPN(14) ROUND(SC,SD,SE,SF,SG,SH,SA,SB)
184 subs COUNT, COUNT, #1
185 EXPN(15) ROUND(SB,SC,SD,SE,SF,SG,SH,SA)
188 ldr STATE, [sp, +#64]
189 C No longer needed registers
190 ldm STATE, {r1,r2,r12,r14}
195 stm STATE!, {SA,SB,SC,SD}
196 ldm STATE, {r1,r2,r12,r14}
201 stm STATE!, {SE,SF,SG,SH}
203 pop {r4,r5,r6,r7,r8,r10,r11,pc}
204 EPILOGUE(_nettle_sha256_compress)