From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D023D81E87 for ; Mon, 14 Nov 2016 21:17:35 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 14 Nov 2016 21:17:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,640,1473145200"; d="scan'208";a="1068555752" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga001.fm.intel.com with ESMTP; 14 Nov 2016 21:17:40 -0800 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 14 Nov 2016 21:17:37 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 14 Nov 2016 21:17:37 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.239]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.239]) with mapi id 14.03.0248.002; Tue, 15 Nov 2016 13:17:34 +0800 From: "Gao, Liming" To: "Long, Qin" , "edk2-devel@lists.01.org" Thread-Topic: [Patch] MdePkg/BaseLib: Add one wrapper on RdRand access for parameter check. Thread-Index: AQHSNnHl4ZjK6ZZZnkqCJCqKRLWYjaDZkjOA Date: Tue, 15 Nov 2016 05:17:34 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B4B20EB@shsmsx102.ccr.corp.intel.com> References: <20161104080256.10728-1-qin.long@intel.com> In-Reply-To: <20161104080256.10728-1-qin.long@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] MdePkg/BaseLib: Add one wrapper on RdRand access for parameter check. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Nov 2016 05:17:36 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Long, Qin > Sent: Friday, November 04, 2016 4:03 PM > To: edk2-devel@lists.01.org; Gao, Liming > Subject: [Patch] MdePkg/BaseLib: Add one wrapper on RdRand access for > parameter check. >=20 > Add one wrapper implementation over assembly RdRand access to check > possible NULL parameter, for better alignment with comment description. >=20 > Cc: Liming Gao > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Qin Long > --- > MdePkg/Library/BaseLib/BaseLib.inf | 2 + > MdePkg/Library/BaseLib/BaseLibInternals.h | 48 ++++++++++++++++++- > MdePkg/Library/BaseLib/Ia32/RdRand.S | 20 ++++---- > MdePkg/Library/BaseLib/Ia32/RdRand.asm | 20 ++++---- > MdePkg/Library/BaseLib/Ia32/RdRand.nasm | 20 ++++---- > MdePkg/Library/BaseLib/X64/RdRand.S | 20 ++++---- > MdePkg/Library/BaseLib/X64/RdRand.asm | 20 ++++---- > MdePkg/Library/BaseLib/X64/RdRand.nasm | 20 ++++---- > MdePkg/Library/BaseLib/X86RdRand.c | 79 > +++++++++++++++++++++++++++++++ > 9 files changed, 188 insertions(+), 61 deletions(-) > create mode 100644 MdePkg/Library/BaseLib/X86RdRand.c >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index 1ffe870..320ac45 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -428,6 +428,7 @@ > X86EnablePaging32.c > X86DisablePaging64.c > X86DisablePaging32.c > + X86RdRand.c >=20 > [Sources.X64] > X64/Thunk16.nasm > @@ -752,6 +753,7 @@ > X86EnablePaging32.c > X86DisablePaging64.c > X86DisablePaging32.c > + X86RdRand.c > X64/GccInline.c | GCC > X64/Thunk16.S | XCODE > X64/SwitchStack.nasm| GCC > diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h > b/MdePkg/Library/BaseLib/BaseLibInternals.h > index fe416a0..a8f712b 100644 > --- a/MdePkg/Library/BaseLib/BaseLibInternals.h > +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h > @@ -1,7 +1,7 @@ > /** @file > Declaration of internal functions in BaseLib. >=20 > - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
> + Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD > License > which accompanies this distribution. The full text of the license may= be > found at > @@ -728,6 +728,52 @@ InternalX86DisablePaging64 ( > IN UINT32 NewStack > ); >=20 > +/** > + Generates a 16-bit random number through RDRAND instruction. > + > + @param[out] Rand Buffer pointer to store the random result. > + > + @retval TRUE RDRAND call was successful. > + @retval FALSE Failed attempts to call RDRAND. > + > + **/ > +BOOLEAN > +EFIAPI > +InternalX86RdRand16 ( > + OUT UINT16 *Rand > + ); > + > +/** > + Generates a 32-bit random number through RDRAND instruction. > + > + @param[out] Rand Buffer pointer to store the random result. > + > + @retval TRUE RDRAND call was successful. > + @retval FALSE Failed attempts to call RDRAND. > + > +**/ > +BOOLEAN > +EFIAPI > +InternalX86RdRand32 ( > + OUT UINT32 *Rand > + ); > + > +/** > + Generates a 64-bit random number through RDRAND instruction. > + > + > + @param[out] Rand Buffer pointer to store the random result. > + > + @retval TRUE RDRAND call was successful. > + @retval FALSE Failed attempts to call RDRAND. > + > +**/ > +BOOLEAN > +EFIAPI > +InternalX86RdRand64 ( > + OUT UINT64 *Rand > + ); > + >=20 > #elif defined (MDE_CPU_IPF) > // > diff --git a/MdePkg/Library/BaseLib/Ia32/RdRand.S > b/MdePkg/Library/BaseLib/Ia32/RdRand.S > index 503f65a..d00075a 100644 > --- a/MdePkg/Library/BaseLib/Ia32/RdRand.S > +++ b/MdePkg/Library/BaseLib/Ia32/RdRand.S > @@ -1,5 +1,5 @@ > #-----------------------------------------------------------------------= ------- ; > -# Copyright (c) 2015, Intel Corporation. All rights reserved.
> +# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> # This program and the accompanying materials > # are licensed and made available under the terms and conditions of the = BSD > License > # which accompanies this distribution. The full text of the license may= be > found at > @@ -24,10 +24,10 @@ > // Generates a 16 bit random number through RDRAND instruction. > // Return TRUE if Rand generated successfully, or FALSE if not. > // > -// BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand); > +// BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand); > //----------------------------------------------------------------------= -------- > -ASM_GLOBAL ASM_PFX(AsmRdRand16) > -ASM_PFX(AsmRdRand16): > +ASM_GLOBAL ASM_PFX(InternalX86RdRand16) > +ASM_PFX(InternalX86RdRand16): > .byte 0x0f, 0xc7, 0xf0 // rdrand r16: "0f c7 /6 ModRM:r/m(w= )" > jc rn16_ok // jmp if CF=3D1 > xor %eax, %eax // reg=3D0 if CF=3D0 > @@ -42,10 +42,10 @@ rn16_ok: > // Generates a 32 bit random number through RDRAND instruction. > // Return TRUE if Rand generated successfully, or FALSE if not. > // > -// BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand); > +// BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand); > //----------------------------------------------------------------------= -------- > -ASM_GLOBAL ASM_PFX(AsmRdRand32) > -ASM_PFX(AsmRdRand32): > +ASM_GLOBAL ASM_PFX(InternalX86RdRand32) > +ASM_PFX(InternalX86RdRand32): > .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w= )" > jc rn32_ok // jmp if CF=3D1 > xor %eax, %eax // reg=3D0 if CF=3D0 > @@ -60,10 +60,10 @@ rn32_ok: > // Generates a 64 bit random number through RDRAND instruction. > // Return TRUE if Rand generated successfully, or FALSE if not. > // > -// BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand); > +// BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand); > //----------------------------------------------------------------------= -------- > -ASM_GLOBAL ASM_PFX(AsmRdRand64) > -ASM_PFX(AsmRdRand64): > +ASM_GLOBAL ASM_PFX(InternalX86RdRand64) > +ASM_PFX(InternalX86RdRand64): > .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w= )" > jnc rn64_ret // jmp if CF=3D0 > mov 0x4(%esp), %edx > diff --git a/MdePkg/Library/BaseLib/Ia32/RdRand.asm > b/MdePkg/Library/BaseLib/Ia32/RdRand.asm > index 21349b0..cb4e811 100644 > --- a/MdePkg/Library/BaseLib/Ia32/RdRand.asm > +++ b/MdePkg/Library/BaseLib/Ia32/RdRand.asm > @@ -1,6 +1,6 @@ > ;-----------------------------------------------------------------------= ------- > ; > -; Copyright (c) 2015, Intel Corporation. All rights reserved.
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> ; This program and the accompanying materials > ; are licensed and made available under the terms and conditions of the = BSD > License > ; which accompanies this distribution. The full text of the license may= be > found at > @@ -30,9 +30,9 @@ > ; Generates a 16 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand); > ;-----------------------------------------------------------------------= ------- > -AsmRdRand16 PROC > +InternalX86RdRand16 PROC > ; rdrand ax ; generate a 16 bit RN into ax > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0fh, 0c7h, 0f0h ; rdrand r16: "0f c7 /6 ModRM:r/m(w)= " > @@ -44,15 +44,15 @@ rn16_ok: > mov [edx], ax > mov eax, 1 > ret > -AsmRdRand16 ENDP > +InternalX86RdRand16 ENDP >=20 > ;-----------------------------------------------------------------------= ------- > ; Generates a 32 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand); > ;-----------------------------------------------------------------------= ------- > -AsmRdRand32 PROC > +InternalX86RdRand32 PROC > ; rdrand eax ; generate a 32 bit RN into eax > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)= " > @@ -64,15 +64,15 @@ rn32_ok: > mov [edx], eax > mov eax, 1 > ret > -AsmRdRand32 ENDP > +InternalX86RdRand32 ENDP >=20 > ;-----------------------------------------------------------------------= ------- > ; Generates a 64 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand); > ;-----------------------------------------------------------------------= ------- > -AsmRdRand64 PROC > +InternalX86RdRand64 PROC > ; rdrand eax ; generate a 32 bit RN into eax > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)= " > @@ -89,6 +89,6 @@ AsmRdRand64 PROC > rn64_ret: > xor eax, eax > ret ; return with failure status > -AsmRdRand64 ENDP > +InternalX86RdRand64 ENDP >=20 > END > diff --git a/MdePkg/Library/BaseLib/Ia32/RdRand.nasm > b/MdePkg/Library/BaseLib/Ia32/RdRand.nasm > index 1365dfc..64e8cdb 100644 > --- a/MdePkg/Library/BaseLib/Ia32/RdRand.nasm > +++ b/MdePkg/Library/BaseLib/Ia32/RdRand.nasm > @@ -1,6 +1,6 @@ > ;-----------------------------------------------------------------------= ------- > ; > -; Copyright (c) 2015, Intel Corporation. All rights reserved.
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> ; This program and the accompanying materials > ; are licensed and made available under the terms and conditions of the = BSD > License > ; which accompanies this distribution. The full text of the license may= be > found at > @@ -27,10 +27,10 @@ SECTION .text > ; Generates a 16 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand); > ;-----------------------------------------------------------------------= ------- > -global ASM_PFX(AsmRdRand16) > -ASM_PFX(AsmRdRand16): > +global ASM_PFX(InternalX86RdRand16) > +ASM_PFX(InternalX86RdRand16): > ; rdrand ax ; generate a 16 bit RN into ax > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0xf, 0xc7, 0xf0 ; rdrand r16: "0f c7 /6 ModRM:r/m(w)= " > @@ -47,10 +47,10 @@ rn16_ok: > ; Generates a 32 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand); > ;-----------------------------------------------------------------------= ------- > -global ASM_PFX(AsmRdRand32) > -ASM_PFX(AsmRdRand32): > +global ASM_PFX(InternalX86RdRand32) > +ASM_PFX(InternalX86RdRand32): > ; rdrand eax ; generate a 32 bit RN into eax > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0xf, 0xc7, 0xf0 ; rdrand r32: "0f c7 /6 ModRM:r/m(w)= " > @@ -67,10 +67,10 @@ rn32_ok: > ; Generates a 64 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand); > ;-----------------------------------------------------------------------= ------- > -global ASM_PFX(AsmRdRand64) > -ASM_PFX(AsmRdRand64): > +global ASM_PFX(InternalX86RdRand64) > +ASM_PFX(InternalX86RdRand64): > ; rdrand eax ; generate a 32 bit RN into eax > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0xf, 0xc7, 0xf0 ; rdrand r32: "0f c7 /6 ModRM:r/m(w)= " > diff --git a/MdePkg/Library/BaseLib/X64/RdRand.S > b/MdePkg/Library/BaseLib/X64/RdRand.S > index 49b50e6..55724c0 100644 > --- a/MdePkg/Library/BaseLib/X64/RdRand.S > +++ b/MdePkg/Library/BaseLib/X64/RdRand.S > @@ -1,5 +1,5 @@ > #-----------------------------------------------------------------------= ------- ; > -# Copyright (c) 2015, Intel Corporation. All rights reserved.
> +# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> # This program and the accompanying materials > # are licensed and made available under the terms and conditions of the = BSD > License > # which accompanies this distribution. The full text of the license may= be > found at > @@ -24,10 +24,10 @@ > // Generates a 16 bit random number through RDRAND instruction. > // Return TRUE if Rand generated successfully, or FALSE if not. > // > -// BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand); > +// BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand); > //----------------------------------------------------------------------= -------- > -ASM_GLOBAL ASM_PFX(AsmRdRand16) > -ASM_PFX(AsmRdRand16): > +ASM_GLOBAL ASM_PFX(InternalX86RdRand16) > +ASM_PFX(InternalX86RdRand16): > .byte 0x0f, 0xc7, 0xf0 // rdrand r16: "0f c7 /6 ModRM:r/m(w= )" > jc rn16_ok // jmp if CF=3D1 > xor %rax, %rax // reg=3D0 if CF=3D0 > @@ -41,10 +41,10 @@ rn16_ok: > // Generates a 32 bit random number through RDRAND instruction. > // Return TRUE if Rand generated successfully, or FALSE if not. > // > -// BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand); > +// BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand); > //----------------------------------------------------------------------= -------- > -ASM_GLOBAL ASM_PFX(AsmRdRand32) > -ASM_PFX(AsmRdRand32): > +ASM_GLOBAL ASM_PFX(InternalX86RdRand32) > +ASM_PFX(InternalX86RdRand32): > .byte 0x0f, 0xc7, 0xf0 // rdrand r32: "0f c7 /6 ModRM:r/m(w= )" > jc rn32_ok // jmp if CF=3D1 > xor %rax, %rax // reg=3D0 if CF=3D0 > @@ -58,10 +58,10 @@ rn32_ok: > // Generates a 64 bit random number through RDRAND instruction. > // Return TRUE if Rand generated successfully, or FALSE if not. > // > -// BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand); > +// BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand); > //----------------------------------------------------------------------= -------- > -ASM_GLOBAL ASM_PFX(AsmRdRand64) > -ASM_PFX(AsmRdRand64): > +ASM_GLOBAL ASM_PFX(InternalX86RdRand64) > +ASM_PFX(InternalX86RdRand64): > .byte 0x48, 0x0f, 0xc7, 0xf0 // rdrand r64: "REX.W + 0f c7 /6 > ModRM:r/m(w)" > jc rn64_ok // jmp if CF=3D1 > xor %rax, %rax // reg=3D0 if CF=3D0 > diff --git a/MdePkg/Library/BaseLib/X64/RdRand.asm > b/MdePkg/Library/BaseLib/X64/RdRand.asm > index 370cdb6..8e2074e 100644 > --- a/MdePkg/Library/BaseLib/X64/RdRand.asm > +++ b/MdePkg/Library/BaseLib/X64/RdRand.asm > @@ -1,6 +1,6 @@ > ;-----------------------------------------------------------------------= ------- > ; > -; Copyright (c) 2015, Intel Corporation. All rights reserved.
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> ; This program and the accompanying materials > ; are licensed and made available under the terms and conditions of the = BSD > License > ; which accompanies this distribution. The full text of the license may= be > found at > @@ -27,9 +27,9 @@ > ; Generates a 16 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand); > ;-----------------------------------------------------------------------= ------- > -AsmRdRand16 PROC > +InternalX86RdRand16 PROC > ; rdrand ax ; generate a 16 bit RN into eax, > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0fh, 0c7h, 0f0h ; rdrand r16: "0f c7 /6 ModRM:r/m(w)= " > @@ -40,15 +40,15 @@ rn16_ok: > mov [rcx], ax > mov rax, 1 > ret > -AsmRdRand16 ENDP > +InternalX86RdRand16 ENDP >=20 > ;-----------------------------------------------------------------------= ------- > ; Generates a 32 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand); > ;-----------------------------------------------------------------------= ------- > -AsmRdRand32 PROC > +InternalX86RdRand32 PROC > ; rdrand eax ; generate a 32 bit RN into eax, > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0fh, 0c7h, 0f0h ; rdrand r32: "0f c7 /6 ModRM:r/m(w)= " > @@ -59,15 +59,15 @@ rn32_ok: > mov [rcx], eax > mov rax, 1 > ret > -AsmRdRand32 ENDP > +InternalX86RdRand32 ENDP >=20 > ;-----------------------------------------------------------------------= ------- > ; Generates a 64 bit random number through one RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Random); > +; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random); > ;-----------------------------------------------------------------------= ------- > -AsmRdRand64 PROC > +InternalX86RdRand64 PROC > ; rdrand rax ; generate a 64 bit RN into rax, > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 048h, 0fh, 0c7h, 0f0h ; rdrand r64: "REX.W + 0f c7 /6 ModRM= :r/m(w)" > @@ -78,6 +78,6 @@ rn64_ok: > mov [rcx], rax > mov rax, 1 > ret > -AsmRdRand64 ENDP > +InternalX86RdRand64 ENDP >=20 > END > diff --git a/MdePkg/Library/BaseLib/X64/RdRand.nasm > b/MdePkg/Library/BaseLib/X64/RdRand.nasm > index f6d83a3..b9050d2 100644 > --- a/MdePkg/Library/BaseLib/X64/RdRand.nasm > +++ b/MdePkg/Library/BaseLib/X64/RdRand.nasm > @@ -1,6 +1,6 @@ > ;-----------------------------------------------------------------------= ------- > ; > -; Copyright (c) 2015, Intel Corporation. All rights reserved.
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> ; This program and the accompanying materials > ; are licensed and made available under the terms and conditions of the = BSD > License > ; which accompanies this distribution. The full text of the license may= be > found at > @@ -28,10 +28,10 @@ > ; Generates a 16 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand); > ;-----------------------------------------------------------------------= ------- > -global ASM_PFX(AsmRdRand16) > -ASM_PFX(AsmRdRand16): > +global ASM_PFX(InternalX86RdRand16) > +ASM_PFX(InternalX86RdRand16): > ; rdrand ax ; generate a 16 bit RN into eax, > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0xf, 0xc7, 0xf0 ; rdrand r16: "0f c7 /6 ModRM:r/m(w)= " > @@ -47,10 +47,10 @@ rn16_ok: > ; Generates a 32 bit random number through RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand); > +; BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand); > ;-----------------------------------------------------------------------= ------- > -global ASM_PFX(AsmRdRand32) > -ASM_PFX(AsmRdRand32): > +global ASM_PFX(InternalX86RdRand32) > +ASM_PFX(InternalX86RdRand32): > ; rdrand eax ; generate a 32 bit RN into eax, > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0xf, 0xc7, 0xf0 ; rdrand r32: "0f c7 /6 ModRM:r/m(w)= " > @@ -66,10 +66,10 @@ rn32_ok: > ; Generates a 64 bit random number through one RDRAND instruction. > ; Return TRUE if Rand generated successfully, or FALSE if not. > ; > -; BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Random); > +; BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random); > ;-----------------------------------------------------------------------= ------- > -global ASM_PFX(AsmRdRand64) > -ASM_PFX(AsmRdRand64): > +global ASM_PFX(InternalX86RdRand64) > +ASM_PFX(InternalX86RdRand64): > ; rdrand rax ; generate a 64 bit RN into rax, > ; CF=3D1 if RN generated ok, otherwis= e CF=3D0 > db 0x48, 0xf, 0xc7, 0xf0 ; rdrand r64: "REX.W + 0f c7 /6 ModRM= :r/m(w)" > diff --git a/MdePkg/Library/BaseLib/X86RdRand.c > b/MdePkg/Library/BaseLib/X86RdRand.c > new file mode 100644 > index 0000000..36d5457 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/X86RdRand.c > @@ -0,0 +1,79 @@ > +/** @file > + IA-32/x64 AsmRdRandxx() > + Generates random number through CPU RdRand instruction. > + > + Copyright (c) 2016, Intel Corporation. All rights reserved.
> + This program and the accompanying materials > + are licensed and made available under the terms and conditions of the = BSD > License > + which accompanies this distribution. The full text of the license may= be > found at > + http://opensource.org/licenses/bsd-license.php. > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > +**/ > + > +#include "BaseLibInternals.h" > + > +/** > + Generates a 16-bit random number through RDRAND instruction. > + > + if Rand is NULL, then ASSERT(). > + > + @param[out] Rand Buffer pointer to store the random result. > + > + @retval TRUE RDRAND call was successful. > + @retval FALSE Failed attempts to call RDRAND. > + > + **/ > +BOOLEAN > +EFIAPI > +AsmRdRand16 ( > + OUT UINT16 *Rand > + ) > +{ > + ASSERT (Rand !=3D NULL); > + return InternalX86RdRand16 (Rand); > +} > + > +/** > + Generates a 32-bit random number through RDRAND instruction. > + > + if Rand is NULL, then ASSERT(). > + > + @param[out] Rand Buffer pointer to store the random result. > + > + @retval TRUE RDRAND call was successful. > + @retval FALSE Failed attempts to call RDRAND. > + > +**/ > +BOOLEAN > +EFIAPI > +AsmRdRand32 ( > + OUT UINT32 *Rand > + ) > +{ > + ASSERT (Rand !=3D NULL); > + return InternalX86RdRand32 (Rand); > +} > + > +/** > + Generates a 64-bit random number through RDRAND instruction. > + > + if Rand is NULL, then ASSERT(). > + > + @param[out] Rand Buffer pointer to store the random result. > + > + @retval TRUE RDRAND call was successful. > + @retval FALSE Failed attempts to call RDRAND. > + > +**/ > +BOOLEAN > +EFIAPI > +AsmRdRand64 ( > + OUT UINT64 *Rand > + ) > +{ > + ASSERT (Rand !=3D NULL); > + return InternalX86RdRand64 (Rand); > +} > -- > 2.10.1.windows.1