Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; The MIT License (MIT)
- ;
- ; Copyright © 2015 alice
- ;
- ; Permission is hereby granted, free of charge, to any person obtaining a copy of
- ; this software and associated documentation files (the "Software"), to deal in
- ; the Software without restriction, including without limitation the rights to
- ; use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
- ; the Software, and to permit persons to whom the Software is furnished to do so,
- ; subject to the following conditions:
- ;
- ; The above copyright notice and this permission notice shall be included in all
- ; copies or substantial portions of the Software.
- ;
- ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
- ; FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- ; COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
- ; IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- ; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- TITLE RAND_ASM.ASM
- ; ml64 /c rand_asm.asm
- EXTERN __imp_rand:NEAR
- .CODE
- hw_rand PROC
- call check_rdrand
- test al, al
- jnz rdrand_supported
- call qword ptr [__imp_rand]
- ret
- rdrand_supported:
- rdrand rax
- jnc hw_rand
- ret
- hw_rand ENDP
- hw_srand PROC
- call check_rdseed
- test al, al
- jnz rdseed_supported
- call qword ptr [__imp_rand]
- ret
- rdseed_supported:
- rdseed rcx
- jnc hw_srand
- mov rax, rcx
- ret
- hw_srand ENDP
- check_hw_rng PROC
- push r14
- xor r14, r14
- call check_rdrand
- test al, al
- jz no_rdrand
- or r14b, 001h
- no_rdrand:
- call check_rdseed
- test al, al
- jz no_rdseed
- or r14b, 002h
- no_rdseed:
- mov al, r14b
- pop r14
- ret
- check_hw_rng ENDP
- check_rdrand PROC
- push rbx
- mov eax, 001h
- cpuid
- xor eax, eax
- test ecx, 040000000h ; 30
- jz rdrand_not_supported
- inc al
- rdrand_not_supported:
- pop rbx
- ret
- check_rdrand ENDP
- check_rdseed PROC
- push rbx
- mov eax, 007h
- xor ecx, ecx
- cpuid
- xor eax, eax
- test ebx, 000040000h ; 18
- jz rdseed_not_supported
- inc al
- rdseed_not_supported:
- pop rbx
- ret
- check_rdseed ENDP
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement