October 29, 2025, 09:28:22 AM

News:

IWBasic runs in Windows 11!


Hash algorithms

Started by zaphod, November 08, 2009, 03:39:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

zaphod

Hello,
Here is port for EB of 2 hash algorithms : ADLER32 and ELF32.



' HASH algorithms
' EB port by Z@ph0d : 08 nov 2009
'
OPENCONSOLE
'
  def crc AS int
  def str AS STRING
  str = "Mark Adler"
  crc = 1
  crc = ADLER32asm(&str, len(str), crc) ' should be: 13070394
  print HEX$(crc)
'
crc=elf32asm(&str,len(str))
print hex$(crc)
'
CLOSECONSOLE
END


SUB Elf32asm(adresse:int,length:int ),INT
' by Wayne Diamond, 24 July 2002
' 32 bits unsigned hash
' EB port by Z@ph0d - 08 nov 2009
'
def rez=0 AS INT
'
_asm
lea edi,[ebp-4]   ; rez
xor ebx, ebx      ; ebx = result holder (H)
        mov edx, [ebp+12] ; edx = Length
        mov ecx, [ebp+8]  ; ecx = Ptr to string
        xor esi, esi      ; esi = temp holder
    Elf1:
        xor eax, eax
        shl ebx, 4
        mov al, [ecx]
        add ebx, eax
        inc ecx
        mov eax, ebx
        and eax, 0xF0000000 ;???
        cmp eax, 0
        je Elf2
        mov esi, eax
        shr esi, 24
        xor ebx, esi
    Elf2:
        not eax
        and ebx,eax
        dec edx
        cmp edx, 0
        jne Elf1
        mov [edi],ebx
_endasm
'
    return rez
ENDSUB



SUB ADLER32asm(Address :int, Length : int, Seed :int),int
  ' Marc Sven Schultze
  ' 32 bits checksum 33% faster tha CRC 32
  ' EB port by Z@ph0d - 08 nov 2009
  '
  def rez=0 :INT
  '
  _asm
   lea edi,[ebp-4] ;rez
   mov edx, [ebp+16] ;Seed
   movzx ecx, dx
   shr edx, 16
   mov esi, [ebp+8] ;Address
   mov eax, [ebp+12] ;Length
   add eax, esi
   xor ebx, ebx
  LP:
   mov bl, [esi]
   add ecx, ebx
   cmp ecx, 65521
   jb M1
   sub ecx, 65521
  M1:
   add edx, ecx
   cmp edx, 65521
   jb M2
   sub edx, 65521
  M2:
   inc esi
   cmp esi, eax
   jnz LP
   shl edx, 16
   add ecx, edx
   mov [edi],ecx
  _endasm
  RETURN rez
ENDSUB

pistol350

Hi all !
"
...
SUB ADLER32asm(Address :int, Length : int, Seed :int),int
...
"
In the above statement, i'd rather expect a pointer receiving the adress , instead of an Integer...
Could anybody shed more light on that please ?

Regards,

Peter B.

zaphod

maybe because pointer is int ?.?.?

pistol350

Regards,

Peter B.