1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2015 - 2022, 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 eax ; generate a 16 bit RN into eax,
30 ; CF=1 if RN generated ok, otherwise CF=0
31 jc rn16_ok ; jmp if CF=1
32 xor rax, rax ; reg=0 if CF=0
33 ret ; return with failure status
39 ;------------------------------------------------------------------------------
40 ; Generates a 32 bit random number through RDRAND instruction.
41 ; Return TRUE if Rand generated successfully, or FALSE if not.
43 ; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
44 ;------------------------------------------------------------------------------
45 global ASM_PFX(InternalX86RdRand32)
46 ASM_PFX(InternalX86RdRand32):
47 rdrand eax ; generate a 32 bit RN into eax,
48 ; CF=1 if RN generated ok, otherwise CF=0
49 jc rn32_ok ; jmp if CF=1
50 xor rax, rax ; reg=0 if CF=0
51 ret ; return with failure status
57 ;------------------------------------------------------------------------------
58 ; Generates a 64 bit random number through one RDRAND instruction.
59 ; Return TRUE if Rand generated successfully, or FALSE if not.
61 ; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);
62 ;------------------------------------------------------------------------------
63 global ASM_PFX(InternalX86RdRand64)
64 ASM_PFX(InternalX86RdRand64):
65 rdrand rax ; generate a 64 bit RN into rax,
66 ; CF=1 if RN generated ok, otherwise CF=0
67 jc rn64_ok ; jmp if CF=1
68 xor rax, rax ; reg=0 if CF=0
69 ret ; return with failure status