From nobody Fri May 10 15:41:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106857+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106857+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168607; cv=none; d=zohomail.com; s=zohoarc; b=VN+cYDO0qzWxqGMFmQTCbhkt3FedszfzZtqmN2YXRJgb6zmeJ0PyIkmyY/gCLuxe8c6r20xU9jXp/R+z+FUkQ94Puy0AYSEjxX6xbAN8ONu/43eD03afGN6iSFduJHTq8UeHTlCZTpiHSX00qY8ko61d10ad3o8VYNb2ZAdeHn8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168607; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Li9peI3aANJA5S6WwwiyhGICh6a9PVekWS+O7JiTVLA=; b=KOkcCerk0udYTHspLGq/KlDyrnXAJHYSpXebvBsL8WqgwHAlAXOiisPF56BEZa2CtGk75DzGl6DY/b8E/lzl27Gt15nJXm3iFAGK2XxgTdAYJuIeVVAt9igqGXCnueZZxRYyYsuj+jDsh0SXPWW9cHcXbTLTe+N4W+Gh87oV8N8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106857+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 168916860795465.16133639751035; Wed, 12 Jul 2023 06:30:07 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=rtef7l43PLrTaJi90EyC02JW3hjRKUZ19HViJM0oIL0=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168607; v=1; b=EUtwnH6sggkpnBKslsZe9FSjMC++dGIqQy2SxYmLrYpcxO/tfPTAWczZnZZWORjmE0bt0BSf efx2YOjKE6AE8mS0elllmMsoO0BC+YWldZJzS6+uGRn3LEH9j1nCwaRUyVj5oDwWeSnJYOQyahe IMYGiEyquPQ88GteBD35Mu0k= X-Received: by 127.0.0.2 with SMTP id BvxoYY1788612xIVGBdRwwgc; Wed, 12 Jul 2023 06:30:07 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.7314.1689168606700438404 for ; Wed, 12 Jul 2023 06:30:06 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A67F912FC; Wed, 12 Jul 2023 06:30:48 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 338303F67D; Wed, 12 Jul 2023 06:30:03 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 1/8] MdePkg: Move BaseRngLibTimerLib to MdeModulePkg Date: Wed, 12 Jul 2023 15:29:40 +0200 Message-Id: <20230712132947.332643-2-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: zqNwggxIL0QyDPpBaejynWl0x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168609274100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The BaseRngLibTimerLib allows to generate number based on a timer. This mechanism allows to have a basic non-secure implementation for non-production platforms. To bind and identify Random Number Generators implementations with a GUID, an unsafe GUID should be added. This GUID cannot be added to the MdePkg unless it is also added to a specification. To keep the MdePkg self-contained, move the BaseRngLibTimerLib to the MdeModulePkg. This will allow to define an unsafe Rng GUID in a later patch in the MdeModulePkg. Signed-off-by: Pierre Gondois --- ArmVirtPkg/ArmVirt.dsc.inc | 2 +- EmulatorPkg/EmulatorPkg.dsc | 2 +- .../Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 0 .../Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni | 0 .../Library/BaseRngLibTimerLib/RngLibTimer.c | 0 MdeModulePkg/MdeModulePkg.dsc | 1 + MdePkg/MdePkg.dsc | 1 - NetworkPkg/NetworkPkg.dsc | 4 ++-- OvmfPkg/AmdSev/AmdSevX64.dsc | 2 +- OvmfPkg/Bhyve/BhyveX64.dsc | 2 +- OvmfPkg/CloudHv/CloudHvX64.dsc | 2 +- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 2 +- OvmfPkg/Microvm/MicrovmX64.dsc | 2 +- OvmfPkg/OvmfPkgIa32.dsc | 2 +- OvmfPkg/OvmfPkgIa32X64.dsc | 2 +- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/OvmfXen.dsc | 2 +- OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc | 2 +- SecurityPkg/SecurityPkg.dsc | 4 ++-- SignedCapsulePkg/SignedCapsulePkg.dsc | 4 ++-- 20 files changed, 19 insertions(+), 19 deletions(-) rename {MdePkg =3D> MdeModulePkg}/Library/BaseRngLibTimerLib/BaseRngLibTim= erLib.inf (100%) rename {MdePkg =3D> MdeModulePkg}/Library/BaseRngLibTimerLib/BaseRngLibTim= erLib.uni (100%) rename {MdePkg =3D> MdeModulePkg}/Library/BaseRngLibTimerLib/RngLibTimer.c= (100%) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 2443e8351c99..3f7bac6bf33a 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -154,7 +154,7 @@ [LibraryClasses.common] OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 # # Secure Boot dependencies diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index b44435d7e6ee..b14654739b54 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -128,7 +128,7 @@ [LibraryClasses] FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecu= reLibNull.inf diff --git a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf b/Mde= ModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf similarity index 100% rename from MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf rename to MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf diff --git a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni b/Mde= ModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni similarity index 100% rename from MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni rename to MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni diff --git a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdeModulePkg= /Library/BaseRngLibTimerLib/RngLibTimer.c similarity index 100% rename from MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c rename to MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 1aedfe280ae1..ca16c7f8d552 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -341,6 +341,7 @@ [Components] MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgr= essLibGraphics.inf MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdateProgressL= ibText.inf + MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 MdeModulePkg/Universal/BdsDxe/BdsDxe.inf MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 3abd1a1e2310..809d3a09500d 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -68,7 +68,6 @@ [Components] MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.i= nf MdePkg/Library/DxeRngLib/DxeRngLib.inf MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf - MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf diff --git a/NetworkPkg/NetworkPkg.dsc b/NetworkPkg/NetworkPkg.dsc index 6c231c97b544..808c6bffce2c 100644 --- a/NetworkPkg/NetworkPkg.dsc +++ b/NetworkPkg/NetworkPkg.dsc @@ -82,10 +82,10 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf =20 [LibraryClasses.ARM] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.RISCV64] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [PcdsFeatureFlag] gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 2c6ed7c9745f..022104dfdce6 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -185,7 +185,7 @@ [LibraryClasses] =20 IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 7fa40998ae80..cc1f85d1be50 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -196,7 +196,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index e000deed9e4d..35942e02df93 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -206,7 +206,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 193657ff2d61..bbf218488127 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -184,7 +184,7 @@ [LibraryClasses] =20 IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 2f7585639374..d5c1a2fe3a91 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -203,7 +203,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index ed36935770f3..c1f1733a483d 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -210,7 +210,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 919315e4cb33..bdd6c3bc96ae 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -215,7 +215,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 823de0d0f9e0..a54e17dd087d 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -231,7 +231,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 210578c1d74d..26d2a6963de5 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -194,7 +194,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVV= irt.dsc.inc index 731f54f73f81..8da89ef09f62 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc +++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc @@ -117,7 +117,7 @@ [LibraryClasses.common] OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 # # Secure Boot dependencies diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 3c62205162ce..7682066cd9fe 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -92,10 +92,10 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] ArmTrngLib|MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf =20 [LibraryClasses.ARM] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.RISCV64] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.X64.SEC] HashLib|SecurityPkg/Library/HashLibTdx/HashLibTdx.inf diff --git a/SignedCapsulePkg/SignedCapsulePkg.dsc b/SignedCapsulePkg/Signe= dCapsulePkg.dsc index 8a27207a6f20..4c656666e981 100644 --- a/SignedCapsulePkg/SignedCapsulePkg.dsc +++ b/SignedCapsulePkg/SignedCapsulePkg.dsc @@ -110,10 +110,10 @@ [LibraryClasses.AARCH64, LibraryClasses.ARM] NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf =20 [LibraryClasses.ARM] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.RISCV64] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106857): https://edk2.groups.io/g/devel/message/106857 Mute This Topic: https://groups.io/mt/100099379/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 10 15:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106858+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106858+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168609; cv=none; d=zohomail.com; s=zohoarc; b=VVKvxxqTUv+ZyuVoxGOWxAueecDuhkEPbS800Zv+izw/MyRhJMMr7ei4Jtb5YxNYdDRHS8BTnYsj4+GE5PG7QgMyiPWsNXU5Vlku5Z2VETqqYZLR9iP8WPQwMyAw2KZm8OCy92PHXXmqg0xQMLZG5/vlWf0UHGtkT+bmij5klhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168609; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=GEe9lUcjOVpyXGyqdqopbOpUxtfY0uHXA/2829grc+Q=; b=S+XzoCKozCKr0HcFqefAu2P3cgzFJ2BdJlSSq//AZeBy2TFzqkjcDLEv3GbL5AL9f/UiV+KNsWjOMldgyuVuxo7xTfBjZGsco/dj1x6c1UaEL5pM3Wcl2QNV4pcyZY3aey92Tk+/SqO/GkvsiBTfS1bJlL6UBAjlcjmnOc7ZwZw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106858+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689168609976304.19306237511853; Wed, 12 Jul 2023 06:30:09 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=xOM/918nSU3Gg3rDPZBZIDwtPhPJ+/OPriHP3Kq1kog=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168609; v=1; b=F5HoM1vDOxCunqOriWcIIRo3W++9jzlgurtJRLeUV5lbeJuAJ6DGFCIaNnBDNlw1ah22FNNe urcgDF+v/9+jXrvJh/xsz60zoCscZGm42+t31AGb/Nty5yPMRPuPTCUSSYgbCLj9C+PiZ7b6dp3 NlbiXUfFE39ebBK4v6F+HzRE= X-Received: by 127.0.0.2 with SMTP id 1KydYY1788612xQgcTZUBg8g; Wed, 12 Jul 2023 06:30:09 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.7377.1689168608919359149 for ; Wed, 12 Jul 2023 06:30:09 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 10B191480; Wed, 12 Jul 2023 06:30:51 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 898C23F67D; Wed, 12 Jul 2023 06:30:06 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 2/8] SecurityPkg/SecurityPkg.dec: Move PcdCpuRngSupportedAlgorithm to MdePkg Date: Wed, 12 Jul 2023 15:29:41 +0200 Message-Id: <20230712132947.332643-3-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: dhhLi2ovvUsTMahxW7aQ9oXvx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168611278100010 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois In order to use PcdCpuRngSupportedAlgorithm in the MdePkg in a following patch and to avoid making the MdePkg dependent on another package, move PcdCpuRngSupportedAlgorithm to the MdePkg. As the Pcd is only used for AARCH64, place it in an AARCH64 specific sections. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- MdePkg/MdePkg.dec | 5 +++++ SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 4 ++-- SecurityPkg/SecurityPkg.dec | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index b85614992b94..5b8477f4cb8f 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -2393,6 +2393,11 @@ [PcdsFixedAtBuild,PcdsPatchableInModule] # @Prompt Time-out for a response, internal gEfiMdePkgTokenSpaceGuid.PcdIpmiSsifResponseRetryIntervalMicrosecond|600= 00|UINT32|0x00000036 =20 +[PcdsFixedAtBuild.AARCH64, PcdsPatchableInModule.AARCH64] + ## GUID identifying the Rng algorithm implemented by CPU instruction. + # @Prompt CPU Rng algorithm's GUID. + gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm|{0x00,0x00,0x00,0x0= 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}|VOID*|0x0000= 0037 + [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] ## This value is used to set the base address of PCI express hierarchy. # @Prompt PCI Express Base Address. diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index c8e0ee4ae5d9..d6c2d30195bf 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -79,8 +79,8 @@ [Guids] [Protocols] gEfiRngProtocolGuid ## PRODUCES =20 -[Pcd] - gEfiSecurityPkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm ## CONSUM= ES +[Pcd.AARCH64] + gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm ## CONSUMES =20 [Depex] TRUE diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec index 53aa7ec43557..00c4ebdbed59 100644 --- a/SecurityPkg/SecurityPkg.dec +++ b/SecurityPkg/SecurityPkg.dec @@ -325,8 +325,6 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] gEfiSecurityPkgTokenSpaceGuid.PcdStatusCodeFvVerificationPass|0x0303100A= |UINT32|0x00010030 gEfiSecurityPkgTokenSpaceGuid.PcdStatusCodeFvVerificationFail|0x0303100B= |UINT32|0x00010031 =20 - gEfiSecurityPkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm|{0x00,0x00,0x0= 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}|VOID*|0= x00010032 - [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] ## Image verification policy for OptionRom. Only following values are va= lid:

# NOTE: Do NOT use 0x5 and 0x2 since it violates the UEFI specification= and has been removed.
--=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106858): https://edk2.groups.io/g/devel/message/106858 Mute This Topic: https://groups.io/mt/100099382/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 10 15:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106859+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106859+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168612; cv=none; d=zohomail.com; s=zohoarc; b=Bh3lLi0DIgYk78i94T1jxNByaae6J/nKCC6pIDPNWeRvJ6ba/9Mtt9Pog5i0+uvXjCZWVS1sF9+FaP1Hl65KDVO4lc4Exw7uCqmEAREV7QF+oM7DwaqndybayeEyTCeRbSQiY3Ur7c7bFXULLazjQ8LjC+nZdv7MrAiaZOG8DV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168612; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hFLnI+mMpfpqVkUw4Wbkae8kide6MQioFnCaX0QsRjA=; b=F+P9c47eubOgoTy4xfQAXhlnHgUIt4a0X/IX9JaulbMQk/bAc/x0eO0TQAhRYQYlS9Zib0cdPf2YjoeopSEX09VUojzgQxNQ4iMpOZx6BXT1yXTk4TO19rfGHwtkLA2rk1RHfEkTAXlnCAGGEye1RyhrX8TuWdcB3yU+86HHKjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106859+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689168612775286.1853838711437; Wed, 12 Jul 2023 06:30:12 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=J2Rw+XnsIEDWKjHmUmSwy0ofYuDnnjlDFa2QzRKduA0=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168612; v=1; b=e6S5YyjMMO85jMKwinG3w6gEH0p8+x5J5+nPmLwMfiJu9sCieK1kXbzrwdx1xOlhcHYtU7DE sMup5mPz2Ml89qRceRbS9cTFVTkoXgd4Cx7JyIH+a7y0CADwbiGOUVc4GOVMHS9mN7SRdRYY1Oh guDHzlnhzcr+noo3rsMPvlGI= X-Received: by 127.0.0.2 with SMTP id wqgsYY1788612x5UHFChBg6I; Wed, 12 Jul 2023 06:30:12 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.7379.1689168611892733007 for ; Wed, 12 Jul 2023 06:30:12 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 080F714BF; Wed, 12 Jul 2023 06:30:54 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 05B1C3F67D; Wed, 12 Jul 2023 06:30:08 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 3/8] MdePkg/DxeRngLib: Request raw algorithm instead of default Date: Wed, 12 Jul 2023 15:29:42 +0200 Message-Id: <20230712132947.332643-4-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: rFB15whhYiXg1lXxDU52rfjcx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168614271100015 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The DxeRngLib tries to generate a random number using the 3 NIST SP 800-90 compliant DRBG algorithms, i.e. 256-bits CTR, HASH and HMAC. If none of the call is successful, the fallback option is the default RNG algorithm of the EFI_RNG_PROTOCOL. This default algorithm might be an unsafe implementation. Try requesting the Raw algorithm before requesting the default one. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- MdePkg/Library/DxeRngLib/DxeRngLib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/DxeRngLib/DxeRngLib.c b/MdePkg/Library/DxeRngLi= b/DxeRngLib.c index 46aea515924f..a01b66ad7d20 100644 --- a/MdePkg/Library/DxeRngLib/DxeRngLib.c +++ b/MdePkg/Library/DxeRngLib/DxeRngLib.c @@ -65,9 +65,15 @@ GenerateRandomNumberViaNist800Algorithm ( return Status; } =20 + Status =3D RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmRaw, Buffe= rSize, Buffer); + DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Raw - Status =3D %r\n", __func= __, Status)); + if (!EFI_ERROR (Status)) { + return Status; + } + // If all the other methods have failed, use the default method from the= RngProtocol Status =3D RngProtocol->GetRNG (RngProtocol, NULL, BufferSize, Buffer); - DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status =3D %r\n", _= _func__, Status)); + DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm default - Status =3D %r\n", __= func__, Status)); if (!EFI_ERROR (Status)) { return Status; } --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106859): https://edk2.groups.io/g/devel/message/106859 Mute This Topic: https://groups.io/mt/100099383/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 10 15:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106860+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106860+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168615; cv=none; d=zohomail.com; s=zohoarc; b=IeeU58lP2z7UgyfCYX3TYGZMOCt7KO7HcbNx32RHNIHqMu+LoKj24H1fQHtcYOGED3aclkA/xegendjO+p0ksWvo0qb3evIKZlPTFj71N8WYVTSN7BLaZs0iNNvV0Ch2lGCRwc/LG9BFWzTiKP4+7y4tT00PxKmsYdAj5KzZDZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168615; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Tro6O7K1wi3j8J7iuwYCURDYDQbIotlDoXLooR5BF60=; b=Q7reWJsExPL1V8IoP+ZPwEL+G88a9Ow3HCUqLAh1fxqWLbWQW7cVIlRTyB7Sb9/Kf4JdT9GeM2dNGosYC8Ml8mATXi0MQiY58dwcxe5F1bkbH7vMK7+fbbdoGQLjqRj5yXPmP/6YdDFGnMvCo9k3gHnrd0NVbYO5nPQGcQoccNA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106860+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689168615669136.67544813669633; Wed, 12 Jul 2023 06:30:15 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=st43hh6K6Gl3b4yu+P3iUrLmCZmH5D+9P+VtKX/VgP8=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168615; v=1; b=aP58Md9q/5W7FU7cC8yqC3tCiCKMY5KrOF5nWgJqCjeHDXWKXzUvhwxb1Nf0J7CyrVEh3UGl NFg8vdcNvvCm+/bir44cznLSr3nt4qDUslMF+9430zuP+0k87wA9iZHkB6CWv0KbPdfYrvMFdhY Bv4ZBfnIEc34paGsLZPq3zFI= X-Received: by 127.0.0.2 with SMTP id 6zlUYY1788612xufhrL2z9Bb; Wed, 12 Jul 2023 06:30:15 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.7322.1689168614491636025 for ; Wed, 12 Jul 2023 06:30:14 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B3D6150C; Wed, 12 Jul 2023 06:30:56 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F266D3F67D; Wed, 12 Jul 2023 06:30:11 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 4/8] MdePkg/Rng: Add GUID to describe Arm Rndr Rng algorithms Date: Wed, 12 Jul 2023 15:29:43 +0200 Message-Id: <20230712132947.332643-5-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: UcQRGaPY7ZT4lE5SCTqsMcnVx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168616348100017 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4441 The EFI_RNG_PROTOCOL can rely on the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, a GetRngGuid() function is added in a following patch. Prepare GetRngGuid() return values and add a gEfiRngAlgorithmArmRndr to describe a Rng algorithm accessed through Arm's RNDR instruction. [1] states that the implementation of this algorithm should be compliant to NIST SP900-80. The compliance is not guaranteed. [1] Arm Architecture Reference Manual Armv8, for A-profile architecture sK12.1 'Properties of the generated random number' Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- MdePkg/Include/Protocol/Rng.h | 10 ++++++++++ MdePkg/MdePkg.dec | 1 + 2 files changed, 11 insertions(+) diff --git a/MdePkg/Include/Protocol/Rng.h b/MdePkg/Include/Protocol/Rng.h index baf425587b3c..38bde53240d1 100644 --- a/MdePkg/Include/Protocol/Rng.h +++ b/MdePkg/Include/Protocol/Rng.h @@ -67,6 +67,15 @@ typedef EFI_GUID EFI_RNG_ALGORITHM; { \ 0xe43176d7, 0xb6e8, 0x4827, {0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85,= 0x61 } \ } +/// +/// The Arm Architecture states the RNDR that the DRBG algorithm should be= compliant +/// with NIST SP800-90A, while not mandating a particular algorithm, so as= to be +/// inclusive of different geographies. +/// +#define EFI_RNG_ALGORITHM_ARM_RNDR \ + { \ + 0x43d2fde3, 0x9d4e, 0x4d79, {0x02, 0x96, 0xa8, 0x9b, 0xca, 0x78, 0x08= , 0x41} \ + } =20 /** Returns information about the random number generation implementation. @@ -146,5 +155,6 @@ extern EFI_GUID gEfiRngAlgorithmSp80090Ctr256Guid; extern EFI_GUID gEfiRngAlgorithmX9313DesGuid; extern EFI_GUID gEfiRngAlgorithmX931AesGuid; extern EFI_GUID gEfiRngAlgorithmRaw; +extern EFI_GUID gEfiRngAlgorithmArmRndr; =20 #endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 5b8477f4cb8f..ac54338089e8 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -643,6 +643,7 @@ [Guids] gEfiRngAlgorithmX9313DesGuid =3D { 0x63c4785a, 0xca34, 0x4012, {0x= a3, 0xc8, 0x0b, 0x6a, 0x32, 0x4f, 0x55, 0x46 }} gEfiRngAlgorithmX931AesGuid =3D { 0xacd03321, 0x777e, 0x4d3d, {0x= b1, 0xc8, 0x20, 0xcf, 0xd8, 0x88, 0x20, 0xc9 }} gEfiRngAlgorithmRaw =3D { 0xe43176d7, 0xb6e8, 0x4827, {0x= b7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61 }} + gEfiRngAlgorithmArmRndr =3D { 0x43d2fde3, 0x9d4e, 0x4d79, {0x= 02, 0x96, 0xa8, 0x9b, 0xca, 0x78, 0x08, 0x41 }} =20 ## Include/Protocol/AdapterInformation.h gEfiAdapterInfoMediaStateGuid =3D { 0xD7C74207, 0xA831, 0x4A26, {0= xB1, 0xF5, 0xD1, 0x93, 0x06, 0x5C, 0xE8, 0xB6 }} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106860): https://edk2.groups.io/g/devel/message/106860 Mute This Topic: https://groups.io/mt/100099384/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 10 15:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106861+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106861+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168618; cv=none; d=zohomail.com; s=zohoarc; b=oCscQQROsEWp22GAWx3Csyz6bulkmSvtDgIYzQRYWghr+tDtlsnve1A7E0bXNuYJLGMIv9G+2ce9sMoinmXB6W6KKsW5mYEOdgBkIo9hUG0M8bkpmdzFh36NZm6uAMzrzOYPN3RzA9ZoEFAoEKAPl6qxhjzw3wWUIMds9nylU1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168618; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=/aaJdVGPGn9rSfnZSKtt4JnkajjiG2B+MjUg/IVLO/k=; b=M6562dulK5zY2RASnwEjFvjZ3XYlTKkBqKqTXrLLxGigejEDzyX4nhjRX+ub6uWmRtgNp2UFhM/zvjgrjzG97l4IDQVRgc5VkHMudzByvB76jAb8GWVC+KELtF9cjbozpKjTdTOf5MVvSg+BUX8EvwmLPNJROOekap/kgzsZPBE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106861+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 168916861819122.470679137525394; Wed, 12 Jul 2023 06:30:18 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Py7FtRW3gU2cxT4K54m74QWQKAXh+ciGxMoD19n5atI=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168617; v=1; b=rS8vD0RQEiz26P01qss4Hnr8ANaA0dd3Fs2Bi09SvTIi+kfWxWM9IyTCdh6zLrTsmXfXHaq3 oK5GMK7DyC0HLmZlzSHXlhH3rkL4p9wNnBZNPh3lwG2jZ/1Yi9iHgfbLzDwNwyAEXgwt+n2g3Mu 7LCMW8R9kcFIPm/MoVfLuR4A= X-Received: by 127.0.0.2 with SMTP id 52Y9YY1788612xzLvTVguKOB; Wed, 12 Jul 2023 06:30:17 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.7383.1689168617174089189 for ; Wed, 12 Jul 2023 06:30:17 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3E5D6D75; Wed, 12 Jul 2023 06:30:59 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6F5BA3F67D; Wed, 12 Jul 2023 06:30:14 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 5/8] MdeModulePkg/Rng: Add GUID to describe unsafe Rng algorithms Date: Wed, 12 Jul 2023 15:29:44 +0200 Message-Id: <20230712132947.332643-6-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: 0L09Wb0AmZglAk0KYy5pDQx1x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168618557100021 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4441 The EFI_RNG_PROTOCOL can rely on the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, a GetRngGuid() function is added in a following patch. Prepare GetRngGuid() return values and add a gEdkiiRngAlgorithmUnSafe to describe an unsafe implementation, cf. the BaseRngLibTimerLib. Signed-off-by: Pierre Gondois --- MdeModulePkg/Include/Guid/RngAlgorithm.h | 23 +++++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 MdeModulePkg/Include/Guid/RngAlgorithm.h diff --git a/MdeModulePkg/Include/Guid/RngAlgorithm.h b/MdeModulePkg/Includ= e/Guid/RngAlgorithm.h new file mode 100644 index 000000000000..e2ac2ba3e5c6 --- /dev/null +++ b/MdeModulePkg/Include/Guid/RngAlgorithm.h @@ -0,0 +1,23 @@ +/** @file + Rng Algorithm + + Copyright (c) 2023, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef RNG_ALGORITHM_GUID_H_ +#define RNG_ALGORITHM_GUID_H_ + +/// +/// The implementation of a Random Number Generator might be unsafe, when = using +/// a dummy implementation for instance. Allow identifying such implementa= tion +/// with this GUID. +/// +#define EDKII_RNG_ALGORITHM_UNSAFE \ + { \ + 0x869f728c, 0x409d, 0x4ab4, {0xac, 0x03, 0x71, 0xd3, 0x09, 0xc1, 0xb3,= 0xf4 } \ + } + +extern EFI_GUID gEdkiiRngAlgorithmUnSafe; + +#endif // #ifndef RNG_ALGORITHM_GUID_H_ diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index d65dae18aa81..55617c3f9bd2 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -418,6 +418,9 @@ [Guids] ## Include/Guid/MigratedFvInfo.h gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4,= 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } } =20 + ## Include/Guid/RngAlgorithm.h + gEdkiiRngAlgorithmUnSafe =3D { 0x869f728c, 0x409d, 0x4ab4, {0xac, 0x03, = 0x71, 0xd3, 0x09, 0xc1, 0xb3, 0xf4 }} + # # GUID defined in UniversalPayload # --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106861): https://edk2.groups.io/g/devel/message/106861 Mute This Topic: https://groups.io/mt/100099385/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 10 15:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106862+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106862+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168620; cv=none; d=zohomail.com; s=zohoarc; b=mTvE1kpVB585VsGIQyYk08Ps3IIi75/PGyOqFOQmyP855nK04moI00MJOqsR50YX94cjYDO5jc/I+f2ui4RUBdmuSxoAJb/ysXEQ2UyhjtFpRpv0dzwr9a0Qg/SP6jkamudY44NEJRf30x18NM6y/xmEgtmTjms3b1RlxIuvEFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168620; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=oivnYyN0GpHS+yJ/efXJgjDvDISBsH3aAgajTh2HqsU=; b=eIN7gPMoMnpz6NTdkTQlrN9lZFbGnumYKQx7NzxkPbyJpfrr9nx9jyfFNXHHNXavcMov9Cy+DCsWzvvva0USFpzrsNtkwiON8io8vIC56KdQ6YRcAKZNKJJ3Djnye25Qr+yVIeMqfY7h7TmLEd2ZzxiikuldORO/Msy+/8760Lo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106862+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689168620816437.8579847361209; Wed, 12 Jul 2023 06:30:20 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=bfVzi1KMkytrsmUysElunf2BUUog1I435MCrRxhNGYo=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168620; v=1; b=uSr9e4NLtyq3T+m/MKeCEA/meygWFTQ+G/vMe4U5ju9AlCSa1JOpzAMZu+T7U/ErXiyI03vb 44eUhtJNF26jOc9BGv89qQm0WL1PppnEvKm/EJC4pj2TUGeOTThJw/AP1IWAJje7/5OFEAaSoTx tZYn19SFDk2CEcVixfDG4wBE= X-Received: by 127.0.0.2 with SMTP id xsieYY1788612xS8hroJHEGw; Wed, 12 Jul 2023 06:30:20 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.7385.1689168619817324429 for ; Wed, 12 Jul 2023 06:30:19 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E0AD312FC; Wed, 12 Jul 2023 06:31:01 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1B96E3F67D; Wed, 12 Jul 2023 06:30:16 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 6/8] MdePkg/Rng: Add GetRngGuid() to RngLib Date: Wed, 12 Jul 2023 15:29:45 +0200 Message-Id: <20230712132947.332643-7-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: LT0a882OsM8A7HZQmuPNG9DCx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168621367100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The EFI_RNG_PROTOCOL can use the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, add a GetRngGuid() function to the RngLib. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 4 ++ .../Library/BaseRngLibTimerLib/RngLibTimer.c | 28 +++++++++++++ MdePkg/Include/Library/RngLib.h | 17 ++++++++ MdePkg/Library/BaseRngLib/AArch64/Rndr.c | 42 +++++++++++++++++++ MdePkg/Library/BaseRngLib/BaseRngLib.inf | 10 +++++ MdePkg/Library/BaseRngLib/Rand/RdRand.c | 26 ++++++++++++ .../Library/BaseRngLibNull/BaseRngLibNull.c | 22 ++++++++++ MdePkg/Library/DxeRngLib/DxeRngLib.c | 28 +++++++++++++ 8 files changed, 177 insertions(+) diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf= b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf index f857290e823b..25b04a0c3fce 100644 --- a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -29,6 +29,10 @@ [Sources] =20 [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Guids] + gEdkiiRngAlgorithmUnSafe =20 [LibraryClasses] BaseLib diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdeMod= ulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c index 980854d67b72..28ff46c71fa2 100644 --- a/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c @@ -2,14 +2,18 @@ BaseRng Library that uses the TimerLib to provide reasonably random numb= ers. Do not use this on a production system. =20 + Copyright (c) 2023, Arm Limited. All rights reserved. Copyright (c) Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include +#include #include +#include #include #include +#include =20 #define DEFAULT_DELAY_TIME_IN_MICROSECONDS 10 =20 @@ -190,3 +194,27 @@ GetRandomNumber128 ( // Read second 64 bits return GetRandomNumber64 (++Rand); } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + if (RngGuid =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CopyMem (RngGuid, &gEdkiiRngAlgorithmUnSafe, sizeof (*RngGuid)); + return EFI_SUCCESS; +} diff --git a/MdePkg/Include/Library/RngLib.h b/MdePkg/Include/Library/RngLi= b.h index 429ed19e287e..945482cd5e56 100644 --- a/MdePkg/Include/Library/RngLib.h +++ b/MdePkg/Include/Library/RngLib.h @@ -1,6 +1,7 @@ /** @file Provides random number generator services. =20 +Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2015, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -77,4 +78,20 @@ GetRandomNumber128 ( OUT UINT64 *Rand ); =20 +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ); + #endif // __RNG_LIB_H__ diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c b/MdePkg/Library/Base= RngLib/AArch64/Rndr.c index 20811bf3ebf3..d39db62153ee 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c +++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c @@ -2,6 +2,7 @@ Random number generator service that uses the RNDR instruction to provide pseudorandom numbers. =20 + Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2021, NUVIA Inc. All rights reserved.
Copyright (c) 2015, Intel Corporation. All rights reserved.
=20 @@ -11,6 +12,7 @@ =20 #include #include +#include #include #include =20 @@ -138,3 +140,43 @@ ArchIsRngSupported ( { return mRndrSupported; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + GUID *RngLibGuid; + + if (RngGuid =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (!mRndrSupported) { + return EFI_UNSUPPORTED; + } + + // + // If the platform advertises the algorithm behind RNDR instruction, + // use it. Otherwise use gEfiRngAlgorithmArmRndr. + // + RngLibGuid =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); + if (!IsZeroGuid (RngLibGuid)) { + CopyMem (RngGuid, RngLibGuid, sizeof (*RngGuid)); + } else { + CopyMem (RngGuid, &gEfiRngAlgorithmArmRndr, sizeof (*RngGuid)); + } + + return EFI_SUCCESS; +} diff --git a/MdePkg/Library/BaseRngLib/BaseRngLib.inf b/MdePkg/Library/Base= RngLib/BaseRngLib.inf index 1fcceb941495..49503b139be9 100644 --- a/MdePkg/Library/BaseRngLib/BaseRngLib.inf +++ b/MdePkg/Library/BaseRngLib/BaseRngLib.inf @@ -4,6 +4,7 @@ # BaseRng Library that uses CPU RNG instructions (e.g. RdRand) to # provide random numbers. # +# Copyright (c) 2023, Arm Limited. All rights reserved.
# Copyright (c) 2021, NUVIA Inc. All rights reserved.
# Copyright (c) 2015, Intel Corporation. All rights reserved.
# @@ -43,9 +44,18 @@ [Sources.AARCH64] AArch64/ArmReadIdIsar0.asm | MSFT AArch64/ArmRng.asm | MSFT =20 +[Guids.AARCH64] + gEfiRngAlgorithmArmRndr + +[Guids.Ia32, Guids.X64] + gEfiRngAlgorithmSp80090Ctr256Guid + [Packages] MdePkg/MdePkg.dec =20 +[Pcd.AARCH64] + gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm + [LibraryClasses] BaseLib DebugLib diff --git a/MdePkg/Library/BaseRngLib/Rand/RdRand.c b/MdePkg/Library/BaseR= ngLib/Rand/RdRand.c index 070d41e2555f..9bd68352f9f7 100644 --- a/MdePkg/Library/BaseRngLib/Rand/RdRand.c +++ b/MdePkg/Library/BaseRngLib/Rand/RdRand.c @@ -2,6 +2,7 @@ Random number generator services that uses RdRand instruction access to provide high-quality random numbers. =20 +Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2021, NUVIA Inc. All rights reserved.
Copyright (c) 2015, Intel Corporation. All rights reserved.
=20 @@ -11,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include +#include #include =20 #include "BaseRngLibInternals.h" @@ -128,3 +130,27 @@ ArchIsRngSupported ( */ return TRUE; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + if (RngGuid =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CopyMem (RngGuid, &gEfiRngAlgorithmSp80090Ctr256Guid, sizeof (*RngGuid)); + return EFI_SUCCESS; +} diff --git a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c b/MdePkg/Librar= y/BaseRngLibNull/BaseRngLibNull.c index efba5c851ead..af5e8eb8f72a 100644 --- a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c +++ b/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c @@ -1,13 +1,16 @@ /** @file Null version of Random number generator services. =20 +Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 +#include #include #include +#include =20 /** Generates a 16-bit random number. @@ -92,3 +95,22 @@ GetRandomNumber128 ( ASSERT (FALSE); return FALSE; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/MdePkg/Library/DxeRngLib/DxeRngLib.c b/MdePkg/Library/DxeRngLi= b/DxeRngLib.c index a01b66ad7d20..cd23859e3112 100644 --- a/MdePkg/Library/DxeRngLib/DxeRngLib.c +++ b/MdePkg/Library/DxeRngLib/DxeRngLib.c @@ -1,6 +1,7 @@ /** @file Provides an implementation of the library class RngLib that uses the Rng = protocol. =20 + Copyright (c) 2023, Arm Limited. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -207,3 +208,30 @@ GetRandomNumber128 ( =20 return TRUE; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + /* It is not possible to know beforehand which Rng algorithm will + be used by this library. + This API is mainly used by RngDxe. RngDxe relies on the RngLib. + The RngLib|DxeRngLib.inf implementation locates and uses an installed + EFI_RNG_PROTOCOL. + It is thus not possible to have both RngDxe and RngLib|DxeRngLib.inf. + and it is ok not to support this API. + */ + return EFI_UNSUPPORTED; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106862): https://edk2.groups.io/g/devel/message/106862 Mute This Topic: https://groups.io/mt/100099388/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 10 15:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106863+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106863+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168623; cv=none; d=zohomail.com; s=zohoarc; b=WixcUJk/2+wCsux/Lqxry2c/a6d0MjCmO1WffohNFnQTu1vla0Q/skDflzzp2ktcrSJgtU/bxfwDMASJfQnGy0Aadq0arNcw1XdM2vCbCKmgHjbXvy8Zg3EzXGSI4OwVomgXJhh+grv9FRX6S5lc7Odl0N3gP1k6FtgpjknZ8IQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168623; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5YH+1miVm0VCcR1Ep8VkFZqChD/MmUN/LR7SRiU86lo=; b=IX7VfgsJsvogjkUCaRQTclYDJNasWXxLQB4Oly4m3pNgeytGvwu3kVHL9eJNyJ7br+k1rO0iQd9UqM8hML9U+5jsir/ANVRCB9j4K39AT++gHD2LDKGv37oNtNxBOE2TOiZt2LymG4q2W7UQjZX9tZk3Cfn0lmNkIgTd1KAN7/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106863+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689168623097225.57580492817158; Wed, 12 Jul 2023 06:30:23 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=dJZqER0AN1GooImEF4zGofNSOCE6SZE9hbKMz5oQgPE=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168622; v=1; b=bdcfQUSbl98wRvfBUrmGM4WYOrt3HDbXoutP1vpZeu/z3zr7dZzT1ql6il2wamxy1Hz4t/YY Ok7Xz/XMsw2Mg5bjTbRs7R/2I+ZF+OwAQ0Sj4Qtks0T53VBvFl+y1aw5yHhRJosQCF2jHoOQaDD Cw62od1tVPff6QYCiMpmmbBM= X-Received: by 127.0.0.2 with SMTP id kumEYY1788612x3fFzIRSkmj; Wed, 12 Jul 2023 06:30:22 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.7332.1689168621983706548 for ; Wed, 12 Jul 2023 06:30:22 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 29D0B1480; Wed, 12 Jul 2023 06:31:04 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BD60A3F67D; Wed, 12 Jul 2023 06:30:19 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 7/8] SecurityPkg/RngDxe: Use GetRngGuid() when probing RngLib Date: Wed, 12 Jul 2023 15:29:46 +0200 Message-Id: <20230712132947.332643-8-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: mNG8mI63TJf9xoXlaqrahp3ox1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168625129100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4151 The EFI_RNG_PROTOCOL can rely on the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, a GetRngGuid() function was added in a previous patch. The EFI_RNG_PROTOCOL can advertise multiple algorithms through Guids. The PcdCpuRngSupportedAlgorithm is currently used to advertise the RngLib in the Arm implementation. The issues of doing that are: - the RngLib implementation might not use CPU instructions, cf. the BaseRngLibTimerLib - most platforms don't set PcdCpuRngSupportedAlgorithm A GetRngGuid() was added to the RngLib in a previous patch, allowing to identify the algorithm implemented by the RngLib. Make use of this function and place the unsage algorithm at the last position in the mAvailableAlgoArray. Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/AArch64Algo.c | 55 +++++++++++++------ .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 6 +- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 5 +- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c= b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c index e8be217f8a8c..a270441ebba0 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include =20 #include "RngDxeInternals.h" =20 @@ -28,9 +30,13 @@ GetAvailableAlgorithms ( VOID ) { - UINT64 DummyRand; - UINT16 MajorRevision; - UINT16 MinorRevision; + EFI_STATUS Status; + UINT16 MajorRevision; + UINT16 MinorRevision; + GUID RngGuid; + BOOLEAN UnSafeAlgo; + + UnSafeAlgo =3D FALSE; =20 // Rng algorithms 2 times, one for the allocation, one to populate. mAvailableAlgoArray =3D AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX); @@ -38,24 +44,29 @@ GetAvailableAlgorithms ( return EFI_OUT_OF_RESOURCES; } =20 - // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. - if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) { - CopyMem ( - &mAvailableAlgoArray[mAvailableAlgoArrayCount], - PcdGetPtr (PcdCpuRngSupportedAlgorithm), - sizeof (EFI_RNG_ALGORITHM) - ); - mAvailableAlgoArrayCount++; - - DEBUG_CODE_BEGIN (); - if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { + // Identify RngLib algorithm. + Status =3D GetRngGuid (&RngGuid); + if (!EFI_ERROR (Status)) { + if (IsZeroGuid (&RngGuid) || + CompareGuid (&RngGuid, &gEdkiiRngAlgorithmUnSafe)) + { + // Treat zero GUID as an unsafe algorithm DEBUG (( DEBUG_WARN, - "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" + "RngLib uses an Unsafe algorithm and " + "must not be used for production builds.\n" )); + // Set the UnSafeAlgo flag to indicate an unsafe algorithm was found + // so that it can be added at the end of the algorithm list. + UnSafeAlgo =3D TRUE; + } else { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &RngGuid, + sizeof (RngGuid) + ); + mAvailableAlgoArrayCount++; } - - DEBUG_CODE_END (); } =20 // Raw algorithm (Trng) @@ -68,5 +79,15 @@ GetAvailableAlgorithms ( mAvailableAlgoArrayCount++; } =20 + // Add unsafe algorithm at the end of the list. + if (UnSafeAlgo) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &gEdkiiRngAlgorithmUnSafe, + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + return EFI_SUCCESS; } diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index ce49ff7ae661..78a18c5e1177 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -78,6 +78,7 @@ RngGetRNG ( { EFI_STATUS Status; UINTN Index; + GUID RngGuid; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; @@ -102,7 +103,10 @@ RngGetRNG ( } =20 FoundAlgo: - if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)))= { + Status =3D GetRngGuid (&RngGuid); + if (!EFI_ERROR (Status) && + CompareGuid (RNGAlgorithm, &RngGuid)) + { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; } diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index d6c2d30195bf..27d3e39a675b 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -75,13 +75,12 @@ [Guids] gEfiRngAlgorithmX9313DesGuid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG gEfiRngAlgorithmX931AesGuid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG gEfiRngAlgorithmRaw ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG + gEfiRngAlgorithmArmRndr ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG + gEdkiiRngAlgorithmUnSafe ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG =20 [Protocols] gEfiRngProtocolGuid ## PRODUCES =20 -[Pcd.AARCH64] - gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm ## CONSUMES - [Depex] TRUE =20 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106863): https://edk2.groups.io/g/devel/message/106863 Mute This Topic: https://groups.io/mt/100099395/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri May 10 15:41:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+106864+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106864+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689168625; cv=none; d=zohomail.com; s=zohoarc; b=NA11QcC50T8HLF2IJMU5kOuEUcbtbNzctsWH+lOI6IyMFvoNBntYWEf/7ZNgMqFvfyFA7FsrA8iMO2MY26UWE4be/UyKwu9GPD9XJi2037hddWxom4GpGQiRvFVMTTRncsdopyLxcFltSY617KJuE8jWKj68XOASXOstBx1DK0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689168625; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6A4fPxm+iX4xAozO4U9vVG7m9ru3uG9jsStr5bFwrGU=; b=aRFwibnc5ZjIfwSJIJfoN9nOzjqAei8vhR+P+bOg5MQPCY35Acpxbd2emtbm+/bZ/bgnnkJmpKsClemdOqD0kGt3+oP0W1GbsB5TFTAc3WSiXr8vRpuy0xY+6DKIiAYwwJEQnsBzh7A//XVN5vJDJJkL5xCeYVdxUON92CeUhmA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+106864+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1689168625417925.7076462383399; Wed, 12 Jul 2023 06:30:25 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=9Jd92mUp7uWaMgRJ8rJfyz1y6iJcKT+7aXufY86onlo=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689168625; v=1; b=r7+NsWYshod4TPf6m/iOuvBzp/05Pn+K/+zxfdit3xbSmVgfPgF5hZGSf3Tjd9BFHP0u2hsR rEjBbyEia3JBqrgIzUn9PIMWh1YNkksY5iVPFXxuKP56Nzm90zXQA2cK5l255pYjQuP+TAJtXMF GY8bYddurN2jn3LdbUxUi4Yw= X-Received: by 127.0.0.2 with SMTP id M2lnYY1788612xjNJ6A3ImOH; Wed, 12 Jul 2023 06:30:25 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.7392.1689168624456375518 for ; Wed, 12 Jul 2023 06:30:24 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9A41DD75; Wed, 12 Jul 2023 06:31:06 -0700 (PDT) X-Received: from e126645.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0FA053F7C5; Wed, 12 Jul 2023 06:30:21 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Jose Marinho , Kun Qin , pierre.gondois@arm.com Subject: [edk2-devel] [PATCH v4 8/8] SecurityPkg/RngDxe: Simplify Rng algorithm selection for Arm Date: Wed, 12 Jul 2023 15:29:47 +0200 Message-Id: <20230712132947.332643-9-pierre.gondois@arm.com> In-Reply-To: <20230712132947.332643-1-pierre.gondois@arm.com> References: <20230712132947.332643-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: uam341Qx2bAz40d8ALJ310qlx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689168627438100006 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The first element of mAvailableAlgoArray is defined as the default Rng algorithm to use. Don't go through the array at each RngGetRNG() call and just return the first element of the array. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index 78a18c5e1177..7a42e3cbe3d2 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -77,7 +77,6 @@ RngGetRNG ( ) { EFI_STATUS Status; - UINTN Index; GUID RngGuid; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { @@ -88,21 +87,13 @@ RngGetRNG ( // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - for (Index =3D 0; Index < mAvailableAlgoArrayCount; Index++) { - if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { - RNGAlgorithm =3D &mAvailableAlgoArray[Index]; - goto FoundAlgo; - } - } - - if (Index =3D=3D mAvailableAlgoArrayCount) { - // No algorithm available. - ASSERT (Index !=3D mAvailableAlgoArrayCount); - return EFI_DEVICE_ERROR; + if (mAvailableAlgoArrayCount !=3D 0) { + RNGAlgorithm =3D &mAvailableAlgoArray[0]; + } else { + return EFI_UNSUPPORTED; } } =20 -FoundAlgo: Status =3D GetRngGuid (&RngGuid); if (!EFI_ERROR (Status) && CompareGuid (RNGAlgorithm, &RngGuid)) --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#106864): https://edk2.groups.io/g/devel/message/106864 Mute This Topic: https://groups.io/mt/100099396/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-