flat assembler
Message board for the users of flat assembler.

Index > Heap > CRYPTOGRAPHY

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4238
Location: 2018
edfed
as you are all passioned by crytptography, i propose a thread, about cryptography theory, and asm coding...
to make a set of crytpographs programs...

Lets go then. Wink


Last edited by edfed on 04 Jun 2014, 09:24; edited 1 time in total
Post 31 Dec 2007, 02:24
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4238
Location: 2018
edfed
and one more version, this time, it saves up to 256M random bytes, for windows, fool compliant.

if you come from cacert, you should login here to download the source code.
foolw.zip/fool_crypt.inc Smile

the part responsible of the random generation is
Code:
;transparent return
crypt:
.call=0
.file=4
.key=8
.seed=12
        push eax ebx ecx edx edi
        mov edi,[esi+.key]
        mov edx,[esi+.seed]
        call .init
        mov ebx,[esi+.file]
        mov ecx,[ebx+lptr.size]
        mov ebx,[ebx+lptr.off]
@@:
        call .rnd
        xor [ebx],al
        ror eax,8
        xor [ebx],al
        ror eax,8
        xor [ebx],al
        ror eax,8
        xor [ebx],al
        inc ebx
        loop @b
        pop edi edx ecx ebx eax
        ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.init:                            ;
;edi=[key]                        ;
;edx=[seed]                       ;
        push ecx                  ;
        mov ecx,[edx]             ; key size
        shr ecx,2                 ;
        dec ecx                   ;
        jl .end                   ;
@@:                               ;
        mov [edx+4+ecx*4],ecx     ;
        dec ecx                   ;
        jnl @b                    ;
        mov ecx,[edi]             ;
        add edi,4                 ;
        or ecx,ecx                ;
        je .end                   ;
.loop:                            ;
        movsx eax,byte[edi]       ;
        movzx ebx,al              ;
        rol ebx,cl                ;
        adc eax,ecx               ;
        xor eax,ebx               ;
        push ecx                  ;
        mov ecx,[edx]             ;
        shr ecx,2                 ;
        dec ecx                   ;
        clc                       ;
@@:                               ;
        adc [edx+ecx*4],eax       ;
        sbb [edx+ecx*4],ecx       ;
        loop @b                   ;
        pop ecx                   ;
        inc edi                   ;
        loop .loop                ;
.end:                             ;
        pop ecx                   ;
        ret                       ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.rnd:                             ;
;edx=seed                         ;
;return eax = rnd                 ;
        push ebx ecx              ;
        xor eax,eax               ; eax=0
        mov ecx,[edx]             ; size of seed
        shr ecx,2                 ; in dwords
        dec ecx                   ; zero based size
        jl .not                   ; null seed? (size <=0)
        push ecx                  ; save size, cause we reuse the size later
        stc                       ; carry flag = 1
        xor ebx,ebx               ; ebx=0
@@:                               ;loop on seed digest operation
        sbb eax,[edx+ecx*4]       ;   first digest iteration on seed content in eax
        xor eax,ecx               ;   size value influence the value of this digest
        lea ebx,[eax*4+ecx+127]   ;   second part of the digest in ebx
        loop @b                   ; do it with all the seed
        xor eax,ecx               ; invert bits in eax
        stc                       ; carry flag = 0
        pop ecx                   ; restore seed size value
@@:                               ;loop on seed re construct operation
        adc [edx+ecx*4],eax       ;   make new value in seed
        adc eax,[edx+ecx*4]       ;   re make iteration on digest
        adc ebx,eax               ;   make on second part of the digest
        xor eax,ebx               ;   switch digest parts
        ror eax,cl                ;   rotate first part
        loop @b                   ; do it with all the seed
.not:                             ;
        pop ecx ebx               ;
        ret                       ; random value ready in eax, edx unchanged
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    

and should be used like this:
Code:
f:
.crypt dd crypt ;point to crypt method

Crypter:dd f.crypt,buffer,.ckey,.seed

.seed:  dd @f-$-4
        rd 128/32
        @@:
.ckey:  dd @f-$-4
        db "blablabla"
        @@:
        align 32
        dd 0

buffer: dd .off,.size
.off = @f
.size = 256*1024*1024

@@:
rb .size                 ;sorry, i don't want to use allocation for the moment, lazyness is cruel i know
db 0                  
    


don't be affraid, i don't use HeapAlloc for now, but next version will use it in order to generate many more bytes.

After, the crypt object should be able to iterate on blocks, in order to generate infinite random strings.

And just after, or before, depends on the borringness of the problem, i will fix the writeFile crash.


Description: fool_crypt.inc is the subject of your need, for windows.
Download
Filename: foolw.zip
Filesize: 12.43 KB
Downloaded: 185 Time(s)

Description: hope you'll cannot decrypt anything... old version of my crypto. for dos only
Download
Filename: CRYPT.ASM
Filesize: 2.58 KB
Downloaded: 281 Time(s)

Post 31 Dec 2007, 04:46
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 can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.