flat assembler
Message board for the users of flat assembler.
Index
> Main > simple 32byte hashing |
Author |
|
revolution 15 Jan 2008, 03:35
With the crypto API you can get pseudo-random bytes:
Code: push eax mov esi,esp invoke CryptAcquireContext,esi,NULL,NULL,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT test eax,eax jz .failed invoke CryptGenRandom,dword[esi],byte_count,address test eax,eax setz bl invoke CryptReleaseContext,dword[esi],0 test eax,eax setz al or al,bl jnz .failed pop eax clc ret .failed: pop eax stc ret |
|||
15 Jan 2008, 03:35 |
|
zxcv 15 Jan 2008, 04:17
my code is not much longer, without calls
so thers no smth like md5(DWORD seed) ? |
|||
15 Jan 2008, 04:17 |
|
revolution 15 Jan 2008, 04:34
Windows will give you MD5 see CryptCreateHash. Just do your own if you only need a simple dword seed as your entropy.
But if you want good entropy pseudo-randomness then the API method is very good. To do your own with similar entropy is not easy and requires good planning and lots of effort. |
|||
15 Jan 2008, 04:34 |
|
zxcv 15 Jan 2008, 06:50
i already have this:
but i feel its not random. i use rand to switch between number, lower, and bigger. So only /3 goes to number, /2 smaller etc.. Code: format pe console section '.code' code readable executable push 768 call [malloc] mov [buffer],eax add eax,335 mov [hash],eax add eax,33 push eax push 0x0202 call [WSAStartup] push 0 call [time] push eax call [srand] add esp,12 mov ebp,[hash] mov edi,3 mov esi,ebp add esi,32 hashproc: call [rand] xor edx,edx div edi cmp edx,1 jg hash_big jl hash_small mov ebx,10 mov ecx,48 jmp hash_end hash_big: mov ebx,26 mov ecx,65 jmp hash_end hash_small: mov ebx,26 mov ecx,97 hash_end: xor edx,edx div ebx add edx,ecx mov [ebp],dl inc ebp cmp esi,ebp jne hashproc mov [ebp],byte 0 push [hash] push f call [printf] add esp, 8 retn section '.data' data readable writeable f db '%s',13,10,0 buffer dd ? hash dd ? section '.idata' import data readable dd 0,0,0,RVA msvcrt_name,RVA msvcrt_table dd 0,0,0,RVA ws2_32_name,RVA ws2_32_table dd 0,0,0,RVA kernel32_name,RVA kernel32_table dd 5 dup ? msvcrt_table: printf dd RVA _printf time dd RVA _time srand dd RVA _srand rand dd RVA _rand malloc dd RVA _malloc memset dd RVA _memset dd 0 ws2_32_table: WSAStartup dd RVA _WSAStartup socket dd RVA _socket closesocket dd RVA _closesocket connect dd RVA _connect recv dd RVA _recv send dd RVA _send sendto dd RVA _sendto dd 0 kernel32_table: dd 0 msvcrt_name db 'msvcrt.dll',0 ws2_32_name db 'ws2_32.dll',0 kernel32_name db 'kernel32.dll',0 _printf db 0,0,'printf',0 _time db 0,0,'time',0 _srand db 0,0,'srand',0 _rand db 0,0,'rand',0 _malloc db 0,0,'malloc',0 _memset db 0,0,'memset',0 _WSAStartup db 0,0,'WSAStartup',0 _socket db 0,0,'socket',0 _closesocket db 0,0,'closesocket',0 _connect db 0,0,'connect',0 _recv db 0,0,'recv',0 _send db 0,0,'send',0 _sendto db 0,0,'sendto',0 |
|||
15 Jan 2008, 06:50 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.