hum.... maybe someone would be interested, or if you can optimize it....
FF proto :dword,:dword,:dword,:dword,:dword,:byte,:dword
GG proto :dword,:dword,:dword,:dword,:dword,:byte,:dword
HH proto :dword,:dword,:dword,:dword,:dword,:byte,:dword
II proto :dword,:dword,:dword,:dword,:dword,:byte,:dword
procMD5hash proto :dword,:dword,:dword
MD5RESULT STRUCT
dtA dd ?
dtB dd ?
dtC dd ?
dtD dd ?
MD5RESULT ENDS
.data
szMD5Format db '%.8x%.8x%.8x%.8x',0
.data?
stMD5Result MD5RESULT >
.code
procMD5hash proc uses eax ebx ecx edx edi esi,ptBuffer:dword,dtBufferLength:dword,ptMD5Result:dword
local dta:dword,dtb:dword,dtc:dword,dtd:dword
; phase I · padding
mov edi,ptBuffer
mov eax,dtBufferLength
inc eax
add edi,eax
mov byte ptr ,080h
xor edx,edx
mov ebx,64
div ebx
neg edx
add edx,64
cmp edx,8
jae @f
add edx,64
@@: mov ecx,edx
xor al,al
rep stosb
mov eax,dtBufferLength
inc edx
add dtBufferLength,edx
xor edx,edx
mov ebx,8
mul ebx
mov dword ptr ,eax
mov dword ptr ,edx
mov edx,dtBufferLength
mov edi,ptBuffer
; phase II · chaining variables initialization
mov esi,ptMD5Result
assume esi:ptr MD5RESULT
mov .dtA,067452301h
mov .dtB,0efcdab89h
mov .dtC,098badcfeh
mov .dtD,010325476h
; phase III · hashing
hashloop: mov eax,.dtA
mov dta,eax
mov eax,.dtB
mov dtb,eax
mov eax,.dtC
mov dtc,eax
mov eax,.dtD
mov dtd,eax
; round 1
invoke FF,dta,dtb,dtc,dtd,dword ptr ,07,0d76aa478h
mov dta,eax
invoke FF,dtd,dta,dtb,dtc,dword ptr ,12,0e8c7b756h
mov dtd,eax
invoke FF,dtc,dtd,dta,dtb,dword ptr ,17,0242070dbh
mov dtc,eax
invoke FF,dtb,dtc,dtd,dta,dword ptr ,22,0c1bdceeeh
mov dtb,eax
invoke FF,dta,dtb,dtc,dtd,dword ptr ,07,0f57c0fafh
mov dta,eax
invoke FF,dtd,dta,dtb,dtc,dword ptr ,12,04787c62ah
mov dtd,eax
invoke FF,dtc,dtd,dta,dtb,dword ptr ,17,0a8304613h
mov dtc,eax
invoke FF,dtb,dtc,dtd,dta,dword ptr ,22,0fd469501h
mov dtb,eax
invoke FF,dta,dtb,dtc,dtd,dword ptr ,07,0698098d8h
mov dta,eax
invoke FF,dtd,dta,dtb,dtc,dword ptr ,12,08b44f7afh
mov dtd,eax
invoke FF,dtc,dtd,dta,dtb,dword ptr ,17,0ffff5bb1h
mov dtc,eax
invoke FF,dtb,dtc,dtd,dta,dword ptr ,22,0895cd7beh
mov dtb,eax
invoke FF,dta,dtb,dtc,dtd,dword ptr ,07,06b901122h
mov dta,eax
invoke FF,dtd,dta,dtb,dtc,dword ptr ,12,0fd987193h
mov dtd,eax
invoke FF,dtc,dtd,dta,dtb,dword ptr ,17,0a679438eh
mov dtc,eax
invoke FF,dtb,dtc,dtd,dta,dword ptr ,22,049b40821h
mov dtb,eax
; round 2
invoke GG,dta,dtb,dtc,dtd,dword ptr ,05,0f61e2562h
mov dta,eax
invoke GG,dtd,dta,dtb,dtc,dword ptr ,09,0c040b340h
mov dtd,eax
invoke GG,dtc,dtd,dta,dtb,dword ptr ,14,0265e5a51h
mov dtc,eax
invoke GG,dtb,dtc,dtd,dta,dword ptr ,20,0e9b6c7aah
mov dtb,eax
invoke GG,dta,dtb,dtc,dtd,dword ptr ,05,0d62f105dh
mov dta,eax
invoke GG,dtd,dta,dtb,dtc,dword ptr ,09,002441453h
mov dtd,eax
invoke GG,dtc,dtd,dta,dtb,dword ptr ,14,0d8a1e681h
mov dtc,eax
invoke GG,dtb,dtc,dtd,dta,dword ptr ,20,0e7d3fbc8h
mov dtb,eax
invoke GG,dta,dtb,dtc,dtd,dword ptr ,05,021e1cde6h
mov dta,eax
invoke GG,dtd,dta,dtb,dtc,dword ptr ,09,0c33707d6h
mov dtd,eax
invoke GG,dtc,dtd,dta,dtb,dword ptr ,14,0f4d50d87h
mov dtc,eax
invoke GG,dtb,dtc,dtd,dta,dword ptr ,20,0455a14edh
mov dtb,eax
invoke GG,dta,dtb,dtc,dtd,dword ptr ,05,0a9e3e905h
mov dta,eax
invoke GG,dtd,dta,dtb,dtc,dword ptr ,09,0fcefa
I'm assuming this is some sort of proc to create a hash value of some data, but for the encryption-challenged among us, could you please elaborate on this post???
sure, this is a md5 hashing function.
to get an extended information, u need to search for rfc1321 in a rfc search engine. basically, it generates a fixed size key for a variable-size text (there' s even a key for no-text-at-all =)).
ptBuffer is a pointer to the buffer to encrypt
dtBufferLength is the lenght of the buffer, and ptMD5Result a pointer to a MD5Result structure.
I don't know MD5, but I'd replace the PROCs with MACROS - keeping dtA, dtB, dtC, dtD in registers. Where do the constants come from?
Here is some code that I started, so you can see my direction:
procMD5hash proc uses eax ebx ecx edx edi esi,ptBuffer:dword,dtBufferLength:dword,ptMD5Result:dword
LOCAL dta:dword,dtb:dword,dtc:dword,dtd:dword
; phase I · padding
mov eax,dtBufferLength
mov edi,ptBuffer
mov ecx, eax
mov edx, eax
add ecx, 9 + (64 - 1)
and ecx, 1 - 64
mov dtBufferLength, ecx
sub ecx, eax
add edi, eax
mov , 080h ; Mark the begining of the pading
inc edi
xor eax, eax
sub ecx, 8 ; Two DWORDs are used by the hash bit count below
rep stosb ; Zero pad the rest
shl edx, 3
stosd
mov , edx ;Number of bits hashed (64 bit number)
mov edx,dtBufferLength
mov edi,ptBuffer
; phase II · chaining variables initialization
mov esi,ptMD5Result
assume esi:ptr MD5RESULT
mov .dtA,067452301h
mov .dtB,0efcdab89h
mov .dtC,098badcfeh
mov .dtD,010325476h
; phase III · hashing
hashloop:
mov eax,.dtA
mov dta,eax
mov eax,.dtB
mov dtb,eax
mov eax,.dtC
mov dtc,eax
mov eax,.dtD
mov dtd,eax
; round 1
R_ eax, _F,dta,dtb,dtc,dtd,dword ptr ,07,0d76aa478h
R_ eax, _F,dtd,dta,dtb,dtc,dword ptr ,12,0e8c7b756h
R_ eax, _F,dtc,dtd,dta,dtb,dword ptr ,17,0242070dbh
R_ eax, _F,dtb,dtc,dtd,dta,dword ptr ,22,0c1bdceeeh
R_ eax, _F,dta,dtb,dtc,dtd,dword ptr ,07,0f57c0fafh
R_ eax, _F,dtd,dta,dtb,dtc,dword ptr ,12,04787c62ah
R_ eax, _F,dtc,dtd,dta,dtb,dword ptr ,17,0a8304613h
R_ eax, _F,dtb,dtc,dtd,dta,dword ptr ,22,0fd469501h
R_ eax, _F,dta,dtb,dtc,dtd,dword ptr ,07,0698098d8h
R_ eax, _F,dtd,dta,dtb,dtc,dword ptr ,12,08b44f7afh
R_ eax, _F,dtc,dtd,dta,dtb,dword ptr ,17,0ffff5bb1h
R_ eax, _F,dtb,dtc,dtd,dta,dword ptr ,22,0895cd7beh
R_ eax, _F,dta,dtb,dtc,dtd,dword ptr ,07,06b901122h
R_ eax, _F,dtd,dta,dtb,dtc,dword ptr ,12,0fd987193h
R_ eax, _F,dtc,dtd,dta,dtb,dword ptr ,17,0a679438eh
R_ eax, _F,dtb,dtc,dtd,dta,dword ptr ,22,049b40821h
; round 2
R_ eax, _G,dta,dtb,dtc,dtd,dword ptr ,05,0f61e2562h
R_ eax, _G,dtd,dta,dtb,dtc,dword ptr ,09,0c040b340h
R_ eax, _G,dtc,dtd,dta,dtb,dword ptr ,14,0265e5a51h
R_ eax, _G,dtb,dtc,dtd,dta,dword ptr ,20,0e9b6c7aah
R_ eax, _G,dta,dtb,dtc,dtd,dword ptr ,05,0d62f105dh
R_ eax, _G,dtd,dta,dtb,dtc,dword ptr ,09,002441453h
R_ eax, _G,dtc,dtd,dta,dtb,dword ptr ,14,0d8a1e681h
R_ eax, _G,dtb,dtc,dtd,dta,dword ptr ,20,0e7d3fbc8h
R_ eax, _G,dta,dtb,dtc,dtd,dword ptr ,05,021e1cde6h
R_ eax, _G,dtd,dta,dtb,dtc,dword ptr ,09,0c33707d6h
R_ eax, _G,dtc,dtd,dta,dtb,dword ptr ,14,0f4d50d87h
R_ eax, _G,dtb,dtc,dtd,dta,dword ptr ,20,0455a14edh
R_ eax, _G,dta,dtb,dtc,dtd,dword ptr ,05,0a9e3e905h
R_ eax, _G,dtd,dta,dtb,dtc,dword ptr ,09,0fcefa3f8h
R_ eax, _G,dtc,dtd,dta,dtb,dword ptr ,14,0676f02d9h
R_ eax, _G,dtb,dtc,dtd,dta,dword ptr ,20,08d2a4c8ah
; round 3
R_ eax, _H,dta,dtb,dtc,dtd,dword ptr ,04,0fffa3942h
R_ eax, _H,dtd,dta,dtb,dtc,dword ptr ,11,08771f681h
R_ eax, _H,dtc,dtd,dta,dtb,dword ptr ,16,06d9d6122h
R_ eax, _H,dtb,dtc,dtd,dta,dword ptr ,23,0fde5380ch
R_ eax, _H,dta,dtb,dtc,dtd,dword ptr ,04,0a4beea44h
R_ eax, _H,dtd,dta,dtb,dtc,dword ptr ,11,04bdecfa9h
R_ eax, _H,dtc,dtd,dta,dtb,dword ptr
nice work on macros.
for sure this will be faster, but it will also be bigger. so i don' t know, if we should only look at speed, or try to find a solution between speed and size.
uhh.. you may want to check out rudeboy's source:
http://www.crosswinds.net/~win32asm/files/mdxsrc05.zip
hope this is any help
:)
I think the macros can be used for both versions speed/size, and switch with a #define. Coding like this takes more planning, but less lines of code and changes are easier to make. This is no where near fastest. Certainly, MMX/SSE or overlaping multiple R_ MACRO calls code would be faster? There are dependancies everywhere in this code. :( RudeBoy's code should be a little faster than Roy's, and a bit slower than mine (when it's finished). :) I see that the constants come from a sin table.
bitRAKE: please let me know when you finished your version. I'm working on a database engine and I need good hash code for the strings in it.
Thomas
heh u should see john ripper md5 algo, mmx optiomization
I haven't had a chance to look at the algorithm, but here is a link to get it.
This message was edited by bitRAKE, on 5/29/2001 2:19:37 PM
Posted on 2001-05-29 14:18:00 by bitRAKE
This message was edited by bitRAKE, on 5/29/2001 2:19:37 PM
Posted on 2001-05-29 14:18:00 by bitRAKE
Anyone still have http://www.crosswinds.net/~win32asm/files/mdxsrc05.zip ? The link is dead
All I can dig out that are related to md5 are these 2 files
Maybe this is it.
http://www.movsd.com/source/mdx.zip
It has mdxsrc051.zip in it.
http://www.movsd.com/source/mdx.zip
It has mdxsrc051.zip in it.
That looks like it, indeed.
Thank you both, roticv and dsouza123.
Thank you both, roticv and dsouza123.