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 for Thumb.
14 # The code does not present direct interest to OpenSSL, because of low
15 # performance. Its purpose is to establish _size_ benchmark. Pretty
16 # useless one I must say, because 30% or 88 bytes larger ARMv4 code
17 # [avialable on demand] is almost _twice_ as fast. It should also be
18 # noted that in-lining of .Lcommon and .Lrotate improves performance
19 # by over 40%, while code increases by only 10% or 32 bytes. But once
20 # again, the goal was to establish _size_ benchmark, not performance.
23 open STDOUT,">$output";
26 #$cheat_on_binutils=1;
36 $K="r8"; # "upper" registers can be used in add/sub and mov insns
46 add $e,$K @ E+=K_xx_xx
50 add $t2,$e @ E+=ROR(A,27)
60 orr $c,$b @ C=ROR(B,2)
62 add $a,$t2,$t1 @ A=E+F_xx_xx(B,C,D)
67 $code.=$inline?&common():"\tbl .Lcommon\n";
72 eor $t1,$d @ F_00_19(B,C,D)
74 $code.=$inline?&rotate():"\tbl .Lrotate\n";
78 $code.=$inline?&common():"\tbl .Lcommon\n";
82 eor $t1,$d @ F_20_39(B,C,D)
84 $code.=$inline?&rotate():"\tbl .Lrotate\n";
88 $code.=$inline?&common():"\tbl .Lcommon\n";
95 orr $t1,$e @ F_40_59(B,C,D)
97 $code.=$inline?&rotate():"\tbl .Lrotate\n";
104 .global sha1_block_data_order
105 .type sha1_block_data_order,%function
108 sha1_block_data_order:
110 if ($cheat_on_binutils) {
114 bx r3 @ switch to Thumb ISA
127 mov $ctx,r0 @ save context
128 mov $inp,r1 @ save inp
129 mov $len,r2 @ save len
130 add $len,$inp @ $len to point at inp end
137 ldrb $a,[$t1,#0] @ $t1 is r1 and holds inp
150 bne .LXload @ [+14*16]
152 mov $inp,$t1 @ update $inp
167 bne .LXupdate @ [+(11+1)*64]
169 ldmia $t0!,{$a,$b,$c,$d,$e} @ $t0 is r0 and holds ctx
182 bne .L_00_19 @ [+(2+9+4+2+8+2)*20]
194 bne .L_20_39_or_60_79 @ [+(2+9+3+2+8+2)*20*2]
208 bne .L_40_59 @ [+(2+9+6+2+8+2)*20]
213 b .L_20_39_or_60_79 @ [+4]
226 stmia $t0!,{$a,$b,$c,$d,$e} @ [+20]
228 add sp,#80*4 @ deallocate stack frame
229 mov $t0,$ctx @ restore ctx
230 mov $t1,$inp @ restore inp
233 b .Lloop @ [+6] total 3212 cycles
246 $code.=".Lcommon:\n".&common()."\tmov pc,lr\n" if (!$inline);
247 $code.=".Lrotate:\n".&rotate()."\tmov pc,lr\n" if (!$inline);
250 .LK_00_19: .word 0x5a827999
251 .LK_20_39: .word 0x6ed9eba1
252 .LK_40_59: .word 0x8f1bbcdc
253 .LK_60_79: .word 0xca62c1d6
254 .size sha1_block_data_order,.-sha1_block_data_order
255 .asciz "SHA1 block transform for Thumb, CRYPTOGAMS by <appro\@openssl.org>"
259 close STDOUT; # enforce flush