flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > CRC-24

Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 726
Ali.Z 13 May 2021, 06:40
this CRC-24 is used by OpenPGP, pretty simple one.

Code:
  include 'win32a.inc'
  format PE console 4.0

section '.text' code readable executable

    mov                 eax,00B704CEh ; init
    mov                 ebx,01864CFBh ; poly
    mov                 esi,_data ; input
    mov                 ecx,[length] ; input length
    xor                 edi,edi ; used to iterate thru input
begin:
    movzx               edx,byte [esi+edi]
    shl                 edx,10h
    xor                 eax,edx
    mov                 edx,8
_loop:
    shl                 eax,1
    test                eax,01000000h
    jz                  update
    xor                 eax,ebx
update:
    dec                 edx
    jnz                 _loop
    inc                 edi
    cmp                 edi,ecx
    jnz                 begin
    and                 eax,00FFFFFFh
finish:
    cinvoke             itoa,eax,checksum,10h
    invoke              MessageBox,0,0,eax,0
    sub                 eax,eax
    ret
    int3

section '.data' data readable writeable

  length dd 4
  _data db 'fasm',0
  checksum rb 6


section '.idata' import data readable

  library user32,'user32.dll',\
          ntdll,'ntdll.dll'

  import user32,\
         MessageBox,'MessageBoxA'

  import ntdll,\
         itoa,'_itoa'

section '.reloc' fixups data readable discardable    

_________________
Asm For Wise Humans
Post 13 May 2021, 06:40
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 14 Aug 2021, 04:49
Code:
        mov edi,_data           ; input
        mov esi,edi
        add edi,[length]        ; end address

        xor ecx,ecx
        mov edx,$B704CE'00      ; init shl 8
        mov ebx,$864CFB'00      ; poly shl 8
.2:     xchg eax,ecx            ; set to zero
        lodsb
        bswap eax
        xor edx,eax
        mov ecx,8
.1:     shl edx,1
        jnc .0
        xor edx,ebx
.0:     loop .1
        cmp esi,edi
        jnz .2
        shr edx,8
        xchg eax,edx    

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 14 Aug 2021, 04:49
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.