+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 2015 - 2016, 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
-; RdRand.asm\r
-;\r
-; Abstract:\r
-;\r
-; Generates random number through CPU RdRand instruction under 32-bit platform.\r
-;\r
-; Notes:\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
-.686P\r
-.model flat, C\r
-\r
-.code\r
-\r
-;------------------------------------------------------------------------------\r
-; Generates a 16 bit random number through RDRAND instruction.\r
-; Return TRUE if Rand generated successfully, or FALSE if not.\r
-;\r
-; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);\r
-;------------------------------------------------------------------------------\r
-InternalX86RdRand16 PROC\r
- ; rdrand ax ; generate a 16 bit RN into ax\r
- ; CF=1 if RN generated ok, otherwise CF=0\r
- db 0fh, 0c7h, 0f0h ; rdrand r16: "0f c7 /6 ModRM:r/m(w)"\r
- jc 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 edx, dword ptr [esp + 4]\r
- mov [edx], ax\r
- mov eax, 1\r
- ret\r
-InternalX86RdRand16 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; Generates a 32 bit random number through RDRAND instruction.\r
-; Return TRUE if Rand generated successfully, or FALSE if not.\r
-;\r
-; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);\r
-;------------------------------------------------------------------------------\r
-InternalX86RdRand32 PROC\r
- ; rdrand eax ; generate a 32 bit RN into eax\r
- ; CF=1 if RN generated ok, otherwise CF=0\r
- db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r
- jc 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 edx, dword ptr [esp + 4]\r
- mov [edx], eax\r
- mov eax, 1\r
- ret\r
-InternalX86RdRand32 ENDP\r
-\r
-;------------------------------------------------------------------------------\r
-; Generates a 64 bit random number through RDRAND instruction.\r
-; Return TRUE if Rand generated successfully, or FALSE if not.\r
-;\r
-; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);\r
-;------------------------------------------------------------------------------\r
-InternalX86RdRand64 PROC\r
- ; rdrand eax ; generate a 32 bit RN into eax\r
- ; CF=1 if RN generated ok, otherwise CF=0\r
- db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)"\r
- jnc rn64_ret ; jmp if CF=0\r
- mov edx, dword ptr [esp + 4]\r
- mov [edx], eax\r
-\r
- db 0fh, 0c7h, 0f0h ; generate another 32 bit RN\r
- jnc rn64_ret ; jmp if CF=0\r
- mov [edx + 4], eax\r
-\r
- mov eax, 1\r
- ret\r
-rn64_ret:\r
- xor eax, eax\r
- ret ; return with failure status\r
-InternalX86RdRand64 ENDP\r
-\r
- END\r