diff options
Diffstat (limited to 'sha1/msauth.asm')
-rw-r--r-- | sha1/msauth.asm | 353 |
1 files changed, 285 insertions, 68 deletions
diff --git a/sha1/msauth.asm b/sha1/msauth.asm index e4d0929..5e03d48 100644 --- a/sha1/msauth.asm +++ b/sha1/msauth.asm @@ -5,11 +5,13 @@ idx EQU $60 -rot_cnt EQU $61 +lidx EQU $61 k EQU $62 src1 EQU $63 src2 EQU $64 dest EQU $65 +i EQU $66 +j EQU $67 ; BYTES 60-67 are persisent RAM for our use @@ -88,26 +90,197 @@ handle_st0_event: test: - jsr sha1 - stop -sha1: - ldx #0 -sha1_copy_h_to_ae_loop: - lda H,x - sta VA,x + lda #0 + sta lidx + + ; data starts off as all zeros + ; fixme correct time here + lda #$a6 + sta DATA1+4 + lda #$a7 + sta DATA1+5 + + ; don't need to init H from IH already there + jsr sha1_block + inc lidx + jsr sha1_block + + ; Copy H->DATA, IH->H + ldx #20 +test_l1: + lda (H-1),x + sta (DATA1-1),x + lda (IH-1),x + sta (H-1),x + decx + bne test_l1 + + lda #$80 + sta DATA1+23 + + lda #$a0 + sta DATA2 + + ; set KEYOR = 5c5c5c5c + lda #$5c + ldx #4 +test_l2: + sta (KEYOR-1),x + decx + bne test_l2 + + dec lidx + jsr sha1_block + inc lidx + jsr sha1_block + + lda H+16 + and #$F + tax + add #(H-BASE_START) + sta src1 + lda H+3,x + and #$7F + sta H+3,x + lda #(T1-BASE_START) + sta dest + lda #(ZERO-BASE_START) + jsr add4 + + + +end: bra end + + + +get_w32_015_to_t2: + lda #(T2-BASE_START) + sta dest + lda #(ZERO-BASE_START) + sta src1 + + lda lidx + cmp #0 + bne get_w32_015_to_t2_l1 + + lda j + cmp #3 + bhs get_w32_015_to_t2_z1 + lsla + lsla + add #(KEY-BASE_START) + sta src1 +get_w32_015_to_t2_z1: + lda #(ZERO-BASE_START) + jsr add4 + lda #(T2-BASE_START) + sta src1 + lda #(KEYOR-BASE_START) + jsr xor4 + rts +get_w32_015_to_t2_l1: + lda j + cmp #6 + bhs get_w32_015_to_t2_l2 + lsla + lsla + add #(DATA1-BASE_START) + bra get_w32_015_to_t2_e +get_w32_015_to_t2_l2: + cmp #15 + bne get_w32_015_to_t2_l3 + lda #(DATA2-BASE_START) + bra get_w32_015_to_t2_e +get_w32_015_to_t2_l3: + lda #(ZERO-BASE_START) +get_w32_015_to_t2_e: + jsr add4 + rts + +get_w32_to_t2: + lda idx + cmp #16 + bhs get_w32_to_t2_l0 + sta j ; <16 use our function + jsr get_w32_015_to_t2 + rts +get_w32_to_t2_l0: + sub #15 ; store number of iterations needed in i + sta i + + ; fill W + lda #0 + sta j +get_w32_to_t2_l1: + jsr get_w32_015_to_t2 + lda j + lsla + lsla + add #(WBUF-BASE_START) + sta dest + lda #(T2-BASE_START) + sta src1 + lda #(ZERO-BASE_START) + jsr add4 + + inc j + lda j + cmp #16 + bne get_w32_to_t2_l1 + + +get_w32_to_t2_l2: + lda #(T2-BASE_START) + sta dest + lda #(WBUF13 - BASE_START) + sta src1 + lda #(WBUF8 - BASE_START) + jsr xor4 ; T2 =W13 ^ W8 + lda #(T2-BASE_START) + sta src1 + lda #(WBUF2 - BASE_START) + jsr xor4 ; T2 = T2 ^ W2 + lda #(WBUF0 - BASE_START) + jsr xor4 ; T2= T2 ^ W0 + lda #1 + jsr rot_left ; T2= ROTLEFT(T2,1) + + + ; for (x=0;x<14;++x) wbuf[x]=wbuf[x+1] + ldx #((WBUF0 + $FF - 3 ) - WBUF14) +get_w32_to_t2_l3: + lda (WBUF15 + 3 - $FF),x + sta (WBUF14 + 3 - $FF),x incx - cpx #20 - bne sha1_copy_h_to_ae_loop + bne get_w32_to_t2_l3 + lda #(WBUF15-BASE_START) + sta dest + lda #(ZERO-BASE_START) + jsr add4 ; WBUF15=T2 + + dec i + bne get_w32_to_t2_l2 + rts + + +sha1_block: + ldx #20 + +sha1_block_copy_h_to_ae_loop: + lda (H-1),x + sta (VA-1),x + decx + bne sha1_block_copy_h_to_ae_loop lda #0 -sha1_loop: +sha1_block_loop: ; a contains idx sta idx cmp #20 - bhs sha1_k2 + bhs sha1_block_k2 lda #(K1-BASE_START) sta k @@ -124,17 +297,17 @@ sha1_loop: lda #(VD-BASE_START) jsr and4 ;T2=T2&D - bra sha1_t2_or_bandc ; T1=T2 | (B&C) -sha1_k2: + bra sha1_block_t2_or_bandc ; T1=T2 | (B&C) +sha1_block_k2: cmp #40 - bhs sha1_k3 + bhs sha1_block_k3 lda #(K2-BASE_START) sta k - bra sha1_k24 ; T1 = B ^ C ^ D + bra sha1_block_k24 ; T1 = B ^ C ^ D -sha1_k3: +sha1_block_k3: cmp #60 - bhs sha1_k4 + bhs sha1_block_k4 ; T1 = (B & C) | (B & D) | (C & D) lda #(K3-BASE_START) sta k @@ -156,7 +329,7 @@ sha1_k3: lda #(T1-BASE_START) jsr or4 ; T2=T1|T2 -sha1_t2_or_bandc: +sha1_block_t2_or_bandc: lda #(T1-BASE_START) sta dest @@ -170,12 +343,12 @@ sha1_t2_or_bandc: lda #(T2-BASE_START) jsr or4 ; T1= T1|T2 - bra sha1_shuffle + bra sha1_block_shuffle -sha1_k4: +sha1_block_k4: lda #(K4-BASE_START) sta k -sha1_k24: +sha1_block_k24: ; T1 = B ^ C ^ D lda #(T1-BASE_START) sta dest @@ -187,7 +360,7 @@ sha1_k24: sta src1 lda #(VD-BASE_START) jsr xor4 -sha1_shuffle: +sha1_block_shuffle: ; T1 is src1 and dest here lda #(VE-BASE_START) @@ -196,20 +369,24 @@ sha1_shuffle: lda k jsr add4 ; T1=T1+k - ; get data here - lda #(ZERO-BASE_START) + jsr get_w32_to_t2 ; W[i]->T2 + + lda #(T1-BASE_START) + sta dest + sta src1 + lda #(T2-BASE_START) jsr add4 ; T1=T1+data lda #(VD-BASE_START) - jsr copy_down ; E=D + jsr copy_up ; E=D lda #(VC-BASE_START) - jsr copy_down ; D=C + jsr copy_up ; D=C lda #(VB-BASE_START) - jsr copy_down ; C=B + jsr copy_up ; C=B lda #30 jsr rot_left ; C=ROTLEFT(C,30) lda #(VA-BASE_START) - jsr copy_down ; B=A + jsr copy_up ; B=A lda #(VA-BASE_START) sta dest @@ -224,29 +401,29 @@ sha1_shuffle: lda idx add #1 cmp #80 - bhs sha1_done - jmp sha1_loop -sha1_done: + bhs sha1_block_done + jmp sha1_block_loop +sha1_block_done: ldx #0 -sha1_add0: +sha1_block_add0: clc -sha1_add1: +sha1_block_add1: lda VA,x adc H,x - sta VA,x + sta H,x incx txa and #3 - bne sha1_add1 + bne sha1_block_add1 cpx #20 - bne sha1_add0 + bne sha1_block_add0 rts -copy_down: +copy_up: sta src1 add #4 sta dest @@ -312,7 +489,7 @@ op4_dst: rot_left: ldx dest - sta rot_cnt + sta j rot_loop: lda BASE_START,x rola @@ -328,7 +505,7 @@ rot_loop: lda BASE_START,x rola sta BASE_START,x - dec rot_cnt + dec j bne rot_loop rts @@ -336,14 +513,46 @@ rot_loop: BASE_START: KEY: - DW $0e89 - DW $6e38 - DW $3cbb - DW $e9cf - DW $0000 - DW $e44f + DB $89 + DB $0e + DB $38 + DB $6e + + + DB $bb + DB $3c + DB $cf + DB $e9 + + DB $00 + DB $00 + DB $4f + DB $e4 + +IH: + DB $01 + DB $23 + DB $45 + DB $67 + DB $89 + DB $AB + DB $CD + DB $EF + DB $FE + DB $DC + DB $BA + DB $98 + DB $76 + DB $54 + DB $32 + DB $10 + DB $F0 + DB $E1 + DB $D2 + DB $C3 -IH: DB $01 +H: + DB $01 DB $23 DB $45 DB $67 @@ -395,6 +604,11 @@ FFFFFFFF: DB $FF DB $FF +KEYOR: + DW $3636 + DW $3636 + + bss: VA: DW 0 @@ -419,53 +633,52 @@ ZERO: DW 0 WBUF: +WBUF0: DW 0 DW 0 +WBUF1: DW 0 DW 0 +WBUF2: DW 0 DW 0 +WBUF3: DW 0 DW 0 +WBUF4: DW 0 DW 0 +WBUF5: DW 0 DW 0 +WBUF6: DW 0 DW 0 +WBUF7: DW 0 DW 0 +WBUF8: DW 0 DW 0 +WBUF9: DW 0 DW 0 +WBUF10: DW 0 DW 0 +WBUF11: DW 0 DW 0 +WBUF12: DW 0 DW 0 +WBUF13: DW 0 DW 0 +WBUF14: DW 0 DW 0 - DW 0 - DW 0 - -KEYOR: - DW 0 - DW 0 - - -H: - DW 0 - DW 0 - DW 0 - DW 0 - DW 0 - DW 0 - DW 0 - DW 0 +WBUF15: DW 0 DW 0 @@ -475,8 +688,10 @@ DATA1: DW 0 DW 0 DW 0 - DW 0 - DW 0 + DB 0 + DB 0 + DB 0 + DB $80 DW 0 DW 0 DW 0 @@ -484,8 +699,10 @@ DATA1: DW 0 DW 0 DATA2: - DW 0 - DW 0 + DB $40 + DB $02 + DB 0 + DB 0 BASE_END: |