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 32-bit platform.
16 ;------------------------------------------------------------------------------
20 ;------------------------------------------------------------------------------
21 ; Generates a 16 bit random number through RDRAND instruction.
22 ; Return TRUE if Rand generated successfully, or FALSE if not.
24 ; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
25 ;------------------------------------------------------------------------------
26 global ASM_PFX(InternalX86RdRand16)
27 ASM_PFX(InternalX86RdRand16):
28 ; rdrand ax ; generate a 16 bit RN into ax
29 ; CF=1 if RN generated ok, otherwise CF=0
30 db 0xf, 0xc7, 0xf0 ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"
31 jc rn16_ok ; jmp if CF=1
32 xor eax, eax ; reg=0 if CF=0
33 ret ; return with failure status
35 mov edx, dword [esp + 4]
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 eax, eax ; reg=0 if CF=0
53 ret ; return with failure status
55 mov edx, dword [esp + 4]
60 ;------------------------------------------------------------------------------
61 ; Generates a 64 bit random number through RDRAND instruction.
62 ; Return TRUE if Rand generated successfully, or FALSE if not.
64 ; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);
65 ;------------------------------------------------------------------------------
66 global ASM_PFX(InternalX86RdRand64)
67 ASM_PFX(InternalX86RdRand64):
68 ; rdrand eax ; generate a 32 bit RN into eax
69 ; CF=1 if RN generated ok, otherwise CF=0
70 db 0xf, 0xc7, 0xf0 ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"
71 jnc rn64_ret ; jmp if CF=0
72 mov edx, dword [esp + 4]
75 db 0xf, 0xc7, 0xf0 ; generate another 32 bit RN
76 jnc rn64_ret ; jmp if CF=0
83 ret ; return with failure status