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 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 eax ; generate a 16 bit RN into ax
29 ; CF=1 if RN generated ok, otherwise CF=0
30 jc rn16_ok ; jmp if CF=1
31 xor eax, eax ; reg=0 if CF=0
32 ret ; return with failure status
34 mov edx, dword [esp + 4]
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 eax, eax ; reg=0 if CF=0
51 ret ; return with failure status
53 mov edx, dword [esp + 4]
58 ;------------------------------------------------------------------------------
59 ; Generates a 64 bit random number through RDRAND instruction.
60 ; Return TRUE if Rand generated successfully, or FALSE if not.
62 ; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);
63 ;------------------------------------------------------------------------------
64 global ASM_PFX(InternalX86RdRand64)
65 ASM_PFX(InternalX86RdRand64):
66 rdrand eax ; generate a 32 bit RN into eax
67 ; CF=1 if RN generated ok, otherwise CF=0
68 jnc rn64_ret ; jmp if CF=0
69 mov edx, dword [esp + 4]
72 rdrand eax ; generate another 32 bit RN
73 jnc rn64_ret ; jmp if CF=0
80 ret ; return with failure status