3 # ====================================================================
4 # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5 # project. The module is, however, dual licensed under OpenSSL and
6 # CRYPTOGAMS licenses depending on where you obtain it. For further
7 # details see http://www.openssl.org/~appro/cryptogams/.
8 # ====================================================================
10 # sha1_block precedure for ARMv4.
14 # Size/performance trade-off
15 # ====================================================================
16 # impl size in bytes comp cycles[*] measured performance
17 # ====================================================================
19 # armv4-small 392/+29% 1958/+64% 2290/+93%
20 # armv4-compact 740/+89% 1552/+26% 1910/+20%
21 # armv4-large 1420/+92% 1307/+19% 1630/+17%
22 # full unroll ~5100/+260% ~1260/+4% ~1600/+2%
23 # ====================================================================
24 # thumb = same as 'small' but in Thumb instructions[**] and
25 # with recurring code in two private functions;
26 # small = detached Xload/update, loops are folded;
27 # compact = detached Xload/update, 5x unroll;
28 # large = interleaved Xload/update, 5x unroll;
29 # full unroll = interleaved Xload/update, full unroll, estimated[!];
31 # [*] Manually counted instructions in "grand" loop body. Measured
32 # performance is affected by prologue and epilogue overhead,
33 # i-cache availability, branch penalties, etc.
34 # [**] While each Thumb instruction is twice smaller, they are not as
35 # diverse as ARM ones: e.g., there are only two arithmetic
36 # instructions with 3 arguments, no [fixed] rotate, addressing
37 # modes are limited. As result it takes more instructions to do
38 # the same job in Thumb, therefore the code is never twice as
39 # small and always slower.
56 # One can optimize this for aligned access on big-endian architecture,
57 # but code's endian neutrality makes it too pretty:-)
59 my ($a,$b,$c,$d,$e)=@_;
64 add $e,$K,$e,ror#2 @ E+=K_00_19
67 add $e,$e,$a,ror#27 @ E+=ROR(A,27)
70 add $e,$e,$t0 @ E+=X[i]
75 my ($a,$b,$c,$d,$e)=@_;
80 add $e,$K,$e,ror#2 @ E+=K_xx_xx
83 add $e,$e,$a,ror#27 @ E+=ROR(A,27)
87 add $e,$e,$t0 @ E+=X[i]
93 my ($a,$b,$c,$d,$e)=@_;
98 eor $t1,$t1,$d,ror#2 @ F_00_19(B,C,D)
99 add $e,$e,$t1 @ E+=F_00_19(B,C,D)
104 my ($a,$b,$c,$d,$e)=@_;
109 eor $t1,$t1,$d,ror#2 @ F_00_19(B,C,D)
110 add $e,$e,$t1 @ E+=F_00_19(B,C,D)
115 my ($a,$b,$c,$d,$e)=@_;
119 eor $t1,$b,$t1,ror#2 @ F_20_39(B,C,D)
120 add $e,$e,$t1 @ E+=F_20_39(B,C,D)
125 my ($a,$b,$c,$d,$e)=@_;
131 orr $t1,$t1,$t2 @ F_40_59(B,C,D)
132 add $e,$e,$t1 @ E+=F_40_59(B,C,D)
139 .global sha1_block_data_order
140 .type sha1_block_data_order,%function
143 sha1_block_data_order:
144 stmdb sp!,{r4-r12,lr}
145 add $len,$inp,$len,lsl#6 @ $len to point at the end of $inp
146 ldmia $ctx,{$a,$b,$c,$d,$e}
153 mov $e,$e,ror#30 @ [6]
156 for($i=0;$i<5;$i++) {
157 &BODY_00_15(@V); unshift(@V,pop(@V));
161 bne .L_00_15 @ [((11+4)*5+2)*3]
163 &BODY_00_15(@V); unshift(@V,pop(@V));
164 &BODY_16_19(@V); unshift(@V,pop(@V));
165 &BODY_16_19(@V); unshift(@V,pop(@V));
166 &BODY_16_19(@V); unshift(@V,pop(@V));
167 &BODY_16_19(@V); unshift(@V,pop(@V));
170 ldr $K,.LK_20_39 @ [+15+16*4]
172 cmn sp,#0 @ [+3], clear carry to denote 20_39
175 for($i=0;$i<5;$i++) {
176 &BODY_20_39(@V); unshift(@V,pop(@V));
179 teq $Xi,sp @ preserve carry
180 bne .L_20_39_or_60_79 @ [+((12+3)*5+2)*4]
181 bcs .L_done @ [+((12+3)*5+2)*4], spare 300 bytes
184 sub sp,sp,#20*4 @ [+2]
187 for($i=0;$i<5;$i++) {
188 &BODY_40_59(@V); unshift(@V,pop(@V));
192 bne .L_40_59 @ [+((12+5)*5+2)*4]
196 cmp sp,#0 @ set carry to denote 60_79
197 b .L_20_39_or_60_79 @ [+4], spare 300 bytes
199 add sp,sp,#80*4 @ "deallocate" stack frame
200 ldmia $ctx,{$K,$t0,$t1,$t2,$Xi}
206 stmia $ctx,{$a,$b,$c,$d,$e}
208 bne .Lloop @ [+18], total 1307
210 ldmia sp!,{r4-r12,lr}
212 moveq pc,lr @ be binary compatible with V4, yet
213 bx lr @ interoperable with Thumb ISA:-)
215 .LK_00_19: .word 0x5a827999
216 .LK_20_39: .word 0x6ed9eba1
217 .LK_40_59: .word 0x8f1bbcdc
218 .LK_60_79: .word 0xca62c1d6
219 .size sha1_block_data_order,.-sha1_block_data_order
220 .asciz "SHA1 block transform for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"