Here is the next version, it solves the problem of being vulnerable to brute force attack by doing a second xor pass which makes reconstructing the pad almost impossible. Source is attached. Something to note, if you set the pad size in excess of installed memory, it will stop the OS stone dead so if you modify the pad size, stay under your installed memory. The extra pass incurred a longer run time but it is still reasonably fast, it moved from about 900 ms on a 1 gig pad to about 1350 ms with the extra pass. I will try a multi-threaded version to see if I can reduce the timing.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include64\masm64rt.inc
.code
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
entry_point proc
USING rsi,r12,r13,r14,r15
LOCAL hMMF :QWORD ; memory mapped file handle
LOCAL pMMF :QWORD ; pointer to mapped memory
LOCAL hFile :QWORD ; save file handle
LOCAL block :QWORD ; loop counter
SaveRegs
HighPriority
mov r13, 1024*1024*1024*1 ; the requested pad size
mov r14, r13 ; preserve original length in r14
conout "Creating random pad",lf
mov hFile, flcreate("random.pad") ; create the open file
invoke OpenMapFile,hFile,"mapfile", \
r13,ADDR hMMF,ADDR pMMF ; open the file mapping
mov r15, rv(GetTickCount) ; start timing
; *********************************************
; write data pass
; *********************************************
shr r13, 3 ; set block size from request size
call reseed ; get a seed for the random algo
rcall seed_irand,rax
mov r12, pMMF ; mapped memory address into r12
mov rsi, 1 ; set the initial reseeding count
call reseed ; get a seed for the range random algo
rcall seed_rrand,rax ; reseed the range random algo
@@:
rcall irand ; call random algo
mov QWORD PTR [r12], rax
add r12, 8 ; set next write location
sub rsi, 1 ; decrement the interval counter
jnz nxt
; ----------------------
rcall rrand, 11,1663 ; call range random for reseeding interval
mov rsi, rax
call reseed ; get a seed for the random algo
rcall seed_irand,rax ; reseed the integer random algo
; ----------------------
nxt:
sub r13, 1 ; decrement loop counter
jnz @B
; *********************************************
; xor data pass
; *********************************************
rcall rrand, 15,60
rcall SleepEx,rax,0
call reseed ; get a seed for the random algo
rcall seed_irand,rax
mov r12, pMMF ; mapped memory address into r12
mov rsi, 3 ; set the initial reseeding count
call reseed ; get a seed for the range random algo
rcall seed_rrand,rax ; reseed the range random algo
mov r13, r14
shr r13, 3
@@:
rcall irand ; call random algo
xor QWORD PTR [r12], rax
add r12, 8 ; set next write location
sub rsi, 1 ; decrement the interval counter
jnz nxt1
; ----------------------
rcall rrand, 17,4923 ; call range random for reseeding interval
mov rsi, rax
call reseed ; get a seed for the random algo
rcall seed_irand,rax ; reseed the integer random algo
; ----------------------
nxt1:
sub r13, 1 ; decrement loop counter
jnz @B
; *********************************************
rcall GetTickCount ; end timing
sub rax, r15
conout "Timing = ",str$(rax)," ms",lf
conout "File written to disk at ",str$(r14)," bytes",lf
rcall CloseMMF,pMMF,hMMF ; close the file mapping
rcall CloseHandle,hFile ; close the file
NormalPriority
waitkey
RestoreRegs
.exit
entry_point endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
OpenMapFile proc hFile:QWORD,lpName:QWORD,bcnt:QWORD,pHandle:QWORD,pMemory:QWORD
LOCAL hi32 :DWORD
LOCAL lo32 :DWORD
mov lo32, r8d ; split hi and lo DWORDS of bcnt
rol r8, 32
mov hi32, r8d
invoke CreateFileMapping, \
hFile, \ ; open file handle
NULL, \
PAGE_READWRITE, \ ; read write access to memory
hi32, \ ; high DWORD of bcnt
lo32, \ ; low DWORD of bcnt
lpName ; set file object name here
mov rdx, rax ; MMF handle in RDX
mov rcx, pHandle ; address of variable in RCX
mov [rcx], rax ; write MMF handle to variable
invoke MapViewOfFile, \
rdx, FILE_MAP_WRITE,0,0,0
mov rcx, pMemory ; address of variable in RCX
mov [rcx], rax ; write start address to variable
ret
OpenMapFile endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
NOSTACKFRAME
reseed proc
mov rax, 100 ; out of range number
cpuid ; set all regs to 0
rdtsc ; date time counter
pause ; spinlock pause
bswap rax ; reverse byte order
mov r11, rax ; store rax in r11
mov rcx, 10 ; loop count
@@:
rdtsc ; date time counter
pause ; spinlock pause
bswap rax ; reverse byte order
rol rax, 7 ; rotate left by prime
xor r11, rax ; xor rax to r11
rol r11, 5 ; rotate left by prime
sub rcx, 1 ; decrement counter
jnz @B
mov rax, r11 ; return the value in r11
ret
reseed endp
STACKFRAME
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end