Upload files to "ircc_v8930_vigenere/TLS-Library-RNG"

This commit is contained in:
floppy121 committed 2026-01-24 22:43:33 +00:00
1 parent 68a03e3575
commit 1f3654933c
1 file changed
+118
@@ -0,0 +1,118 @@
; Get entropy for PRNG from the various sources...
get_entropy:
pusha
mcall 18, 20, entropy ; SysFn18.20 : SF_SYSTEM (18) / SSF_GET_RAM_INFO (20)
mcall 18, 4 ; SysFn18.4 : SF_SYSTEM (18) / SSF_GET_IDLE_COUNT (4)
mov dword[entropy+36], eax
mcall 37, 0 ; SysFn37.0 : SF_MOUSE_GET (37) / SSF_SCREEN_POSITION (0)
mov dword[entropy+40], eax
mcall 26, 10 ; SysFn26.10 : SF_SYSTEM_GET (26) / SSF_TIME_COUNT_PRO (10)
mov dword[entropy+44], edx
mov dword[entropy+48], eax
mcall 68, 0 ; SysFn68.0 : SF_SYS_MISC (68) / SSF_GET_TASK_SWITCH_COUNT (0)
mov dword[entropy+52], eax
mov esi, entropy
mov ebx, ENTROPY_SIZE
call replace_00_with_ff
popa
ret
; replace_00_with_ff:
; replace 00 with ff in a memory area
;
; IN: ESI - pointer to a memory area
; EBX - size of a memory area
replace_00_with_ff:
push eax ecx
xor ecx, ecx
.cycle_replace_00_with_ff:
cmp byte[esi], 0
jne .not_00
mov byte[esi], 0xff
.not_00:
inc esi
inc ecx
cmp ecx, ebx
jb .cycle_replace_00_with_ff
pop ecx eax
ret
; Prepare, then call a Pseudo Random function based on HMAC
fill_random_buffer:
pusha
call get_entropy
xor ebx, ebx
xor edx, edx
xor eax, eax
xor esi, esi
stdcall prf, entropy, ENTROPY_SIZE+1, random_buffer
popa
ret
; convert_random_buffer_to_ascii:
; convert a part of random buffer to ASCII chars
;
; IN: ECX = size of a part of random buffer which will be converted
convert_random_buffer_to_ascii:
push esi edx ebx eax
cmp ecx, 1
jb .wrong_part_size
cmp ecx, RANDOM_BUFFER_SIZE
ja .wrong_part_size
xor eax, eax
xor ebx, ebx
mov esi, random_buffer
mov edx, 95
.cycle_conversion:
mov al, byte[esi]
cmp al, 95
jb .skip_division
div dl
mov al, ah
.skip_division:
add al, 32
mov byte[esi], al
inc ebx
inc esi
cmp ebx, ecx
jne .cycle_conversion
.wrong_part_size:
pop eax ebx edx esi
ret