1 #------------------------------------------------------------------------------ ;
2 # Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
3 # This program and the accompanying materials
4 # are licensed and made available under the terms and conditions of the BSD License
5 # which accompanies this distribution. The full text of the license may be found at
6 # http://opensource.org/licenses/bsd-license.php.
8 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 # Generates random number through CPU RdRand instruction under 32-bit platform.
21 #------------------------------------------------------------------------------
23 //------------------------------------------------------------------------------
24 // Generates a 16 bit random number through RDRAND instruction.
25 // Return TRUE if Rand generated successfully, or FALSE if not.
27 // BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
28 //------------------------------------------------------------------------------
29 ASM_GLOBAL ASM_PFX(AsmRdRand16)
31 .byte 0x0f, 0xc7, 0xf0 // rdrand r16: "0f c7 /6 ModRM:r/m(w)"
32 jc rn16_ok // jmp if CF=1
33 xor %eax, %eax // reg=0 if CF=0
34 ret // return with failure status
41 //------------------------------------------------------------------------------
42 // Generates a 32 bit random number through RDRAND instruction.
43 // Return TRUE if Rand generated successfully, or FALSE if not.
45 // BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
46 //------------------------------------------------------------------------------
47 ASM_GLOBAL ASM_PFX(AsmRdRand32)
49 .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w)"
50 jc rn32_ok // jmp if CF=1
51 xor %eax, %eax // reg=0 if CF=0
52 ret // return with failure status
59 //------------------------------------------------------------------------------
60 // Generates a 64 bit random number through RDRAND instruction.
61 // Return TRUE if Rand generated successfully, or FALSE if not.
63 // BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);
64 //------------------------------------------------------------------------------
65 ASM_GLOBAL ASM_PFX(AsmRdRand64)
67 .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w)"
68 jnc rn64_ret // jmp if CF=0
72 .byte 0x0f, 0xc7, 0xf0 // generate another 32 bit RN
73 jnc rn64_ret // jmp if CF=0
80 ret // return with failure status