Use more efficient approach for addressing into k array in SHA-256 computation.

This commit is contained in:
Stephen Heumann 2017-07-03 20:14:36 -05:00
parent f0f034760b
commit 7034be04fb
3 changed files with 64 additions and 17 deletions

View File

@ -50,6 +50,22 @@ temp3 gequ 156
temp4 gequ 160 temp4 gequ 160
k_ptr gequ 164 k_ptr gequ 164
zero gequ 168 zero gequ 168
two gequ 170
four gequ 172
six gequ 174
eight gequ 176
ten gequ 178
twelve gequ 180
fourteen gequ 182
sixteen gequ 184
eighteen gequ 186
twenty gequ 188
twentytwo gequ 190
twentyfour gequ 192
twentysix gequ 194
twentyeight gequ 196
thirty gequ 198
k private k private
dc i4'$428a2f98, $71374491, $b5c0fbcf, $e9b5dba5' dc i4'$428a2f98, $71374491, $b5c0fbcf, $e9b5dba5'
@ -117,6 +133,37 @@ SHA256_INIT start
stz extra stz extra
stz zero stz zero
lda #2
sta two
lda #4
sta four
lda #6
sta six
lda #8
sta eight
lda #10
sta ten
lda #12
sta twelve
lda #14
sta fourteen
lda #16
sta sixteen
lda #18
sta eighteen
lda #20
sta twenty
lda #22
sta twentytwo
lda #24
sta twentyfour
lda #26
sta twentysix
lda #28
sta twentyeight
lda #30
sta thirty
rtl rtl
end end

View File

@ -23,7 +23,7 @@ struct sha256_context {
unsigned char reserved1[16]; unsigned char reserved1[16];
unsigned char hash[32]; unsigned char hash[32];
unsigned char block[64]; unsigned char block[64];
unsigned char reserved2[16]; unsigned char reserved2[44];
}; };
/* /*

View File

@ -353,7 +353,7 @@
* The a,b,c,d,e,f,g,h variables are given as parameters so we can avoid * The a,b,c,d,e,f,g,h variables are given as parameters so we can avoid
* cycling them. * cycling them.
macro macro
BlockLoopIter &a,&b,&c,&d,&e,&f,&g,&h,&iter BlockLoopIter &a,&b,&c,&d,&e,&f,&g,&h,&iter,&k_idx1,&k_idx2
; Sigma_1+w[i] computation ; Sigma_1+w[i] computation
lda &e+1 lda &e+1
@ -418,17 +418,12 @@
clc clc
tya tya
ldy k_ptr ldy k_ptr
adc (zero),y adc (&k_idx1),y
sta temp1 sta temp1
txa txa
iny adc (&k_idx2),y
iny
adc (zero),y
sta temp1+2 sta temp1+2
tax tax
iny
iny
sty k_ptr
clc clc
lda temp1 lda temp1
@ -498,14 +493,19 @@
stz idx stz idx
loop&part anop loop&part anop
BlockLoopIter a_,b,c,d,e,f,g,h,0 BlockLoopIter a_,b,c,d,e,f,g,h,0,zero,two
BlockLoopIter h,a_,b,c,d,e,f,g,1 BlockLoopIter h,a_,b,c,d,e,f,g,1,four,six
BlockLoopIter g,h,a_,b,c,d,e,f,2 BlockLoopIter g,h,a_,b,c,d,e,f,2,eight,ten
BlockLoopIter f,g,h,a_,b,c,d,e,3 BlockLoopIter f,g,h,a_,b,c,d,e,3,twelve,fourteen
BlockLoopIter e,f,g,h,a_,b,c,d,4 BlockLoopIter e,f,g,h,a_,b,c,d,4,sixteen,eighteen
BlockLoopIter d,e,f,g,h,a_,b,c,5 BlockLoopIter d,e,f,g,h,a_,b,c,5,twenty,twentytwo
BlockLoopIter c,d,e,f,g,h,a_,b,6 BlockLoopIter c,d,e,f,g,h,a_,b,6,twentyfour,twentysix
BlockLoopIter b,c,d,e,f,g,h,a_,7 BlockLoopIter b,c,d,e,f,g,h,a_,7,twentyeight,thirty
clc
lda k_ptr
adc #4*8
sta k_ptr
clc clc
lda idx lda idx