1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
4 ; This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php.
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 ; Generates random number through CPU RdRand instruction under 32-bit platform.
22 ;------------------------------------------------------------------------------
26 ;------------------------------------------------------------------------------
27 ; Generates a 16 bit random number through RDRAND instruction.
28 ; Return TRUE if Rand generated successfully, or FALSE if not.
30 ; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
31 ;------------------------------------------------------------------------------
32 global ASM_PFX(InternalX86RdRand16)
33 ASM_PFX(InternalX86RdRand16):
34 ; rdrand ax ; generate a 16 bit RN into ax
35 ; CF=1 if RN generated ok, otherwise CF=0
36 db 0xf, 0xc7, 0xf0 ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"
37 jc rn16_ok ; jmp if CF=1
38 xor eax, eax ; reg=0 if CF=0
39 ret ; return with failure status
41 mov edx, dword [esp + 4]
46 ;------------------------------------------------------------------------------
47 ; Generates a 32 bit random number through RDRAND instruction.
48 ; Return TRUE if Rand generated successfully, or FALSE if not.
50 ; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
51 ;------------------------------------------------------------------------------
52 global ASM_PFX(InternalX86RdRand32)
53 ASM_PFX(InternalX86RdRand32):
54 ; rdrand eax ; generate a 32 bit RN into eax
55 ; CF=1 if RN generated ok, otherwise CF=0
56 db 0xf, 0xc7, 0xf0 ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"
57 jc rn32_ok ; jmp if CF=1
58 xor eax, eax ; reg=0 if CF=0
59 ret ; return with failure status
61 mov edx, dword [esp + 4]
66 ;------------------------------------------------------------------------------
67 ; Generates a 64 bit random number through RDRAND instruction.
68 ; Return TRUE if Rand generated successfully, or FALSE if not.
70 ; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);
71 ;------------------------------------------------------------------------------
72 global ASM_PFX(InternalX86RdRand64)
73 ASM_PFX(InternalX86RdRand64):
74 ; rdrand eax ; generate a 32 bit RN into eax
75 ; CF=1 if RN generated ok, otherwise CF=0
76 db 0xf, 0xc7, 0xf0 ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"
77 jnc rn64_ret ; jmp if CF=0
78 mov edx, dword [esp + 4]
81 db 0xf, 0xc7, 0xf0 ; generate another 32 bit RN
82 jnc rn64_ret ; jmp if CF=0
89 ret ; return with failure status