forgot to commit this one after ZP reorg

This commit is contained in:
Rémy GIBERT 2016-02-24 21:07:19 +01:00
parent 1fc656e102
commit 9ec40dba75

View File

@ -6,12 +6,17 @@ AUTO 6
.LIST OFF .LIST OFF
.OP 65C02 .OP 65C02
.OR $2000 .OR $2000
.TF LIB/LIBCRYPT.O .TF /A2OSX.BOOT/LIB/LIBCRYPT.O
*-------------------------------------- *--------------------------------------
.INB INC/MACROS.I .INB INC/MACROS.I
.INB INC/A2OSX.I .INB INC/A2OSX.I
.INB INC/LIBCRYPT.I .INB INC/LIBCRYPT.I
*-------------------------------------- *--------------------------------------
ZPTmpPtr1 .EQ ZPLIB
ZPTmpPtr2 .EQ ZPLIB+2
ZPTmpPtr3 .EQ ZPLIB+4
ZPTmpPtr4 .EQ ZPLIB+6
*--------------------------------------
* DWORD Macros : Do NOT disturb carry with cpx, cpy... * DWORD Macros : Do NOT disturb carry with cpx, cpy...
*-------------------------------------- *--------------------------------------
.MA ADC32 .MA ADC32
@ -81,28 +86,26 @@ AUTO 6
bne :2 bne :2
.EM .EM
*-------------------------------------- *--------------------------------------
* Main entry point * File Header (16 Bytes)
* input :
* X = Function
*--------------------------------------
* Code signature and relocation table
*--------------------------------------
* CLD $D8
* JMP (*,x) $7C
* #JMPTABLE
* /JMPTABLE
*-------------------------------------- *--------------------------------------
CS.START cld CS.START cld
jmp (.1,x) jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START
.DA 0
.DA 0
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA LIB.LOAD .1 .DA LIB.LOAD
.DA LIB.UNLOAD .DA LIB.UNLOAD
.DA MD5PStrA .DA MD5PStrA
.DA MD5Init .DA MD5Init
.DA MD5Update .DA MD5Update
.DA MD5FinalizeA .DA MD5FinalizeA
*--------------------------------------
.DA 0
.DA CS.END-CS.START
.DA 0 .DA 0
*-------------------------------------- *--------------------------------------
LIB.LOAD LIB.LOAD
@ -116,19 +119,19 @@ LIB.UNLOAD clc
* A = hMem To MessageDigest * A = hMem To MessageDigest
*-------------------------------------- *--------------------------------------
MD5PStrA >SYSCALL SYS.GetMemPtrA MD5PStrA >SYSCALL SYS.GetMemPtrA
>STYA ZPQuickPtr3 1 and 2 used by other MD5 functions >STYA ZPTmpPtr3 1 and 2 used by other MD5 functions
ldy #0 ldy #0
lda (ZPQuickPtr3),y get PStr len lda (ZPTmpPtr3),y get PStr len
sta ZPQuickPtr4 ZPQuickPtr4 = str len sta ZPTmpPtr4 ZPTmpPtr4 = str len
stz ZPQuickPtr4+1 0,PSTR len <= 255 stz ZPTmpPtr4+1 0,PSTR len <= 255
inc ZPQuickPtr3 inc ZPTmpPtr3
bne .1 bne .1
inc ZPQuickPtr3+1 Make DATA skip PSTR Len Byte inc ZPTmpPtr3+1 Make DATA skip PSTR Len Byte
.1 jsr MD5Init .1 jsr MD5Init
bcs .9 bcs .9
pha save MD5 Context hMem pha save MD5 Context hMem
>PUSHW ZPQuickPtr4 Push LEN >PUSHW ZPTmpPtr4 Push LEN
>PUSHW ZPQuickPtr3 Push DATA >PUSHW ZPTmpPtr3 Push DATA
pla pla
pha pha
>PUSHA Push MD5 Context >PUSHA Push MD5 Context
@ -153,15 +156,15 @@ MD5Init >PUSHWI S.MD5.SIZE
>PUSHBI 0 >PUSHBI 0
>SYSCALL SYS.GetMem >SYSCALL SYS.GetMem
bcs .9 bcs .9
>STYA ZPQuickPtr1 >STYA ZPTmpPtr1
ldy #0 ldy #0
.1 lda MD5.ABCDINIT,y .1 lda MD5.ABCDINIT,y
sta (ZPQuickPtr1),y sta (ZPTmpPtr1),y
iny iny
cpy #16 cpy #16
bne .1 bne .1
lda #0 lda #0
.2 sta (ZPQuickPtr1),y .2 sta (ZPTmpPtr1),y
iny iny
cpy #S.MD5.SIZE Includes S.MD5.FINALIZED Flag cpy #S.MD5.SIZE Includes S.MD5.FINALIZED Flag
bne .2 bne .2
@ -177,11 +180,11 @@ MD5Init >PUSHWI S.MD5.SIZE
*-------------------------------------- *--------------------------------------
MD5Update >PULLA get MD5 Context MD5Update >PULLA get MD5 Context
>SYSCALL SYS.GetMemPtrA >SYSCALL SYS.GetMemPtrA
>STYA ZPQuickPtr1 get MD5 Context >STYA ZPTmpPtr1 get MD5 Context
>PULLW R.AX get DATA >PULLW R.AX get DATA
>PULLW R.BX get LEN >PULLW R.BX get LEN
ldy #S.MD5.FINALIZED ldy #S.MD5.FINALIZED
lda (ZPQuickPtr1),y lda (ZPTmpPtr1),y
beq .1 beq .1
sec sec
rts rts
@ -214,7 +217,7 @@ MD5Update >PULLA get MD5 Context
bra .52 bra .52
.53 ldy #S.MD5.EXTRABIT Mark MD5 Context as Appended .53 ldy #S.MD5.EXTRABIT Mark MD5 Context as Appended
lda #$80 lda #$80
sta (ZPQuickPtr1),y sta (ZPTmpPtr1),y
lda R.CL lda R.CL
cmp #56 Enough room for BITCOUNT ? cmp #56 Enough room for BITCOUNT ?
bcs .58 no bcs .58 no
@ -242,42 +245,42 @@ MD5Update >PULLA get MD5 Context
* A = MessageDigest (PSTR, 16 Bytes, 32 Chars) * A = MessageDigest (PSTR, 16 Bytes, 32 Chars)
*-------------------------------------- *--------------------------------------
MD5FinalizeA >SYSCALL SYS.GetMemPtrA MD5FinalizeA >SYSCALL SYS.GetMemPtrA
>STYA ZPQuickPtr1 get MD5 Context >STYA ZPTmpPtr1 get MD5 Context
ldy #S.MD5.FINALIZED ldy #S.MD5.FINALIZED
lda (ZPQuickPtr1),y lda (ZPTmpPtr1),y
bne .11 bne .11
jsr MD5ExtraChunk jsr MD5ExtraChunk
.11 >PUSHWI 33 Len + 32 Digits .11 >PUSHWI 33 Len + 32 Digits
>PUSHBI 0 >PUSHBI 0
>SYSCALL SYS.GetMem >SYSCALL SYS.GetMem
bcs .9 bcs .9
>STYA ZPQuickPtr2 >STYA ZPTmpPtr2
phx save hMem for return phx save hMem for return
lda #32 lda #32
sta (ZPQuickPtr2) sta (ZPTmpPtr2)
inc ZPQuickPtr2 inc ZPTmpPtr2
bne .10 bne .10
inc ZPQuickPtr2+1 inc ZPTmpPtr2+1
.10 ldy #S.MD5.ABCD0 .10 ldy #S.MD5.ABCD0
.1 lda (ZPQuickPtr1),y .1 lda (ZPTmpPtr1),y
lsr lsr
lsr lsr
lsr lsr
lsr lsr
tax tax
lda MD5.DIGITS,x lda MD5.DIGITS,x
sta (ZPQuickPtr2) sta (ZPTmpPtr2)
inc ZPQuickPtr2 inc ZPTmpPtr2
bne .2 bne .2
inc ZPQuickPtr2+1 inc ZPTmpPtr2+1
.2 lda (ZPQuickPtr1),y .2 lda (ZPTmpPtr1),y
and #$0F and #$0F
tax tax
lda MD5.DIGITS,x lda MD5.DIGITS,x
sta (ZPQuickPtr2) sta (ZPTmpPtr2)
inc ZPQuickPtr2 inc ZPTmpPtr2
bne .3 bne .3
inc ZPQuickPtr2+1 inc ZPTmpPtr2+1
.3 iny .3 iny
cpy #S.MD5.ABCD0+16 cpy #S.MD5.ABCD0+16
bne .1 bne .1
@ -289,12 +292,12 @@ MD5FinalizeA >SYSCALL SYS.GetMemPtrA
*-------------------------------------- *--------------------------------------
* MD5AppendBitCount * MD5AppendBitCount
* In : * In :
* ZPQuickPtr1 = MD5 Context * ZPTmpPtr1 = MD5 Context
*-------------------------------------- *--------------------------------------
MD5AppendBitCount MD5AppendBitCount
ldx #56 ldx #56
ldy #S.MD5.BITCOUNT Append 8 Bytes of BITCOUNT ldy #S.MD5.BITCOUNT Append 8 Bytes of BITCOUNT
.1 lda (ZPQuickPtr1),y .1 lda (ZPTmpPtr1),y
sta MD5.BUFFER64,x sta MD5.BUFFER64,x
inx inx
iny iny
@ -302,13 +305,13 @@ MD5AppendBitCount
bne .1 bne .1
ldy #S.MD5.FINALIZED Mark MD5 Context as Finalized ldy #S.MD5.FINALIZED Mark MD5 Context as Finalized
lda #$80 lda #$80
sta (ZPQuickPtr1),y sta (ZPTmpPtr1),y
rts rts
*-------------------------------------- *--------------------------------------
* MD5UpdateBitCount * MD5UpdateBitCount
* In : * In :
* CL = Size (in bytes) to add to MD5 context * CL = Size (in bytes) to add to MD5 context
* ZPQuickPtr1 = MD5 Context * ZPTmpPtr1 = MD5 Context
*-------------------------------------- *--------------------------------------
MD5UpdateBitCount MD5UpdateBitCount
stz R.CH stz R.CH
@ -321,17 +324,17 @@ MD5UpdateBitCount
rol R.CH rol R.CH
clc clc
ldy #S.MD5.BITCOUNT ldy #S.MD5.BITCOUNT
adc (ZPQuickPtr1),y adc (ZPTmpPtr1),y
sta (ZPQuickPtr1),y sta (ZPTmpPtr1),y
iny iny
lda R.CH lda R.CH
adc (ZPQuickPtr1),y adc (ZPTmpPtr1),y
sta (ZPQuickPtr1),y sta (ZPTmpPtr1),y
bcc .8 bcc .8
.1 iny .1 iny
lda (ZPQuickPtr1),y lda (ZPTmpPtr1),y
inc inc
sta (ZPQuickPtr1),y sta (ZPTmpPtr1),y
bne .8 bne .8
cpy #7 cpy #7
bne .1 bne .1
@ -339,18 +342,18 @@ MD5UpdateBitCount
*-------------------------------------- *--------------------------------------
* MD5ExtraChunk * MD5ExtraChunk
* In : * In :
* ZPQuickPtr1 = MD5 Context * ZPTmpPtr1 = MD5 Context
*-------------------------------------- *--------------------------------------
MD5ExtraChunk ldy #S.MD5.FINALIZED MD5ExtraChunk ldy #S.MD5.FINALIZED
lda #$80 lda #$80
sta (ZPQuickPtr1),y Mark MD5 Context as "finalized" sta (ZPTmpPtr1),y Mark MD5 Context as "finalized"
ldx #0 ldx #0
ldy #S.MD5.EXTRABIT Extra Bit already appended ? ldy #S.MD5.EXTRABIT Extra Bit already appended ?
lda (ZPQuickPtr1),y lda (ZPTmpPtr1),y
bne .1 bne .1
lda #$80 lda #$80
sta MD5.BUFFER64 Add extra bit to buffer sta MD5.BUFFER64 Add extra bit to buffer
sta (ZPQuickPtr1),y Mark Extrabit added sta (ZPTmpPtr1),y Mark Extrabit added
inx inx
.1 stz MD5.BUFFER64,x pad with "0"... .1 stz MD5.BUFFER64,x pad with "0"...
inx inx
@ -361,13 +364,13 @@ MD5ExtraChunk ldy #S.MD5.FINALIZED
*-------------------------------------- *--------------------------------------
* MD5UpdateABCD0 * MD5UpdateABCD0
* In: * In:
* ZPQuickPtr1 = MD5 Context * ZPTmpPtr1 = MD5 Context
*-------------------------------------- *--------------------------------------
MD5UpdateABCD0 ldy #0 MD5UpdateABCD0 ldy #0
.1 clc ADC32 A+A0->A0, B, C, D.... .1 clc ADC32 A+A0->A0, B, C, D....
.2 lda MD5.ABCD,y .2 lda MD5.ABCD,y
adc (ZPQuickPtr1),y adc (ZPTmpPtr1),y
sta (ZPQuickPtr1),y sta (ZPTmpPtr1),y
iny iny
tya tya
and #3 and #3
@ -378,13 +381,13 @@ MD5UpdateABCD0 ldy #0
*-------------------------------------- *--------------------------------------
* MD5Transform * MD5Transform
* In: * In:
* ZPQuickPtr1 = MD5 Context * ZPTmpPtr1 = MD5 Context
* 512 Bits Padded chunk in MD5.BUFFER64 * 512 Bits Padded chunk in MD5.BUFFER64
* Out: * Out:
* Updated MD5.ABCD * Updated MD5.ABCD
*-------------------------------------- *--------------------------------------
MD5Transform ldy #15 init ABCD Chunk with Context ABCD0 MD5Transform ldy #15 init ABCD Chunk with Context ABCD0
.1 lda (ZPQuickPtr1),y .1 lda (ZPTmpPtr1),y
sta MD5.ABCD,y sta MD5.ABCD,y
dey dey
bpl .1 bpl .1