BIN: add HMAC-MD5

This commit is contained in:
Peter Ferrie 2021-06-09 15:52:44 -07:00
parent 61d4cc9a42
commit 90ae0b3a54
2 changed files with 260 additions and 0 deletions

221
BIN/HMACMD5.S.txt Normal file
View File

@ -0,0 +1,221 @@
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

39
TESTS/HMACMD5TEST.txt Normal file
View File

@ -0,0 +1,39 @@
NEW
PREFIX
AUTO 4,1
#!/BIN/SH
#
# This script tests the HMAC-MD5 command to make
# sure it is properly generating and returning
# correct MD5 values.
#
# This test uses the SET var = `command` directive,
# testing that facility as well.
#
SET TestPhrase = "Hello World"
SET TestKey = "Super Secret Key"
SET CorrectValue = "41E1F2EE77BA4551318745CE12A4A6A4"
ECHO "\f\n HMAC-MD5 Test"
ECHO "\n\nThis script tests the HMAC-MD5 command to make"
ECHO "sure it is properly generating and returning"
ECHO "correct HMAC-MD5 values.\n\n"
SET Result = `HMACMD5 -D "$TestPhrase" -K "$TestKey"`
IF [ $Result = $CorrectValue ]
ECHO "This Test Passed"
IF [ -N $Log ]
SET T = $T + 1
SET P = $P + 1
ECHO "HMACMD5 Test Passed" >> ${Log}
FI
ELSE
ECHO "This Test Failed"
ECHO "The returned result was: $Result"
IF [ -N $Log ]
SET T = $T + 1
SET F = $F + 1
ECHO "HMACMD5 Test Failed" >> ${Log}
FI
FI
echo \n\n
MAN
TEXT root/HMACMD5TEST