2020-10-12 09:19:39 +00:00
|
|
|
|
NEW
|
|
|
|
|
AUTO 3,1
|
|
|
|
|
.LIST OFF
|
|
|
|
|
.OP 65C02
|
|
|
|
|
.OR $2000
|
|
|
|
|
.TF lib/libcrypt
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.INB inc/macros.i
|
|
|
|
|
.INB inc/a2osx.i
|
|
|
|
|
.INB inc/libcrypt.i
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.DUMMY
|
|
|
|
|
.OR ZPLIB
|
|
|
|
|
ZS.START
|
|
|
|
|
ZPCtxPtr .BS 2
|
|
|
|
|
ZPDataPtr .BS 2
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ZPKeyPtr .BS 2
|
2020-10-12 09:19:39 +00:00
|
|
|
|
ZPHashPtr .BS 2
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDx.ABCD
|
|
|
|
|
MDx.A .BS 4 Chunk Level,A,B,C,D
|
|
|
|
|
MDx.B .BS 4
|
|
|
|
|
MDx.C .BS 4
|
|
|
|
|
MDx.D .BS 4
|
|
|
|
|
|
|
|
|
|
MDx.F1 .BS 4
|
|
|
|
|
MDx.F2 .BS 4
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
|
|
|
|
ZS.END .ED
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
* TEMP storage allowed here because of:
|
|
|
|
|
* - No Task switching when in a LIB
|
|
|
|
|
* - No I/O (printf....)
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.DUMMY
|
|
|
|
|
.OR $1100
|
|
|
|
|
ZPDataLen .BS 2
|
|
|
|
|
ZPChunkLen .BS 2
|
|
|
|
|
|
|
|
|
|
MDx.MODE .BS 1
|
|
|
|
|
|
|
|
|
|
MDx.DTemp .BS 4
|
|
|
|
|
MDx.F .BS 4
|
|
|
|
|
MDx.i .BS 1
|
|
|
|
|
MDx.BUFFER64 .BS 64
|
|
|
|
|
|
|
|
|
|
HMACMD5.IPAD .BS 65
|
|
|
|
|
HMACMD5.OPAD .BS 65
|
|
|
|
|
.ED
|
|
|
|
|
*--------------------------------------
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* DWORD Macros : Do NOT disturb carry with cpx, cpy...
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.MA ADC32
|
2021-06-06 01:35:30 +00:00
|
|
|
|
ldy #3
|
|
|
|
|
ldx #0
|
2020-10-12 09:19:39 +00:00
|
|
|
|
clc
|
2021-06-06 01:35:30 +00:00
|
|
|
|
:1 lda ]1,x
|
|
|
|
|
adc ]2,x
|
|
|
|
|
sta ]3,x
|
|
|
|
|
inx
|
|
|
|
|
dey
|
2020-10-12 09:19:39 +00:00
|
|
|
|
bpl :1
|
|
|
|
|
.EM
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.MA AND32
|
|
|
|
|
ldx #3
|
|
|
|
|
:1 lda ]1,x
|
|
|
|
|
and ]2,x
|
|
|
|
|
sta ]3,x
|
|
|
|
|
dex
|
|
|
|
|
bpl :1
|
|
|
|
|
.EM
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.MA ORA32
|
|
|
|
|
ldx #3
|
|
|
|
|
:1 lda ]1,x
|
|
|
|
|
ora ]2,x
|
|
|
|
|
sta ]3,x
|
|
|
|
|
dex
|
|
|
|
|
bpl :1
|
|
|
|
|
.EM
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.MA EOR32
|
|
|
|
|
ldx #3
|
|
|
|
|
:1 lda ]1,x
|
|
|
|
|
eor ]2,x
|
|
|
|
|
sta ]3,x
|
|
|
|
|
dex
|
|
|
|
|
bpl :1
|
|
|
|
|
.EM
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.MA NOT32
|
|
|
|
|
ldx #3
|
|
|
|
|
:1 lda ]1,x
|
|
|
|
|
eor #$FF
|
|
|
|
|
sta ]2,x
|
|
|
|
|
dex
|
|
|
|
|
bpl :1
|
|
|
|
|
.EM
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.MA MOV32
|
|
|
|
|
ldx #3
|
|
|
|
|
:1 lda ]1,x
|
|
|
|
|
sta ]2,x
|
|
|
|
|
dex
|
|
|
|
|
bpl :1
|
|
|
|
|
.EM
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.MA ROL32x
|
|
|
|
|
:2 lda ]1+3
|
|
|
|
|
rol
|
|
|
|
|
rol ]1
|
|
|
|
|
rol ]1+1
|
|
|
|
|
rol ]1+2
|
|
|
|
|
rol ]1+3
|
|
|
|
|
dex
|
|
|
|
|
bne :2
|
|
|
|
|
.EM
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* 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
|
|
|
|
|
.DA 0
|
|
|
|
|
.DA 0
|
|
|
|
|
.DA 0
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Relocation Table
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.1 .DA LIB.LOAD
|
|
|
|
|
.DA LIB.UNLOAD
|
2021-03-26 17:30:56 +00:00
|
|
|
|
.DA MD4
|
|
|
|
|
.DA MD4Init
|
|
|
|
|
.DA MD4Update
|
|
|
|
|
.DA MD4Finalize
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.DA MD5
|
|
|
|
|
.DA MD5Init
|
|
|
|
|
.DA MD5Update
|
|
|
|
|
.DA MD5Finalize
|
2021-06-06 19:06:49 +00:00
|
|
|
|
.DA HMACMD5
|
|
|
|
|
*--------------------------------------
|
2021-03-26 17:30:56 +00:00
|
|
|
|
J.MD4.XXXX .DA MD4.0015
|
|
|
|
|
.DA MD4.1631
|
|
|
|
|
.DA MD4.3247
|
2021-06-06 01:35:30 +00:00
|
|
|
|
J.MD5.XXXX .DA MD5.0015
|
|
|
|
|
.DA MD5.1631
|
|
|
|
|
.DA MD5.3247
|
|
|
|
|
.DA MD5.4863
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.DA 0
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
LIB.LOAD
|
|
|
|
|
LIB.UNLOAD clc
|
|
|
|
|
rts
|
|
|
|
|
*/--------------------------------------
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* ## MD4
|
|
|
|
|
* Return MD4 Hash for input String
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # C
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* `void MD4 (const char* str, char* digest);`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # ASM
|
|
|
|
|
* `>PUSHW str`
|
2021-06-06 19:06:49 +00:00
|
|
|
|
* `>PUSHW digest`
|
2021-06-06 01:35:30 +00:00
|
|
|
|
* `>LIBCALL hLIBCRYPT,LIBCRYPT.MD4`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
* CC
|
|
|
|
|
*\--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4 clc
|
|
|
|
|
.HS B0 BCS
|
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* ## MD5
|
|
|
|
|
* Return MD5 Hash for input String
|
|
|
|
|
* # C
|
|
|
|
|
* `void MD5 (const char* str, char* digest);`
|
|
|
|
|
* # ASM
|
|
|
|
|
* `>PUSHW str`
|
|
|
|
|
* `>PUSHW digest`
|
|
|
|
|
* `>LIBCALL hLIBCRYPT,LIBCRYPT.MD5`
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
* CC
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
MD5 sec
|
|
|
|
|
|
|
|
|
|
ror MDx.MODE
|
|
|
|
|
|
|
|
|
|
>PULLW ZPHashPtr
|
2021-06-06 19:06:49 +00:00
|
|
|
|
>PULLYA
|
|
|
|
|
>STYA ZPDataPtr
|
2020-10-12 09:19:39 +00:00
|
|
|
|
>SYSCALL2 strlen
|
|
|
|
|
>STYA ZPDataLen
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.1 jsr MD5Init
|
2020-10-12 09:19:39 +00:00
|
|
|
|
bcs .9
|
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
pha save MD4 Context hMem
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
jsr MDxUpdate.I
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxFinalize.I
|
2021-06-06 01:35:30 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
pla
|
2021-07-27 16:21:58 +00:00
|
|
|
|
>SYSCALL2 FreeMem Free MD4 Context
|
2020-10-12 09:19:39 +00:00
|
|
|
|
clc
|
|
|
|
|
.9 rts
|
|
|
|
|
*/--------------------------------------
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* ## MD4Init
|
|
|
|
|
* Initialize a MD4 computation
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # C
|
2021-06-06 19:06:49 +00:00
|
|
|
|
* `hMD4 MD4init();`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # ASM
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* `>LIBCALL hLIBCRYPT,LIBCRYPT.MD4Init`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* ## RETURN VALUE
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* A = hMem To S.MD4
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*\--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4Init
|
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* ## MD5Init
|
|
|
|
|
* Initialize a MD5 computation
|
|
|
|
|
* # C
|
|
|
|
|
* `hMD5 MD5init();`
|
|
|
|
|
* # ASM
|
|
|
|
|
* `>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Init`
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
* A = hMem To S.MD5
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
MD5Init >LDYAI S.MDx
|
2020-10-12 09:19:39 +00:00
|
|
|
|
>SYSCALL2 getmem
|
2021-07-27 16:21:58 +00:00
|
|
|
|
bcs MDxInit.9
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
>STYA ZPCtxPtr
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDxReset.I ldy #0
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.1 lda MDx.ABCDINIT,y
|
2020-10-12 09:19:39 +00:00
|
|
|
|
sta (ZPCtxPtr),y
|
|
|
|
|
iny
|
2021-07-29 16:41:57 +00:00
|
|
|
|
cpy #S.MDx.BITCOUNT
|
2020-10-12 09:19:39 +00:00
|
|
|
|
bne .1
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda #0
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.2 sta (ZPCtxPtr),y
|
|
|
|
|
iny
|
2021-07-29 16:41:57 +00:00
|
|
|
|
cpy #S.MDx Includes S.MDx.FINALIZED Flag
|
2020-10-12 09:19:39 +00:00
|
|
|
|
bne .2
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
txa
|
|
|
|
|
clc
|
2021-07-27 16:21:58 +00:00
|
|
|
|
MDxInit.9 rts
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*/--------------------------------------
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* ## MD4Update
|
|
|
|
|
* Add Data to MD4 computation
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # C
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* `void MD4update (hMD4 MD4, char* data, int len);`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # ASM
|
2021-06-06 19:06:49 +00:00
|
|
|
|
* `>PUSHB MD4`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* `>PUSHW data`
|
2021-06-06 19:06:49 +00:00
|
|
|
|
* `>PUSHW len`
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* `>hLIBCRYPT,LIBCRYPT.MD4Update`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
*\--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4Update clc
|
|
|
|
|
.HS B0 BCS
|
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* ## MD5Update
|
|
|
|
|
* Add Data to MD5 computation
|
|
|
|
|
* # C
|
|
|
|
|
* `void MD5update (hMD5 MD5, char* data, int len);`
|
|
|
|
|
* # ASM
|
|
|
|
|
* `>PUSHB MD5`
|
|
|
|
|
* `>PUSHW data`
|
|
|
|
|
* `>PUSHW len`
|
|
|
|
|
* `>hLIBCRYPT,LIBCRYPT.MD5Update`
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
MD5Update sec
|
|
|
|
|
|
|
|
|
|
ror MDx.MODE
|
|
|
|
|
|
|
|
|
|
>PULLW ZPDataLen get LEN
|
2021-06-06 19:06:49 +00:00
|
|
|
|
>PULLW ZPDataPtr get DATA
|
|
|
|
|
|
|
|
|
|
>PULLA
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>SYSCALL2 GetMemPtr get MD5 Context
|
2020-10-12 09:19:39 +00:00
|
|
|
|
>STYA ZPCtxPtr
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDxUpdate.I ldy #S.MDx.FINALIZED
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda (ZPCtxPtr),y
|
|
|
|
|
beq .1
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
sec
|
|
|
|
|
rts
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.1 lda ZPDataLen+1 More than 256 Bytes remaining to hash ?
|
|
|
|
|
bne .3 yes
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda ZPDataLen
|
|
|
|
|
bne .2 Len = O ?
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
clc All data processed
|
|
|
|
|
rts
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.2 cmp #64 More than 64 Bytes remaining to hash ?
|
|
|
|
|
bcc .50 yes
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.3 lda #64
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.50 sta ZPChunkLen Save Chunk Len
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxUpdateBitCnt
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
ldy #0
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.51 lda (ZPDataPtr),y Load Buffer with data
|
2021-07-29 16:41:57 +00:00
|
|
|
|
sta MDx.BUFFER64,y
|
2020-10-12 09:19:39 +00:00
|
|
|
|
iny
|
|
|
|
|
cpy ZPChunkLen
|
|
|
|
|
bne .51
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
cpy #64 Full 64 Bytes DATA ?
|
|
|
|
|
beq .58
|
|
|
|
|
* Append "$80" & Padding & original size
|
|
|
|
|
|
|
|
|
|
lda #$80 no, Append $80
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.52 sta MDx.BUFFER64,y
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-06-06 01:35:30 +00:00
|
|
|
|
asl
|
|
|
|
|
* lda #0
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-06-06 01:35:30 +00:00
|
|
|
|
iny Pad with 0 to 64
|
2020-10-12 09:19:39 +00:00
|
|
|
|
cpy #64
|
2021-06-06 01:35:30 +00:00
|
|
|
|
bcc .52
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy #S.MDx.EXTRABIT Mark MD5 Context as Appended
|
2021-06-06 01:35:30 +00:00
|
|
|
|
ror
|
|
|
|
|
* lda #$80
|
2020-10-12 09:19:39 +00:00
|
|
|
|
sta (ZPCtxPtr),y
|
|
|
|
|
lda ZPChunkLen
|
|
|
|
|
cmp #56 Enough room for BITCOUNT ?
|
|
|
|
|
bcs .58 no
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxAppendBitCnt
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
.58 jsr MDxTransform
|
2021-06-06 01:35:30 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxUpdateABCD0
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.8 lda ZPDataLen Substract Bytes processed from LEN
|
|
|
|
|
sec
|
|
|
|
|
sbc ZPChunkLen get back chunk Len
|
|
|
|
|
sta ZPDataLen
|
|
|
|
|
bcs .81
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
dec ZPDataLen+1
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.81 lda ZPDataPtr Add Bytes processed to DATA
|
|
|
|
|
clc
|
|
|
|
|
adc ZPChunkLen
|
|
|
|
|
sta ZPDataPtr
|
|
|
|
|
bcc .1
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
inc ZPDataPtr+1
|
|
|
|
|
bra .1
|
|
|
|
|
*/--------------------------------------
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* ## MD4Finalize
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # C
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* `void MD4finalize (hMD4 MD4, char* digest);`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* # ASM
|
2021-06-06 19:06:49 +00:00
|
|
|
|
* `>PUSHB MD4`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* `>PUSHW digest`
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* `>LIBCALL hLIBCRYPT,LIBCRYPT.MD4Finalize`
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
*\--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4Finalize clc
|
|
|
|
|
.HS B0 BCS
|
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* ## MD5Finalize
|
|
|
|
|
* # C
|
|
|
|
|
* `void MD5finalize (hMD5 MD5, char* digest);`
|
|
|
|
|
* # ASM
|
|
|
|
|
* `>PUSHB MD5`
|
|
|
|
|
* `>PUSHW digest`
|
|
|
|
|
* `>LIBCALL hLIBCRYPT,LIBCRYPT.MD5Finalize`
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
MD5Finalize sec
|
|
|
|
|
|
|
|
|
|
ror MDx.MODE
|
|
|
|
|
|
|
|
|
|
>PULLW ZPHashPtr
|
2021-06-06 19:06:49 +00:00
|
|
|
|
>PULLA
|
|
|
|
|
pha
|
2020-10-12 09:19:39 +00:00
|
|
|
|
>SYSCALL2 GetMemPtr
|
2021-06-06 01:35:30 +00:00
|
|
|
|
>STYA ZPCtxPtr get MD5 Context
|
2021-06-06 19:06:49 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxFinalize.I
|
2021-06-06 19:06:49 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
pla
|
|
|
|
|
>SYSCALL2 FreeMem
|
|
|
|
|
rts
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDxFinalize.I ldy #S.MDx.FINALIZED
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
|
|
|
|
lda (ZPCtxPtr),y
|
|
|
|
|
bne .11
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxExtraChunk
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
.11 ldy #0
|
2021-07-29 16:41:57 +00:00
|
|
|
|
sty MDx.i
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
|
|
|
|
.1 lda (ZPCtxPtr),y
|
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
tax
|
2021-07-29 16:41:57 +00:00
|
|
|
|
lda MDx.DIGITS,x
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr .7
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
lda (ZPCtxPtr),y
|
2020-10-12 09:19:39 +00:00
|
|
|
|
and #$0F
|
|
|
|
|
tax
|
2021-07-29 16:41:57 +00:00
|
|
|
|
lda MDx.DIGITS,x
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr .7
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
iny
|
|
|
|
|
cpy #16
|
2020-10-12 09:19:39 +00:00
|
|
|
|
bne .1
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda #0
|
|
|
|
|
clc
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.7 phy
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy MDx.i
|
|
|
|
|
inc MDx.i
|
|
|
|
|
sta (ZPHashPtr),y
|
|
|
|
|
|
|
|
|
|
ply
|
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
MDxFinalize.RTS rts
|
2021-06-06 19:06:49 +00:00
|
|
|
|
*/--------------------------------------
|
|
|
|
|
* ## HMACMD5
|
|
|
|
|
* Return HMACMD5 Hash for input String
|
|
|
|
|
* # C
|
|
|
|
|
* `void HMACMD5(const char* str, const char* key, char* digest);`
|
|
|
|
|
* # ASM
|
|
|
|
|
* `>PUSHW str`
|
|
|
|
|
* `>PUSHW key`
|
|
|
|
|
* `>PUSHW digest`
|
|
|
|
|
* `>LIBCALL hLIBCRYPT,LIBCRYPT.HMACMD5`
|
|
|
|
|
* ## RETURN VALUE
|
|
|
|
|
* CC
|
|
|
|
|
*\--------------------------------------
|
|
|
|
|
* https://github.com/fab13n/org.eclipse.mihini/blob/master/libs/hmac-md5/hmac_rfc2104/hmac-md5.c
|
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
HMACMD5 >PULLW ZPHashPtr
|
2021-06-08 01:46:33 +00:00
|
|
|
|
>PULLW ZPDataPtr
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>PULLW ZPKeyPtr
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
jsr MD5Init
|
2021-07-27 16:21:58 +00:00
|
|
|
|
bcs MDxFinalize.RTS
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
sec
|
|
|
|
|
|
|
|
|
|
ror MDx.MODE Switch to MD5
|
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
pha
|
|
|
|
|
|
|
|
|
|
>LDYA ZPDataPtr
|
2021-06-08 01:46:33 +00:00
|
|
|
|
>SYSCALL2 strlen
|
|
|
|
|
>STYA ZPDataLen
|
|
|
|
|
cpy #65
|
2021-06-30 18:33:18 +00:00
|
|
|
|
bcs .2
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
tay
|
|
|
|
|
beq .4
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.2 jsr MDxUpdate.I
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxFinalize.I
|
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
>LDYA ZPCtxPtr
|
|
|
|
|
>STYA ZPDataPtr
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
lda #16
|
|
|
|
|
sta ZPDataLen
|
|
|
|
|
|
|
|
|
|
.4 ldy #0
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
.5 lda #$36
|
|
|
|
|
cpy ZPDataLen
|
|
|
|
|
bcs .6
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
eor (ZPDataPtr),y
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
.6 sta HMACMD5.IPAD,y
|
2021-07-27 16:21:58 +00:00
|
|
|
|
eor #$6A #$36 eor #$5C
|
2021-06-08 01:46:33 +00:00
|
|
|
|
sta HMACMD5.OPAD,y
|
|
|
|
|
iny
|
|
|
|
|
cpy #64
|
|
|
|
|
bne .5
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
stz HMACMD5.IPAD+64
|
|
|
|
|
stz HMACMD5.OPAD+64
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
jsr MDxReset.I
|
2021-06-08 01:46:33 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>LDYAI HMACMD5.IPAD
|
2021-06-08 01:46:33 +00:00
|
|
|
|
>STYA ZPDataPtr
|
|
|
|
|
>LDYAI 64
|
|
|
|
|
>STYA ZPDataLen
|
2021-07-29 16:41:57 +00:00
|
|
|
|
|
|
|
|
|
jsr MDxUpdate.I
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>LDYA ZPKeyPtr
|
2021-06-08 01:46:33 +00:00
|
|
|
|
>STYA ZPDataPtr
|
|
|
|
|
>SYSCALL2 strlen
|
|
|
|
|
>STYA ZPDataLen
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
jsr MDxUpdate.I
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxFinalize.I
|
|
|
|
|
|
|
|
|
|
ldy #0
|
2021-06-08 01:46:33 +00:00
|
|
|
|
|
|
|
|
|
.8 lda (ZPCtxPtr),y
|
|
|
|
|
sta HMACMD5.IPAD,y
|
|
|
|
|
iny
|
2021-07-27 16:21:58 +00:00
|
|
|
|
cpy #16
|
2021-06-08 01:46:33 +00:00
|
|
|
|
bne .8
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
jsr MDxReset.I
|
2021-06-08 01:46:33 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>LDYAI HMACMD5.OPAD
|
2021-06-08 01:46:33 +00:00
|
|
|
|
>STYA ZPDataPtr
|
|
|
|
|
>LDYAI 64
|
|
|
|
|
>STYA ZPDataLen
|
2021-07-29 16:41:57 +00:00
|
|
|
|
jsr MDxUpdate.I
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>LDYAI HMACMD5.IPAD
|
2021-06-08 01:46:33 +00:00
|
|
|
|
>STYA ZPDataPtr
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2021-06-08 01:46:33 +00:00
|
|
|
|
ldy #16
|
|
|
|
|
sty ZPDataLen
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
jsr MDxUpdate.I
|
|
|
|
|
jsr MDxFinalize.I MDx.MODE setup by MD5Update
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
|
|
|
|
pla
|
|
|
|
|
>SYSCALL2 FreeMem
|
2021-06-08 01:46:33 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
rts
|
2021-06-06 19:06:49 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* https://waterjuiceweb.wordpress.com/aes/
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* PRIVATE
|
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
* MDxAppendBitCount
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* In :
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* ZPCtxPtr = MD4 Context
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
MDxAppendBitCnt ldx #56
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy #S.MDx.BITCOUNT Append 8 Bytes of BITCOUNT
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
|
|
|
|
.1 lda (ZPCtxPtr),y
|
2021-07-29 16:41:57 +00:00
|
|
|
|
sta MDx.BUFFER64,x
|
2020-10-12 09:19:39 +00:00
|
|
|
|
inx
|
|
|
|
|
iny
|
2021-07-29 16:41:57 +00:00
|
|
|
|
cpy #S.MDx.BITCOUNT+8
|
2020-10-12 09:19:39 +00:00
|
|
|
|
bne .1
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy #S.MDx.FINALIZED Mark MD5 Context as Finalized
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda #$80
|
|
|
|
|
sta (ZPCtxPtr),y
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
* MDxUpdateBitCnt
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* In :
|
2021-07-27 16:21:58 +00:00
|
|
|
|
* CL = Size (in bytes) to add to MDx context
|
|
|
|
|
* ZPCtxPtr = MDx Context
|
2021-06-06 01:35:30 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
MDxUpdateBitCnt stz ZPChunkLen+1
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda ZPChunkLen
|
|
|
|
|
asl
|
|
|
|
|
rol ZPChunkLen+1
|
2021-07-29 16:41:57 +00:00
|
|
|
|
asl times 8 to get BITCOUNT
|
2020-10-12 09:19:39 +00:00
|
|
|
|
rol ZPChunkLen+1
|
|
|
|
|
asl
|
|
|
|
|
rol ZPChunkLen+1
|
|
|
|
|
clc
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy #S.MDx.BITCOUNT
|
2020-10-12 09:19:39 +00:00
|
|
|
|
adc (ZPCtxPtr),y
|
|
|
|
|
sta (ZPCtxPtr),y
|
|
|
|
|
iny
|
|
|
|
|
lda ZPChunkLen+1
|
|
|
|
|
adc (ZPCtxPtr),y
|
|
|
|
|
sta (ZPCtxPtr),y
|
|
|
|
|
bcc .8
|
|
|
|
|
|
|
|
|
|
.1 iny
|
|
|
|
|
lda (ZPCtxPtr),y
|
|
|
|
|
inc
|
|
|
|
|
sta (ZPCtxPtr),y
|
|
|
|
|
bne .8
|
|
|
|
|
|
|
|
|
|
cpy #7
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
.8 rts
|
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
* MDxExtraChunk
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* In :
|
2021-07-27 16:21:58 +00:00
|
|
|
|
* ZPCtxPtr = MDx Context
|
2021-06-06 01:35:30 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDxExtraChunk ldy #S.MDx.FINALIZED
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda #$80
|
2021-06-06 01:35:30 +00:00
|
|
|
|
sta (ZPCtxPtr),y Mark MD5 Context as "finalized"
|
2020-10-12 09:19:39 +00:00
|
|
|
|
ldx #0
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy #S.MDx.EXTRABIT Extra Bit already appended ?
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lda (ZPCtxPtr),y
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
lda #$80
|
2021-07-29 16:41:57 +00:00
|
|
|
|
sta MDx.BUFFER64 Add extra bit to buffer
|
2020-10-12 09:19:39 +00:00
|
|
|
|
sta (ZPCtxPtr),y Mark Extrabit added
|
|
|
|
|
inx
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.1 stz MDx.BUFFER64,x pad with "0"...
|
2020-10-12 09:19:39 +00:00
|
|
|
|
inx
|
|
|
|
|
cpx #56
|
2021-07-29 16:41:57 +00:00
|
|
|
|
bne .1 ...until room for BITCOUNT
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
2021-07-27 16:21:58 +00:00
|
|
|
|
jsr MDxAppendBitCnt
|
|
|
|
|
jsr MDxTransform
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
* MDxUpdateABCD0
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* In:
|
2021-07-27 16:21:58 +00:00
|
|
|
|
* ZPCtxPtr = MDx Context
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-27 16:21:58 +00:00
|
|
|
|
MDxUpdateABCD0 ldy #0
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
|
|
|
|
.1 clc ADC32 A+A0->A0, B, C, D....
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.2 lda MDx.ABCD,y
|
2020-10-12 09:19:39 +00:00
|
|
|
|
adc (ZPCtxPtr),y
|
|
|
|
|
sta (ZPCtxPtr),y
|
|
|
|
|
iny
|
|
|
|
|
tya
|
|
|
|
|
and #3
|
|
|
|
|
bne .2
|
|
|
|
|
|
|
|
|
|
cpy #16
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDxTransform ldy #15 init ABCD Chunk with Context ABCD0
|
|
|
|
|
|
|
|
|
|
.1 lda (ZPCtxPtr),y
|
|
|
|
|
sta MDx.ABCD,y
|
|
|
|
|
dey
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
lda #0 make sure A = MDx.i = 0 before transform
|
|
|
|
|
sta MDx.i
|
|
|
|
|
|
|
|
|
|
bit MDx.MODE
|
2021-07-27 16:21:58 +00:00
|
|
|
|
bpl MD4Transform
|
|
|
|
|
|
|
|
|
|
jmp MD5Transform
|
|
|
|
|
*--------------------------------------
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* MD4Transform
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* In:
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* ZPCtxPtr = MD4 Context
|
2021-07-29 16:41:57 +00:00
|
|
|
|
* 512 Bits Padded chunk in MDx.BUFFER64
|
2020-10-12 09:19:39 +00:00
|
|
|
|
* Out:
|
2021-07-29 16:41:57 +00:00
|
|
|
|
* Updated MDx.ABCD
|
2021-03-26 17:30:56 +00:00
|
|
|
|
* https://tools.ietf.org/html/rfc1320 MD4
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4Transform lsr
|
2020-10-12 09:19:39 +00:00
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
and #6
|
2021-06-06 01:35:30 +00:00
|
|
|
|
cmp #6
|
2021-07-29 16:41:57 +00:00
|
|
|
|
bne .1
|
|
|
|
|
|
2021-06-06 01:35:30 +00:00
|
|
|
|
lda #0
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.1 tax
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
2021-03-26 17:30:56 +00:00
|
|
|
|
jsr MD4.XXXX
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
inc MDx.i
|
|
|
|
|
lda MDx.i
|
2021-06-06 01:35:30 +00:00
|
|
|
|
cmp #48
|
2021-07-29 16:41:57 +00:00
|
|
|
|
bne MD4Transform
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-03-26 17:30:56 +00:00
|
|
|
|
MD4.XXXX jmp (J.MD4.XXXX,x)
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4.0015 >NOT32 MDx.B,MDx.F2
|
|
|
|
|
>AND32 MDx.B,MDx.C,MDx.F1
|
|
|
|
|
>AND32 MDx.F2,MDx.D,MDx.F2
|
|
|
|
|
>ORA32 MDx.F1,MDx.F2,MDx.F
|
2021-03-26 17:30:56 +00:00
|
|
|
|
bra MD4.XXXX.END
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4.1631 >AND32 MDx.B,MDx.C,MDx.F1
|
|
|
|
|
>AND32 MDx.B,MDx.D,MDx.F2
|
|
|
|
|
>ORA32 MDx.F1,MDx.F2,MDx.F1
|
|
|
|
|
>AND32 MDx.C,MDx.D,MDx.F2
|
|
|
|
|
>ORA32 MDx.F1,MDx.F2,MDx.F
|
2021-03-26 17:30:56 +00:00
|
|
|
|
bra MD4.XXXX.END
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4.3247 >EOR32 MDx.B,MDx.C,MDx.F
|
|
|
|
|
>EOR32 MDx.F,MDx.D,MDx.F
|
2021-03-26 17:30:56 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD4.XXXX.END >MOV32 MDx.D,MDx.DTemp
|
|
|
|
|
>MOV32 MDx.C,MDx.D
|
|
|
|
|
>MOV32 MDx.B,MDx.C
|
|
|
|
|
>ADC32 MDx.A,MDx.F,MDx.B
|
|
|
|
|
lda MDx.i
|
2021-06-06 01:35:30 +00:00
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
and #$0C
|
|
|
|
|
beq .3
|
2021-07-27 16:21:58 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
tay
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
ldx #0
|
|
|
|
|
clc
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.1 lda MD4.K-4,y ADC32 MDx.K[i],MDx.F,MDx.F
|
|
|
|
|
adc MDx.B,x
|
|
|
|
|
sta MDx.B,x
|
2020-10-12 09:19:39 +00:00
|
|
|
|
iny
|
|
|
|
|
inx
|
|
|
|
|
txa
|
|
|
|
|
eor #4 DO NOT DISTURB carry with cpx !!!
|
|
|
|
|
bne .1
|
|
|
|
|
|
2021-06-06 01:35:30 +00:00
|
|
|
|
.3 tax
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy MDx.i
|
2021-03-26 17:30:56 +00:00
|
|
|
|
lda MD4.g,y
|
2020-10-12 09:19:39 +00:00
|
|
|
|
asl
|
|
|
|
|
asl
|
|
|
|
|
tay
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2020-10-12 09:19:39 +00:00
|
|
|
|
clc
|
2021-03-26 17:30:56 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.2 lda MDx.BUFFER64,y ADC32 M[g],MDx.F,MDx.F
|
|
|
|
|
adc MDx.B,x
|
|
|
|
|
sta MDx.B,x
|
2020-10-12 09:19:39 +00:00
|
|
|
|
iny
|
|
|
|
|
inx
|
|
|
|
|
txa
|
|
|
|
|
eor #4 DO NOT DISTURB carry with cpx !!!
|
|
|
|
|
bne .2
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy MDx.i
|
2021-03-26 17:30:56 +00:00
|
|
|
|
ldx MD4.s,y get s[i] in x
|
2020-10-12 09:19:39 +00:00
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>ROL32x MDx.B
|
|
|
|
|
>MOV32 MDx.DTemp,MDx.A
|
2020-10-12 09:19:39 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-06-06 01:35:30 +00:00
|
|
|
|
* MD5Transform
|
|
|
|
|
* In:
|
|
|
|
|
* ZPCtxPtr = MD5 Context
|
2021-07-29 16:41:57 +00:00
|
|
|
|
* 512 Bits Padded chunk in MDx.BUFFER64
|
2021-06-06 01:35:30 +00:00
|
|
|
|
* Out:
|
2021-07-29 16:41:57 +00:00
|
|
|
|
* Updated MDx.ABCD
|
2021-06-06 01:35:30 +00:00
|
|
|
|
* https://tools.ietf.org/html/rfc1321 MD5
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD5Transform lsr
|
2021-06-06 01:35:30 +00:00
|
|
|
|
lsr
|
|
|
|
|
lsr
|
|
|
|
|
and #6
|
|
|
|
|
tax
|
|
|
|
|
|
|
|
|
|
jsr MD5.XXXX
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
inc MDx.i
|
|
|
|
|
lda MDx.i
|
2021-06-06 01:35:30 +00:00
|
|
|
|
cmp #64
|
2021-07-29 16:41:57 +00:00
|
|
|
|
bne MD5Transform
|
2021-06-06 01:35:30 +00:00
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MD5.XXXX jmp (J.MD5.XXXX,x)
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD5.0015 >NOT32 MDx.B,MDx.F2
|
|
|
|
|
>AND32 MDx.B,MDx.C,MDx.F1
|
|
|
|
|
>AND32 MDx.F2,MDx.D,MDx.F2
|
|
|
|
|
>ORA32 MDx.F1,MDx.F2,MDx.F
|
2021-06-06 01:35:30 +00:00
|
|
|
|
bra MD5.XXXX.END
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD5.1631 >NOT32 MDx.D,MDx.F2
|
|
|
|
|
>AND32 MDx.D,MDx.B,MDx.F1
|
|
|
|
|
>AND32 MDx.F2,MDx.C,MDx.F2
|
|
|
|
|
>ORA32 MDx.F1,MDx.F2,MDx.F
|
2021-06-06 01:35:30 +00:00
|
|
|
|
bra MD5.XXXX.END
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD5.3247 >EOR32 MDx.B,MDx.C,MDx.F
|
|
|
|
|
>EOR32 MDx.F,MDx.D,MDx.F
|
2021-06-06 01:35:30 +00:00
|
|
|
|
bra MD5.XXXX.END
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD5.4863 >NOT32 MDx.D,MDx.F1
|
|
|
|
|
>ORA32 MDx.F1,MDx.B,MDx.F2
|
|
|
|
|
>EOR32 MDx.F2,MDx.C,MDx.F
|
2021-06-06 01:35:30 +00:00
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MD5.XXXX.END >MOV32 MDx.D,MDx.DTemp
|
|
|
|
|
>MOV32 MDx.C,MDx.D
|
|
|
|
|
>MOV32 MDx.B,MDx.C
|
|
|
|
|
>ADC32 MDx.A,MDx.F,MDx.F
|
|
|
|
|
lda MDx.i
|
2021-06-06 01:35:30 +00:00
|
|
|
|
asl
|
|
|
|
|
asl
|
|
|
|
|
tay
|
|
|
|
|
|
|
|
|
|
ldx #0
|
|
|
|
|
clc
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.1 lda MD5.K,y ADC32 MD5.K[i],MDx.F,MDx.F
|
|
|
|
|
adc MDx.F,x
|
|
|
|
|
sta MDx.F,x
|
2021-06-06 01:35:30 +00:00
|
|
|
|
iny
|
|
|
|
|
inx
|
|
|
|
|
txa
|
|
|
|
|
eor #4 DO NOT DISTURB carry with cpx !!!
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
tax
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy MDx.i
|
2021-06-06 01:35:30 +00:00
|
|
|
|
lda MD5.g,y
|
|
|
|
|
asl
|
|
|
|
|
asl
|
|
|
|
|
tay
|
|
|
|
|
|
|
|
|
|
clc
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
.2 lda MDx.BUFFER64,y ADC32 M[g],MDx.F,MDx.F
|
|
|
|
|
adc MDx.F,x
|
|
|
|
|
sta MDx.F,x
|
2021-06-06 01:35:30 +00:00
|
|
|
|
iny
|
|
|
|
|
inx
|
|
|
|
|
txa
|
|
|
|
|
eor #4 DO NOT DISTURB carry with cpx !!!
|
|
|
|
|
bne .2
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
ldy MDx.i
|
2021-06-06 01:35:30 +00:00
|
|
|
|
ldx MD5.s,y get s[i] in x
|
|
|
|
|
|
2021-07-29 16:41:57 +00:00
|
|
|
|
>ROL32x MDx.F
|
|
|
|
|
>ADC32 MDx.B,MDx.F,MDx.B
|
|
|
|
|
>MOV32 MDx.DTemp,MDx.A
|
2021-06-06 01:35:30 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2020-10-12 09:19:39 +00:00
|
|
|
|
CS.END
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDx.ABCDINIT .HS 01234567.89ABCDEF.FEDCBA98.76543210
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*--------------------------------------
|
2021-06-06 01:35:30 +00:00
|
|
|
|
MD4.s .DA #3,#7,#11,#19,#3,#7,#11,#19,#3,#7,#11,#19,#3,#7,#11,#19
|
|
|
|
|
.DA #3,#5,#9,#13,#3,#5,#9,#13,#3,#5,#9,#13,#3,#5,#9,#13
|
|
|
|
|
.DA #3,#9,#11,#15,#3,#9,#11,#15,#3,#9,#11,#15,#3,#9,#11,#15
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MD4.g .DA #0,#1,#2,#3,#4,#5,#6,#7,#8,#9,#10,#11,#12,#13,#14,#15
|
|
|
|
|
.DA #0,#4,#8,#12,#1,#5,#9,#13,#2,#6,#10,#14,#3,#7,#11,#15
|
|
|
|
|
.DA #0,#8,#4,#12,#2,#10,#6,#14,#1,#9,#5,#13,#3,#11,#7,#15
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MD4.K .HS 9979825A.A1EBD96E
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
MD5.s .DA #7,#12,#17,#22,#7,#12,#17,#22,#7,#12,#17,#22,#7,#12,#17,#22
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.DA #5,#9,#14,#20,#5,#9,#14,#20,#5,#9,#14,#20,#5,#9,#14,#20
|
|
|
|
|
.DA #4,#11,#16,#23,#4,#11,#16,#23,#4,#11,#16,#23,#4,#11,#16,#23
|
|
|
|
|
.DA #6,#10,#15,#21,#6,#10,#15,#21,#6,#10,#15,#21,#6,#10,#15,#21
|
|
|
|
|
*--------------------------------------
|
2021-06-06 01:35:30 +00:00
|
|
|
|
MD5.g .DA #0,#1,#2,#3,#4,#5,#6,#7,#8,#9,#10,#11,#12,#13,#14,#15
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.DA #1,#6,#11,#0,#5,#10,#15,#4,#9,#14,#3,#8,#13,#2,#7,#12
|
|
|
|
|
.DA #5,#8,#11,#14,#1,#4,#7,#10,#13,#0,#3,#6,#9,#12,#15,#2
|
|
|
|
|
.DA #0,#7,#14,#5,#12,#3,#10,#1,#8,#15,#6,#13,#4,#11,#2,#9
|
|
|
|
|
*--------------------------------------
|
2021-06-06 01:35:30 +00:00
|
|
|
|
MD5.K .HS 78A46AD7.56B7C7E8.DB702024.EECEBDC1
|
2020-10-12 09:19:39 +00:00
|
|
|
|
.HS AF0F7CF5.2AC68747.134630A8.019546FD
|
|
|
|
|
.HS D8988069.AFF7448B.B15BFFFF.BED75C89
|
|
|
|
|
.HS 2211906B.937198FD.8E4379A6.2108B449
|
|
|
|
|
.HS 62251EF6.40B340C0.515A5E26.AAC7B6E9
|
|
|
|
|
.HS 5D102FD6.53144402.81E6A1D8.C8FBD3E7
|
|
|
|
|
.HS E6CDE121.D60737C3.870DD5F4.ED145A45
|
|
|
|
|
.HS 05E9E3A9.F8A3EFFC.D9026F67.8A4C2A8D
|
|
|
|
|
.HS 4239FAFF.81F67187.22619D6D.0C38E5FD
|
|
|
|
|
.HS 44EABEA4.A9CFDE4B.604BBBF6.70BCBFBE
|
|
|
|
|
.HS C67E9B28.FA27A1EA.8530EFD4.051D8804
|
|
|
|
|
.HS 39D0D4D9.E599DBE6.F87CA21F.6556ACC4
|
|
|
|
|
.HS 442229F4.97FF2A43.A72394AB.39A093FC
|
|
|
|
|
.HS C3595B65.92CC0C8F.7DF4EFFF.D15D8485
|
|
|
|
|
.HS 4F7EA86F.E0E62CFE.144301A3.A111084E
|
|
|
|
|
.HS 827E53F7.35F23ABD.BBD2D72A.91D386EB
|
|
|
|
|
*--------------------------------------
|
2021-07-29 16:41:57 +00:00
|
|
|
|
MDx.DIGITS .AS "0123456789abcdef"
|
2020-10-12 09:19:39 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
MAN
|
|
|
|
|
SAVE usr/src/lib/libcrypt.s
|
|
|
|
|
ASM
|