A2osX/BIN/HMACMD5.S.txt
2021-06-09 15:52:44 -07:00

222 lines
3.7 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/hmacmd5
*--------------------------------------
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/mli.e.i
.INB inc/libcrypt.i
*--------------------------------------
FILEBUF.SIZE .EQ 4096
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPPtr1 .BS 2
ZPDataBufPtr .BS 2
ZPDataLen .BS 2
ArgIndex .BS 1
Arg1 .BS 1
Arg2 .BS 1
bText .BS 1
bKey .BS 1
hFile .BS 1
hDataBuf .BS 1
hHMACMD5Ctx .BS 1
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #ZS.END-ZS.START ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBCRYPT .DA LIBCRYPT
L.MSG.USAGE .DA MSG.USAGE
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBCRYPT
>SYSCALL LoadLib
bcs .9
sta hLIBCRYPT
* clc
.9 rts
*--------------------------------------
CS.RUN ldy #S.PS.ARGC
lda (pPS),y
beq .99
.0 ldx #0
.1 inc ArgIndex
lda ArgIndex
phx
>SYSCALL ArgV
plx
bcs .8
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
ldy #1
lda (ZPPtr1),y
beq .99
ldy #OptionVars-OptionList-1
.2 cmp OptionList,y
beq .3
dey
bpl .2
.99 >PUSHW L.MSG.USAGE
>PUSHBI 0
>SYSCALL PrintF
lda #E.SYN
sec
rts
.3 ldx OptionVars,y
sec
ror 0,x
bra .1
.4 txa
bpl .99
lda ArgIndex
sta $fe,x
bra .0
.8 lda Arg1
beq .99
lda Arg2
beq .99
lda bText
beq CS.RUN.FILE
*--------------------------------------
CS.RUN.TEXT lda Arg1
>SYSCALL ArgV
>PUSHYA
lda Arg2
>SYSCALL ArgV
>PUSHYA
>PUSHEA.G HMACMD5Buf
>LIBCALL hLIBCRYPT,LIBCRYPT.HMACMD5
jmp CS.RUN.PRINT
*--------------------------------------
CS.RUN.FILE >LDYAI FILEBUF.SIZE
>SYSCALL GetMem
bcs .9
>STYA ZPDataBufPtr
stx hDataBuf
lda Arg1
>SYSCALL ArgV
>PUSHYA
>PUSHBI O.RDONLY
>PUSHBI 0 ftype
>PUSHWZ Aux type
>SYSCALL FOpen
bcs .9
sta hFile
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Init
bcs .9
sta hHMACMD5Ctx
.1 >SLEEP
>PUSHB hFile
>PUSHW ZPDataBufPtr Dst Ptr
>PUSHWI FILEBUF.SIZE Bytes To Read
>SYSCALL FRead
bcc .2
cmp #MLI.E.EOF
beq .8
.9 rts
.2 >STYA ZPDataLen
>SLEEP
>PUSHB hHMACMD5Ctx
>PUSHW ZPDataBufPtr
>PUSHW ZPDataLen
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Update
bra .1
.8 >PUSHB hHMACMD5Ctx
>PUSHEA.G HMACMD5Buf
>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Finalize
CS.RUN.PRINT >LEA.G HMACMD5Buf
>SYSCALL PutS
lda #0
* sec
* rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT lda hLIBCRYPT
beq .1
>SYSCALL UnloadLib
.1 lda hDataBuf
beq .2
>SYSCALL FreeMem
.2 lda hFile
beq .3
>SYSCALL FClose
.3 clc
rts
*--------------------------------------
CS.END
LIBCRYPT .AZ "libcrypt"
hLIBCRYPT .BS 1
*--------------------------------------
OptionList .AS "DdKk"
OptionVars .DA #bText,#bText, #bKey,#bKey
*--------------------------------------
MSG.USAGE .AZ "Usage : HMACMD5 [ -d input text | input file -k key ]\r\n"
*--------------------------------------
.DUMMY
.OR 0
DS.START
HMACMD5Buf .BS 33
DS.END .ED
*--------------------------------------
MAN
SAVE usr/src/bin/hmacmd5.s
ASM