mirror of https://github.com/zellyn/a2audit.git
reorganize langcard and shasum code
This commit is contained in:
parent
01503fddff
commit
5ae6c9cea7
|
@ -27,10 +27,13 @@ main:
|
||||||
!src "detect.asm"
|
!src "detect.asm"
|
||||||
|
|
||||||
;; Language card tests.
|
;; Language card tests.
|
||||||
!src "langcard.asm"
|
jsr LANGCARDTESTS
|
||||||
|
|
||||||
end: jmp *
|
end: jmp *
|
||||||
|
|
||||||
|
!src "langcard.asm"
|
||||||
|
!src "shasumtests.asm"
|
||||||
|
|
||||||
print
|
print
|
||||||
lda $C081
|
lda $C081
|
||||||
lda $C081
|
lda $C081
|
||||||
|
@ -77,7 +80,8 @@ getche lda $FEED ; FEED gets modified
|
||||||
jsr PRNTYX
|
jsr PRNTYX
|
||||||
rts
|
rts
|
||||||
!src "technote2.asm"
|
!src "technote2.asm"
|
||||||
|
!src "../shasum/shasum.asm"
|
||||||
|
|
||||||
; !if * != STRINGS {
|
; !if * != STRINGS {
|
||||||
; !error "Expected STRINGS to be ", *
|
; !error "Expected STRINGS to be ", *
|
||||||
; }
|
; }
|
||||||
|
|
BIN
audit/audit.dsk
BIN
audit/audit.dsk
Binary file not shown.
|
@ -2,14 +2,14 @@
|
||||||
;;; Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
|
;;; Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
|
||||||
|
|
||||||
!zone langcard {
|
!zone langcard {
|
||||||
|
LANGCARDTESTS
|
||||||
lda MEMORY
|
lda MEMORY
|
||||||
cmp #49
|
cmp #49
|
||||||
bcs +
|
bcs +
|
||||||
+print
|
+print
|
||||||
!text "48K:SKIPPING LANGUAGE CARD TEST",$8D
|
!text "48K:SKIPPING LANGUAGE CARD TEST",$8D
|
||||||
+printed
|
+printed
|
||||||
beq .jdone
|
rts
|
||||||
;; Setup - store differing values in bank first and second banked areas.
|
;; Setup - store differing values in bank first and second banked areas.
|
||||||
+ lda $C08B ; Read and write bank 1
|
+ lda $C08B ; Read and write bank 1
|
||||||
lda $C08B
|
lda $C08B
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
+prerr $0003 ;; E0003: We tried to put the language card into read bank 1, write bank 1, but failed to write.
|
+prerr $0003 ;; E0003: We tried to put the language card into read bank 1, write bank 1, but failed to write.
|
||||||
!text "CANNOT WRITE TO LC BANK 1 RAM"
|
!text "CANNOT WRITE TO LC BANK 1 RAM"
|
||||||
+prerred
|
+prerred
|
||||||
beq .jdone
|
rts
|
||||||
lda #$33
|
lda #$33
|
||||||
+ sta $FE1F ; FE1F is $60 in Apple II/plus/e/enhanced
|
+ sta $FE1F ; FE1F is $60 in Apple II/plus/e/enhanced
|
||||||
cmp $FE1F
|
cmp $FE1F
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
+prerr $0004 ;; E0004: We tried to put the language card into read RAM, write RAM, but failed to write.
|
+prerr $0004 ;; E0004: We tried to put the language card into read RAM, write RAM, but failed to write.
|
||||||
!text "CANNOT WRITE TO LC RAM"
|
!text "CANNOT WRITE TO LC RAM"
|
||||||
+prerred
|
+prerred
|
||||||
beq .jdone
|
rts
|
||||||
+ lda $C083 ; Read and write bank 2
|
+ lda $C083 ; Read and write bank 2
|
||||||
lda $C083
|
lda $C083
|
||||||
lda #$22
|
lda #$22
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
+prerr $0005 ;; E0005: We tried to put the language card into read bank 2, write bank 2, but failed to write.
|
+prerr $0005 ;; E0005: We tried to put the language card into read bank 2, write bank 2, but failed to write.
|
||||||
!text "CANNOT WRITE TO LC BANK 2 RAM"
|
!text "CANNOT WRITE TO LC BANK 2 RAM"
|
||||||
+prerred
|
+prerred
|
||||||
.jdone jmp .done
|
rts
|
||||||
|
|
||||||
;; Parameterized tests
|
;; Parameterized tests
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@
|
||||||
+prerr $0006 ;; E0006: This is a data-driven test of Language Card operation. We initialize $D17B in RAM bank 1 to $11, $D17B in RAM bank 2 to $22, and $FE1F in RAM to $33. Then, we perform a testdata-driven sequence of LDA and STA to the $C08X range. Finally we (try to) increment $D17B and $FE1F. Then we test (a) the current live value in $D17B, (b) the current live value in $FE1F, (c) the RAM bank 1 value of $D17B, (d) the RAM bank 2 value of $D17B, and (e) the RAM value of $FE1F, to see whether they match expected values. $D17B is usually $53 in ROM, and $FE1F is usally $60. For more information on the operation of the language card soft-switches, see Understanding the Apple IIe, by James Fielding Sather, Pg 5-24.
|
+prerr $0006 ;; E0006: This is a data-driven test of Language Card operation. We initialize $D17B in RAM bank 1 to $11, $D17B in RAM bank 2 to $22, and $FE1F in RAM to $33. Then, we perform a testdata-driven sequence of LDA and STA to the $C08X range. Finally we (try to) increment $D17B and $FE1F. Then we test (a) the current live value in $D17B, (b) the current live value in $FE1F, (c) the RAM bank 1 value of $D17B, (d) the RAM bank 2 value of $D17B, and (e) the RAM value of $FE1F, to see whether they match expected values. $D17B is usually $53 in ROM, and $FE1F is usally $60. For more information on the operation of the language card soft-switches, see Understanding the Apple IIe, by James Fielding Sather, Pg 5-24.
|
||||||
!text "DATA-DRIVEN TEST FAILED"
|
!text "DATA-DRIVEN TEST FAILED"
|
||||||
+prerred
|
+prerred
|
||||||
jmp .done
|
rts
|
||||||
|
|
||||||
.printseq
|
.printseq
|
||||||
tya
|
tya
|
||||||
|
@ -281,6 +281,8 @@
|
||||||
!byte $22, $33, $11, $22, $33 ;
|
!byte $22, $33, $11, $22, $33 ;
|
||||||
!byte $0b, $0b, $ff ; Read $C08B, $C08B (read/write RAM bank 1)
|
!byte $0b, $0b, $ff ; Read $C08B, $C08B (read/write RAM bank 1)
|
||||||
!byte $12, $34, $12, $22, $34 ;
|
!byte $12, $34, $12, $22, $34 ;
|
||||||
|
!byte $0f, $07, $ff ; Read $C08F, $C087 (read/write RAM bank 2)
|
||||||
|
!byte $23, $34, $11, $23, $34 ;
|
||||||
!byte $07, $0D, $ff ; Read $C087, read $C08D (read ROM, write bank 1)
|
!byte $07, $0D, $ff ; Read $C087, read $C08D (read ROM, write bank 1)
|
||||||
!byte $53, $60, $54, $22, $61 ;
|
!byte $53, $60, $54, $22, $61 ;
|
||||||
!byte $0b, $8b, $0b, $ff ; Read $C08B, write $C08B, read $C08B (read RAM bank 1, no write)
|
!byte $0b, $8b, $0b, $ff ; Read $C08B, write $C08B, read $C08B (read RAM bank 1, no write)
|
||||||
|
@ -297,4 +299,5 @@
|
||||||
!text "LANGUAGE CARD TESTS SUCCEEDED",$8D
|
!text "LANGUAGE CARD TESTS SUCCEEDED",$8D
|
||||||
+printed
|
+printed
|
||||||
.done
|
.done
|
||||||
|
rts
|
||||||
} ;langcard
|
} ;langcard
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
;;; Apple II ROM shasum audit routines
|
||||||
|
;;; Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
|
||||||
|
|
||||||
|
!zone shasumtests {
|
||||||
|
SHASUMTESTS
|
||||||
|
.done
|
||||||
|
rts
|
||||||
|
} ;shasumtests
|
|
@ -0,0 +1,145 @@
|
||||||
|
!to "shasum.o", plain
|
||||||
|
* = $6000
|
||||||
|
jmp main
|
||||||
|
|
||||||
|
!addr SRC = $06
|
||||||
|
!addr DST = $08
|
||||||
|
!addr SHAINPUT = $eb
|
||||||
|
!addr SHALENGTH = $ee
|
||||||
|
|
||||||
|
!addr PRBYTE = $FDDA
|
||||||
|
!addr COUT = $FDED
|
||||||
|
|
||||||
|
|
||||||
|
!macro set32 .target, .value {
|
||||||
|
lda #<(.value >> 24)
|
||||||
|
sta .target
|
||||||
|
lda #<(.value >> 16)
|
||||||
|
sta .target+1
|
||||||
|
lda #<(.value >> 8)
|
||||||
|
sta .target+2
|
||||||
|
lda #<(.value)
|
||||||
|
sta .target+3
|
||||||
|
}
|
||||||
|
|
||||||
|
!macro setSRC .source {
|
||||||
|
lda #<.source
|
||||||
|
sta SRC
|
||||||
|
lda #>.source
|
||||||
|
sta SRC+1
|
||||||
|
}
|
||||||
|
!macro setDST .dest {
|
||||||
|
lda #<.dest
|
||||||
|
sta DST
|
||||||
|
lda #>.dest
|
||||||
|
sta DST+1
|
||||||
|
}
|
||||||
|
|
||||||
|
;;; Print a string of bytes, as hex.
|
||||||
|
;;; Address in SRC, count in A.
|
||||||
|
;;; Burns A,Y.
|
||||||
|
prbytes:
|
||||||
|
ldy #0
|
||||||
|
- pha
|
||||||
|
lda (SRC),y
|
||||||
|
jsr PRBYTE
|
||||||
|
iny
|
||||||
|
pla
|
||||||
|
adc #$ff
|
||||||
|
bne -
|
||||||
|
rts
|
||||||
|
|
||||||
|
main:
|
||||||
|
;; Test shasum ""
|
||||||
|
lda #0
|
||||||
|
sta SHAINPUT
|
||||||
|
lda #$fe
|
||||||
|
sta SHAINPUT+1
|
||||||
|
lda #0
|
||||||
|
sta SHALENGTH+1
|
||||||
|
lda #0 ; da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||||
|
sta SHALENGTH
|
||||||
|
jsr SHASUM
|
||||||
|
|
||||||
|
; lda #$8d
|
||||||
|
; jsr COUT
|
||||||
|
|
||||||
|
+setSRC SHA
|
||||||
|
lda #SHALEN
|
||||||
|
jsr prbytes
|
||||||
|
|
||||||
|
;; Test shasum FE00[:0x37]
|
||||||
|
lda #0
|
||||||
|
sta SHAINPUT
|
||||||
|
lda #$fe
|
||||||
|
sta SHAINPUT+1
|
||||||
|
lda #0
|
||||||
|
sta SHALENGTH+1
|
||||||
|
lda #$37 ; 1CF73FC6156B548A949D315120B5256245EAA33E
|
||||||
|
sta SHALENGTH
|
||||||
|
jsr SHASUM
|
||||||
|
|
||||||
|
; lda #$8d
|
||||||
|
; jsr COUT
|
||||||
|
|
||||||
|
+setSRC SHA
|
||||||
|
lda #SHALEN
|
||||||
|
jsr prbytes
|
||||||
|
|
||||||
|
;; Test shasum FE00[:0x100]
|
||||||
|
lda #0
|
||||||
|
sta SHAINPUT
|
||||||
|
lda #$fe
|
||||||
|
sta SHAINPUT+1
|
||||||
|
lda #1
|
||||||
|
sta SHALENGTH+1
|
||||||
|
lda #0 ; 7B3D05347B52210065E27054FDFD0B8B699F0965
|
||||||
|
sta SHALENGTH
|
||||||
|
jsr SHASUM
|
||||||
|
|
||||||
|
; lda #$8d
|
||||||
|
; jsr COUT
|
||||||
|
|
||||||
|
+setSRC SHA
|
||||||
|
lda #SHALEN
|
||||||
|
jsr prbytes
|
||||||
|
|
||||||
|
;; Test shasum FE00[:0x1ff]
|
||||||
|
lda #0
|
||||||
|
sta SHAINPUT
|
||||||
|
lda #$fe
|
||||||
|
sta SHAINPUT+1
|
||||||
|
lda #$1
|
||||||
|
sta SHALENGTH+1
|
||||||
|
lda #$ff ; 269CA6B0C644DAC01D908B20C10C0D5B19C52ABF
|
||||||
|
sta SHALENGTH
|
||||||
|
jsr SHASUM
|
||||||
|
|
||||||
|
; lda #$8d
|
||||||
|
; jsr COUT
|
||||||
|
|
||||||
|
+setSRC SHA
|
||||||
|
lda #SHALEN
|
||||||
|
jsr prbytes
|
||||||
|
|
||||||
|
;; Test shasum FE00[:0x200]
|
||||||
|
lda #0
|
||||||
|
sta SHAINPUT
|
||||||
|
lda #$fe
|
||||||
|
sta SHAINPUT+1
|
||||||
|
lda #2
|
||||||
|
sta SHALENGTH+1
|
||||||
|
lda #0 ; D5AC71D5EE76E31CC82CF5136151BF4CDA503601
|
||||||
|
sta SHALENGTH
|
||||||
|
jsr SHASUM
|
||||||
|
|
||||||
|
; lda #$8d
|
||||||
|
; jsr COUT
|
||||||
|
|
||||||
|
+setSRC SHA
|
||||||
|
lda #SHALEN
|
||||||
|
jsr prbytes
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
!src "shasum.asm"
|
|
@ -1,6 +1,9 @@
|
||||||
!to "shasum.o", plain
|
;;; SHA-1 implementation in 6502 assembly.
|
||||||
* = $6000
|
;;; A straightforward implementation of:
|
||||||
jmp main
|
;;; https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode
|
||||||
|
;;; Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
|
||||||
|
|
||||||
|
!zone shasum {
|
||||||
|
|
||||||
;; clear addresses:
|
;; clear addresses:
|
||||||
;; (http://apple2.org.za/gswv/a2zine/faqs/csa2pfaq.html#017)
|
;; (http://apple2.org.za/gswv/a2zine/faqs/csa2pfaq.html#017)
|
||||||
|
@ -10,42 +13,15 @@
|
||||||
|
|
||||||
!addr SRC = $06
|
!addr SRC = $06
|
||||||
!addr DST = $08
|
!addr DST = $08
|
||||||
!addr INPUT = $eb
|
!addr SHAINPUT = $eb
|
||||||
!addr LENGTH = $ee
|
!addr SHALENGTH = $ee
|
||||||
!addr TMP1 = $fa
|
!addr .tmp1 = $fa
|
||||||
!addr TMP2 = $fb
|
!addr .tmp2 = $fb
|
||||||
|
|
||||||
!addr PRBYTE = $FDDA
|
!addr PRBYTE = $FDDA
|
||||||
!addr COUT = $FDED
|
!addr COUT = $FDED
|
||||||
|
|
||||||
h0: !32 0 ; return value (hash)
|
!macro .set32 .target, .value {
|
||||||
h1: !32 0
|
|
||||||
h2: !32 0
|
|
||||||
h3: !32 0
|
|
||||||
h4: !32 0
|
|
||||||
h5:
|
|
||||||
ml: !32 0, 0 ; message length
|
|
||||||
w: !fill 64, 0
|
|
||||||
w_next: !fill 64, 0
|
|
||||||
a: !32 0
|
|
||||||
b: !32 0
|
|
||||||
c: !32 0
|
|
||||||
d: !32 0
|
|
||||||
e: !32 0
|
|
||||||
f: !32 0
|
|
||||||
temp: !32 0
|
|
||||||
k: !32 0
|
|
||||||
kh0: !be32 $67452301 ; initial values for h0..h4
|
|
||||||
kh1: !be32 $EFCDAB89
|
|
||||||
kh2: !be32 $98BADCFE
|
|
||||||
kh3: !be32 $10325476
|
|
||||||
kh4: !be32 $C3D2E1F0
|
|
||||||
k1 = $5A827999 ; k constants
|
|
||||||
k2 = $6ED9EBA1
|
|
||||||
k3 = $8F1BBCDC
|
|
||||||
k4 = $CA62C1D6
|
|
||||||
|
|
||||||
!macro set32 .target, .value {
|
|
||||||
lda #<(.value >> 24)
|
lda #<(.value >> 24)
|
||||||
sta .target
|
sta .target
|
||||||
lda #<(.value >> 16)
|
lda #<(.value >> 16)
|
||||||
|
@ -56,149 +32,73 @@ k4 = $CA62C1D6
|
||||||
sta .target+3
|
sta .target+3
|
||||||
}
|
}
|
||||||
|
|
||||||
!macro setSRC .source {
|
!macro .setSRC .source {
|
||||||
lda #<.source
|
lda #<.source
|
||||||
sta SRC
|
sta SRC
|
||||||
lda #>.source
|
lda #>.source
|
||||||
sta SRC+1
|
sta SRC+1
|
||||||
}
|
}
|
||||||
!macro setDST .dest {
|
!macro .setDST .dest {
|
||||||
lda #<.dest
|
lda #<.dest
|
||||||
sta DST
|
sta DST
|
||||||
lda #>.dest
|
lda #>.dest
|
||||||
sta DST+1
|
sta DST+1
|
||||||
}
|
}
|
||||||
|
|
||||||
;;; Print a string of bytes, as hex.
|
|
||||||
;;; Address in SRC, count in A.
|
|
||||||
;;; Burns A,Y.
|
|
||||||
prbytes:
|
|
||||||
ldy #0
|
|
||||||
- pha
|
|
||||||
lda (SRC),y
|
|
||||||
jsr PRBYTE
|
|
||||||
iny
|
|
||||||
pla
|
|
||||||
adc #$ff
|
|
||||||
bne -
|
|
||||||
rts
|
|
||||||
|
|
||||||
main:
|
!align 255, 0 ; align data area to page boundary
|
||||||
;; Test shasum ""
|
SHA:
|
||||||
lda #0
|
SHALEN = 20
|
||||||
sta INPUT
|
.h0: !32 0 ; return value (hash)
|
||||||
lda #$fe
|
.h1: !32 0
|
||||||
sta INPUT+1
|
.h2: !32 0
|
||||||
lda #0
|
.h3: !32 0
|
||||||
sta LENGTH+1
|
.h4: !32 0
|
||||||
lda #0 ; da39a3ee5e6b4b0d3255bfef95601890afd80709
|
.h5:
|
||||||
sta LENGTH
|
.ml: !32 0, 0 ; message length
|
||||||
jsr shasum
|
.w: !fill 64, 0
|
||||||
|
.w_next: !fill 64, 0
|
||||||
|
.a: !32 0
|
||||||
|
.b: !32 0
|
||||||
|
.c: !32 0
|
||||||
|
.d: !32 0
|
||||||
|
.e: !32 0
|
||||||
|
.f: !32 0
|
||||||
|
.temp: !32 0
|
||||||
|
.k: !32 0
|
||||||
|
.kh0: !be32 $67452301 ; initial values for h0..h4
|
||||||
|
.kh1: !be32 $EFCDAB89
|
||||||
|
.kh2: !be32 $98BADCFE
|
||||||
|
.kh3: !be32 $10325476
|
||||||
|
.kh4: !be32 $C3D2E1F0
|
||||||
|
.k1 = $5A827999 ; k constants
|
||||||
|
.k2 = $6ED9EBA1
|
||||||
|
.k3 = $8F1BBCDC
|
||||||
|
.k4 = $CA62C1D6
|
||||||
|
|
||||||
; lda #$8d
|
SHASUM:
|
||||||
; jsr COUT
|
|
||||||
|
|
||||||
+setSRC h0
|
|
||||||
lda #(h5-h0)
|
|
||||||
jsr prbytes
|
|
||||||
|
|
||||||
;; Test shasum FE00[:0x37]
|
|
||||||
lda #0
|
|
||||||
sta INPUT
|
|
||||||
lda #$fe
|
|
||||||
sta INPUT+1
|
|
||||||
lda #0
|
|
||||||
sta LENGTH+1
|
|
||||||
lda #$37 ; 1CF73FC6156B548A949D315120B5256245EAA33E
|
|
||||||
sta LENGTH
|
|
||||||
jsr shasum
|
|
||||||
|
|
||||||
; lda #$8d
|
|
||||||
; jsr COUT
|
|
||||||
|
|
||||||
+setSRC h0
|
|
||||||
lda #(h5-h0)
|
|
||||||
jsr prbytes
|
|
||||||
|
|
||||||
;; Test shasum FE00[:0x100]
|
|
||||||
lda #0
|
|
||||||
sta INPUT
|
|
||||||
lda #$fe
|
|
||||||
sta INPUT+1
|
|
||||||
lda #1
|
|
||||||
sta LENGTH+1
|
|
||||||
lda #0 ; 7B3D05347B52210065E27054FDFD0B8B699F0965
|
|
||||||
sta LENGTH
|
|
||||||
jsr shasum
|
|
||||||
|
|
||||||
; lda #$8d
|
|
||||||
; jsr COUT
|
|
||||||
|
|
||||||
+setSRC h0
|
|
||||||
lda #(h5-h0)
|
|
||||||
jsr prbytes
|
|
||||||
|
|
||||||
;; Test shasum FE00[:0x1ff]
|
|
||||||
lda #0
|
|
||||||
sta INPUT
|
|
||||||
lda #$fe
|
|
||||||
sta INPUT+1
|
|
||||||
lda #$1
|
|
||||||
sta LENGTH+1
|
|
||||||
lda #$ff ; 269CA6B0C644DAC01D908B20C10C0D5B19C52ABF
|
|
||||||
sta LENGTH
|
|
||||||
jsr shasum
|
|
||||||
|
|
||||||
; lda #$8d
|
|
||||||
; jsr COUT
|
|
||||||
|
|
||||||
+setSRC h0
|
|
||||||
lda #(h5-h0)
|
|
||||||
jsr prbytes
|
|
||||||
|
|
||||||
;; Test shasum FE00[:0x200]
|
|
||||||
lda #0
|
|
||||||
sta INPUT
|
|
||||||
lda #$fe
|
|
||||||
sta INPUT+1
|
|
||||||
lda #2
|
|
||||||
sta LENGTH+1
|
|
||||||
lda #0 ; D5AC71D5EE76E31CC82CF5136151BF4CDA503601
|
|
||||||
sta LENGTH
|
|
||||||
jsr shasum
|
|
||||||
|
|
||||||
; lda #$8d
|
|
||||||
; jsr COUT
|
|
||||||
|
|
||||||
+setSRC h0
|
|
||||||
lda #(h5-h0)
|
|
||||||
jsr prbytes
|
|
||||||
|
|
||||||
rts
|
|
||||||
|
|
||||||
shasum:
|
|
||||||
;; Initialize h0..h4
|
;; Initialize h0..h4
|
||||||
ldy #(h5-h0-1)
|
ldy #(.h5-.h0-1)
|
||||||
- lda kh0,y
|
- lda .kh0,y
|
||||||
sta h0,y
|
sta .h0,y
|
||||||
dey
|
dey
|
||||||
bpl -
|
bpl -
|
||||||
;; Initialize message length (ml)
|
;; Initialize message length (.ml)
|
||||||
lda #0
|
lda #0
|
||||||
ldy #4
|
ldy #4
|
||||||
- sta ml, y
|
- sta .ml, y
|
||||||
dey
|
dey
|
||||||
bpl -
|
bpl -
|
||||||
lda LENGTH
|
lda SHALENGTH
|
||||||
sta ml+7
|
sta .ml+7
|
||||||
lda LENGTH+1
|
lda SHALENGTH+1
|
||||||
sta ml+6
|
sta .ml+6
|
||||||
|
|
||||||
;; Message length is in bits
|
;; Message length is in bits
|
||||||
ldy #3
|
ldy #3
|
||||||
- asl ml+7
|
- asl .ml+7
|
||||||
rol ml+6
|
rol .ml+6
|
||||||
rol ml+5
|
rol .ml+5
|
||||||
dey
|
dey
|
||||||
bne -
|
bne -
|
||||||
|
|
||||||
|
@ -206,19 +106,19 @@ shasum:
|
||||||
;; ldy #0 ; already zero
|
;; ldy #0 ; already zero
|
||||||
|
|
||||||
;; Invert length so we can inc instead of dec
|
;; Invert length so we can inc instead of dec
|
||||||
lda LENGTH
|
lda SHALENGTH
|
||||||
sec
|
sec
|
||||||
lda #0
|
lda #0
|
||||||
sbc LENGTH
|
sbc SHALENGTH
|
||||||
sta LENGTH
|
sta SHALENGTH
|
||||||
lda #0
|
lda #0
|
||||||
sbc LENGTH+1
|
sbc SHALENGTH+1
|
||||||
sta LENGTH+1
|
sta SHALENGTH+1
|
||||||
ora LENGTH
|
ora SHALENGTH
|
||||||
beq .msgdone
|
beq .msgdone
|
||||||
|
|
||||||
.loop lda (INPUT),y
|
.loop lda (SHAINPUT),y
|
||||||
sta w,y
|
sta .w,y
|
||||||
iny
|
iny
|
||||||
cpy #$40
|
cpy #$40
|
||||||
bne +
|
bne +
|
||||||
|
@ -228,20 +128,20 @@ shasum:
|
||||||
ldy #0
|
ldy #0
|
||||||
|
|
||||||
clc
|
clc
|
||||||
lda INPUT
|
lda SHAINPUT
|
||||||
adc #$40
|
adc #$40
|
||||||
sta INPUT
|
sta SHAINPUT
|
||||||
bcc +
|
bcc +
|
||||||
inc INPUT+1
|
inc SHAINPUT+1
|
||||||
|
|
||||||
+ inc LENGTH
|
+ inc SHALENGTH
|
||||||
bne .loop
|
bne .loop
|
||||||
inc LENGTH+1
|
inc SHALENGTH+1
|
||||||
bne .loop
|
bne .loop
|
||||||
|
|
||||||
.msgdone:
|
.msgdone:
|
||||||
lda #$80
|
lda #$80
|
||||||
sta w,y
|
sta .w,y
|
||||||
iny
|
iny
|
||||||
cpy #$40
|
cpy #$40
|
||||||
bne .zeros
|
bne .zeros
|
||||||
|
@ -252,7 +152,7 @@ shasum:
|
||||||
cpy #$38
|
cpy #$38
|
||||||
beq .length
|
beq .length
|
||||||
lda #0
|
lda #0
|
||||||
sta w,y
|
sta .w,y
|
||||||
iny
|
iny
|
||||||
cpy #$40
|
cpy #$40
|
||||||
bne .zeros
|
bne .zeros
|
||||||
|
@ -261,27 +161,27 @@ shasum:
|
||||||
jmp .zeros
|
jmp .zeros
|
||||||
.length
|
.length
|
||||||
ldy #7
|
ldy #7
|
||||||
- lda ml,y
|
- lda .ml,y
|
||||||
sta w+$38,y
|
sta .w+$38,y
|
||||||
dey
|
dey
|
||||||
bpl -
|
bpl -
|
||||||
jsr do_chunk
|
jsr do_chunk
|
||||||
rts
|
rts
|
||||||
|
|
||||||
;;; do_chunk processes a chunk of input. It burns A,X,Y,TMP1,TMP2.
|
;;; do_chunk processes a chunk of input. It burns A,X,Y,.tmp1,.tmp2.
|
||||||
do_chunk:
|
do_chunk:
|
||||||
;; Copy a..e from h0..h4
|
;; Copy a..e from h0..h4
|
||||||
|
|
||||||
ldy #(f-a-1)
|
ldy #(.f-.a-1)
|
||||||
- lda h0,y
|
- lda .h0,y
|
||||||
sta a,y
|
sta .a,y
|
||||||
dey
|
dey
|
||||||
bpl -
|
bpl -
|
||||||
|
|
||||||
ldy #0 ; y is index into w
|
ldy #0 ; y is index into w
|
||||||
|
|
||||||
;; First 20: k1
|
;; First 20: k1
|
||||||
+set32 k, k1
|
+.set32 .k, .k1
|
||||||
|
|
||||||
ldx #16
|
ldx #16
|
||||||
- jsr kind1
|
- jsr kind1
|
||||||
|
@ -293,7 +193,7 @@ do_chunk:
|
||||||
dex
|
dex
|
||||||
bne -
|
bne -
|
||||||
;; Second 20: k2
|
;; Second 20: k2
|
||||||
+set32 k, k2
|
+.set32 .k, .k2
|
||||||
|
|
||||||
ldx #12
|
ldx #12
|
||||||
- jsr kind2
|
- jsr kind2
|
||||||
|
@ -306,7 +206,7 @@ do_chunk:
|
||||||
bne -
|
bne -
|
||||||
|
|
||||||
;; Third 20: k3
|
;; Third 20: k3
|
||||||
+set32 k, k3
|
+.set32 .k, .k3
|
||||||
|
|
||||||
ldx #8
|
ldx #8
|
||||||
- jsr kind3
|
- jsr kind3
|
||||||
|
@ -319,7 +219,7 @@ do_chunk:
|
||||||
bne -
|
bne -
|
||||||
|
|
||||||
;; Fourth 20: k4
|
;; Fourth 20: k4
|
||||||
+set32 k, k4
|
+.set32 .k, .k4
|
||||||
|
|
||||||
ldx #4
|
ldx #4
|
||||||
- jsr kind2
|
- jsr kind2
|
||||||
|
@ -331,8 +231,8 @@ do_chunk:
|
||||||
dex
|
dex
|
||||||
bne -
|
bne -
|
||||||
|
|
||||||
+setSRC a
|
+.setSRC .a
|
||||||
+setDST h0
|
+.setDST .h0
|
||||||
ldx #5
|
ldx #5
|
||||||
- jsr add32
|
- jsr add32
|
||||||
clc
|
clc
|
||||||
|
@ -347,57 +247,57 @@ do_chunk:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
kind1:
|
kind1:
|
||||||
sty TMP1
|
sty .tmp1
|
||||||
stx TMP2
|
stx .tmp2
|
||||||
;; f = d xor (b and (c xor d))
|
;; f = d xor (b and (c xor d))
|
||||||
+setDST f
|
+.setDST .f
|
||||||
+setSRC d
|
+.setSRC .d
|
||||||
jsr cp32
|
jsr cp32
|
||||||
+setSRC c
|
+.setSRC .c
|
||||||
jsr xor32
|
jsr xor32
|
||||||
+setSRC b
|
+.setSRC .b
|
||||||
jsr and32
|
jsr and32
|
||||||
+setSRC d
|
+.setSRC .d
|
||||||
jsr xor32
|
jsr xor32
|
||||||
|
|
||||||
jmp common
|
jmp common
|
||||||
kind2:
|
kind2:
|
||||||
sty TMP1
|
sty .tmp1
|
||||||
stx TMP2
|
stx .tmp2
|
||||||
;; f = b xor c xor d
|
;; f = b xor c xor d
|
||||||
+setDST f
|
+.setDST .f
|
||||||
+setSRC d
|
+.setSRC .d
|
||||||
jsr cp32
|
jsr cp32
|
||||||
+setSRC c
|
+.setSRC .c
|
||||||
jsr xor32
|
jsr xor32
|
||||||
+setSRC b
|
+.setSRC .b
|
||||||
jsr xor32
|
jsr xor32
|
||||||
|
|
||||||
jmp common
|
jmp common
|
||||||
kind3:
|
kind3:
|
||||||
sty TMP1
|
sty .tmp1
|
||||||
stx TMP2
|
stx .tmp2
|
||||||
;; f = (b and c) or (d and (b or c))
|
;; f = (b and c) or (d and (b or c))
|
||||||
+setSRC c
|
+.setSRC .c
|
||||||
+setDST f
|
+.setDST .f
|
||||||
jsr cp32
|
jsr cp32
|
||||||
+setDST temp
|
+.setDST .temp
|
||||||
jsr cp32
|
jsr cp32
|
||||||
+setSRC b
|
+.setSRC .b
|
||||||
jsr and32
|
jsr and32
|
||||||
+setDST f
|
+.setDST .f
|
||||||
jsr or32
|
jsr or32
|
||||||
+setSRC d
|
+.setSRC .d
|
||||||
jsr and32
|
jsr and32
|
||||||
+setSRC temp
|
+.setSRC .temp
|
||||||
jsr or32
|
jsr or32
|
||||||
; jmp common
|
; jmp common
|
||||||
|
|
||||||
common:
|
common:
|
||||||
|
|
||||||
;; temp = (a leftrotate 5) + f + e + k + w[i]
|
;; temp = (a leftrotate 5) + f + e + k + w[i]
|
||||||
+setDST temp
|
+.setDST .temp
|
||||||
+setSRC a
|
+.setSRC .a
|
||||||
jsr cp32
|
jsr cp32
|
||||||
jsr rol8
|
jsr rol8
|
||||||
|
|
||||||
|
@ -405,53 +305,53 @@ common:
|
||||||
jsr ror1
|
jsr ror1
|
||||||
jsr ror1
|
jsr ror1
|
||||||
|
|
||||||
+setSRC f
|
+.setSRC .f
|
||||||
jsr add32
|
jsr add32
|
||||||
+setSRC e
|
+.setSRC .e
|
||||||
jsr add32
|
jsr add32
|
||||||
+setSRC k
|
+.setSRC .k
|
||||||
jsr add32
|
jsr add32
|
||||||
|
|
||||||
;; !setSRC w[i], and call add32
|
;; !.setSRC w[i], and call add32
|
||||||
ldy TMP1
|
ldy .tmp1
|
||||||
clc
|
clc
|
||||||
tya
|
tya
|
||||||
adc #<w
|
adc #<.w
|
||||||
sta SRC
|
sta SRC
|
||||||
lda #0
|
lda #0
|
||||||
adc #>w
|
adc #>.w
|
||||||
sta SRC+1
|
sta SRC+1
|
||||||
jsr add32
|
jsr add32
|
||||||
|
|
||||||
;; e = d
|
;; e = d
|
||||||
+setSRC d
|
+.setSRC .d
|
||||||
+setDST e
|
+.setDST .e
|
||||||
jsr cp32
|
jsr cp32
|
||||||
|
|
||||||
;; d = c
|
;; d = c
|
||||||
+setSRC c
|
+.setSRC .c
|
||||||
+setDST d
|
+.setDST .d
|
||||||
jsr cp32
|
jsr cp32
|
||||||
|
|
||||||
;; c = b leftrotate 30
|
;; c = b leftrotate 30
|
||||||
+setSRC b
|
+.setSRC .b
|
||||||
+setDST c
|
+.setDST .c
|
||||||
jsr cp32
|
jsr cp32
|
||||||
jsr ror1
|
jsr ror1
|
||||||
jsr ror1
|
jsr ror1
|
||||||
|
|
||||||
;; b = a
|
;; b = a
|
||||||
+setSRC a
|
+.setSRC .a
|
||||||
+setDST b
|
+.setDST .b
|
||||||
jsr cp32
|
jsr cp32
|
||||||
|
|
||||||
;; a = temp
|
;; a = temp
|
||||||
+setSRC temp
|
+.setSRC .temp
|
||||||
+setDST a
|
+.setDST .a
|
||||||
jsr cp32
|
jsr cp32
|
||||||
|
|
||||||
ldy TMP1
|
ldy .tmp1
|
||||||
ldx TMP2
|
ldx .tmp2
|
||||||
iny
|
iny
|
||||||
iny
|
iny
|
||||||
iny
|
iny
|
||||||
|
@ -460,8 +360,8 @@ common:
|
||||||
|
|
||||||
;; Replace w[i:i+16] with w[i+16:i+32]. Burns a. Sets y=0.
|
;; Replace w[i:i+16] with w[i+16:i+32]. Burns a. Sets y=0.
|
||||||
fill:
|
fill:
|
||||||
+setDST w_next
|
+.setDST .w_next
|
||||||
+setSRC w
|
+.setSRC .w
|
||||||
ldx #0x10
|
ldx #0x10
|
||||||
|
|
||||||
- sec
|
- sec
|
||||||
|
@ -491,9 +391,9 @@ fill:
|
||||||
dex
|
dex
|
||||||
bne -
|
bne -
|
||||||
|
|
||||||
ldx #w_next-w-1
|
ldx #.w_next-.w-1
|
||||||
- lda w_next,x
|
- lda .w_next,x
|
||||||
sta w,x
|
sta .w,x
|
||||||
dex
|
dex
|
||||||
bpl -
|
bpl -
|
||||||
|
|
||||||
|
@ -599,19 +499,4 @@ rol8:
|
||||||
txa
|
txa
|
||||||
sta (DST),y
|
sta (DST),y
|
||||||
rts
|
rts
|
||||||
|
} ;shasum
|
||||||
!eof
|
|
||||||
TODOs
|
|
||||||
[X] Routine to print n hex bytes (address, length (byte))
|
|
||||||
[X] Routine to get the next 16 values (64 bytes) of input
|
|
||||||
[X] Routine to get w[i] one i at a time, and rebuild next 16 values
|
|
||||||
|
|
||||||
Needed arithmetic routines for sha1sum:
|
|
||||||
- [X] add32
|
|
||||||
- [X] and32
|
|
||||||
- [X] or32
|
|
||||||
- [X] xor32
|
|
||||||
- [X] ROL1
|
|
||||||
- [X] ROR1
|
|
||||||
- [X] ROL5 --> ROL8, (ROR1,ROR1,ROR1)
|
|
||||||
- [X] ROL30 --> (ROR1,ROR1)
|
|
Loading…
Reference in New Issue