1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
12 ; Generates random number through CPU RdRand instruction under 64-bit platform.
16 ;------------------------------------------------------------------------------
21 ;------------------------------------------------------------------------------
22 ; Generates a 16 bit random number through RDRAND instruction.
23 ; Return TRUE if Rand generated successfully, or FALSE if not.
25 ; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
26 ;------------------------------------------------------------------------------
27 global ASM_PFX(InternalX86RdRand16)
28 ASM_PFX(InternalX86RdRand16):
29 ; rdrand ax ; generate a 16 bit RN into eax,
30 ; CF=1 if RN generated ok, otherwise CF=0
31 db 0xf, 0xc7, 0xf0 ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"
32 jc rn16_ok ; jmp if CF=1
33 xor rax, rax ; reg=0 if CF=0
34 ret ; return with failure status
40 ;------------------------------------------------------------------------------
41 ; Generates a 32 bit random number through RDRAND instruction.
42 ; Return TRUE if Rand generated successfully, or FALSE if not.
44 ; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
45 ;------------------------------------------------------------------------------
46 global ASM_PFX(InternalX86RdRand32)
47 ASM_PFX(InternalX86RdRand32):
48 ; rdrand eax ; generate a 32 bit RN into eax,
49 ; CF=1 if RN generated ok, otherwise CF=0
50 db 0xf, 0xc7, 0xf0 ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"
51 jc rn32_ok ; jmp if CF=1
52 xor rax, rax ; reg=0 if CF=0
53 ret ; return with failure status
59 ;------------------------------------------------------------------------------
60 ; Generates a 64 bit random number through one RDRAND instruction.
61 ; Return TRUE if Rand generated successfully, or FALSE if not.
63 ; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);
64 ;------------------------------------------------------------------------------
65 global ASM_PFX(InternalX86RdRand64)
66 ASM_PFX(InternalX86RdRand64):
67 ; rdrand rax ; generate a 64 bit RN into rax,
68 ; CF=1 if RN generated ok, otherwise CF=0
69 db 0x48, 0xf, 0xc7, 0xf0 ; rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"
70 jc rn64_ok ; jmp if CF=1
71 xor rax, rax ; reg=0 if CF=0
72 ret ; return with failure status