-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.asm
37 lines (34 loc) · 850 Bytes
/
random.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
.686P; Pentium Pro or later
.MODEL flat, stdcall
.STACK 4096
includelib Bcrypt.lib
.data
rngHandle DWORD ?
rngIdentifier WORD 52h, 4eh, 47h, 0
randomNum BYTE 0
.code
BCryptGenRandom PROTO,
hAlgorithm : PTR DWORD,
pbBuffer : PTR BYTE,
cbBuffer : DWORD,
dwFlags : DWORD,
BCryptOpenAlgorithmProvider PROTO,
phAlgorithm : PTR DWORD,
pszAlgId : PTR BYTE,
pszImplementation : DWORD,
dwFlags : DWORD
randInit PROC
invoke BCryptOpenAlgorithmProvider, ADDR rngHandle, ADDR rngIdentifier, 0, 0
randInit ENDP
; ------------------------------------------------------------------------------ -
randRange PROC USES ECX,
upperBound:BYTE
; ------------------------------------------------------------------------------ -
try:
invoke BCryptGenRandom, rngHandle, ADDR randomNum, 1, 0
mov al, randomNum
cmp al, upperBound
ja try
ret
randRange ENDP
END