flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > CRC-24

Thread Post new topic Reply to topic

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

  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
    movzx               edx,byte [esi+edi]
    shl                 edx,10h
    xor                 eax,edx
    mov                 edx,8
    shl                 eax,1
    test                eax,01000000h
    jz                  update
    xor                 eax,ebx
    dec                 edx
    jnz                 _loop
    inc                 edi
    cmp                 edi,ecx
    jnz                 begin
    and                 eax,00FFFFFFh
    cinvoke             itoa,eax,checksum,10h
    invoke              MessageBox,0,0,eax,0
    sub                 eax,eax

section '.data' data readable writeable

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

section '.idata' import data readable

  library user32,'user32.dll',\

  import user32,\

  import ntdll,\

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

Joined: 21 Jul 2003
Posts: 3946
Location: vpcmipstrm
bitRAKE 14 Aug 2021, 04:49
        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
        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.