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 64-bit platform.
22 ;------------------------------------------------------------------------------
27 ;------------------------------------------------------------------------------
28 ; Generates a 16 bit random number through RDRAND instruction.
29 ; Return TRUE if Rand generated successfully, or FALSE if not.
31 ; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
32 ;------------------------------------------------------------------------------
33 global ASM_PFX(InternalX86RdRand16)
34 ASM_PFX(InternalX86RdRand16):
35 ; rdrand ax ; generate a 16 bit RN into eax,
36 ; CF=1 if RN generated ok, otherwise CF=0
37 db 0xf, 0xc7, 0xf0 ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"
38 jc rn16_ok ; jmp if CF=1
39 xor rax, rax ; reg=0 if CF=0
40 ret ; return with failure status
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 rax, rax ; reg=0 if CF=0
59 ret ; return with failure status
65 ;------------------------------------------------------------------------------
66 ; Generates a 64 bit random number through one RDRAND instruction.
67 ; Return TRUE if Rand generated successfully, or FALSE if not.
69 ; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);
70 ;------------------------------------------------------------------------------
71 global ASM_PFX(InternalX86RdRand64)
72 ASM_PFX(InternalX86RdRand64):
73 ; rdrand rax ; generate a 64 bit RN into rax,
74 ; CF=1 if RN generated ok, otherwise CF=0
75 db 0x48, 0xf, 0xc7, 0xf0 ; rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"
76 jc rn64_ok ; jmp if CF=1
77 xor rax, rax ; reg=0 if CF=0
78 ret ; return with failure status