+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
-; This program and the accompanying materials\r
-; are licensed and made available under the terms and conditions of the BSD License\r
-; which accompanies this distribution. The full text of the license may be found at\r
-; http://opensource.org/licenses/bsd-license.php.\r
-;\r
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-;\r
-; Module Name:\r
-;\r
-; AsmRdRand.Asm\r
-;\r
-; Abstract:\r
-;\r
-; Implementation for 16-, and 32- invocations of RDRAND instruction under 32bit platform.\r
-;\r
-; Notes:\r
-;\r
-; Visual Studio coding practices do not use inline asm since multiple compilers and \r
-; architectures are supported assembler not recognizing rdrand instruction so using DB's.\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .586P\r
- .model flat, C\r
- .code\r
- \r
-;------------------------------------------------------------------------------\r
-; Generate a 16 bit random number\r
-; Return TRUE if Rand generated successfully, or FALSE if not\r
-;\r
-; BOOLEAN EFIAPI RdRand16Step (UINT16 *Rand); ECX\r
-;------------------------------------------------------------------------------\r
-RdRand16Step PROC\r
- ; rdrand ax ; generate a 16 bit RN into ax, CF=1 if RN generated ok, otherwise CF=0\r
- db 0fh, 0c7h, 0f0h ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"\r
- jb rn16_ok ; jmp if CF=1\r
- xor eax, eax ; reg=0 if CF=0\r
- ret ; return with failure status\r
-rn16_ok:\r
- mov [ecx], ax\r
- mov eax, 1\r
- ret\r
-RdRand16Step ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; Generate a 32 bit random number\r
-; Return TRUE if Rand generated successfully, or FALSE if not\r
-;\r
-; BOOLEAN EFIAPI RdRand32Step (UINT32 *Rand); ECX\r
-;------------------------------------------------------------------------------\r
-RdRand32Step PROC\r
- ; rdrand eax ; generate a 32 bit RN into eax, CF=1 if RN generated ok, otherwise CF=0\r
- db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r
- jb rn32_ok ; jmp if CF=1\r
- xor eax, eax ; reg=0 if CF=0\r
- ret ; return with failure status\r
-rn32_ok:\r
- mov [ecx], eax\r
- mov eax, 1\r
- ret\r
-RdRand32Step ENDP\r
-\r
- END\r
+++ /dev/null
-/** @file\r
- RDRAND Support Routines for GCC environment.\r
-\r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-/**\r
- Generates a 16-bit random number through RDRAND instruction.\r
-\r
- @param[out] Rand Buffer pointer to store the random result.\r
-\r
- @retval TRUE RDRAND call was successful.\r
- @retval FALSE Failed attempts to call RDRAND.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RdRand16Step (\r
- OUT UINT16 *Rand\r
- )\r
-{\r
- UINT8 Carry;\r
-\r
- //\r
- // Uses byte code for RDRAND instruction,\r
- // in case that GCC version has no direct support on RDRAND assembly.\r
- //\r
- __asm__ __volatile__ (\r
- ".byte 0x66; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"\r
- :"=a" (*Rand), \r
- "=qm" (Carry)\r
- ); \r
-\r
- return (BOOLEAN) Carry;\r
-}\r
-\r
-/**\r
- Generates a 32-bit random number through RDRAND instruction.\r
-\r
- @param[out] Rand Buffer pointer to store the random result.\r
-\r
- @retval TRUE RDRAND call was successful.\r
- @retval FALSE Failed attempts to call RDRAND.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RdRand32Step (\r
- OUT UINT32 *Rand\r
- )\r
-{\r
- UINT8 Carry;\r
-\r
- __asm__ __volatile__ (\r
- ".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"\r
- :"=a" (*Rand), \r
- "=qm" (Carry)\r
- );\r
-\r
- return (BOOLEAN) Carry;\r
-}
\ No newline at end of file
+++ /dev/null
-/** @file\r
- RDRAND Support Routines.\r
-\r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "RdRand.h"\r
-\r
-/**\r
- Generates a 64-bit random number through RDRAND instruction.\r
-\r
- @param[out] Rand Buffer pointer to store the random result.\r
-\r
- @retval TRUE RDRAND call was successful.\r
- @retval FALSE Failed attempts to call RDRAND.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RdRand64Step (\r
- OUT UINT64 *Rand\r
- )\r
-{\r
- UINT32 RandLow;\r
- UINT32 RandHigh;\r
-\r
- //\r
- // Generating a 64-bit rand on a 32-bit system by \r
- // mapping two 32-bit RDRAND instructions.\r
- //\r
- if (!RdRand32Step (&RandLow)) {\r
- return FALSE;\r
- }\r
- if (!RdRand32Step (&RandHigh)) {\r
- return FALSE;\r
- }\r
-\r
- *Rand = (UINT64) RandLow | LShiftU64 ((UINT64)RandHigh, 32);\r
-\r
- return TRUE;\r
-}\r
-\r
-/**\r
- Calls RDRAND to request a word-length random number.\r
-\r
- @param[out] Rand Buffer pointer to store the random number.\r
- @param[in] NeedRetry Determine whether or not to loop retry.\r
-\r
- @retval EFI_SUCCESS Random word generation succeeded.\r
- @retval EFI_NOT_READY Failed to request random word.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RdRandWord (\r
- OUT UINTN *Rand,\r
- IN BOOLEAN NeedRetry\r
- )\r
-{\r
- return RdRand32 (Rand, NeedRetry);\r
-}\r
-\r
-/**\r
- Calls RDRAND to request multiple word-length random numbers.\r
-\r
- @param[in] Length Size of the buffer, in words, to fill with.\r
- @param[out] RandBuffer Pointer to the buffer to store the random result.\r
-\r
- @retval EFI_SUCCESS Random words generation succeeded.\r
- @retval EFI_NOT_READY Failed to request random words.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RdRandGetWords (\r
- IN UINTN Length,\r
- OUT UINTN *RandBuffer\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINT32 Index;\r
-\r
- for (Index = 0; Index < Length; Index++) {\r
- //\r
- // Obtain one word-length (32-bit) Random Number with possible retry-loop.\r
- //\r
- Status = RdRand32 (RandBuffer, TRUE);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- \r
- RandBuffer++;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
-; This program and the accompanying materials\r
-; are licensed and made available under the terms and conditions of the BSD License\r
-; which accompanies this distribution. The full text of the license may be found at\r
-; http://opensource.org/licenses/bsd-license.php.\r
-;\r
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-;\r
-; Module Name:\r
-;\r
-; AsmRdRand.Asm\r
-;\r
-; Abstract:\r
-;\r
-; Implementation for 16-, 32-, and 64-bit invocations of RDRAND instruction under 64bit platform.\r
-;\r
-; Notes:\r
-;\r
-; Visual Studio coding practices do not use inline asm since multiple compilers and \r
-; architectures are supported assembler not recognizing rdrand instruction so using DB's.\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
- .code\r
- \r
-;------------------------------------------------------------------------------\r
-; Generate a 16 bit random number\r
-; Return TRUE if Rand generated successfully, or FALSE if not\r
-;\r
-; BOOLEAN EFIAPI RdRand16Step (UINT16 *Rand); RCX\r
-;------------------------------------------------------------------------------\r
-RdRand16Step PROC\r
- ; rdrand ax ; generate a 16 bit RN into ax, CF=1 if RN generated ok, otherwise CF=0\r
- db 0fh, 0c7h, 0f0h ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"\r
- jb rn16_ok ; jmp if CF=1\r
- xor rax, rax ; reg=0 if CF=0\r
- ret ; return with failure status\r
-rn16_ok:\r
- mov [rcx], ax\r
- mov rax, 1\r
- ret\r
-RdRand16Step ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; Generate a 32 bit random number\r
-; Return TRUE if Rand generated successfully, or FALSE if not\r
-;\r
-; BOOLEAN EFIAPI RdRand32Step (UINT32 *Rand); RCX\r
-;------------------------------------------------------------------------------\r
-RdRand32Step PROC\r
- ; rdrand eax ; generate a 32 bit RN into eax, CF=1 if RN generated ok, otherwise CF=0\r
- db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r
- jb rn32_ok ; jmp if CF=1\r
- xor rax, rax ; reg=0 if CF=0\r
- ret ; return with failure status\r
-rn32_ok:\r
- mov [rcx], eax\r
- mov rax, 1\r
- ret\r
-RdRand32Step ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; Generate a 64 bit random number\r
-; Return TRUE if RN generated successfully, or FALSE if not\r
-;\r
-; BOOLEAN EFIAPI RdRand64Step (UINT64 *Random); RCX\r
-;------------------------------------------------------------------------------\r
-RdRand64Step PROC\r
- ; rdrand rax ; generate a 64 bit RN into rax, CF=1 if RN generated ok, otherwise CF=0\r
- db 048h, 0fh, 0c7h, 0f0h ; rdrand r64: "REX.W + 0F C7 /6 ModRM:r/m(w)" \r
- jb rn64_ok ; jmp if CF=1\r
- xor rax, rax ; reg=0 if CF=0\r
- ret ; return with failure status\r
-rn64_ok:\r
- mov [rcx], rax\r
- mov rax, 1\r
- ret\r
-RdRand64Step ENDP\r
-\r
- END\r
+++ /dev/null
-/** @file\r
- RDRAND Support Routines for GCC environment.\r
-\r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-/**\r
- Generates a 16-bit random number through RDRAND instruction.\r
-\r
- @param[out] Rand Buffer pointer to store the random result.\r
-\r
- @retval TRUE RDRAND call was successful.\r
- @retval FALSE Failed attempts to call RDRAND.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RdRand16Step (\r
- OUT UINT16 *Rand\r
- )\r
-{\r
- UINT8 Carry;\r
-\r
- //\r
- // Uses byte code for RDRAND instruction,\r
- // in case that GCC version has no direct support on RDRAND assembly.\r
- //\r
- __asm__ __volatile__ (\r
- ".byte 0x66; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"\r
- :"=a" (*Rand),\r
- "=qm" (Carry)\r
- ); \r
-\r
- return (BOOLEAN) Carry;\r
-}\r
-\r
-/**\r
- Generates a 32-bit random number through RDRAND instruction.\r
-\r
- @param[out] Rand Buffer pointer to store the random result.\r
-\r
- @retval TRUE RDRAND call was successful.\r
- @retval FALSE Failed attempts to call RDRAND.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RdRand32Step (\r
- OUT UINT32 *Rand\r
- )\r
-{\r
- UINT8 Carry;\r
-\r
- __asm__ __volatile__ (\r
- ".byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"\r
- :"=a" (*Rand), \r
- "=qm" (Carry)\r
- );\r
-\r
- return (BOOLEAN) Carry;\r
-}\r
-\r
-/**\r
- Generates a 64-bit random number through RDRAND instruction.\r
-\r
- @param[out] Rand Buffer pointer to store the random result.\r
-\r
- @retval TRUE RDRAND call was successful.\r
- @retval FALSE Failed attempts to call RDRAND.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-RdRand64Step (\r
- OUT UINT64 *Rand\r
- )\r
-{\r
- UINT8 Carry;\r
-\r
- __asm__ __volatile__ (\r
- ".byte 0x48; .byte 0x0f; .byte 0xc7; .byte 0xf0; setc %1"\r
- :"=a" (*Rand), \r
- "=qm" (Carry)\r
- );\r
- \r
- return (BOOLEAN) Carry;\r
-}\r
+++ /dev/null
-/** @file\r
- RDRAND Support Routines.\r
-\r
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "RdRand.h"\r
-\r
-/**\r
- Calls RDRAND to request a word-length random number.\r
-\r
- @param[out] Rand Buffer pointer to store the random number.\r
- @param[in] NeedRetry Determine whether or not to loop retry.\r
-\r
- @retval EFI_SUCCESS Random word generation succeeded.\r
- @retval EFI_NOT_READY Failed to request random word.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RdRandWord (\r
- OUT UINTN *Rand,\r
- IN BOOLEAN NeedRetry\r
- )\r
-{\r
- return RdRand64 (Rand, NeedRetry);\r
-}\r
-\r
-/**\r
- Calls RDRAND to request multiple word-length random numbers.\r
-\r
- @param[in] Length Size of the buffer, in words, to fill with.\r
- @param[out] RandBuffer Pointer to the buffer to store the random result.\r
-\r
- @retval EFI_SUCCESS Random words generation succeeded.\r
- @retval EFI_NOT_READY Failed to request random words.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RdRandGetWords (\r
- IN UINTN Length,\r
- OUT UINTN *RandBuffer\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINT32 Index;\r
-\r
- for (Index = 0; Index < Length; Index++) {\r
- //\r
- // Obtain one word-length (64-bit) Random Number with possible retry-loop.\r
- //\r
- Status = RdRand64 (RandBuffer, TRUE);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- \r
- RandBuffer++;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}
\ No newline at end of file