Small optimizations in SHA-1 computation.

This commit is contained in:
Stephen Heumann 2017-06-29 19:52:52 -05:00
parent a519776847
commit 13654c0888

View File

@ -9,8 +9,8 @@ b gequ 12
c gequ 16 c gequ 16
d gequ 20 d gequ 20
e gequ 24 e gequ 24
f gequ 28 ; result of function in hash computation unused gequ 28 ; result of function in hash computation
k gequ 32 f_plus_k gequ 32
temp gequ 36 temp gequ 36
h0 gequ 40 h0 gequ 40
h1 gequ 44 h1 gequ 44
@ -91,7 +91,8 @@ SHA1_PROCESSCHUNK start
sta e+2 sta e+2
ldy #0 ldy #0
loop cpy #60 loop phy
cpy #60
bge f_60 bge f_60
cpy #40 cpy #40
bge f_40 bge f_40
@ -103,33 +104,31 @@ f_0 lda c
eor d eor d
and b and b
eor d eor d
sta f clc
lda #$7999 adc #$7999
sta k sta f_plus_k
lda c+2 lda c+2
eor d+2 eor d+2
and b+2 and b+2
eor d+2 eor d+2
sta f+2 adc #$5A82
lda #$5A82 sta f_plus_k+2
sta k+2
bra after_f bra after_f
* f_20 to f_39 * f_20 to f_39
f_20 lda b f_20 lda b
eor c eor c
eor d eor d
sta f clc
lda #$EBA1 adc #$EBA1
sta k sta f_plus_k
lda b+2 lda b+2
eor c+2 eor c+2
eor d+2 eor d+2
sta f+2 adc #$6ED9
lda #$6ED9 sta f_plus_k+2
sta k+2
bra after_f bra after_f
* f_40 to f_59 * f_40 to f_59
@ -140,9 +139,9 @@ f_40 lda c
lda c lda c
and d and d
ora temp ora temp
sta f clc
lda #$BCDC adc #$BCDC
sta k sta f_plus_k
lda c+2 lda c+2
ora d+2 ora d+2
@ -151,31 +150,28 @@ f_40 lda c
lda c+2 lda c+2
and d+2 and d+2
ora temp ora temp
sta f+2 adc #$8F1B
lda #$8F1B sta f_plus_k+2
sta k+2
bra after_f bra after_f
* f_60 to f_79 * f_60 to f_79
f_60 lda b f_60 lda b
eor c eor c
eor d eor d
sta f clc
lda #$C1D6 adc #$C1D6
sta k sta f_plus_k
lda b+2 lda b+2
eor c+2 eor c+2
eor d+2 eor d+2
sta f+2 adc #$CA62
lda #$CA62 sta f_plus_k+2
sta k+2
bra after_f bra after_f
after_f anop after_f anop
ROTL4MOVE temp,a_,5 ROTL4MOVE temp,a_,5
phy lda 1,s
tya
asl a asl a
asl a asl a
tax tax
@ -188,13 +184,6 @@ after_f anop
tax tax
clc clc
tya tya
adc f
tay
txa
adc f+2
tax
clc
tya
adc e adc e
tay tay
txa txa
@ -202,12 +191,11 @@ after_f anop
tax tax
clc clc
tya tya
adc k adc f_plus_k
sta temp sta temp
txa txa
adc k+2 adc f_plus_k+2
sta temp+2 sta temp+2
ply
lda d lda d
sta e sta e
@ -231,6 +219,7 @@ after_f anop
lda temp+2 lda temp+2
sta a_+2 sta a_+2
ply
iny iny
cpy #80 cpy #80
bge endloop bge endloop