2016-09-13 01:52:46 +00:00
|
|
|
!to "shasum.o", plain
|
|
|
|
* = $6000
|
2016-09-19 03:19:26 +00:00
|
|
|
jmp main
|
2016-09-13 01:52:46 +00:00
|
|
|
|
|
|
|
;; clear addresses:
|
|
|
|
;; (http://apple2.org.za/gswv/a2zine/faqs/csa2pfaq.html#017)
|
|
|
|
;; 06-09
|
|
|
|
;; EB-EF
|
|
|
|
;; FA-FD
|
|
|
|
|
2016-09-19 03:19:26 +00:00
|
|
|
!addr SRC = $06
|
|
|
|
!addr DEST = $08
|
|
|
|
!addr INPUT = $eb
|
|
|
|
!addr LENGTH = $ee
|
|
|
|
|
|
|
|
!addr PRBYTE = $FDDA
|
|
|
|
!addr COUT = $FDED
|
2016-09-13 01:52:46 +00:00
|
|
|
|
|
|
|
h0: !32 0 ; return value (hash)
|
|
|
|
h1: !32 0
|
|
|
|
h2: !32 0
|
|
|
|
h3: !32 0
|
|
|
|
h4: !32 0
|
|
|
|
ml: !32 0 ; message length
|
|
|
|
w: !fill 64, 0
|
|
|
|
w_next: !fill 64, 0
|
|
|
|
kh0: !be32 $67452301 ; initial values for h0..h4
|
|
|
|
kh1: !be32 $EFCDAB89
|
|
|
|
kh2: !be32 $98BADCFE
|
|
|
|
kh3: !be32 $10325476
|
|
|
|
kh4: !be32 $C3D2E1F0
|
|
|
|
k1: !be32 $5A827999 ; k = constants
|
|
|
|
k2: !be32 $6ED9EBA1
|
|
|
|
k3: !be32 $8F1BBCDC
|
|
|
|
k4: !be32 $CA62C1D6
|
2016-09-19 03:19:26 +00:00
|
|
|
|
|
|
|
;;; Print a string of bytes, as hex.
|
|
|
|
;;; Address in SRC, count in A.
|
|
|
|
;;; Burns Y, A.
|
|
|
|
prbytes:
|
|
|
|
ldy #0
|
|
|
|
- pha
|
|
|
|
lda (SRC),y
|
|
|
|
jsr PRBYTE
|
|
|
|
iny
|
|
|
|
pla
|
|
|
|
adc #$ff
|
|
|
|
bne -
|
2016-09-13 01:52:46 +00:00
|
|
|
rts
|
2016-09-19 03:19:26 +00:00
|
|
|
|
|
|
|
main:
|
|
|
|
;; Test PRBYTES
|
|
|
|
;; lda #<kh0
|
|
|
|
;; sta SRC
|
|
|
|
;; lda #>kh0
|
|
|
|
;; sta SRC+1
|
|
|
|
;; lda #8
|
|
|
|
;; jsr prbytes
|
|
|
|
;; LDA #$8D
|
|
|
|
;; jsr COUT
|
2016-09-13 01:52:46 +00:00
|
|
|
|
2016-09-19 03:19:26 +00:00
|
|
|
;; Test shasum
|
|
|
|
lda #0
|
|
|
|
sta INPUT
|
|
|
|
lda #$ff
|
|
|
|
sta INPUT+1
|
|
|
|
lda #0
|
|
|
|
sta LENGTH+1
|
|
|
|
lda #$3b
|
|
|
|
sta LENGTH
|
|
|
|
jsr shasum
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
shasum:
|
|
|
|
;; Initialize h0..h4
|
|
|
|
ldy #(ml-h0-1)
|
|
|
|
- lda kh0,y
|
|
|
|
sta h0,y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
;; Initialize message length (ml)
|
|
|
|
lda #0
|
|
|
|
sta ml
|
|
|
|
sta ml+1
|
|
|
|
lda LENGTH
|
|
|
|
sta ml+3
|
|
|
|
lda LENGTH+1
|
|
|
|
sta ml+2
|
|
|
|
|
|
|
|
;; Message length is in bits
|
|
|
|
ldy #3
|
|
|
|
- clc
|
|
|
|
rol ml+3
|
|
|
|
rol ml+2
|
|
|
|
rol ml+1
|
|
|
|
dey
|
|
|
|
bne -
|
|
|
|
|
|
|
|
;; Initialize chunk counter
|
|
|
|
;; ldy #0 ; already zero
|
|
|
|
|
|
|
|
;; Invert length so we can inc instead of dec
|
|
|
|
lda LENGTH
|
|
|
|
sec
|
|
|
|
lda #0
|
|
|
|
sbc LENGTH
|
|
|
|
sta LENGTH
|
|
|
|
lda #0
|
|
|
|
sbc LENGTH+1
|
|
|
|
sta LENGTH+1
|
|
|
|
ora LENGTH
|
|
|
|
beq .msgdone
|
|
|
|
|
|
|
|
.loop lda (INPUT),y
|
|
|
|
sta w,y
|
|
|
|
iny
|
|
|
|
cpy #$40
|
|
|
|
bne +
|
|
|
|
|
|
|
|
;; Call do_chunk
|
|
|
|
jsr do_chunk
|
|
|
|
ldy #0
|
|
|
|
|
|
|
|
clc
|
|
|
|
lda INPUT
|
|
|
|
adc #$40
|
|
|
|
sta INPUT
|
|
|
|
bcc +
|
|
|
|
inc INPUT+1
|
|
|
|
|
|
|
|
+ inc LENGTH
|
|
|
|
bne .loop
|
|
|
|
inc LENGTH+1
|
|
|
|
bne .loop
|
|
|
|
|
|
|
|
.msgdone:
|
|
|
|
lda #$80
|
|
|
|
sta w,y
|
|
|
|
iny
|
|
|
|
cpy #$40
|
|
|
|
bne .zeros
|
|
|
|
jsr do_chunk
|
|
|
|
ldy #0
|
2016-09-13 01:52:46 +00:00
|
|
|
|
2016-09-19 03:19:26 +00:00
|
|
|
.zeros
|
|
|
|
cpy #$3C
|
|
|
|
beq .length
|
|
|
|
lda #0
|
|
|
|
sta w,y
|
|
|
|
iny
|
|
|
|
cpy #$40
|
|
|
|
bne .zeros
|
|
|
|
jsr do_chunk
|
|
|
|
ldy #0
|
|
|
|
jmp .zeros
|
|
|
|
.length
|
|
|
|
ldy #3
|
|
|
|
- lda ml,y
|
|
|
|
sta w+$3c,y
|
|
|
|
dey
|
|
|
|
bpl -
|
|
|
|
jsr do_chunk
|
|
|
|
rts
|
|
|
|
|
|
|
|
do_chunk:
|
|
|
|
lda #<w
|
|
|
|
sta SRC
|
|
|
|
lda #>w
|
|
|
|
sta SRC+1
|
|
|
|
lda #$40
|
|
|
|
jsr prbytes
|
|
|
|
lda #$8D
|
|
|
|
jsr COUT
|
|
|
|
rts
|
|
|
|
|
|
|
|
!eof
|
2016-09-13 01:52:46 +00:00
|
|
|
TODOs
|
2016-09-19 03:19:26 +00:00
|
|
|
[X] Routine to print n hex bytes (address, length (byte))
|
2016-09-19 03:26:30 +00:00
|
|
|
[X] Routine to get the next 16 values (64 bytes) of input
|
2016-09-13 01:52:46 +00:00
|
|
|
[ ] Routine to get w[i] one i at a time, and rebuild next 16 values
|
|
|
|
|
2016-09-19 03:26:30 +00:00
|
|
|
Needed arithmetic routines for sha1sum:
|
|
|
|
- [ ] add32
|
|
|
|
- [ ] and32
|
|
|
|
- [ ] or32
|
|
|
|
- [ ] xor32
|
|
|
|
- [ ] not32
|
|
|
|
- [ ] ROL1
|
|
|
|
- [ ] ROR1
|
|
|
|
- [ ] ROL5 --> ROL8, (ROR1,ROR1,ROR1)
|
|
|
|
- [ ] ROL30 --> (ROR1,ROR1)
|