diff --git a/sha256.asm b/sha256.asm index fe659ac..44d5972 100644 --- a/sha256.asm +++ b/sha256.asm @@ -50,6 +50,22 @@ temp3 gequ 156 temp4 gequ 160 k_ptr gequ 164 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 dc i4'$428a2f98, $71374491, $b5c0fbcf, $e9b5dba5' @@ -117,6 +133,37 @@ SHA256_INIT start stz extra 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 end diff --git a/sha256.h b/sha256.h index b035cc8..6062dbe 100644 --- a/sha256.h +++ b/sha256.h @@ -23,7 +23,7 @@ struct sha256_context { unsigned char reserved1[16]; unsigned char hash[32]; unsigned char block[64]; - unsigned char reserved2[16]; + unsigned char reserved2[44]; }; /* diff --git a/sha256.macros b/sha256.macros index f671b19..4472434 100644 --- a/sha256.macros +++ b/sha256.macros @@ -353,7 +353,7 @@ * The a,b,c,d,e,f,g,h variables are given as parameters so we can avoid * cycling them. 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 lda &e+1 @@ -418,17 +418,12 @@ clc tya ldy k_ptr - adc (zero),y + adc (&k_idx1),y sta temp1 txa - iny - iny - adc (zero),y + adc (&k_idx2),y sta temp1+2 tax - iny - iny - sty k_ptr clc lda temp1 @@ -498,14 +493,19 @@ stz idx loop&part anop - BlockLoopIter a_,b,c,d,e,f,g,h,0 - BlockLoopIter h,a_,b,c,d,e,f,g,1 - BlockLoopIter g,h,a_,b,c,d,e,f,2 - BlockLoopIter f,g,h,a_,b,c,d,e,3 - BlockLoopIter e,f,g,h,a_,b,c,d,4 - BlockLoopIter d,e,f,g,h,a_,b,c,5 - BlockLoopIter c,d,e,f,g,h,a_,b,6 - BlockLoopIter b,c,d,e,f,g,h,a_,7 + BlockLoopIter a_,b,c,d,e,f,g,h,0,zero,two + BlockLoopIter h,a_,b,c,d,e,f,g,1,four,six + BlockLoopIter g,h,a_,b,c,d,e,f,2,eight,ten + BlockLoopIter f,g,h,a_,b,c,d,e,3,twelve,fourteen + BlockLoopIter e,f,g,h,a_,b,c,d,4,sixteen,eighteen + BlockLoopIter d,e,f,g,h,a_,b,c,5,twenty,twentytwo + BlockLoopIter c,d,e,f,g,h,a_,b,6,twentyfour,twentysix + BlockLoopIter b,c,d,e,f,g,h,a_,7,twentyeight,thirty + + clc + lda k_ptr + adc #4*8 + sta k_ptr clc lda idx