From nobody Fri May 17 07:07:51 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+90846+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+90846+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515038; cv=none; d=zohomail.com; s=zohoarc; b=fdYY/k0jhNwFaCWvfQQgAQqL+dbzA/C/rEI3e9Cf+iBVA9LyBRXJRbSJ76+C/wAqipejG10SfMnrW69InliA1FSV0p+0Ghp8QFV/UN6tIfWvUQ6y2VqdIh8BgJPiUl3keJWaF47SL6NsWAKlAKh2nmBnc2+2ut8lXE1e+Jj52kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515038; 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=4t6NUzTaXz/mB0yhIHNYr/J5DaoRnoSbkYbYbIRQoig=; b=eIUH4W4G+GKxasHiZjHg4e3q4/1b8cfP7JWBhIEfhzCWeNIhV6cuygMcKwRodW+HjvUZmtWK+OlaJRPtps1Mbljj6Gp2whg3PCFKGz5AQwsmgjIqjePnXAdn5SaKwUp+eC1v02JLtpm63/DRAzE/EycAoA7rIOhJCQo0LLQcoXA= 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+90846+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 1656515038013599.1429634712887; Wed, 29 Jun 2022 08:03:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id rZKfYY1788612xn8tLKrriKz; Wed, 29 Jun 2022 08:03:57 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12706.1656515036581254139 for ; Wed, 29 Jun 2022 08:03:57 -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 52863153B; Wed, 29 Jun 2022 08:03:56 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6C8D13F792; Wed, 29 Jun 2022 08:03:54 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 01/22] ArmPkg: PCD to select conduit for monitor calls Date: Wed, 29 Jun 2022 17:02:10 +0200 Message-Id: <20220629150241.2597898-2-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: H8wfBVwHjs1rKdD8YR6LO5wex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515037; bh=hDA0SYJ1mfDTq6EFbxEqBSZYSjoA+yULwLO9nz/SS98=; h=Cc:Date:From:Reply-To:Subject:To; b=AXjtBSuh6Jwp1aokT7KtMymO8NExmC32AoJXSpkNRGkIhPkSOqYF4hqk/exchoJE51E hHX7dMwK6UlKZspD7EduRwyI6rtdrP4ERZG73FtXxSMWOMoEetqJ9hhFfKPHpR19YxXaN j2vgfSJf7GwmMEilPu2MzFLAQjnnatFIYfo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515038507100003 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Define a PCD 'PcdMonitorConduitHvc' to select the conduit to use for monitor calls. PcdMonitorConduitHvc is defined as FALSE by default, meaning the SMC conduit is enabled as default. Adding PcdMonitorConduitHvc allows selection of HVC conduit to be used by virtual firmware implementations. Signed-off-by: Sami Mujawar --- ArmPkg/ArmPkg.dec | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 9da1bbc9f216..bb5cbecbc228 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -2,7 +2,7 @@ # ARM processor package. # # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.
-# Copyright (c) 2011 - 2021, ARM Limited. All rights reserved. +# Copyright (c) 2011 - 2022, ARM Limited. All rights reserved. # Copyright (c) 2021, Ampere Computing LLC. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -132,6 +132,11 @@ [PcdsFeatureFlag.common] # Define if the GICv3 controller should use the GICv2 legacy gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x00000042 =20 + ## Define the conduit to use for monitor calls. + # Default PcdMonitorConduitHvc =3D FALSE, conduit =3D SMC + # If PcdMonitorConduitHvc =3D TRUE, conduit =3D HVC + gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x00000047 + [PcdsFeatureFlag.ARM] # Whether to map normal memory as non-shareable. FALSE is the safe choic= e, but # TRUE may be appropriate to fix performance problems if you don't care = about --=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 (#90846): https://edk2.groups.io/g/devel/message/90846 Mute This Topic: https://groups.io/mt/92066720/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 17 07:07:51 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+90847+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+90847+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515039; cv=none; d=zohomail.com; s=zohoarc; b=gDy/IbpwsoekMuF+zQea1juEIGfAvL2TI9fbZsKW+YeDQbWPESX78VVjnSrGikD6dEeqlz99PdCmeJMwm80eTs4iX2S+01cPZ5IGJQb1WPU1dW/jgdPcK85/I6Mtq6Jm3umZFLFOdV0cBW8eEcXyzSqjhq0xniXHZUu9XnA+UIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515039; 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=GWfvyuoELmw5eV8s+d3vnsv54vYNX+OOxaBn4xTZCs4=; b=X9OaSNM8e1wc+SNNgk8pYPN9fesdhOlGE7hPr0QfeoQQV1i7lfZ6FogyyX5KtIrzDtcDdfi4kMiG9IndWmOlfHUUFBoRBcjboCka1DmXpUEFM72xRwh6JNAGXcDvkv/+N3DkRKT7/iCSevLxsSw/83hsfyw2FKOQrTzZ2RArfqg= 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+90847+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 1656515039787585.4950782610589; Wed, 29 Jun 2022 08:03:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Vc9LYY1788612xoJQK1KHz74; Wed, 29 Jun 2022 08:03:59 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.12643.1656515038526075165 for ; Wed, 29 Jun 2022 08:03:58 -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 6D9791691; Wed, 29 Jun 2022 08:03:58 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5ACAC3F792; Wed, 29 Jun 2022 08:03:56 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 02/22] ArmPkg/ArmMonitorLib: Definition for ArmMonitorLib library class Date: Wed, 29 Jun 2022 17:02:11 +0200 Message-Id: <20220629150241.2597898-3-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: ge8Qr99wDWlc1AN7aS2w9WNex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515039; bh=pKeB1CAi6/tOKsL7nzddaJyfl1egphL6PV26Atv6Fhc=; h=Cc:Date:From:Reply-To:Subject:To; b=GlTIlp88W1FJbycJVRUEb3Swln0dVUoj0SnNCP3SYzR1wUcRmo2/YaxpbhMuyGyXttm 9wjjYFf9HsAFoXJ+0+RqQH55j3G6tCgMwefnuOrLNxpEXR9GUVbCwKYbcAmD9v8QyfA9P y6MUmsiIJf2yARFQ27PJPIuak7pJ6mhlTFY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515040353100009 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The ArmMonitorLib provides an abstract interface to issue an HyperVisor Call (HVC) or System Monitor Call (SMC) depending on the default conduit. The PcdMonitorConduitHvc PCD allows to select the default conduit. The new library relies on the ArmHvcLib and ArmSmcLib libraries. A Null instance of these libraries can be used for the unused conduit. Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dec | 5 +++ ArmPkg/Include/Library/ArmMonitorLib.h | 42 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 ArmPkg/Include/Library/ArmMonitorLib.h diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index bb5cbecbc228..653942ff63c3 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -71,6 +71,11 @@ [LibraryClasses.common] # ArmSvcLib|Include/Library/ArmSvcLib.h =20 + ## @libraryclass Provides a Monitor Call interface that will use the + # default conduit (HVC or SMC). + # + ArmMonitorLib|Include/Library/ArmMonitorLib.h + ## @libraryclass Provides a default exception handler. # DefaultExceptionHandlerLib|Include/Library/DefaultExceptionHandlerLib.h diff --git a/ArmPkg/Include/Library/ArmMonitorLib.h b/ArmPkg/Include/Librar= y/ArmMonitorLib.h new file mode 100644 index 000000000000..8bc430f92036 --- /dev/null +++ b/ArmPkg/Include/Library/ArmMonitorLib.h @@ -0,0 +1,42 @@ +/** @file + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef ARM_MONITOR_LIB_H_ +#define ARM_MONITOR_LIB_H_ + +/** The size of the SMC arguments is different between AArch64 and AArch32. + + The native size is used for the arguments. + It will be casted to either HVC or SMC args. +*/ +typedef struct { + UINTN Arg0; + UINTN Arg1; + UINTN Arg2; + UINTN Arg3; + UINTN Arg4; + UINTN Arg5; + UINTN Arg6; + UINTN Arg7; +} ARM_MONITOR_ARGS; + +/** Monitor call. + + An HyperVisor Call (HVC) or System Monitor Call (SMC) will be issued + depending on the default conduit. PcdMonitorConduitHvc determines the ty= pe + of the call: if true, do an HVC. + + @param [in, out] Args Arguments for the HVC/SMC. +**/ +VOID +EFIAPI +ArmMonitorCall ( + IN OUT ARM_MONITOR_ARGS *Args + ); + +#endif // ARM_MONITOR_LIB_H_ --=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 (#90847): https://edk2.groups.io/g/devel/message/90847 Mute This Topic: https://groups.io/mt/92066721/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 17 07:07:51 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+90848+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+90848+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515041; cv=none; d=zohomail.com; s=zohoarc; b=ZTO4FOoph9Lj598yr4p6amf3MtzL9qAVEutiEuPEiLw9bXye3U6p+Oc2J7V7/itrYasF0xsOMq84YVFfhtmPqXtzZRC2ecJBV8P40HZOBWogqR8T9WTU1lxfQ00mEv0Hb/fAx2IqK3PKbuubRnUdkepmxLSuYSGyiNoKje17sWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515041; 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=Gp/Ya+nh14CKmRdKHhtCsj3EwE/XQRaxbmjwtohjedU=; b=ZeQhF1KLK7uK/dSpbfGn1JZkERPTOay33Hu4Oy5UL4UzVGPNyify9cQUHCBRlBYXW1q2pldSP04WzWllrGjmwrF05/U2q+jGH5ULOVVSgXizEjMA0eUnu8JqpHmFgxLgF672Q21zY3QcbfLWAtuJy5xY23bm2gJlHqHoPVNxJU0= 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+90848+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 165651504150674.2566817170075; Wed, 29 Jun 2022 08:04:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OEmWYY1788612xf7cYyLUNvw; Wed, 29 Jun 2022 08:04:01 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12708.1656515040388565831 for ; Wed, 29 Jun 2022 08:04:00 -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 39D0E169C; Wed, 29 Jun 2022 08:04:00 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 71CD43F792; Wed, 29 Jun 2022 08:03:58 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 03/22] ArmPkg/ArmMonitorLib: Add ArmMonitorLib Date: Wed, 29 Jun 2022 17:02:12 +0200 Message-Id: <20220629150241.2597898-4-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: 28nHy7n43GljpdxlRXtU9JY2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515041; bh=ae+hJwaNXiB8WWMvVa1E72iN4MfpuUmSBHfaFbIoClk=; h=Cc:Date:From:Reply-To:Subject:To; b=Q46qI+MrChABmjeaOYvhwOZDygA0+E6kC7BzC+VIowu3LQmVZ62FoXx7kOrJcSBkkiL k1pnDkg5CDznefaaICwRta++1jCqaWcAzwm9fWL4tWt2yJZVyC6wDeVvj12cp8tUa4qUk ED/UiIKXJYtCsqUNPsgKVvab5AEa923AOfg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515042374100013 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The ArmMonitorLib provides an abstract interface to issue an HyperVisor Call (HVC) or System Monitor Call (SMC) depending on the default conduit. The PcdMonitorConduitHvc PCD allows to select the default conduit. Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c | 34 +++++++++++++++++++ .../Library/ArmMonitorLib/ArmMonitorLib.inf | 29 ++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c create mode 100644 ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 59fd8f295d4f..3afd212f472b 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -135,6 +135,7 @@ [Components.common] ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf + ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/OpteeLib/OpteeLib.inf =20 ArmPkg/Filesystem/SemihostFs/SemihostFs.inf diff --git a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c b/ArmPkg/Library/= ArmMonitorLib/ArmMonitorLib.c new file mode 100644 index 000000000000..5e91f2957325 --- /dev/null +++ b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c @@ -0,0 +1,34 @@ +/** @file + Arm Monitor Library. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** Monitor call. + + An HyperVisor Call (HVC) or System Monitor Call (SMC) will be issued + depending on the default conduit. PcdMonitorConduitHvc determines the ty= pe + of the call: if true, do an HVC. + + @param [in, out] Args Arguments for the HVC/SMC. +**/ +VOID +EFIAPI +ArmMonitorCall ( + IN OUT ARM_MONITOR_ARGS *Args + ) +{ + if (FeaturePcdGet (PcdMonitorConduitHvc)) { + ArmCallHvc ((ARM_HVC_ARGS *)Args); + } else { + ArmCallSmc ((ARM_SMC_ARGS *)Args); + } +} diff --git a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf b/ArmPkg/Librar= y/ArmMonitorLib/ArmMonitorLib.inf new file mode 100644 index 000000000000..abaeb556d471 --- /dev/null +++ b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf @@ -0,0 +1,29 @@ +## @file +# Arm Monitor Library +# +# Copyright (c) 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D ArmMonitorLib + FILE_GUID =3D F918DACB-FBB8-4CB6-A61D-08E75AF0E7CD + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ArmMonitorLib + +[Sources] + ArmMonitorLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmHvcLib + ArmSmcLib + +[Pcd] + gArmTokenSpaceGuid.PcdMonitorConduitHvc --=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 (#90848): https://edk2.groups.io/g/devel/message/90848 Mute This Topic: https://groups.io/mt/92066723/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 17 07:07:51 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+90849+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+90849+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515043; cv=none; d=zohomail.com; s=zohoarc; b=GD3IBkE6HgpfFbQxu4IbaffyaU6hswOxk2Ndd1vv5Xy6miVR6an2CCeX0iGinsmIBcsMejAz+XBpeSXmPlnqcI1YVrtbLRgSkTFTL+tSmOU6tNtfCpanEblAGKb5aws0eNUslw6A+1lsJt2lcqPnW6DWJfXIJFIgunKMxvDaEk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515043; 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=KVgquBdil7pfK0SLAfo0SuV+PPwPDbiqpdllWjh6Prk=; b=GvhDIBDEPo3voWuQdSM5GutRVMA5xrl7+/isVj7kpk6fWaxVZW2nocOTkdPPr8q5Q1f1A57ujkSVuo+ihCOYu5LUUy6VW9ynCDPdZginhAsB/DCyKiBNsyX/zcQX5f8LNJ3IBSZvIcQvs+sx8+mNNc5pPaBCjlctpazRuqfnzXQ= 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+90849+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 1656515043876220.5578332716774; Wed, 29 Jun 2022 08:04:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UuH2YY1788612xAGK1grVqfT; Wed, 29 Jun 2022 08:04:03 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12725.1656515042780980093 for ; Wed, 29 Jun 2022 08:04:02 -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 A55861758; Wed, 29 Jun 2022 08:04:02 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4263D3F792; Wed, 29 Jun 2022 08:04:00 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 04/22] ArmPkg/ArmHvcNullLib: Add NULL instance of ArmHvcLib Date: Wed, 29 Jun 2022 17:02:13 +0200 Message-Id: <20220629150241.2597898-5-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: 2Lwq5okEsSkfJVpOSy4gdEm8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515043; bh=IwrnGoLWBKSQenfMSUbSLGROJKqTav7RAHvGhhrzNT4=; h=Cc:Date:From:Reply-To:Subject:To; b=LWHZmYhKzgjiM6vuOgYn4Uec7gMhML6RNwLsKqr2xrl3/vMf3OPZo19LhGbvhy65wMX DhJOuFH7ldRDEpZXugdVO5/D9uAzs6vgurL5NmFR1CySxxEew8Qdjz/AVBfid0aWVyVza xEvZNzHD4l3qPOUYIjFLojbQlRMsx1QvWa8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515044389100017 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add a Null instance of ArmHvcLib in case of library dependencies. Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.c | 29 +++++++++++++++++++ .../Library/ArmHvcNullLib/ArmHvcNullLib.inf | 22 ++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.c create mode 100644 ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.inf diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 3afd212f472b..e33b40f2c215 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -134,6 +134,7 @@ [Components.common] ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf + ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.inf ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/OpteeLib/OpteeLib.inf diff --git a/ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.c b/ArmPkg/Library/= ArmHvcNullLib/ArmHvcNullLib.c new file mode 100644 index 000000000000..6905631ccb6c --- /dev/null +++ b/ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.c @@ -0,0 +1,29 @@ +/** @file + Arm HyperVisor Call (HVC) Null Library. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +/** + Trigger an HVC call + + HVC calls can take up to 8 arguments and return up to 4 return values. + Therefore, the 4 first fields in the ARM_HVC_ARGS structure are used + for both input and output values. + + @param [in, out] Args Arguments for the HVC call. +**/ +VOID +ArmCallHvc ( + IN OUT ARM_HVC_ARGS *Args + ) +{ + ASSERT (FALSE); + return; +} diff --git a/ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.inf b/ArmPkg/Librar= y/ArmHvcNullLib/ArmHvcNullLib.inf new file mode 100644 index 000000000000..c4665d34018b --- /dev/null +++ b/ArmPkg/Library/ArmHvcNullLib/ArmHvcNullLib.inf @@ -0,0 +1,22 @@ +## @file +# Arm Hvc Null Library +# +# Copyright (c) 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D ArmHvcNullLib + FILE_GUID =3D 02076A46-D6DB-48DD-8E5F-153172DD73A1 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ArmHvcLib + +[Sources] + ArmHvcNullLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec --=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 (#90849): https://edk2.groups.io/g/devel/message/90849 Mute This Topic: https://groups.io/mt/92066724/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 17 07:07:51 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+90850+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+90850+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515046; cv=none; d=zohomail.com; s=zohoarc; b=HSee6KtonmXFK9YQoZqUFrRskoSg2cdlPEzkF4hIdOUFZ7gtGUWdBiD2TcTtsPirRKQ9JUYi1wlPGGNYXvQ8+7zml9Y1aRXK4DOcb4oiHAwj6GoRJti95/kxZCOmMOaRkfgARRDhYF6Oagjj9riaXAd7zKX/OauXtSWGnD6If34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515046; 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=bKXbTAMQKxU7BmrcPU1EzBaTc3PG2JgrNhoe+4bavuk=; b=YfShOiyb0ObGtijmfFhdvfWVT1z5LXbKpph83r8AT0gTskHZzjgiXdrUqiAin9C0mEypgP31tTb74Id+BmTSOrUY0JiqGCOWKER/lI7gpPp9fsRU58QXaPhCYEWbEARlaaHmDgq15c3v57uRKT+QWlVj3684W16Gc+a9PNYPf3s= 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+90850+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 1656515046976831.2884525431575; Wed, 29 Jun 2022 08:04:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pkGoYY1788612xZfdIJzUgEa; Wed, 29 Jun 2022 08:04:06 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12726.1656515045210728639 for ; Wed, 29 Jun 2022 08:04:05 -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 22E79175A; Wed, 29 Jun 2022 08:04:05 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CD3B13F792; Wed, 29 Jun 2022 08:04:02 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 05/22] MdePkg/TrngLib: Definition for TRNG library class interface Date: Wed, 29 Jun 2022 17:02:14 +0200 Message-Id: <20220629150241.2597898-6-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: RvtaPJhZAl2hXjvFo1LkFjDHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515046; bh=Xl+JFxkFmkbPseT9qTIuLDNPeJQXcbYcdTypGQATgWA=; h=Cc:Date:From:Reply-To:Subject:To; b=PskXAEjgFKOygIyyjLs5L5cjPJMkkpy3StGgEck8J+EhUjYjfgb3s21GWzskXjHCwe0 Yj/Fky3PXaqQjzLdzHXbFaJI9QA5LWNPAvAM/ARqLW8Gb7hKcQFyq9pnOiQqcM5vWpUlz 1CUSzhNChpRduf4QKd9fMk0X7Im7an5DUfc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515048420100001 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The NIST Special Publications 800-90A, 800-90B and 800-90C provide recommendations for random number generation. The NIST 800-90C, Recommendation for Random Bit Generator (RBG) Constructions, defines the GetEntropy() interface that is used to access the entropy source. The GetEntropy() interface is further used by Deterministic Random Bit Generators (DRBG) to generate random numbers. The True Random Number Generator (TRNG) library defines an interface to access the entropy source on a platform. Some platforms/architectures may provide access to the entropy using a firmware interface. In such cases the TRNG library shall be used to provide an abstraction. Signed-off-by: Sami Mujawar --- MdePkg/Include/Library/TrngLib.h | 121 +++++++++++++++++++++++++++++++ MdePkg/MdePkg.dec | 5 ++ 2 files changed, 126 insertions(+) create mode 100644 MdePkg/Include/Library/TrngLib.h diff --git a/MdePkg/Include/Library/TrngLib.h b/MdePkg/Include/Library/Trng= Lib.h new file mode 100644 index 000000000000..a6f165b1f918 --- /dev/null +++ b/MdePkg/Include/Library/TrngLib.h @@ -0,0 +1,121 @@ +/** @file + TRNG interface library definitions. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] Arm True Random Number Generator Firmware, Interface 1.0, + Platform Design Document. + (https://developer.arm.com/documentation/den0098/latest/) + - [2] NIST Special Publication 800-90A Revision 1, June 2015, Recommenda= tion + for Random Number Generation Using Deterministic Random Bit Genera= tors. + (https://csrc.nist.gov/publications/detail/sp/800-90a/rev-1/final) + - [3] NIST Special Publication 800-90B, Recommendation for the Entropy + Sources Used for Random Bit Generation. + (https://csrc.nist.gov/publications/detail/sp/800-90b/final) + - [4] (Second Draft) NIST Special Publication 800-90C, Recommendation for + Random Bit Generator (RBG) Constructions. + (https://csrc.nist.gov/publications/detail/sp/800-90c/draft) + + @par Glossary: + - TRNG - True Random Number Generator +**/ + +#ifndef TRNG_LIB_H_ +#define TRNG_LIB_H_ + +/** Get the version of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the version of the TRNG backend. + The implementation must return NOT_SUPPORTED if a Back end is not presen= t. + + @param [out] MajorRevision Major revision. + @param [out] MinorRevision Minor revision. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Backend not present. +**/ +RETURN_STATUS +EFIAPI +GetTrngVersion ( + OUT UINT16 *MajorRevision, + OUT UINT16 *MinorRevision + ); + +/** Get the UUID of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the UUID of the TRNG backend. + Returning the TRNG UUID is optional and if not implemented, RETURN_UNSUP= PORTED + shall be returned. + + Note: The caller must not rely on the returned UUID as a trustworthy TRNG + Back end identity + + @param [out] Guid UUID of the TRNG backend. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +RETURN_STATUS +EFIAPI +GetTrngUuid ( + OUT GUID *Guid + ); + +/** Returns maximum number of entropy bits that can be returned in a single + call. + + @return Returns the maximum number of Entropy bits that can be returned + in a single call to GetTrngEntropy(). +**/ +UINTN +EFIAPI +GetTrngMaxSupportedEntropyBits ( + VOID + ); + +/** Returns N bits of conditioned entropy. + + See [3] Section 2.3.1 GetEntropy: An Interface to the Entropy Source + GetEntropy + Input: + bits_of_entropy: the requested amount of entropy + Output: + entropy_bitstring: The string that provides the requested entropy. + status: A Boolean value that is TRUE if the request has been satisfi= ed, + and is FALSE otherwise. + + Note: In this implementation this function returns a status code instead + of a boolean value. + This is also compatible with the definition of Get_Entropy, see [4] + Section 7.4 Entropy Source Calls. + (status, entropy_bitstring) =3D Get_Entropy ( + requested_entropy, + max_length + ) + + @param [in] EntropyBits Number of entropy bits requested. + @param [in] BufferSize Size of the Buffer in bytes. + @param [out] Buffer Buffer to return the entropy bits. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +RETURN_STATUS +EFIAPI +GetTrngEntropy ( + IN UINTN EntropyBits, + IN UINTN BufferSize, + OUT UINT8 *Buffer + ); + +#endif // TRNG_LIB_H_ diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index f1ebf9e251c1..7ff26e22f915 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -7,6 +7,7 @@ # Copyright (c) 2007 - 2022, Intel Corporation. All rights reserved.
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
# (C) Copyright 2016 - 2021 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -275,6 +276,10 @@ [LibraryClasses] ## @libraryclass Provides function for SMM CPU Rendezvous Library. SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h =20 + ## @libraryclass Provides services to generate Entropy using a TRNG. + # + TrngLib|Include/Library/TrngLib.h + [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64] ## @libraryclass Provides services to generate random number. # --=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 (#90850): https://edk2.groups.io/g/devel/message/90850 Mute This Topic: https://groups.io/mt/92066725/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 17 07:07:51 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+90851+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+90851+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515048; cv=none; d=zohomail.com; s=zohoarc; b=LPhrSZjGFsR5uH0blStKCjH+cgpQZrk/cBG0ikYJq/+R/KD+CewTOS7xKs6WivJPf3D3mrASOuxJCYeQ9Z3oD0/usCK0zoHTgLRvpOTdkvt20r5X8PNHU2pELcTwpOpKjlS+DLj48/tNE/hBszY+k0gSB7NS42WG+9xasFuvpzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515048; 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=wN+bSMSVtbdi2hv4Jj9Lhg94uWOMG20g7jI1W/U7eYM=; b=asKfQf+Ev64NUbep7rODHVyQFVNBZENiSk686b/C0xSkso24yf6qk1Q2sKXykGBU7P5qzjCE2LhxhDquO+PUbP5DLOOD6k3BcUiKEZI2LAMoOHSg6H0M+PvnrW/YSVyM+jKfHd31xaobSLKkxa/cTAujUV780qhLao1nP7tV71k= 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+90851+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 1656515048548224.12623994983142; Wed, 29 Jun 2022 08:04:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id La48YY1788612xvDKZigj1Eg; Wed, 29 Jun 2022 08:04:08 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12727.1656515047641523424 for ; Wed, 29 Jun 2022 08:04:07 -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 8977B175D; Wed, 29 Jun 2022 08:04:07 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 48D943F792; Wed, 29 Jun 2022 08:04:05 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 06/22] MdePkg/TrngLib: Add NULL instance of TRNG Library Date: Wed, 29 Jun 2022 17:02:15 +0200 Message-Id: <20220629150241.2597898-7-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: f0s5rU30HQ8TmKPA3KIVePnRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515048; bh=v4tp7aoJuBRN9zgTyiDYwsp6ihsM7oUTxPze6enL9aE=; h=Cc:Date:From:Reply-To:Subject:To; b=LsjrnsUNnHicpzme/GOEAhgRL8gxOb6IdAATc8jr2al+CDknV7Op8VHlwmgk8GS0Qm2 DZo8PJveQNCDeshJc99Ci7WvdFDgkqJjh1ald981KaEdax+sG1mqsrX39RGCWVyqUT+7C wRIN9ILf65/BUzZH64xP+Q3ii28OppuPSTQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515051470100007 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The True Random Number Generator (TRNG) library defines an interface to access the entropy source on a platform. On platforms that do not have access to an entropy source, a NULL instance of the TRNG library may be useful to satisfy the build dependency. Therefore, add a NULL instance of the TRNG library. Signed-off-by: Sami Mujawar --- .../Library/BaseTrngLibNull/BaseTrngLibNull.c | 135 ++++++++++++++++++ .../BaseTrngLibNull/BaseTrngLibNull.inf | 30 ++++ .../BaseTrngLibNull/BaseTrngLibNull.uni | 12 ++ MdePkg/MdePkg.dsc | 1 + 4 files changed, 178 insertions(+) create mode 100644 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c create mode 100644 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf create mode 100644 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c b/MdePkg/Libr= ary/BaseTrngLibNull/BaseTrngLibNull.c new file mode 100644 index 000000000000..e383cd0cf1cc --- /dev/null +++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c @@ -0,0 +1,135 @@ +/** @file + Null version of TRNG (True Random Number Generator) services. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] Arm True Random Number Generator Firmware, Interface 1.0, + Platform Design Document. + (https://developer.arm.com/documentation/den0098/latest/) + - [2] NIST Special Publication 800-90A Revision 1, June 2015, Recommenda= tion + for Random Number Generation Using Deterministic Random Bit Genera= tors. + (https://csrc.nist.gov/publications/detail/sp/800-90a/rev-1/final) + - [3] NIST Special Publication 800-90B, Recommendation for the Entropy + Sources Used for Random Bit Generation. + (https://csrc.nist.gov/publications/detail/sp/800-90b/final) + - [4] (Second Draft) NIST Special Publication 800-90C, Recommendation for + Random Bit Generator (RBG) Constructions. + (https://csrc.nist.gov/publications/detail/sp/800-90c/draft) + + @par Glossary: + - TRNG - True Random Number Generator +**/ + +#include +#include + +/** Get the version of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the version of the TRNG backend. + The implementation must return NOT_SUPPORTED if a Back end is not presen= t. + + @param [out] MajorRevision Major revision. + @param [out] MinorRevision Minor revision. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Backend not present. +**/ +RETURN_STATUS +EFIAPI +GetTrngVersion ( + OUT UINT16 *MajorRevision, + OUT UINT16 *MinorRevision + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} + +/** Get the UUID of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the UUID of the TRNG backend. + Returning the TRNG UUID is optional and if not implemented, RETURN_UNSUP= PORTED + shall be returned. + + Note: The caller must not rely on the returned UUID as a trustworthy TRNG + Back end identity + + @param [out] Guid UUID of the TRNG backend. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +RETURN_STATUS +EFIAPI +GetTrngUuid ( + OUT GUID *Guid + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} + +/** Returns maximum number of entropy bits that can be returned in a single + call. + + @return Returns the maximum number of Entropy bits that can be returned + in a single call to GetTrngEntropy(). +**/ +UINTN +EFIAPI +GetTrngMaxSupportedEntropyBits ( + VOID + ) +{ + ASSERT (FALSE); + return 0; +} + +/** Returns N bits of conditioned entropy. + + See [3] Section 2.3.1 GetEntropy: An Interface to the Entropy Source + GetEntropy + Input: + bits_of_entropy: the requested amount of entropy + Output: + entropy_bitstring: The string that provides the requested entropy. + status: A Boolean value that is TRUE if the request has been satisfi= ed, + and is FALSE otherwise. + + Note: In this implementation this function returns a status code instead + of a boolean value. + This is also compatible with the definition of Get_Entropy, see [4] + Section 7.4 Entropy Source Calls. + (status, entropy_bitstring) =3D Get_Entropy ( + requested_entropy, + max_length + ) + + @param [in] EntropyBits Number of entropy bits requested. + @param [in] BufferSize Size of the Buffer in bytes. + @param [out] Buffer Buffer to return the entropy bits. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +RETURN_STATUS +EFIAPI +GetTrngEntropy ( + IN UINTN EntropyBits, + IN UINTN BufferSize, + OUT UINT8 *Buffer + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf b/MdePkg/Li= brary/BaseTrngLibNull/BaseTrngLibNull.inf new file mode 100644 index 000000000000..004aa8445a25 --- /dev/null +++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf @@ -0,0 +1,30 @@ +## @file +# Null instance of TRNG (True Random Number Generator) Library. +# +# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D BaseTrngLibNull + MODULE_UNI_FILE =3D BaseTrngLibNull.uni + FILE_GUID =3D ABDE1C87-4F50-4B82-9133-7A79E13F69AB + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TrngLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# + +[Sources] + BaseTrngLibNull.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni b/MdePkg/Li= brary/BaseTrngLibNull/BaseTrngLibNull.uni new file mode 100644 index 000000000000..952e4354c0cc --- /dev/null +++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni @@ -0,0 +1,12 @@ +// /** @file +// Null Instance of TRNG (True Random Number Generator) Library. +// +// Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Null instance of = TRNG Library" + +#string STR_MODULE_DESCRIPTION #language en-US "This library inst= ance should be used with modules that inherit an (indirect) dependency on t= he TrngLib class, but never actually call TrngLib APIs for consuming Entrop= y." diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 3d8874e64782..80e7233363d3 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -67,6 +67,7 @@ [Components] MdePkg/Library/DxeRngLib/DxeRngLib.inf MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf =20 MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.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 (#90851): https://edk2.groups.io/g/devel/message/90851 Mute This Topic: https://groups.io/mt/92066726/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 17 07:07:51 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+90852+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+90852+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515051; cv=none; d=zohomail.com; s=zohoarc; b=dOap3KD/DkqtwGM/iybq2np6W+zKrB6OUnrm72Q4xLSACwz54B5EO9UsgbmkLETKwCKQL1EVTpIFu9AlfwQP0AoyFqsrVKUEcIXs2pkIMZ7VR3nFdxG9P5W1PkVHmTnED8YDwQZipqJNK0xNU5ZCyHUOIjKWZnXmuTjzWWahBNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515051; 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=zI6Z5U2f8oM0zdBGV+Jv1tUmCTLvWeusgcP5s9GU5IQ=; b=lKQ73F0KHPMRsTFa8T8rwUznjWaS05zpY8vXanUA398Fzmq0gTz28OXofiaXTuK6THhqRQzlI6WB3WZfyVyMwmSzTCwS2b/QlfzlBjsHZ7Y9gKqtZU9DXdSobxR/OW3o6soEYKF2bHtoBqerctKwQritLz70bM4ZJozOyTG4blI= 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+90852+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 1656515051176147.5174370233732; Wed, 29 Jun 2022 08:04:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MavNYY1788612xkb28a0VvXi; Wed, 29 Jun 2022 08:04:10 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12728.1656515050157136129 for ; Wed, 29 Jun 2022 08:04:10 -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 14EED152B; Wed, 29 Jun 2022 08:04:10 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9F80D3F792; Wed, 29 Jun 2022 08:04:07 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 07/22] ArmPkg: Add FID definitions for Firmware TRNG Date: Wed, 29 Jun 2022 17:02:16 +0200 Message-Id: <20220629150241.2597898-8-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: TWMkJETw7qbhxwIkZcpzmOZyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515050; bh=+X8bSerfukdU4LNjHsW2gH+9TUmGZX27klOPFTFb0hM=; h=Cc:Date:From:Reply-To:Subject:To; b=tI0ocZB3eJK+IoO7R/EYWDZiFUBQfPv+Tbcc6HJYGv1606rbIoPxNAo01ai3wUUdbdp z48CYFqwvzs8CnlBa0pIXV7xod27nRKh4wtDD4KajhyR+kF/N5psgHSZ781LQkqal+TXX L0bptVc7hs2pVv2d6/N+0IOeLUTxOZ5Er6k= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515053602100009 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The Arm True Random Number Generator Firmware, Interface 1.0, Platform Design Document (https://developer.arm.com/documentation/den0098/latest/) defines an interface between an Operating System (OS) executing at EL1 and Firmware (FW) exposing a conditioned entropy source that is provided by a TRNG back end. New function IDs have been defined by the specification for accessing the TRNG services. Therefore, add these definitions to the Arm standard SMC header. Signed-off-by: Sami Mujawar --- ArmPkg/Include/IndustryStandard/ArmStdSmc.h | 109 +++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/I= ndustryStandard/ArmStdSmc.h index 655edc21b205..4b2edcf0154c 100644 --- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h +++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h @@ -1,13 +1,20 @@ /** @file * * Copyright (c) 2020, NUVIA Inc. All rights reserved.
-* Copyright (c) 2012-2017, ARM Limited. All rights reserved. +* Copyright (c) 2012 - 2022, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * * @par Revision Reference: -* - SMC Calling Convention version 1.2 +* - [1] SMC Calling Convention version 1.2 * (https://developer.arm.com/documentation/den0028/c/?lang=3Den) +* - [2] Arm True Random Number Generator Firmware, Interface 1.0, +* Platform Design Document. +* (https://developer.arm.com/documentation/den0098/latest/) +* +* @par Glossary: +* - TRNG - True Random Number Generator +* **/ =20 #ifndef ARM_STD_SMC_H_ @@ -137,4 +144,102 @@ /* 0xbf00ff02 is reserved */ #define ARM_SMC_ID_TOS_REVISION 0xbf00ff03 =20 +// Firmware TRNG interface Function IDs + +/* + SMC/HVC call to get the version of the TRNG backend, + Cf. [2], 2.1 TRNG_VERSION + Input values: + W0 0x8400_0050 + W1-W7 Reserved (MBZ) + Return values: + Success (W0 > 0) W0[31] MBZ + W0[30:16] Major revision + W0[15:0] Minor revision + W1 - W3 Reserved (MBZ) + Error (W0 < 0) + NOT_SUPPORTED Function not implemented +*/ +#define FID_TRNG_VERSION 0x84000050 + +/* + SMC/HVC call to check if a TRNG function ID is implemented by the backen= d, + Cf. [2], Section 2.2 TRNG_FEATURES + Input Values + W0 0x8400_0051 + W1 trng_func_id + W2-W7 Reserved (MBZ) + Return values: + Success (W0 >=3D 0): + SUCCESS Function is implemented. + > 0 Function is implemented and + has specific capabilities, + see function definition. + Error (W0 < 0) + NOT_SUPPORTED Function with FID=3Dtrng_func_id + is not implemented +*/ +#define FID_TRNG_FEATURES 0x84000051 + +/* + SMC/HVC call to get the UUID of the TRNG backend, + Cf. [2], Section 2.3 TRNG_GET_UUID + Input Values: + W0 0x8400_0052 + W1-W7 Reserved (MBZ) + Return Values: + Success (W0 !=3D -1) + W0 UUID[31:0] + W1 UUID[63:32] + W2 UUID[95:64] + W3 UUID[127:96] + Error (W0 =3D -1) + W0 NOT_SUPPORTED +*/ +#define FID_TRNG_GET_UUID 0x84000052 + +/* + AARCH32 SMC/HVC call to get entropy bits, Cf. [2], Section 2.4 TRNG_RND. + Input values: + W0 0x8400_0053 + W2-W7 Reserved (MBZ) + Return values: + Success (W0 =3D 0): + W0 MBZ + W1 Entropy[95:64] + W2 Entropy[63:32] + W3 Entropy[31:0] + Error (W0 < 0) + W0 NOT_SUPPORTED + NO_ENTROPY + INVALID_PARAMETERS + W1 - W3 Reserved (MBZ) +*/ +#define FID_TRNG_RND_AARCH32 0x84000053 + +/* + AARCH64 SMC/HVC call to get entropy bits, Cf. [2], Section 2.4 TRNG_RND. + Input values: + X0 0xC400_0053 + X2-X7 Reserved (MBZ) + Return values: + Success (X0 =3D 0): + X0 MBZ + X1 Entropy[191:128] + X2 Entropy[127:64] + X3 Entropy[63:0] + Error (X0 < 0) + X0 NOT_SUPPORTED + NO_ENTROPY + INVALID_PARAMETERS + X1 - X3 Reserved (MBZ) +*/ +#define FID_TRNG_RND_AARCH64 0xC4000053 + +// Firmware TRNG status codes +#define TRNG_STATUS_SUCCESS (INT32)(0) +#define TRNG_STATUS_NOT_SUPPORTED (INT32)(-1) +#define TRNG_STATUS_INVALID_PARAMETER (INT32)(-2) +#define TRNG_STATUS_NO_ENTROPY (INT32)(-3) + #endif // ARM_STD_SMC_H_ --=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 (#90852): https://edk2.groups.io/g/devel/message/90852 Mute This Topic: https://groups.io/mt/92066727/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 17 07:07:51 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+90853+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+90853+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515053; cv=none; d=zohomail.com; s=zohoarc; b=dAkPmgLSfssLz8qpLarbVtmXcEJACJgULpGWFQK53JG8+OaLljBI4u5Hl/ZdgYwxAMHWHqvFl5hJ9yyxxlkJxragt+LdxYy/lKwqkDIZsPle6GZXSvOm+0rqIPXMb86HrtN2KA8MfyKksJGTXCftnv8rE+2zNVFyT1gfSq8rl68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515053; 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=+kD65jJcz2Uhk2DgvBdMQl/ARKzecutnirzqceWc+0k=; b=Mnx0xH9OfNnaN15YfuKMkh5S72rVwtyVTIcCfycol4VtRfS6mlFbOPPMPq1/vrcpIlgERL2RlxVPVgCRXjpJobaDRVDBi0Cw/3C6UCD31vIsWjZvTukDb0lY1I4O1Jj27SiNvIzGz5ItC2cmq/1NEYzR5tGN4Rcvto5jkjmJ1iQ= 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+90853+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 1656515053826754.6219663548176; Wed, 29 Jun 2022 08:04:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8zmlYY1788612xriBbP7heE6; Wed, 29 Jun 2022 08:04:13 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12729.1656515052755893725 for ; Wed, 29 Jun 2022 08:04:13 -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 A6A43153B; Wed, 29 Jun 2022 08:04:12 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 341213F792; Wed, 29 Jun 2022 08:04:10 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 08/22] ArmPkg/TrngLib: Add Arm Firmware TRNG library Date: Wed, 29 Jun 2022 17:02:17 +0200 Message-Id: <20220629150241.2597898-9-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: b3rhwmkQ5JlFCZ6Pq5Sqp8fRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515053; bh=QatPnvUdpj0v/oATHGX5MZJgkkjiOKuVm5Rb0kFA2PY=; h=Cc:Date:From:Reply-To:Subject:To; b=BiEn8Gsxd2v640P6T0Xl9o0yOnWyaJoi2HYAhhHQtfBGjZ81t92Tss0Oz7JSoYaDpd/ ohO8/5YH6OLyKUcsBAJsi0aQdq7/3Z42OFDhywCRuvlBYpEE26wMJIRPcHDjm/ShjNDIt Auhq4AtIkNuypXYmLh0uDMDM03wmgD8BKFU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515055346100013 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The Arm True Random Number Generator Firmware, Interface 1.0, Platform Design Document (https://developer.arm.com/documentation/den0098/latest/) defines an interface between an Operating System (OS) executing at EL1 and Firmware (FW) exposing a conditioned entropy source that is provided by a TRNG back end. The conditioned entropy, that is provided by the TRNG FW interface, is commonly used to seed deterministic random number generators. This patch adds a TrngLib library that implements the Arm TRNG firmware interface. Signed-off-by: Sami Mujawar --- ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h | 50 +++ ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c | 403 +++++++++++++++++++ ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf | 29 ++ 4 files changed, 483 insertions(+) create mode 100644 ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h create mode 100644 ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c create mode 100644 ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index e33b40f2c215..02d1caa3ab40 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -138,6 +138,7 @@ [Components.common] ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/OpteeLib/OpteeLib.inf + ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf =20 ArmPkg/Filesystem/SemihostFs/SemihostFs.inf =20 diff --git a/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h b/ArmPkg/Library/A= rmFwTrngLib/ArmFwTrngDefs.h new file mode 100644 index 000000000000..150c89fe7969 --- /dev/null +++ b/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h @@ -0,0 +1,50 @@ +/** @file + Arm Firmware TRNG definitions. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] Arm True Random Number Generator Firmware, Interface 1.0, + Platform Design Document. + (https://developer.arm.com/documentation/den0098/latest/) + + @par Glossary: + - TRNG - True Random Number Generator + - FID - Function ID +**/ + +#ifndef ARM_FW_TRNG_DEFS_H_ +#define ARM_FW_TRNG_DEFS_H_ + +#include + +// Firmware TRNG revision mask and shift +#define TRNG_REV_MAJOR_MASK 0x7FFF +#define TRNG_REV_MINOR_MASK 0xFFFF +#define TRNG_REV_MAJOR_SHIFT 16 + +#if defined (MDE_CPU_ARM) + +/** FID to use on AArch32 platform to request entropy. +*/ +#define FID_TRNG_RND FID_TRNG_RND_AARCH32 + +/** Maximum bits of entropy supported on AArch32. +*/ +#define MAX_ENTROPY_BITS 96 +#elif defined (MDE_CPU_AARCH64) + +/** FID to use on AArch64 platform to request entropy. +*/ +#define FID_TRNG_RND FID_TRNG_RND_AARCH64 + +/** Maximum bits of entropy supported on AArch64. +*/ +#define MAX_ENTROPY_BITS 192 +#else + #error "Firmware TRNG not supported. Unknown chipset." +#endif + +#endif // ARM_FW_TRNG_DEFS_H_ diff --git a/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c b/ArmPkg/Library/Ar= mFwTrngLib/ArmFwTrngLib.c new file mode 100644 index 000000000000..5cff23de0250 --- /dev/null +++ b/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c @@ -0,0 +1,403 @@ +/** @file + Arm Firmware TRNG interface library. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] Arm True Random Number Generator Firmware, Interface 1.0, + Platform Design Document. + (https://developer.arm.com/documentation/den0098/latest/) + - [2] NIST Special Publication 800-90A Revision 1, June 2015, Recommenda= tion + for Random Number Generation Using Deterministic Random Bit Genera= tors. + (https://csrc.nist.gov/publications/detail/sp/800-90a/rev-1/final) + - [3] NIST Special Publication 800-90B, Recommendation for the Entropy + Sources Used for Random Bit Generation. + (https://csrc.nist.gov/publications/detail/sp/800-90b/final) + - [4] (Second Draft) NIST Special Publication 800-90C, Recommendation for + Random Bit Generator (RBG) Constructions. + (https://csrc.nist.gov/publications/detail/sp/800-90c/draft) + + @par Glossary: + - TRNG - True Random Number Generator + - FID - Function ID +**/ + +#include +#include +#include +#include +#include + +#include "ArmFwTrngDefs.h" + +/** Convert TRNG status codes to RETURN status codes. + + @param [in] TrngStatus TRNG status code. + + @retval RETURN_SUCCESS Success. + @retval RETURN_UNSUPPORTED Function not implemented or + negative return code. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + @retval RETURN_NOT_READY No Entropy available. +**/ +STATIC +RETURN_STATUS +TrngStatusToReturnStatus ( + IN INT32 TrngStatus + ) +{ + switch (TrngStatus) { + case TRNG_STATUS_NOT_SUPPORTED: + return RETURN_UNSUPPORTED; + + case TRNG_STATUS_INVALID_PARAMETER: + return RETURN_INVALID_PARAMETER; + + case TRNG_STATUS_NO_ENTROPY: + return RETURN_NOT_READY; + + case TRNG_STATUS_SUCCESS: + return RETURN_SUCCESS; + + default: + if (TrngStatus < 0) { + return RETURN_UNSUPPORTED; + } + + return RETURN_SUCCESS; + } +} + +/** Get the version of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the version of the TRNG backend. + The implementation must return NOT_SUPPORTED if a Back end is not presen= t. + + @param [out] MajorRevision Major revision. + @param [out] MinorRevision Minor revision. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Backend not present. +**/ +RETURN_STATUS +EFIAPI +GetTrngVersion ( + OUT UINT16 *MajorRevision, + OUT UINT16 *MinorRevision + ) +{ + RETURN_STATUS Status; + ARM_MONITOR_ARGS Parameters; + INT32 Revision; + + if ((MajorRevision =3D=3D NULL) || (MinorRevision =3D=3D NULL)) { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D FID_TRNG_VERSION; + ArmMonitorCall (&Parameters); + + Revision =3D (INT32)Parameters.Arg0; + Status =3D TrngStatusToReturnStatus (Revision); + if (RETURN_ERROR (Status)) { + return Status; + } + + *MinorRevision =3D (Revision & TRNG_REV_MINOR_MASK); + *MajorRevision =3D ((Revision >> TRNG_REV_MAJOR_SHIFT) & TRNG_REV_MAJOR_= MASK); + return RETURN_SUCCESS; +} + +/** Get the features supported by the TRNG backend. + + The caller can determine if functions defined in the TRNG ABI are + present in the ABI implementation. + + @param [in] FunctionId Function Id. + @param [out] Capability Function specific capability if present. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +STATIC +RETURN_STATUS +EFIAPI +GetTrngFeatures ( + IN CONST UINT32 FunctionId, + OUT UINT32 *Capability OPTIONAL + ) +{ + ARM_MONITOR_ARGS Parameters; + RETURN_STATUS Status; + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D FID_TRNG_FEATURES; + Parameters.Arg1 =3D FunctionId; + ArmMonitorCall (&Parameters); + + Status =3D TrngStatusToReturnStatus (Parameters.Arg0); + if (RETURN_ERROR (Status)) { + return Status; + } + + if (Capability !=3D NULL) { + *Capability =3D (UINT32)Parameters.Arg0; + } + + return RETURN_SUCCESS; +} + +/** Get the UUID of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the UUID of the TRNG backend. + Returning the TRNG UUID is optional and if not implemented, RETURN_UNSUP= PORTED + shall be returned. + + Note: The caller must not rely on the returned UUID as a trustworthy TRNG + Back end identity + + @param [out] Guid UUID of the TRNG backend. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +RETURN_STATUS +EFIAPI +GetTrngUuid ( + OUT GUID *Guid + ) +{ + ARM_MONITOR_ARGS Parameters; + + if (Guid =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D FID_TRNG_GET_UUID; + ArmMonitorCall (&Parameters); + + // Only invalid value is TRNG_STATUS_NOT_SUPPORTED (-1). + if ((INT32)Parameters.Arg0 =3D=3D TRNG_STATUS_NOT_SUPPORTED) { + return TrngStatusToReturnStatus ((INT32)Parameters.Arg0); + } + + Guid->Data1 =3D (Parameters.Arg0 & MAX_UINT32); + Guid->Data2 =3D (Parameters.Arg1 & MAX_UINT16); + Guid->Data3 =3D ((Parameters.Arg1 >> 16) & MAX_UINT16); + + Guid->Data4[0] =3D (Parameters.Arg2 & MAX_UINT8); + Guid->Data4[1] =3D ((Parameters.Arg2 >> 8) & MAX_UINT8); + Guid->Data4[2] =3D ((Parameters.Arg2 >> 16) & MAX_UINT8); + Guid->Data4[3] =3D ((Parameters.Arg2 >> 24) & MAX_UINT8); + + Guid->Data4[4] =3D (Parameters.Arg3 & MAX_UINT8); + Guid->Data4[5] =3D ((Parameters.Arg3 >> 8) & MAX_UINT8); + Guid->Data4[6] =3D ((Parameters.Arg3 >> 16) & MAX_UINT8); + Guid->Data4[7] =3D ((Parameters.Arg3 >> 24) & MAX_UINT8); + + DEBUG ((DEBUG_INFO, "FW-TRNG: UUID %g\n", Guid)); + + return RETURN_SUCCESS; +} + +/** Returns maximum number of entropy bits that can be returned in a single + call. + + @return Returns the maximum number of Entropy bits that can be returned + in a single call to GetTrngEntropy(). +**/ +UINTN +EFIAPI +GetTrngMaxSupportedEntropyBits ( + VOID + ) +{ + return MAX_ENTROPY_BITS; +} + +/** Returns N bits of conditioned entropy. + + See [3] Section 2.3.1 GetEntropy: An Interface to the Entropy Source + GetEntropy + Input: + bits_of_entropy: the requested amount of entropy + Output: + entropy_bitstring: The string that provides the requested entropy. + status: A Boolean value that is TRUE if the request has been satisfi= ed, + and is FALSE otherwise. + + Note: In this implementation this function returns a status code instead + of a boolean value. + This is also compatible with the definition of Get_Entropy, see [4] + Section 7.4 Entropy Source Calls. + (status, entropy_bitstring) =3D Get_Entropy ( + requested_entropy, + max_length + ) + + @param [in] EntropyBits Number of entropy bits requested. + @param [in] BufferSize Size of the Buffer in bytes. + @param [out] Buffer Buffer to return the entropy bits. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +RETURN_STATUS +EFIAPI +GetTrngEntropy ( + IN UINTN EntropyBits, + IN UINTN BufferSize, + OUT UINT8 *Buffer + ) +{ + RETURN_STATUS Status; + ARM_MONITOR_ARGS Parameters; + UINTN EntropyBytes; + UINTN LastValidBits; + UINTN BytesToClear; + UINTN EntropyData[3]; + + if ((EntropyBits =3D=3D 0) || + (EntropyBits > MAX_ENTROPY_BITS) || + (Buffer =3D=3D NULL)) + { + return RETURN_INVALID_PARAMETER; + } + + EntropyBytes =3D (EntropyBits + 7) >> 3; + if (EntropyBytes > BufferSize) { + return RETURN_BAD_BUFFER_SIZE; + } + + ZeroMem (Buffer, BufferSize); + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D FID_TRNG_RND; + Parameters.Arg1 =3D EntropyBits; + ArmMonitorCall (&Parameters); + + Status =3D TrngStatusToReturnStatus ((INT32)Parameters.Arg0); + if (RETURN_ERROR (Status)) { + return Status; + } + + // The entropy data is returned in the Parameters.Arg<3..1> + // With the lower order bytes in Parameters.Arg3 and the higher + // order bytes being stored in Parameters.Arg1. + EntropyData[0] =3D Parameters.Arg3; + EntropyData[1] =3D Parameters.Arg2; + EntropyData[2] =3D Parameters.Arg1; + + CopyMem (Buffer, EntropyData, EntropyBytes); + + // Mask off any unused top bytes, in accordance with specification. + BytesToClear =3D BufferSize - EntropyBytes; + if (BytesToClear !=3D 0) { + ZeroMem (&Buffer[EntropyBytes], BytesToClear); + } + + // Clear the unused MSB bits of the last byte. + LastValidBits =3D EntropyBits & 0x7; + if (LastValidBits !=3D 0) { + Buffer[EntropyBytes - 1] &=3D (0xFF >> (8 - LastValidBits)); + } + + return Status; +} + +/** The constructor checks that the FW-TRNG interface is supported + by the host firmware. + + It will ASSERT() if FW-TRNG is not supported. + It will always return RETURN_SUCCESS. + + @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS. +**/ +RETURN_STATUS +EFIAPI +ArmFwTrngLibConstructor ( + VOID + ) +{ + ARM_MONITOR_ARGS Parameters; + RETURN_STATUS Status; + UINT16 MajorRev; + UINT16 MinorRev; + GUID Guid; + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D SMCCC_VERSION; + ArmMonitorCall (&Parameters); + Status =3D TrngStatusToReturnStatus ((INT32)Parameters.Arg0); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + // Cf [1] s2.1.3 'Caller responsibilities', + // SMCCC version must be greater or equal than 1.1 + if ((INT32)Parameters.Arg0 < 0x10001) { + ASSERT_RETURN_ERROR (RETURN_UNSUPPORTED); + goto ErrorHandler; + } + + Status =3D GetTrngVersion (&MajorRev, &MinorRev); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + // Check that the required features are present. + Status =3D GetTrngFeatures (FID_TRNG_RND, NULL); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + // Check if TRNG UUID is supported and if so trace the GUID. + Status =3D GetTrngFeatures (FID_TRNG_GET_UUID, NULL); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + DEBUG_CODE_BEGIN (); + + Status =3D GetTrngUuid (&Guid); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + DEBUG (( + DEBUG_INFO, + "FW-TRNG: Version %d.%d, GUID {%g}\n", + MajorRev, + MinorRev, + Guid + )); + + DEBUG_CODE_END (); + + return RETURN_SUCCESS; + +ErrorHandler: + DEBUG ((DEBUG_ERROR, "ArmFwTrngLib could not be correctly initialized.\n= ")); + return RETURN_SUCCESS; +} diff --git a/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf b/ArmPkg/Library/= ArmFwTrngLib/ArmFwTrngLib.inf new file mode 100644 index 000000000000..baeb00d832fd --- /dev/null +++ b/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf @@ -0,0 +1,29 @@ +## @file +# Arm Firmware TRNG interface library. +# +# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D ArmFwTrngLib + FILE_GUID =3D 10DE97C9-28E4-4C9B-A53E-8D7D1B0DD4E0 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D TrngLib + CONSTRUCTOR =3D ArmFwTrngLibConstructor + +[Sources] + ArmFwTrngDefs.h + ArmFwTrngLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmMonitorLib + BaseLib + BaseMemoryLib --=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 (#90853): https://edk2.groups.io/g/devel/message/90853 Mute This Topic: https://groups.io/mt/92066728/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 17 07:07:51 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+90854+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+90854+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515058; cv=none; d=zohomail.com; s=zohoarc; b=VdJd9iHL0tCi/yKyZRIf3fUDdHXy3wfiZfma33XxXWIafl2MJBNHgkhoTiUKiW03PAib0mq2l09lqSlp8mwaqeVCS7VqbOra0PJfiWHGQ1Wxege4gCFwC203dMLQ1f3PyrnSa9xX4mJLg/BeD/5Yn093GJtpe1hNHXe9PMzlLEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515058; 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=pdH/vhE2RfKCAXx357Sy+JuFl/9HVE1st7bk1kPG7Zc=; b=AUqpgJndWmNuW48B1zYyXwAs3fSz/94kZ2FtOT7Ps+L3AzygmCTzf/2CeF8DB2FwsaVixh77Ow2DmIVLYSUoj/h36Z7+XTD/AblPbd7t5OseJ1kHafj4FVn4rth4pEGh2tY6lt7lCOR4e6zuFBIvbm+cg0m9pJs3FRoUPI3EeXw= 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+90854+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 1656515058472265.88484095412025; Wed, 29 Jun 2022 08:04:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XxV6YY1788612x1ggombYApd; Wed, 29 Jun 2022 08:04:18 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.12640.1656515055214681273 for ; Wed, 29 Jun 2022 08:04:15 -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 2C0A5169C; Wed, 29 Jun 2022 08:04:15 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BCA1C3F792; Wed, 29 Jun 2022 08:04:12 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 09/22] MdePkg/BaseRngLib: Rename ArmReadIdIsar0() to ArmGetFeatRng() Date: Wed, 29 Jun 2022 17:02:18 +0200 Message-Id: <20220629150241.2597898-10-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: SEZQVV219D2v1OordxBfj6yFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515058; bh=VorALyvidN5FroD5kEt005P14uJhdUcg6M1XdOVxFSc=; h=Cc:Date:From:Reply-To:Subject:To; b=fWtIy+/Q+eIAMPBHWo4nDlIjpDVgqJTm4rnG1gdJ7uQF2S7Ncmj7Aa8J7qxxNF2uIvo w0YD4jiOv9p3GKLt/9456bb6qXvWoHwIHou+4ZHdY+USR1hlLuvkdbK0e2AsnkNZ4KFOH bn3NPq1oaaAaNYKi+KewRoNG+DLh2E1TyGM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515059464100005 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The MdePkg must be self contained and not have external dependencies. ArmReadIdIsar0() is defined in MdePkg/Library/BaseRngLib and is limited to the scope of this library. The same function will be required to check the FEAT_AES and FEAT_RNG extensions in other libraries. As this function is Arm specific, it cannot be added to a library interface in MdePkg. It should be part of ArmPkg/ArmLib. To avoid having mutiple definitions/prototypes of ArmReadIdIsar0(), and as BaseRngLib only requires to check the RNG capability bits, rename the MdePkg/Library/BaseRngLib implementation to ArmGetFeatRng(). Signed-off-by: Pierre Gondois --- .../AArch64/{ArmReadIdIsar0.S =3D> ArmGetFeatRng.S} | 8 ++++---- .../AArch64/{ArmReadIdIsar0.asm =3D> ArmGetFeatRng.asm} | 8 ++++---- MdePkg/Library/BaseRngLib/AArch64/ArmRng.h | 2 +- MdePkg/Library/BaseRngLib/AArch64/Rndr.c | 2 +- MdePkg/Library/BaseRngLib/BaseRngLib.inf | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) rename MdePkg/Library/BaseRngLib/AArch64/{ArmReadIdIsar0.S =3D> ArmGetFeat= Rng.S} (78%) rename MdePkg/Library/BaseRngLib/AArch64/{ArmReadIdIsar0.asm =3D> ArmGetFe= atRng.asm} (81%) diff --git a/MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.S b/MdePkg/Li= brary/BaseRngLib/AArch64/ArmGetFeatRng.S similarity index 78% rename from MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.S rename to MdePkg/Library/BaseRngLib/AArch64/ArmGetFeatRng.S index 82a00d362212..c42d60513077 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.S +++ b/MdePkg/Library/BaseRngLib/AArch64/ArmGetFeatRng.S @@ -1,6 +1,6 @@ #-------------------------------------------------------------------------= ----- # -# ArmReadIdIsar0() for AArch64 +# ArmGetFeatRng() for AArch64 # # Copyright (c) 2021, NUVIA Inc. All rights reserved.
# @@ -10,7 +10,7 @@ =20 .text .p2align 2 -GCC_ASM_EXPORT(ArmReadIdIsar0) +GCC_ASM_EXPORT(ArmGetFeatRng) =20 #/** # Reads the ID_AA64ISAR0 Register. @@ -20,11 +20,11 @@ GCC_ASM_EXPORT(ArmReadIdIsar0) #**/ #UINT64 #EFIAPI -#ArmReadIdIsar0 ( +#ArmGetFeatRng ( # VOID # ); # -ASM_PFX(ArmReadIdIsar0): +ASM_PFX(ArmGetFeatRng): mrs x0, id_aa64isar0_el1 // Read ID_AA64ISAR0 Register ret =20 diff --git a/MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.asm b/MdePkg/= Library/BaseRngLib/AArch64/ArmGetFeatRng.asm similarity index 81% rename from MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.asm rename to MdePkg/Library/BaseRngLib/AArch64/ArmGetFeatRng.asm index 1d9f9a808c0c..947adfcd2749 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/ArmReadIdIsar0.asm +++ b/MdePkg/Library/BaseRngLib/AArch64/ArmGetFeatRng.asm @@ -1,6 +1,6 @@ ;-------------------------------------------------------------------------= ----- ; -; ArmReadIdIsar0() for AArch64 +; ArmGetFeatRng() for AArch64 ; ; Copyright (c) 2021, NUVIA Inc. All rights reserved.
; @@ -8,7 +8,7 @@ ; ;-------------------------------------------------------------------------= ----- =20 - EXPORT ArmReadIdIsar0 + EXPORT ArmGetFeatRng AREA BaseLib_LowLevel, CODE, READONLY =20 ;/** @@ -19,11 +19,11 @@ ;**/ ;UINT64 ;EFIAPI -;ArmReadIdIsar0 ( +;ArmGetFeatRng ( ; VOID ; ); ; -ArmReadIdIsar0 +ArmGetFeatRng mrs x0, id_aa64isar0_el1 // Read ID_AA64ISAR0 Register ret =20 diff --git a/MdePkg/Library/BaseRngLib/AArch64/ArmRng.h b/MdePkg/Library/Ba= seRngLib/AArch64/ArmRng.h index 2d6ef48ab941..b35cba3c063a 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/ArmRng.h +++ b/MdePkg/Library/BaseRngLib/AArch64/ArmRng.h @@ -35,7 +35,7 @@ ArmRndr ( **/ UINT64 EFIAPI -ArmReadIdIsar0 ( +ArmGetFeatRng ( VOID ); =20 diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c b/MdePkg/Library/Base= RngLib/AArch64/Rndr.c index 20811bf3ebf3..0cfdf4c37149 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c +++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c @@ -47,7 +47,7 @@ BaseRngLibConstructor ( // Determine RNDR support by examining bits 63:60 of the ISAR0 register = returned by // MSR. A non-zero value indicates that the processor supports the RNDR = instruction. // - Isar0 =3D ArmReadIdIsar0 (); + Isar0 =3D ArmGetFeatRng (); ASSERT ((Isar0 & RNDR_MASK) !=3D 0); =20 mRndrSupported =3D ((Isar0 & RNDR_MASK) !=3D 0); diff --git a/MdePkg/Library/BaseRngLib/BaseRngLib.inf b/MdePkg/Library/Base= RngLib/BaseRngLib.inf index 1fcceb941495..d6eccb07d469 100644 --- a/MdePkg/Library/BaseRngLib/BaseRngLib.inf +++ b/MdePkg/Library/BaseRngLib/BaseRngLib.inf @@ -37,10 +37,10 @@ [Sources.AARCH64] AArch64/Rndr.c AArch64/ArmRng.h =20 - AArch64/ArmReadIdIsar0.S | GCC + AArch64/ArmGetFeatRng.S | GCC AArch64/ArmRng.S | GCC =20 - AArch64/ArmReadIdIsar0.asm | MSFT + AArch64/ArmGetFeatRng.asm | MSFT AArch64/ArmRng.asm | MSFT =20 [Packages] --=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 (#90854): https://edk2.groups.io/g/devel/message/90854 Mute This Topic: https://groups.io/mt/92066733/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 17 07:07:51 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+90855+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+90855+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515059; cv=none; d=zohomail.com; s=zohoarc; b=lgt9buc5rgBOhTlhHmwQEXJ0mSDEmNlK/0fUeMBzFIf8ytaR8U89oBVL2EUxYjEFdy6btCI3DblD/Z2a1YO0JDoKwOmgFKKeMTT+KIWBg7csaPLIwyzuE6EAQM844ihZfKOuzh+yuYU2dsNx4nfdvMqxalihr7YC5PfKj+kMzTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515059; 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=wwftmcHNO0tgGEz/MayqDjYdo3o6U0B/3q3IEYwV8RE=; b=Jjz/HNdfM14gVCQPodh9PqC42pultjlsiQO2tcG7PKpXvxtyOU87qSwsawtsYJ2e4WdQyHiV2b358pO5wSOZzEzymMOaLAFDCNvQ0imEmfJdh+qJ5UeUAtYl2NGURFNyAfdKk3YozinT4y4CEMDcA6t8v7/VDQSldo1s1KyW8hE= 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+90855+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 165651505985581.28367758161335; Wed, 29 Jun 2022 08:04:19 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 28SbYY1788612xHdcq0vW8tQ; Wed, 29 Jun 2022 08:04:18 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.12643.1656515057760223802 for ; Wed, 29 Jun 2022 08:04: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 9CFDE152B; Wed, 29 Jun 2022 08:04:17 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 42CC63F792; Wed, 29 Jun 2022 08:04:15 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 10/22] ArmPkg/ArmLib: Add ArmReadIdIsar0() helper Date: Wed, 29 Jun 2022 17:02:19 +0200 Message-Id: <20220629150241.2597898-11-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: iRb8H5qCOnhJt9tad2KRuzM8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515058; bh=OpJk2eB3Jm7Dd8MCNYS0oD1ISRHvkT+fUcmnoUNSzpU=; h=Cc:Date:From:Reply-To:Subject:To; b=ta/3e2Vb3hyAvVq6ydm/OPOhValStAwSFFvsuCxmMerapRo/O9JVtsNVacFFv5xHpSH xRAHsa9X1tqbQcuXyw72B++8NfPmTZJrXkH5WxcmEiLNRQk3RlCiphdMRm0at4wvtAv3K t5hfDts45AUWRnMnl3VbpLl2C7WuM5BmrOg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515061338100009 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add a ArmReadIdIsar0() helper function to access the AArch64 ID_ISAR0_EL1 register. Signed-off-by: Pierre Gondois --- ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h | 12 +++++++++++- ArmPkg/Library/ArmLib/AArch64/AArch64Support.S | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h b/ArmPkg/Library/Ar= mLib/AArch64/AArch64Lib.h index 330481fc50db..105a52ee16fe 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h @@ -1,7 +1,7 @@ /** @file =20 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.
+ Portions Copyright (c) 2011 - 2022, Arm Ltd. All rights reserved.
Copyright (c) 2020, NUVIA Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -54,4 +54,14 @@ ArmReadIdAA64Mmfr2 ( VOID ); =20 +/** Reads the ID_ISAR0_EL1 register. + + @return The contents of the ID_ISAR0_EL1 register. +**/ +UINTN +EFIAPI +ArmReadIdIsar0 ( + VOID + ); + #endif // AARCH64_LIB_H_ diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Support.S b/ArmPkg/Librar= y/ArmLib/AArch64/AArch64Support.S index d3cc1e86716b..baba283d01b9 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Support.S +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Support.S @@ -1,7 +1,7 @@ #-------------------------------------------------------------------------= ----- # # Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
-# Copyright (c) 2011 - 2017, ARM Limited. All rights reserved. +# Copyright (c) 2011 - 2022, Arm Limited. All rights reserved. # Copyright (c) 2016, Linaro Limited. All rights reserved. # Copyright (c) 2020, NUVIA Inc. All rights reserved. # @@ -482,4 +482,9 @@ ASM_FUNC(ArmWriteCntHctl) msr cnthctl_el2, x0 ret =20 +// UINTN ArmReadIdIsar0(VOID) +ASM_FUNC(ArmReadIdIsar0) + mrs x0, id_aa64isar0_el1 + ret + ASM_FUNCTION_REMOVE_IF_UNREFERENCED --=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 (#90855): https://edk2.groups.io/g/devel/message/90855 Mute This Topic: https://groups.io/mt/92066736/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 17 07:07:51 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+90856+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+90856+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515062; cv=none; d=zohomail.com; s=zohoarc; b=AMn1gDIGYlrjcxIHj9QgpVkO9lSWIc0BGJ5cJgkkXImEQ4Mh0KFSp4wK6N6T+YkWMat/8q6bTKZAhK9uPgSsOf2o5ZdOQvgl8cs5Z2hIZ2+I6y+b3Sd1U/XZbfGLbq4NN6/gpKEgcCNuz7ODkH7kJ8MlVgk6F0pynXyzFzqvGZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515062; 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=nrgM15/zvWoyb7MbpcleIxiv7sc34A09ac0ZCY2+zGQ=; b=gOJZwK0l8SYnx15M09+fI1JMCLCmEWoXh6AHq1GpADhNdY4H5mPtVx9YbqZlJgy9gKA8r5+vauN960zcpQmxfCSikFg0fiTcjF0HxDV8Uh8+WopVY2jUWk92Ga8HCJ7zCTJZuA/yunuQNim7IIHGY4kmpuhMowKzrQNmDKsHFpc= 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+90856+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 1656515062965950.9484862144242; Wed, 29 Jun 2022 08:04:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NxcOYY1788612xKCW6gCU4ov; Wed, 29 Jun 2022 08:04:20 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12716.1656515060110147344 for ; Wed, 29 Jun 2022 08:04:20 -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 F0075153B; Wed, 29 Jun 2022 08:04:19 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C15683F792; Wed, 29 Jun 2022 08:04:17 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 11/22] ArmPkg/ArmLib: Add ArmHasRngExt() Date: Wed, 29 Jun 2022 17:02:20 +0200 Message-Id: <20220629150241.2597898-12-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: YRnZ4yYTmeUdF09MmAVJMxUUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515060; bh=9lXvaEG4rr2EG+FH7p6cY9WweF/ssTLiowX8asvzVk8=; h=Cc:Date:From:Reply-To:Subject:To; b=CHMmZ2wiLt035S+jJ2EdlaWFBetfNYvM1jT+3SRjIgDSyT4EEqdfeac+ZG2jthZICGc ItVphzxmyqOoq+Y/uxy5lR3Gz2z7UFGUMshSixuQ3Qbk5eTXFmrXmWOPBmLRIHbcQW7Bn 909zYSobE24uMc6A0Z5oh1ghjLm1L8iRhGk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515063365100013 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add a ArmHasRngExt() to check for the FEAT_RNG extension. Also add a mask for the RNDR bits. Signed-off-by: Pierre Gondois --- ArmPkg/Include/Library/ArmLib.h | 12 +++++++++++- ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c | 15 ++++++++++++++- ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h | 2 ++ ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c | 16 +++++++++++++++- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/ArmPkg/Include/Library/ArmLib.h b/ArmPkg/Include/Library/ArmLi= b.h index 6566deebdde2..8058634dbc53 100644 --- a/ArmPkg/Include/Library/ArmLib.h +++ b/ArmPkg/Include/Library/ArmLib.h @@ -1,7 +1,7 @@ /** @file =20 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2020 - 2021, NUVIA Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -769,6 +769,16 @@ ArmHasCcidx ( VOID ); =20 +/** Check if FEAT_RNG extension is available. + + @retval TRUE if FEAT_RNG extension is available. + @retval FALSE otherwise. +**/ +BOOLEAN +ArmHasRngExt ( + VOID + ); + #ifdef MDE_CPU_ARM /// /// AArch32-only ID Register Helper functions diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c b/ArmPkg/Library/Ar= mLib/AArch64/AArch64Lib.c index 7ab28e3e05fe..124b28e16874 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.c @@ -1,7 +1,7 @@ /** @file =20 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Portions copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ Portions copyright (c) 2011 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2021, NUVIA Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -104,3 +104,16 @@ ArmHasCcidx ( Mmfr2 =3D ArmReadIdAA64Mmfr2 (); return (((Mmfr2 >> 20) & 0xF) =3D=3D 1) ? TRUE : FALSE; } + +/** Check if FEAT_RNG extension is available. + + @retval TRUE if FEAT_RNG extension is available. + @retval FALSE otherwise. +**/ +BOOLEAN +ArmHasRngExt ( + VOID + ) +{ + return ArmReadIdIsar0 () & ID_AA64ISAR0_EL1_RNDR_MASK; +} diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h b/ArmPkg/Library/Ar= mLib/AArch64/AArch64Lib.h index 105a52ee16fe..61a775ea27e8 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.h @@ -11,6 +11,8 @@ #ifndef AARCH64_LIB_H_ #define AARCH64_LIB_H_ =20 +#define ID_AA64ISAR0_EL1_RNDR_MASK ((UINT64)0xF << 60U) + typedef VOID (*AARCH64_CACHE_OPERATION)( UINTN ); diff --git a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c b/ArmPkg/Library/ArmLib/A= rm/ArmV7Lib.c index 521d5be0de33..a4ec23c8f8d8 100644 --- a/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c +++ b/ArmPkg/Library/ArmLib/Arm/ArmV7Lib.c @@ -1,7 +1,7 @@ /** @file =20 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- Copyright (c) 2011 - 2014, ARM Limited. All rights reserved. + Copyright (c) 2011 - 2022, Arm Limited. All rights reserved. Copyright (c) 2021, NUVIA Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -119,3 +119,17 @@ ArmHasCcidx ( Mmfr4 =3D ArmReadIdMmfr4 (); return (((Mmfr4 >> 24) & 0xF) =3D=3D 1) ? TRUE : FALSE; } + +/** Check if FEAT_RNG extension is available. + + @retval TRUE if FEAT_RNG extension is available. + @retval FALSE otherwise. +**/ +BOOLEAN +ArmHasRngExt ( + VOID + ) +{ + // Not supported. + return FALSE; +} --=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 (#90856): https://edk2.groups.io/g/devel/message/90856 Mute This Topic: https://groups.io/mt/92066737/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 17 07:07:51 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+90857+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+90857+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515063; cv=none; d=zohomail.com; s=zohoarc; b=d5XrlmDwqOBHQjgSRrESmRISroMLagvbDXX9v+ZEzC9Rq2KAJ7H5AETS91TqJ0VqwLFN0vxEjfwgtTzzafyRnizLOIv+4A2FngeI4mPJg8Owc8Yj31ltKrcduSMdshM1woWJt0OPKkQzvGNweXIVptHACsFIOFL57BQa1Wp9kWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515063; 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=6iKZb27PVgO5+kLVuBR4nuUQSI159Xbi8qXXzs9PrU8=; b=n+g3gvrjWIV8vWvxYShzODSiaKKaa/RqalQTLXNdGXyo5QdrGfmZ4O2unm5XIL93Wd5tUmSE+oL3pg7CvMVtPdf+w97VIv+gA0El01kcfySSpyTfB2NKeko1ngMzTKGIRml5xPSi71GipVEOE4dqf1skIX4Vxo9ag4vVK3IO23s= 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+90857+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 1656515063262591.0702993782878; Wed, 29 Jun 2022 08:04:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wv2qYY1788612xuFPX1QWzCa; Wed, 29 Jun 2022 08:04:22 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.12644.1656515062273462887 for ; Wed, 29 Jun 2022 08:04: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 3A789169C; Wed, 29 Jun 2022 08:04:22 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0A8D73F792; Wed, 29 Jun 2022 08:04:19 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 12/21] SecurityPkg/RngDxe: Rename RdRandGenerateEntropy to generic name Date: Wed, 29 Jun 2022 17:02:21 +0200 Message-Id: <20220629150241.2597898-13-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: khGAV5IrngQyeGOrMdUWyRi9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515062; bh=sGrgT3YHSAyYZw2/L5SvGAQ0RASyxsi7vq9lEOZlmI4=; h=Cc:Date:From:Reply-To:Subject:To; b=jmiun9sDbJrAce6Ow6rzdVy2Cx282ED5P2Jt1CpTRnwyeTUFypn9h6i1g35vuepiIzB FoEXx9TJLPxp4I6OfytE8r9V2PpjwPt+eHN3Y7vmfcE6skK6SoruaAMgGeGpF5X3X2puh YfiHwxDqRD6BhO0RnxUvX8GqD/tyUsAr7n0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515065496100017 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) Rename RdRandGenerateEntropy() to GenerateEntropy() to provide a common interface to generate entropy on other architectures. GenerateEntropy() is intended to generate high quality entropy. Also move the definition to RngDxeInternals.h Signed-off-by: Sami Mujawar --- .../RngDxe/Rand/RdRand.c | 14 ++++-- .../RngDxe/Rand/RdRand.h | 43 ------------------- .../RngDxe/Rand/RngDxe.c | 7 ++- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 2 +- .../RngDxe/RngDxeInternals.h | 19 ++++++++ 5 files changed, 36 insertions(+), 49 deletions(-) delete mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c index 5b6644138231..4b011c7e8e49 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c @@ -1,15 +1,23 @@ /** @file - Support routines for RDRAND instruction access. + Support routines for RDRAND instruction access, which will leverage + Intel Secure Key technology to provide high-quality random numbers for u= se + in applications, or entropy for seeding other random number generators. + Refer to http://software.intel.com/en-us/articles/intel-digital-random-n= umber + -generator-drng-software-implementation-guide/ for more information abou= t Intel + Secure Key technology. =20 +Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ +#include +#include #include +#include =20 #include "AesCore.h" -#include "RdRand.h" #include "RngDxeInternals.h" =20 /** @@ -87,7 +95,7 @@ RdRandGetSeed128 ( **/ EFI_STATUS EFIAPI -RdRandGenerateEntropy ( +GenerateEntropy ( IN UINTN Length, OUT UINT8 *Entropy ) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h deleted file mode 100644 index 7fdb6891bd63..000000000000 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h +++ /dev/null @@ -1,43 +0,0 @@ -/** @file - Header for the RDRAND APIs used by RNG DXE driver. - - Support API definitions for RDRAND instruction access, which will levera= ge - Intel Secure Key technology to provide high-quality random numbers for u= se - in applications, or entropy for seeding other random number generators. - Refer to http://software.intel.com/en-us/articles/intel-digital-random-n= umber - -generator-drng-software-implementation-guide/ for more information abou= t Intel - Secure Key technology. - -Copyright (c) 2013, Intel Corporation. All rights reserved.
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef __RD_RAND_H__ -#define __RD_RAND_H__ - -#include -#include -#include -#include -#include - -/** - Generate high-quality entropy source through RDRAND. - - @param[in] Length Size of the buffer, in bytes, to fill with. - @param[out] Entropy Pointer to the buffer to store the entropy da= ta. - - @retval EFI_SUCCESS Entropy generation succeeded. - @retval EFI_NOT_READY Failed to request random data. - -**/ -EFI_STATUS -EFIAPI -RdRandGenerateEntropy ( - IN UINTN Length, - OUT UINT8 *Entropy - ); - -#endif // __RD_RAND_H__ diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 2df4ed44329a..8d44f0636c3d 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -14,13 +14,16 @@ - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - Unsupported - EFI_RNG_ALGORITHM_X9_31_AES_GUID - Unsupported =20 + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "RdRand.h" +#include +#include + #include "RngDxeInternals.h" =20 /** @@ -88,7 +91,7 @@ RngGetRNG ( return EFI_INVALID_PARAMETER; } =20 - Status =3D RdRandGenerateEntropy (RNGValueLength, RNGValue); + Status =3D GenerateEntropy (RNGValueLength, RNGValue); return Status; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index f3300971993f..60efb5562ee0 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -10,6 +10,7 @@ # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
# (C) Copyright 2015 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -36,7 +37,6 @@ [Sources.common] [Sources.IA32, Sources.X64] Rand/RngDxe.c Rand/RdRand.c - Rand/RdRand.h Rand/AesCore.c Rand/AesCore.h =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/S= ecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index 224d8bd4ea5f..48d2d27c1608 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -10,6 +10,8 @@ #ifndef RNGDXE_INTERNALS_H_ #define RNGDXE_INTERNALS_H_ =20 +#include + /** Returns information about the random number generation implementation. =20 @@ -114,4 +116,21 @@ RngGetBytes ( OUT UINT8 *RandBuffer ); =20 +/** + Generate high-quality entropy source using a TRNG or through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy da= ta. + + @retval EFI_SUCCESS Entropy generation succeeded. + @retval EFI_NOT_READY Failed to request random data. + +**/ +EFI_STATUS +EFIAPI +GenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ); + #endif // RNGDXE_INTERNALS_H_ --=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 (#90857): https://edk2.groups.io/g/devel/message/90857 Mute This Topic: https://groups.io/mt/92066739/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 17 07:07:51 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+90858+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+90858+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515066; cv=none; d=zohomail.com; s=zohoarc; b=HuqPxugAmIwjqztaTBUWgkjm4Mnwx6dv4JZk33HgrLvVg4OXsCVvUfdmyloOSAn5oRfHHojTNUqNo4NumZgoQTvB1ryijv7i7k4EsSh8vywWWOtYEIY9Ke9HffAnSUaeW4wx2hPHztblF1mzFYlxxwcdMs2U12EYI7EwcN9P51Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515066; 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=6ra89yO1hPV5kzr03D3ncKEVXGmuRqB/QtGcZleO1qA=; b=lo8Hgt6b8BrCQ1/7frFokuo/1QJflDLGkYx9cv6DWnHHr9KUobdBnk21un0NCpGliNEzoqK8gSM0RgV3PNnS04aEfHoJkF0jmdu3xXIvy+QzJmrsfaZz9OqxKMAoH6spKxk9jR3c+2deDNGR1+4F5cL7RunWEpkgDOumDyFLhio= 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+90858+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 1656515066111376.8894046559776; Wed, 29 Jun 2022 08:04:26 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id t0M1YY1788612xJaKylyO9ZJ; Wed, 29 Jun 2022 08:04:25 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.12562.1656515064812394232 for ; Wed, 29 Jun 2022 08:04:25 -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 AAB1C153B; Wed, 29 Jun 2022 08:04:24 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5168A3F792; Wed, 29 Jun 2022 08:04:22 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 12/22] SecurityPkg: Update Securitypkg.ci.yaml Date: Wed, 29 Jun 2022 17:02:22 +0200 Message-Id: <20220629150241.2597898-14-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: T5GMMPKOSEW5lF8AecRBY7pIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515065; bh=8nTvBfHn7ohD+tkTxtLRoHJE4K7ZdBMCEha3cAGXpuI=; h=Cc:Date:From:Reply-To:Subject:To; b=IkZD2TH265X67XsBpoiR6s3whM7yHmCKcngwhodzk+HHKF7Z59jsCOuVWikJrBgvCXq lGZ2uL2NVVzZKbfmFhok4qequngPm4D4cfF8AaMkOnIMzjuOo/3OtBIdQBGx6mpYZAC4x Z003tvOPx6gL77lHzR6Uw1iTN5YeYZpJYhg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515067429100021 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add ArmPkg.dec as a valid dependency for the SecurityPkg. Signed-off-by: Pierre Gondois --- SecurityPkg/SecurityPkg.ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/SecurityPkg/SecurityPkg.ci.yaml b/SecurityPkg/SecurityPkg.ci.y= aml index 791214239899..08e98d713224 100644 --- a/SecurityPkg/SecurityPkg.ci.yaml +++ b/SecurityPkg/SecurityPkg.ci.yaml @@ -31,6 +31,7 @@ }, "DependencyCheck": { "AcceptableDependencies": [ + "ArmPkg/ArmPkg.dec", "MdePkg/MdePkg.dec", "MdeModulePkg/MdeModulePkg.dec", "SecurityPkg/SecurityPkg.dec", --=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 (#90858): https://edk2.groups.io/g/devel/message/90858 Mute This Topic: https://groups.io/mt/92066741/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 17 07:07:51 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+90859+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+90859+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515068; cv=none; d=zohomail.com; s=zohoarc; b=gCXiOw11XkBxs2Ig0ohISNIjjEsGFseBmfZUcxYsJmigEwPRejAaBCuVHNd3DKlSrmmngQjgqkutCQz2TW3x+lghPgJUzR3M40KdhaTjep8Ldc8omWKR7Xqyi1wFxRJzeYdfbfTWmEYgiX9sPRqvblNBnAcuP2piUkvtHiZ7afk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515068; 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=7KHyOYmw09lV//0nScW4ZakyUJbZQhycg0GE/TBPYAU=; b=nJHuROE4tpMO9SyN9JMNvMHhSTDEyX2A5moJTaJsLYuxWNA6FWQi8dppc5vv5JvPpeUKZYADVvhVondJ3/E8+k0yH+bhigzzXRBxw5kyLqIrkPQxSn0/hgGhmePqgJLBe+SdQYYwPiu4fgd/UXjM8GaLcOVNEL/HV1albi/lUL0= 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+90859+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 1656515068023229.66235074281565; Wed, 29 Jun 2022 08:04:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7eEdYY1788612xOWRzT5g3kN; Wed, 29 Jun 2022 08:04:27 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12718.1656515067087097350 for ; Wed, 29 Jun 2022 08:04:27 -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 006F21758; Wed, 29 Jun 2022 08:04:27 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C0B083F792; Wed, 29 Jun 2022 08:04:24 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 13/22] SecurityPkg/RngDxe: Rename RdRandGenerateEntropy to generic name Date: Wed, 29 Jun 2022 17:02:23 +0200 Message-Id: <20220629150241.2597898-15-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: VfJKGJr6WOfD9VqlzciDdFDpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515067; bh=7pp0U3D3D9MShrTP5Et1ee619aVEdqfCu6MioNI5p6Q=; h=Cc:Date:From:Reply-To:Subject:To; b=YzB/1ZvF6uL+Lwyoh+Pd5lA+g4t24ps/qfKEaJwBWjRH6qkeqUXf7f4Accxqxg7jyXJ YKQjFKLg6aqE/33XazP6kGET9ohFJL4ElHBHKck1ji54gPUup5DDdmjUvS+lrDXTrkj+l PzD6Q0Wk+Ifq8nKvyXj7nVbJuDFaKz7vsuE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515069447100025 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) Rename RdRandGenerateEntropy() to GenerateEntropy() to provide a common interface to generate entropy on other architectures. GenerateEntropy() is intended to generate high quality entropy. Also move the definition to RngDxeInternals.h Signed-off-by: Sami Mujawar --- .../RngDxe/Rand/RdRand.c | 14 ++++-- .../RngDxe/Rand/RdRand.h | 43 ------------------- .../RngDxe/Rand/RngDxe.c | 7 ++- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 2 +- .../RngDxe/RngDxeInternals.h | 19 ++++++++ 5 files changed, 36 insertions(+), 49 deletions(-) delete mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c index 5b6644138231..4b011c7e8e49 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c @@ -1,15 +1,23 @@ /** @file - Support routines for RDRAND instruction access. + Support routines for RDRAND instruction access, which will leverage + Intel Secure Key technology to provide high-quality random numbers for u= se + in applications, or entropy for seeding other random number generators. + Refer to http://software.intel.com/en-us/articles/intel-digital-random-n= umber + -generator-drng-software-implementation-guide/ for more information abou= t Intel + Secure Key technology. =20 +Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ +#include +#include #include +#include =20 #include "AesCore.h" -#include "RdRand.h" #include "RngDxeInternals.h" =20 /** @@ -87,7 +95,7 @@ RdRandGetSeed128 ( **/ EFI_STATUS EFIAPI -RdRandGenerateEntropy ( +GenerateEntropy ( IN UINTN Length, OUT UINT8 *Entropy ) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h deleted file mode 100644 index 7fdb6891bd63..000000000000 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h +++ /dev/null @@ -1,43 +0,0 @@ -/** @file - Header for the RDRAND APIs used by RNG DXE driver. - - Support API definitions for RDRAND instruction access, which will levera= ge - Intel Secure Key technology to provide high-quality random numbers for u= se - in applications, or entropy for seeding other random number generators. - Refer to http://software.intel.com/en-us/articles/intel-digital-random-n= umber - -generator-drng-software-implementation-guide/ for more information abou= t Intel - Secure Key technology. - -Copyright (c) 2013, Intel Corporation. All rights reserved.
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef __RD_RAND_H__ -#define __RD_RAND_H__ - -#include -#include -#include -#include -#include - -/** - Generate high-quality entropy source through RDRAND. - - @param[in] Length Size of the buffer, in bytes, to fill with. - @param[out] Entropy Pointer to the buffer to store the entropy da= ta. - - @retval EFI_SUCCESS Entropy generation succeeded. - @retval EFI_NOT_READY Failed to request random data. - -**/ -EFI_STATUS -EFIAPI -RdRandGenerateEntropy ( - IN UINTN Length, - OUT UINT8 *Entropy - ); - -#endif // __RD_RAND_H__ diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 2df4ed44329a..8d44f0636c3d 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -14,13 +14,16 @@ - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - Unsupported - EFI_RNG_ALGORITHM_X9_31_AES_GUID - Unsupported =20 + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "RdRand.h" +#include +#include + #include "RngDxeInternals.h" =20 /** @@ -88,7 +91,7 @@ RngGetRNG ( return EFI_INVALID_PARAMETER; } =20 - Status =3D RdRandGenerateEntropy (RNGValueLength, RNGValue); + Status =3D GenerateEntropy (RNGValueLength, RNGValue); return Status; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index f3300971993f..60efb5562ee0 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -10,6 +10,7 @@ # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
# (C) Copyright 2015 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -36,7 +37,6 @@ [Sources.common] [Sources.IA32, Sources.X64] Rand/RngDxe.c Rand/RdRand.c - Rand/RdRand.h Rand/AesCore.c Rand/AesCore.h =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/S= ecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index 224d8bd4ea5f..48d2d27c1608 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -10,6 +10,8 @@ #ifndef RNGDXE_INTERNALS_H_ #define RNGDXE_INTERNALS_H_ =20 +#include + /** Returns information about the random number generation implementation. =20 @@ -114,4 +116,21 @@ RngGetBytes ( OUT UINT8 *RandBuffer ); =20 +/** + Generate high-quality entropy source using a TRNG or through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy da= ta. + + @retval EFI_SUCCESS Entropy generation succeeded. + @retval EFI_NOT_READY Failed to request random data. + +**/ +EFI_STATUS +EFIAPI +GenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ); + #endif // RNGDXE_INTERNALS_H_ --=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 (#90859): https://edk2.groups.io/g/devel/message/90859 Mute This Topic: https://groups.io/mt/92066743/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 17 07:07:51 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+90860+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+90860+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515070; cv=none; d=zohomail.com; s=zohoarc; b=lzRYiqLB0ziUieRTJxZhyjjSWEW/aWH+QTtb0o5yOCns8nKUlJIL7zqJAIjidtAlLT46T5BKtWgH/YtoJubPCsjvUvRGYIEFjyBSrFvfMieGUz2sJVsVt5D5jVMtV/MpihPDlbHUNP4m5HdoekWZcIEIicl10je6lKuFu/Ye5Ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515070; 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=PN8YdzrCpHvicCpPar9V/EohsTyeFxDGPssx0e4gZ04=; b=X6GGBFzaMkp+IW0U7GRziKqY4+xRrXgdxJaifSphH0u34KU/Fp3KnH7I6SR/UHDOft9R1XRu09K2CzjJ0eg0MxKimTv/QMtXnao/hXOXXfY6WXodHwKxQZrnWgj22NHOF2oWTlVXRAGqYMDiugtc+/tBl+2aheJB859Fc27Xsqs= 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+90860+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 1656515070437223.28567724960612; Wed, 29 Jun 2022 08:04:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id GApzYY1788612x4OV4JCUhIs; Wed, 29 Jun 2022 08:04:30 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12719.1656515069419003425 for ; Wed, 29 Jun 2022 08:04:29 -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 54975153B; Wed, 29 Jun 2022 08:04:29 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1AE743F792; Wed, 29 Jun 2022 08:04:26 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 13/21] SecurityPkg/RngDxe: Replace Pcd with Sp80090Ctr256Guid Date: Wed, 29 Jun 2022 17:02:24 +0200 Message-Id: <20220629150241.2597898-16-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: 2MAVCBps240fJASsZAKL7CZrx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515070; bh=99QiPhCJ3zwtV5xyYU0YEgGPAAX361VoV1Ppf5L+z0o=; h=Cc:Date:From:Reply-To:Subject:To; b=I4lrkg237wEVCgO8I7cCkSmAVptQQfgK4mM9NHxAkpZUg9+Oi8CzJzA4lQwEvUT4APV ScTOFMmFVSfqlOnBq6uOvSz9J1ODQWoGy/UqzM4P99+qsNRbdPsUFpkkO8701AF/vkte7 yl60PmVROjTJjo64iZYY8TlJJGpmPTr1hr4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515071413100029 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois gEfiRngAlgorithmSp80090Ctr256Guid was used as the default algorithm in RngGetRNG(). The commit below set the default algorithm to PcdCpuRngSupportedAlgorithm, which is a zero GUID by default. As the Pcd value is not defined for any platform in the edk2-platfoms repository, assume it was an error and go back to the first version, using gEfiRngAlgorithmSp80090Ctr256Guid. Fixes 4e5ecdbac8bd ("SecurityPkg: Add support for RngDxe on AARCH64") Signed-off-by: Pierre Gondois --- SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 8d44f0636c3d..8cfe6b471192 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -126,8 +126,7 @@ ArchGetSupportedRngAlgorithms ( OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { - UINTN RequiredSize; - EFI_RNG_ALGORITHM *CpuRngSupportedAlgorithm; + UINTN RequiredSize; =20 RequiredSize =3D 2 * sizeof (EFI_RNG_ALGORITHM); =20 @@ -136,9 +135,7 @@ ArchGetSupportedRngAlgorithms ( return EFI_BUFFER_TOO_SMALL; } =20 - CpuRngSupportedAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); - - CopyMem (&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof (EFI_RNG= _ALGORITHM)); + CopyMem (&RNGAlgorithmList[0], gEfiRngAlgorithmSp80090Ctr256Guid, sizeof= (EFI_RNG_ALGORITHM)); =20 // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED CopyMem (&RNGAlgorithmList[1], &gEfiRngAlgorithmRaw, sizeof (EFI_RNG_ALG= ORITHM)); --=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 (#90860): https://edk2.groups.io/g/devel/message/90860 Mute This Topic: https://groups.io/mt/92066744/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 17 07:07:51 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+90861+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+90861+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515075; cv=none; d=zohomail.com; s=zohoarc; b=QYh6pHcpG9Fzkzs2PzTpVPFEKgozunvqsdAs+w2Fcp9JF4xiTvE3RBf+A2ZHL7+eoc6kHq9I/IObtWTHpu8UqffGoak1pAALqLsSMGwXtgiR/MA+gPYNHHq8KdQ3t7b4BBL5bPhuKhwxKyuU6msnOpP8YdaC0RPxEgquMwp1Nok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515075; 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=Oz0yvxkh+yZuKFPuQvVg1ykXnYXCPkXWH8s6Xr7zc6k=; b=iOYToVZV2iOXA3fNQDT3QfSwgDZbf7ehQJwonklqmh61fn0akhMOKXKTB9qnAAElaYk9TQD0hB2FJY1tS9zPP2RRylBGLT9fQelnPfHcmKUEsSb6B96X7oLFTSZnvpWQb6aNBLakBHe1ASCRAqpBqYaDoUckapOpGp7eIgQwRPY= 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+90861+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 16565150738713.537451814717997; Wed, 29 Jun 2022 08:04:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wcf6YY1788612xRJIOmtK7Rf; Wed, 29 Jun 2022 08:04:32 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.12650.1656515072084232285 for ; Wed, 29 Jun 2022 08:04:32 -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 EE5CC1763; Wed, 29 Jun 2022 08:04:31 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8AA1B3F792; Wed, 29 Jun 2022 08:04:29 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 14/21] SecurityPkg/RngDxe: Remove ArchGetSupportedRngAlgorithms() Date: Wed, 29 Jun 2022 17:02:25 +0200 Message-Id: <20220629150241.2597898-17-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: o4CtvuBHxOUA4H6mxpMpCFhGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515072; bh=hsOlboSu48h9aEe4AfDb6qwvBjqZVAVavG/9W/V9+BA=; h=Cc:Date:From:Reply-To:Subject:To; b=HZQH4ra0Ktk0R9AcxgR1YvSiZZGyCid5nOOI5jOt13eOl+gprN+lJUt3zrRlik9TI/2 TQRokapgnKopVmHUgGGz5rR+w0BhE4By9LgHep1WvjmZCYYE2jmkEw+/eeujNMMpqXXrL EaWhbwMVxnmkl6ofYGquXWxDR/UHoiGZKjw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515077678100006 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois RngGetInfo() is one of the 2 functions of the EFI_RNG_PROTOCOL. RngGetInfo() is currently a mere wrapper around ArchGetSupportedRngAlgorithms() which is implemented differently depending on the architecture used. RngGetInfo() does nothing more than calling ArchGetSupportedRngAlgorithms(). So remove it, and let RngGetInfo() be implemented differently according to the architecture. This follows the implementation of the other function of the EFI_RNG_PROTOCOL, RngGetRNG(). Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/RngDxe.c | 19 +++++-- .../RngDxe/Rand/RngDxe.c | 24 +++++++-- .../RandomNumberGenerator/RngDxe/RngDxe.c | 49 ------------------- .../RngDxe/RngDxeInternals.h | 25 ---------- 4 files changed, 34 insertions(+), 83 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index 3daf847d46d3..6d989f7ea376 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -14,6 +14,7 @@ Copyright (c) 2021, NUVIA Inc. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -85,6 +86,7 @@ RngGetRNG ( /** Returns information about the random number generation implementation. =20 + @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. On output with a return code of EFI_= SUCCESS, the size in bytes of the data returned in RNG= AlgorithmList. On output @@ -97,14 +99,19 @@ RngGetRNG ( is the default algorithm for the dri= ver. =20 @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. + @retval EFI_UNSUPPORTED The services is not supported by thi= s driver. + @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a + hardware or firmware error. + @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. =20 **/ -UINTN +EFI_STATUS EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList +RngGetInfo ( + IN EFI_RNG_PROTOCOL *This, + IN OUT UINTN *RNGAlgorithmListSize, + OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { UINTN RequiredSize; @@ -112,6 +119,10 @@ ArchGetSupportedRngAlgorithms ( =20 RequiredSize =3D sizeof (EFI_RNG_ALGORITHM); =20 + if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + if (*RNGAlgorithmListSize < RequiredSize) { *RNGAlgorithmListSize =3D RequiredSize; return EFI_BUFFER_TOO_SMALL; diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 8cfe6b471192..b2d2236380fd 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -104,6 +104,7 @@ RngGetRNG ( /** Returns information about the random number generation implementation. =20 + @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. On output with a return code of EFI_= SUCCESS, the size in bytes of the data returned in RNG= AlgorithmList. On output @@ -116,18 +117,27 @@ RngGetRNG ( is the default algorithm for the dri= ver. =20 @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. + @retval EFI_UNSUPPORTED No supported algorithms found. + @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a + hardware or firmware error. + @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. =20 **/ -UINTN +EFI_STATUS EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList +RngGetInfo ( + IN EFI_RNG_PROTOCOL *This, + IN OUT UINTN *RNGAlgorithmListSize, + OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { UINTN RequiredSize; =20 + if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + RequiredSize =3D 2 * sizeof (EFI_RNG_ALGORITHM); =20 if (*RNGAlgorithmListSize < RequiredSize) { @@ -135,7 +145,11 @@ ArchGetSupportedRngAlgorithms ( return EFI_BUFFER_TOO_SMALL; } =20 - CopyMem (&RNGAlgorithmList[0], gEfiRngAlgorithmSp80090Ctr256Guid, sizeof= (EFI_RNG_ALGORITHM)); + if (RNGAlgorithmList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CopyMem (&RNGAlgorithmList[0], &gEfiRngAlgorithmSp80090Ctr256Guid, sizeo= f (EFI_RNG_ALGORITHM)); =20 // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED CopyMem (&RNGAlgorithmList[1], &gEfiRngAlgorithmRaw, sizeof (EFI_RNG_ALG= ORITHM)); diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index 6f52eeff4a09..6608ca8804a5 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -28,55 +28,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "RngDxeInternals.h" =20 -/** - Returns information about the random number generation implementation. - - @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. - @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. - On output with a return code of EFI_= SUCCESS, the size - in bytes of the data returned in RNG= AlgorithmList. On output - with a return code of EFI_BUFFER_TOO= _SMALL, - the size of RNGAlgorithmList require= d to obtain the list. - @param[out] RNGAlgorithmList A caller-allocated memory buffer fil= led by the driver - with one EFI_RNG_ALGORITHM element f= or each supported - RNG algorithm. The list must not cha= nge across multiple - calls to the same driver. The first = algorithm in the list - is the default algorithm for the dri= ver. - - @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. - @retval EFI_UNSUPPORTED The services is not supported by thi= s driver. - @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a - hardware or firmware error. - @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. - @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. - -**/ -EFI_STATUS -EFIAPI -RngGetInfo ( - IN EFI_RNG_PROTOCOL *This, - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList - ) -{ - EFI_STATUS Status; - - if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - // - // Return algorithm list supported by driver. - // - if (RNGAlgorithmList !=3D NULL) { - Status =3D ArchGetSupportedRngAlgorithms (RNGAlgorithmListSize, RNGAlg= orithmList); - } else { - Status =3D EFI_INVALID_PARAMETER; - } - - return Status; -} - // // The Random Number Generator (RNG) protocol // diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/S= ecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index 48d2d27c1608..7ecab140483d 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -74,31 +74,6 @@ RngGetRNG ( OUT UINT8 *RNGValue ); =20 -/** - Returns information about the random number generation implementation. - - @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. - On output with a return code of EFI_= SUCCESS, the size - in bytes of the data returned in RNG= AlgorithmList. On output - with a return code of EFI_BUFFER_TOO= _SMALL, - the size of RNGAlgorithmList require= d to obtain the list. - @param[out] RNGAlgorithmList A caller-allocated memory buffer fil= led by the driver - with one EFI_RNG_ALGORITHM element f= or each supported - RNG algorithm. The list must not cha= nge across multiple - calls to the same driver. The first = algorithm in the list - is the default algorithm for the dri= ver. - - @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. - @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. - -**/ -UINTN -EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList - ); - /** Runs CPU RNG instruction to fill a buffer of arbitrary size with random = bytes. =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 (#90861): https://edk2.groups.io/g/devel/message/90861 Mute This Topic: https://groups.io/mt/92066745/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 17 07:07:51 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+90862+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+90862+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515076; cv=none; d=zohomail.com; s=zohoarc; b=H6zCLYEPkf+dn57YgwbbpXOl6Y0RRQCrwvTzPgKP00RErwpaYLcGHuAmA0V7KWXiH8+3h0qk01+g6Eo0iK0pvAYjyjP/kEsCVGy2HLEKjk6sjzMXPscqI5pSi0YWoBQvAohI6cqFRhs2IRKPpfvUyeXz/Bthm8u3ssRMTsoY9hc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515076; 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=UFCg4Szdndiq0n8E4dO5pmOTN2fR3+hOItMkK2ayRPo=; b=jb9UD7Z6BRZk4iRhbAKBhXBJKhdOXwqkGbAlEu9oHic18bUAgKenhT65WI7lY9yPY5OxnkiokjGRQLHSImqfB6Nf13YgHOl/pODd+Z1rA5YPA5jx5UZMZaXK8dF5Z3hjWLj7XFVFaTQF1aNb6QLswEHbm2kN+94LKu2j2BxcM+E= 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+90862+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 1656515076041936.1561298317193; Wed, 29 Jun 2022 08:04:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5dtHYY1788612xBSH548hybA; Wed, 29 Jun 2022 08:04:35 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12735.1656515074531536027 for ; Wed, 29 Jun 2022 08:04:34 -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 66E54153B; Wed, 29 Jun 2022 08:04:34 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1F09F3F792; Wed, 29 Jun 2022 08:04:31 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 14/22] SecurityPkg/RngDxe: Replace Pcd with Sp80090Ctr256Guid Date: Wed, 29 Jun 2022 17:02:26 +0200 Message-Id: <20220629150241.2597898-18-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: S6EWGnGZ1oxmVdaJt3TdTm5Sx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515075; bh=g+5nUq6ZlbIJi62UgUCRISORH/J07SuGtoL8pg+DaL0=; h=Cc:Date:From:Reply-To:Subject:To; b=gDvN1vOmydF8yYudbmRTljZf5s+uvuW5qjvvspMHsWGTPPsyuZyNTYNxDZvis/48ulO e+buZRIArX8x8tUcpT7A2zM57BtSrTUtKnRcIIZv/rvc/xkmxyiG9VmI83UcFSHmLaup4 S+rAtrKU3Bn15ZWUY1vWWBWQr3kTE/XpAVc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515077528100005 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois gEfiRngAlgorithmSp80090Ctr256Guid was used as the default algorithm in RngGetRNG(). The commit below set the default algorithm to PcdCpuRngSupportedAlgorithm, which is a zero GUID by default. As the Pcd value is not defined for any platform in the edk2-platfoms repository, assume it was an error and go back to the first version, using gEfiRngAlgorithmSp80090Ctr256Guid. Fixes 4e5ecdbac8bd ("SecurityPkg: Add support for RngDxe on AARCH64") Signed-off-by: Pierre Gondois --- SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 8d44f0636c3d..8cfe6b471192 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -126,8 +126,7 @@ ArchGetSupportedRngAlgorithms ( OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { - UINTN RequiredSize; - EFI_RNG_ALGORITHM *CpuRngSupportedAlgorithm; + UINTN RequiredSize; =20 RequiredSize =3D 2 * sizeof (EFI_RNG_ALGORITHM); =20 @@ -136,9 +135,7 @@ ArchGetSupportedRngAlgorithms ( return EFI_BUFFER_TOO_SMALL; } =20 - CpuRngSupportedAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); - - CopyMem (&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof (EFI_RNG= _ALGORITHM)); + CopyMem (&RNGAlgorithmList[0], gEfiRngAlgorithmSp80090Ctr256Guid, sizeof= (EFI_RNG_ALGORITHM)); =20 // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED CopyMem (&RNGAlgorithmList[1], &gEfiRngAlgorithmRaw, sizeof (EFI_RNG_ALG= ORITHM)); --=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 (#90862): https://edk2.groups.io/g/devel/message/90862 Mute This Topic: https://groups.io/mt/92066746/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 17 07:07:51 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+90863+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+90863+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515078; cv=none; d=zohomail.com; s=zohoarc; b=mQTI5eNdhGA08Ta/XEiqKA37UdeYypQjnk4JqS+9S8tSxetXcUKSlpuPCyiOS12yd5pvuWxL2gkxmIa68gYaD1m6GZLEOkYWimaAAiHEZHvBnO6BwFscANxlJnOqjiq3kekdATR/PCj5DTft2vXNlDOW6ocEN/82CmzCo9RmWHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515078; 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=1A7Aba1g+N1HxRMCHn/ktGxF2qET+5gtH2E2g8cqpjY=; b=kGiBDR9pd3eCBEPx9H/+m0ekM5/8jjA7QNHwxS/Y1Vp172oJv6BD0A3ZtcOgI9GbspF2oO/4DfZySBkbXT8vkwbXXyCbD4JyyerxG+1gTyRW+sdg2ykLGptdBudBlhXb83S6nX13LcYqXqfBNX5o8zY+QeALQbMu1EDMJiMSJbo= 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+90863+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 165651507873127.516902197450122; Wed, 29 Jun 2022 08:04:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DxCBYY1788612xL2HMZtlquH; Wed, 29 Jun 2022 08:04:37 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12737.1656515076850902723 for ; Wed, 29 Jun 2022 08:04:37 -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 BDEB71763; Wed, 29 Jun 2022 08:04:36 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8EA363F792; Wed, 29 Jun 2022 08:04:34 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 15/21] SecurityPkg/RngDxe: Documentation/include/parameter cleanup Date: Wed, 29 Jun 2022 17:02:27 +0200 Message-Id: <20220629150241.2597898-19-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: 17Et5CzpnXmN4OxBJ939DvRFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515077; bh=GJ5sSy50pCanNO+ADyavOE391FSywFHw3LFywx4FQTA=; h=Cc:Date:From:Reply-To:Subject:To; b=WwftiHsY6b9DlFyf9LG9NbK2dEQJJqF0LioWaZ05olD3+FPYOO0Zf0B5PkKHlrzTb3G y03NOGcCVLXREo5FoJRlYFD1v81k41C7IWvgDWIKKrO9gc5ECWZoNU1XHhAW7S8asyk3P l2sLYbwGHALaxWvrHRQF/CSEND8AeVL0mJE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515079498100009 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois This patch: -Update RngGetBytes() documentation to align the function definition and declaration. -Improve input parameter checking. Even though 'This' it is not used, the parameter should always point to the current EFI_RNG_PROTOCOL. -Removes TimerLib inclusion as unused. Signed-off-by: Pierre Gondois --- SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c | 3 +-- SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 2 +- SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index 6d989f7ea376..f9c740d761ff 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -23,7 +23,6 @@ #include #include #include -#include #include =20 #include "RngDxeInternals.h" @@ -61,7 +60,7 @@ RngGetRNG ( { EFI_STATUS Status; =20 - if ((RNGValueLength =3D=3D 0) || (RNGValue =3D=3D NULL)) { + if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index b2d2236380fd..8f5d8e740f5e 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -59,7 +59,7 @@ RngGetRNG ( { EFI_STATUS Status; =20 - if ((RNGValueLength =3D=3D 0) || (RNGValue =3D=3D NULL)) { + if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index 6608ca8804a5..d7905a7f4d72 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -23,7 +23,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #include =20 #include "RngDxeInternals.h" @@ -72,7 +71,7 @@ RngDriverEntry ( } =20 /** - Calls RDRAND to fill a buffer of arbitrary size with random bytes. + Runs CPU RNG instruction to fill a buffer of arbitrary size with random = bytes. =20 @param[in] Length Size of the buffer, in bytes, to fill with. @param[out] RandBuffer Pointer to the buffer to store the random res= ult. --=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 (#90863): https://edk2.groups.io/g/devel/message/90863 Mute This Topic: https://groups.io/mt/92066747/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 17 07:07:51 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+90864+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+90864+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515080; cv=none; d=zohomail.com; s=zohoarc; b=Qgw5sJSRfSpgz96gQqGZZg8vpFa/AQoisl4LZPWfP8RN7eR/yELq3zRo4b7adIr8wvJsbeMwrgA2g9frMYqWTqL0FxF94P2xFjlv0/5eLBrXh3jFMXOzuZv0BTfZCH0znDe/HeDgbgeU31hXUu1SIKfOmvoO4kx4vn7xT0ZtD3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515080; 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=rtzXckIUojF6vmUeBELcP6HUyHfcp2v3q8YdDqW7hIc=; b=ew1vVIOdBDTKq4VUohp1clJ5XpTCqE9TCFmcE8CXRe6MI0ERZV84Z7mc9QIKZEYqTXJ7f1a1nR3TP1xvlDDNSt2EDGbYtlFpMZxGjRlHqWosmEH60DX0V+sEsYcw7vcuInkpky+ksNVMmwm+mlxXOYt3KohalJ4AIU7YIRS/NmU= 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+90864+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 165651508040083.56955387684957; Wed, 29 Jun 2022 08:04:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id t3y8YY1788612xY03MYOVpXP; Wed, 29 Jun 2022 08:04:40 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.12651.1656515079368766107 for ; Wed, 29 Jun 2022 08:04:39 -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 3B6A61764; Wed, 29 Jun 2022 08:04:39 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E58F63F792; Wed, 29 Jun 2022 08:04:36 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 15/22] SecurityPkg/RngDxe: Remove ArchGetSupportedRngAlgorithms() Date: Wed, 29 Jun 2022 17:02:28 +0200 Message-Id: <20220629150241.2597898-20-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: AhGjVh1LVqXv0AmgEqRdKVa1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515080; bh=aAk1MQj0bt3jK7+nB6krXdAKcNwVx/Jdbif002hTTZg=; h=Cc:Date:From:Reply-To:Subject:To; b=HiBjYpwW4AZEBaN3QGJ5hCrKDpSYun8PV47HkkT4dYdocld0wq3HrQ/l7jAv53Qkrun RAkBBqFHrCYSkcmMo6HNMC36TzcAWuUla8gjMWx/90FQC5Pq9pRNcPY2ln0LcxgYCo07c spW1SLKERYlPgK0JNRKd5BiILEzLWvxefPE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515081580100013 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois RngGetInfo() is one of the 2 functions of the EFI_RNG_PROTOCOL. RngGetInfo() is currently a mere wrapper around ArchGetSupportedRngAlgorithms() which is implemented differently depending on the architecture used. RngGetInfo() does nothing more than calling ArchGetSupportedRngAlgorithms(). So remove it, and let RngGetInfo() be implemented differently according to the architecture. This follows the implementation of the other function of the EFI_RNG_PROTOCOL, RngGetRNG(). Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/RngDxe.c | 19 +++++-- .../RngDxe/Rand/RngDxe.c | 24 +++++++-- .../RandomNumberGenerator/RngDxe/RngDxe.c | 49 ------------------- .../RngDxe/RngDxeInternals.h | 25 ---------- 4 files changed, 34 insertions(+), 83 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index 3daf847d46d3..6d989f7ea376 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -14,6 +14,7 @@ Copyright (c) 2021, NUVIA Inc. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -85,6 +86,7 @@ RngGetRNG ( /** Returns information about the random number generation implementation. =20 + @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. On output with a return code of EFI_= SUCCESS, the size in bytes of the data returned in RNG= AlgorithmList. On output @@ -97,14 +99,19 @@ RngGetRNG ( is the default algorithm for the dri= ver. =20 @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. + @retval EFI_UNSUPPORTED The services is not supported by thi= s driver. + @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a + hardware or firmware error. + @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. =20 **/ -UINTN +EFI_STATUS EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList +RngGetInfo ( + IN EFI_RNG_PROTOCOL *This, + IN OUT UINTN *RNGAlgorithmListSize, + OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { UINTN RequiredSize; @@ -112,6 +119,10 @@ ArchGetSupportedRngAlgorithms ( =20 RequiredSize =3D sizeof (EFI_RNG_ALGORITHM); =20 + if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + if (*RNGAlgorithmListSize < RequiredSize) { *RNGAlgorithmListSize =3D RequiredSize; return EFI_BUFFER_TOO_SMALL; diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 8cfe6b471192..b2d2236380fd 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -104,6 +104,7 @@ RngGetRNG ( /** Returns information about the random number generation implementation. =20 + @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. On output with a return code of EFI_= SUCCESS, the size in bytes of the data returned in RNG= AlgorithmList. On output @@ -116,18 +117,27 @@ RngGetRNG ( is the default algorithm for the dri= ver. =20 @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. + @retval EFI_UNSUPPORTED No supported algorithms found. + @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a + hardware or firmware error. + @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. =20 **/ -UINTN +EFI_STATUS EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList +RngGetInfo ( + IN EFI_RNG_PROTOCOL *This, + IN OUT UINTN *RNGAlgorithmListSize, + OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { UINTN RequiredSize; =20 + if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + RequiredSize =3D 2 * sizeof (EFI_RNG_ALGORITHM); =20 if (*RNGAlgorithmListSize < RequiredSize) { @@ -135,7 +145,11 @@ ArchGetSupportedRngAlgorithms ( return EFI_BUFFER_TOO_SMALL; } =20 - CopyMem (&RNGAlgorithmList[0], gEfiRngAlgorithmSp80090Ctr256Guid, sizeof= (EFI_RNG_ALGORITHM)); + if (RNGAlgorithmList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CopyMem (&RNGAlgorithmList[0], &gEfiRngAlgorithmSp80090Ctr256Guid, sizeo= f (EFI_RNG_ALGORITHM)); =20 // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED CopyMem (&RNGAlgorithmList[1], &gEfiRngAlgorithmRaw, sizeof (EFI_RNG_ALG= ORITHM)); diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index 6f52eeff4a09..6608ca8804a5 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -28,55 +28,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "RngDxeInternals.h" =20 -/** - Returns information about the random number generation implementation. - - @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. - @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. - On output with a return code of EFI_= SUCCESS, the size - in bytes of the data returned in RNG= AlgorithmList. On output - with a return code of EFI_BUFFER_TOO= _SMALL, - the size of RNGAlgorithmList require= d to obtain the list. - @param[out] RNGAlgorithmList A caller-allocated memory buffer fil= led by the driver - with one EFI_RNG_ALGORITHM element f= or each supported - RNG algorithm. The list must not cha= nge across multiple - calls to the same driver. The first = algorithm in the list - is the default algorithm for the dri= ver. - - @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. - @retval EFI_UNSUPPORTED The services is not supported by thi= s driver. - @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a - hardware or firmware error. - @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. - @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. - -**/ -EFI_STATUS -EFIAPI -RngGetInfo ( - IN EFI_RNG_PROTOCOL *This, - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList - ) -{ - EFI_STATUS Status; - - if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - // - // Return algorithm list supported by driver. - // - if (RNGAlgorithmList !=3D NULL) { - Status =3D ArchGetSupportedRngAlgorithms (RNGAlgorithmListSize, RNGAlg= orithmList); - } else { - Status =3D EFI_INVALID_PARAMETER; - } - - return Status; -} - // // The Random Number Generator (RNG) protocol // diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/S= ecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index 48d2d27c1608..7ecab140483d 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -74,31 +74,6 @@ RngGetRNG ( OUT UINT8 *RNGValue ); =20 -/** - Returns information about the random number generation implementation. - - @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. - On output with a return code of EFI_= SUCCESS, the size - in bytes of the data returned in RNG= AlgorithmList. On output - with a return code of EFI_BUFFER_TOO= _SMALL, - the size of RNGAlgorithmList require= d to obtain the list. - @param[out] RNGAlgorithmList A caller-allocated memory buffer fil= led by the driver - with one EFI_RNG_ALGORITHM element f= or each supported - RNG algorithm. The list must not cha= nge across multiple - calls to the same driver. The first = algorithm in the list - is the default algorithm for the dri= ver. - - @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. - @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. - -**/ -UINTN -EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList - ); - /** Runs CPU RNG instruction to fill a buffer of arbitrary size with random = bytes. =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 (#90864): https://edk2.groups.io/g/devel/message/90864 Mute This Topic: https://groups.io/mt/92066748/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 17 07:07:51 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+90866+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+90866+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515085; cv=none; d=zohomail.com; s=zohoarc; b=Dj2bDjUWfoxwVBuOzjTmP9hhYXTEul8x7yWBtR3kBz8PbHjDi1qCkksB6b2YExaFPpw7RmVO6b8fZST29y45Ort9GhbOSwVrLgwHO4r7TT7dPVgbwxaoc/I2IEoXe2Fw3ObJQovnh0e09qRbahYhcjhnu/G4JqrKlsQrS87lFHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515085; 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=XQFJyVhGgD47aXtIQbd3my+spYPya14RRrw0Js3/UmU=; b=LSA92Ta00aOvCq0pws/Og9RR59k5wKiKrXLjXUvnG7KL1E7/ErmEAAI8W+TLYdSm+/2ImYvS+Dm938k8aur4v+b6pNa7khdkAEzTouwToNKPmuWDf1Z5qKOIoJq1WdXef89YGUNtItVVH1lWpE7kNcYwXkp64Gmp0i6hcTeOcJ8= 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+90866+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 1656515085333634.542490613528; Wed, 29 Jun 2022 08:04:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tvXWYY1788612xFX8Vbb0q4T; Wed, 29 Jun 2022 08:04:45 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12721.1656515084288462783 for ; Wed, 29 Jun 2022 08:04:44 -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 3E1E6176A; Wed, 29 Jun 2022 08:04:44 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E9F6C3F792; Wed, 29 Jun 2022 08:04:41 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 16/22] SecurityPkg/RngDxe: Documentation/include/parameter cleanup Date: Wed, 29 Jun 2022 17:02:30 +0200 Message-Id: <20220629150241.2597898-22-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: TSgy065F2QV7AVnzySyeEJqjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515085; bh=Dus2s1A3PExeO06hnR/8E0QzDeLCUjXIt4NWA0Qjto0=; h=Cc:Date:From:Reply-To:Subject:To; b=OPp8xaGCCBp3KdCKhwkNMkak1CeI6NxXv+AuFCVb//tJIlrysmhg+oI68Bb9ZcMkuOb 76kvbUOFiQFvlco7SfrKgMheASDEi7CXAKPeG9ZVUla2KFu1tuTP/v4RWlYbxCImHBXh9 +wvAVOH8ahV5drrUr18S9oxrYSCTBN2u490= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515087510100023 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois This patch: -Update RngGetBytes() documentation to align the function definition and declaration. -Improve input parameter checking. Even though 'This' it is not used, the parameter should always point to the current EFI_RNG_PROTOCOL. -Removes TimerLib inclusion as unused. Signed-off-by: Pierre Gondois --- SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c | 3 +-- SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 2 +- SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index 6d989f7ea376..f9c740d761ff 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -23,7 +23,6 @@ #include #include #include -#include #include =20 #include "RngDxeInternals.h" @@ -61,7 +60,7 @@ RngGetRNG ( { EFI_STATUS Status; =20 - if ((RNGValueLength =3D=3D 0) || (RNGValue =3D=3D NULL)) { + if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index b2d2236380fd..8f5d8e740f5e 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -59,7 +59,7 @@ RngGetRNG ( { EFI_STATUS Status; =20 - if ((RNGValueLength =3D=3D 0) || (RNGValue =3D=3D NULL)) { + if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index 6608ca8804a5..d7905a7f4d72 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -23,7 +23,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #include =20 #include "RngDxeInternals.h" @@ -72,7 +71,7 @@ RngDriverEntry ( } =20 /** - Calls RDRAND to fill a buffer of arbitrary size with random bytes. + Runs CPU RNG instruction to fill a buffer of arbitrary size with random = bytes. =20 @param[in] Length Size of the buffer, in bytes, to fill with. @param[out] RandBuffer Pointer to the buffer to store the random res= ult. --=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 (#90866): https://edk2.groups.io/g/devel/message/90866 Mute This Topic: https://groups.io/mt/92066751/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 17 07:07:51 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+90865+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+90865+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515082; cv=none; d=zohomail.com; s=zohoarc; b=JP10eQMcqhxfG9Edh0rbTaVuIKXz+Vyj7rxMN1RcicypX/yazdueB1SQGhsH05+HULIhNNHxG0l0/dbDouk1IzV4WonPUjRopCguR7SXNDCMl/x+IDMUINAefwWDYGMLczDh3kzRerVs1zgtsKViNFlJIm7cJblHGRFTaHwRYzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515082; 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=Ht/gblqa0xQVp5AZupe5Mf2f6ynpaSBmSsU+do4RhK4=; b=Fip2lo04HF6OuAZ74R/hzCGyZWbXEtwuKMbwXeNzgbULYXMYYoeQ9r8lDmKR247Li3cTMnk0nY8UVKE9gEuUfs3Q9csBnwR8bLeIQJQ51qA27QslQzR2iPD1lab6ZwVW9v4dPZsKJ6DlffTGFJRLh+/v60S8OwI+QRaWDBOmOXI= 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+90865+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 1656515082928678.1253766614013; Wed, 29 Jun 2022 08:04:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZcKMYY1788612xtBhUPOxX70; Wed, 29 Jun 2022 08:04:42 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.12647.1656515081832624494 for ; Wed, 29 Jun 2022 08:04:42 -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 C385D1763; Wed, 29 Jun 2022 08:04:41 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5385D3F792; Wed, 29 Jun 2022 08:04:39 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 16/21] SecurityPkg/RngDxe: Check before advertising Cpu Rng algo Date: Wed, 29 Jun 2022 17:02:29 +0200 Message-Id: <20220629150241.2597898-21-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: s44LEJH7Fr3cBQwUE1lqMKXVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515082; bh=x8ZwvfPiR/7iPkBW40JjJ1/txb5q7MKifrOd861q6OI=; h=Cc:Date:From:Reply-To:Subject:To; b=ul8orgN62gdjE+8udMJ/MTEedgd2x5aRvk9DDPDLAJbxrbXdTw0vtCJUeKgfaXtBtWx oFHMbJ4U6/On128NIqK9+/gOghV+6M1x0jDNWjlQtfDmYPQ9AbYJa4n4BFxBswWpRaUOw bP4oI1yldPCxrSG+Zg9QAMIHT74Kt6xwvQs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515083575100017 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois RngGetBytes() relies on the RngLib. The RngLib might use the RNDR instruction if the FEAT_RNG feature is present. Check RngGetBytes() is working before advertising it via RngGetInfo(). To only check this one time, create a static array that is shared between RngGetInfo and RngGetRNG. This array contains GUIDs. The Rng algorithm with the lowest GUID and that has been checked will be the default Rng algorithm. This patch also prevents from having PcdCpuRngSupportedAlgorithm let to a zero GUID, but let the possibility to have no valid Rng algorithm in such case. Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/RngDxe.c | 77 +++++++++++++++++-- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index f9c740d761ff..d8b696bbea5f 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -23,10 +23,44 @@ #include #include #include +#include #include =20 #include "RngDxeInternals.h" =20 +// +// Static array containing the validated Rng algorithm. +// This array is used by RngGetInfo and RngGetRNG and needs to be +// populated only once. +// The valid entry with the lowest index will be the default algorithm. +// +#define RNG_AVAILABLE_ALGO_MAX 1 +STATIC BOOLEAN mAvailableAlgoArrayInit =3D FALSE; +STATIC UINTN mAvailableAlgoArrayCount; +STATIC EFI_RNG_ALGORITHM mAvailableAlgoArray[RNG_AVAILABLE_ALGO_MAX]; + +/** Initialize mAvailableAlgoArray with the available Rng algorithms. +**/ +STATIC +VOID +EFIAPI +RngInitAvailableAlgoArray ( + VOID + ) +{ + // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. + if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + PcdGetPtr (PcdCpuRngSupportedAlgorithm), + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + + mAvailableAlgoArrayInit =3D TRUE; +} + /** Produces and returns an RNG value using either the default or specified = RNG algorithm. =20 @@ -59,18 +93,35 @@ RngGetRNG ( ) { EFI_STATUS Status; + UINTN Index; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 + if (!mAvailableAlgoArrayInit) { + RngInitAvailableAlgoArray (); + } + if (RNGAlgorithm =3D=3D NULL) { // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - RNGAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); + for (Index =3D 0; Index < RNG_AVAILABLE_ALGO_MAX; Index++) { + if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { + RNGAlgorithm =3D &mAvailableAlgoArray[Index]; + goto FoundAlgo; + } + } + + if (Index =3D=3D RNG_AVAILABLE_ALGO_MAX) { + // No algorithm available. + ASSERT (Index !=3D RNG_AVAILABLE_ALGO_MAX); + return EFI_DEVICE_ERROR; + } } =20 +FoundAlgo: if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)))= { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; @@ -113,24 +164,34 @@ RngGetInfo ( OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { - UINTN RequiredSize; - EFI_RNG_ALGORITHM *CpuRngSupportedAlgorithm; - - RequiredSize =3D sizeof (EFI_RNG_ALGORITHM); + UINTN RequiredSize; =20 if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } =20 + if (!mAvailableAlgoArrayInit) { + RngInitAvailableAlgoArray (); + } + + RequiredSize =3D mAvailableAlgoArrayCount * sizeof (EFI_RNG_ALGORITHM); + + if (RequiredSize =3D=3D 0) { + // No supported algorithms found. + return EFI_UNSUPPORTED; + } + if (*RNGAlgorithmListSize < RequiredSize) { *RNGAlgorithmListSize =3D RequiredSize; return EFI_BUFFER_TOO_SMALL; } =20 - CpuRngSupportedAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); - - CopyMem (&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof (EFI_RNG= _ALGORITHM)); + if (RNGAlgorithmList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } =20 + // There is no gap in the array, so copy the block. + CopyMem (RNGAlgorithmList, mAvailableAlgoArray, RequiredSize); *RNGAlgorithmListSize =3D RequiredSize; return EFI_SUCCESS; } --=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 (#90865): https://edk2.groups.io/g/devel/message/90865 Mute This Topic: https://groups.io/mt/92066750/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 17 07:07:51 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+90867+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+90867+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515087; cv=none; d=zohomail.com; s=zohoarc; b=dtBzLbh3eJb/rRhAqnwPURKX3HdmkH9tCgVTk0cRgEUFT6R5dVKNeoCreYYB+64XyK0ro7x4MJmx95wvZ4otccXfAoCCTwSlve3tN0THpMtnEI8CcBZVJOJQIeNLKm41gjuFVffyLqen8jzwbXvUmerPeDrONvPBo3K7L9sb/Wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515087; 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=m93qjm48mB9TG5AGK+C1aAGwWd4VQ1cNvVi1SUjVTZs=; b=KDuA79kUqERdXSSfE+qlMCEFqkCCr+owAz0IcyQeTw+1RzL3Mp57Mj64AsKjIBrqbqKIpbMEYa1Kq4tZcaWKWFN9oKNkEgx2DiouAmAlN4eWqw1To9d+47J4jnfHSXdSBp/+BchFGQSoryfARqT2iyT6nxsDhT/qmoBzORy5BcI= 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+90867+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 1656515087903812.6706846894634; Wed, 29 Jun 2022 08:04:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1DNVYY1788612xNEjw6Rbtuh; Wed, 29 Jun 2022 08:04:47 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12738.1656515086856979985 for ; Wed, 29 Jun 2022 08:04:47 -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 B8F8D176B; Wed, 29 Jun 2022 08:04:46 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 659C63F792; Wed, 29 Jun 2022 08:04:44 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 17/21] SecurityPkg/RngDxe: Add AArch64 RawAlgorithm support through TrngLib Date: Wed, 29 Jun 2022 17:02:31 +0200 Message-Id: <20220629150241.2597898-23-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: lH9DWMGvCl4T2IKHkhOY77kfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515087; bh=mY/1cNox7ZKbolzqNzvrsAWZuWcy3JZW+p/DaMFnH5E=; h=Cc:Date:From:Reply-To:Subject:To; b=kHZvAvpIWc5bdXfb8gEehYcs35MsUy1KnP2CjtGaPAWuRTVMYiGSbQoZQfYUZb75z+T dh1EXeqUWnjRY+M637urbk+y4jMNAHBuKHfbhlZuvQaGyWcZddOEo1vU5mEc65tp/qA5A yfs5UeYeQbNNLbr6sONZUh1fhmVfD5mm+1Y= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515089567100027 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) RawAlgorithm is used to provide access to entropy that is suitable for cryptographic applications. Therefore, add RawAlgorithm support that provides access to entropy using the TrngLib. Also remove unused UefiBootServicesTableLib library inclusion and Status variable. Signed-off-by: Sami Mujawar --- .../RngDxe/AArch64/RngDxe.c | 28 +++++++- .../RandomNumberGenerator/RngDxe/ArmTrng.c | 71 +++++++++++++++++++ .../RandomNumberGenerator/RngDxe/RngDxe.inf | 5 ++ SecurityPkg/SecurityPkg.dsc | 7 ++ 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index d8b696bbea5f..ee3f1ee78434 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -1,11 +1,13 @@ /** @file RNG Driver to produce the UEFI Random Number Generator protocol. =20 - The driver will use the RNDR instruction to produce random numbers. + The driver can use RNDR instruction (through the RngLib and if FEAT_RNG = is + present) to produce random numbers. It also uses the Arm FW-TRNG interfa= ce + to implement EFI_RNG_ALGORITHM_RAW. =20 RNG Algorithms defined in UEFI 2.4: - EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID - - EFI_RNG_ALGORITHM_RAW - Unsupported + - EFI_RNG_ALGORITHM_RAW - EFI_RNG_ALGORITHM_SP800_90_HMAC_256_GUID - EFI_RNG_ALGORITHM_SP800_90_HASH_256_GUID - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - Unsupported @@ -24,6 +26,8 @@ #include #include #include +#include +#include #include =20 #include "RngDxeInternals.h" @@ -34,7 +38,7 @@ // populated only once. // The valid entry with the lowest index will be the default algorithm. // -#define RNG_AVAILABLE_ALGO_MAX 1 +#define RNG_AVAILABLE_ALGO_MAX 2 STATIC BOOLEAN mAvailableAlgoArrayInit =3D FALSE; STATIC UINTN mAvailableAlgoArrayCount; STATIC EFI_RNG_ALGORITHM mAvailableAlgoArray[RNG_AVAILABLE_ALGO_MAX]; @@ -48,6 +52,9 @@ RngInitAvailableAlgoArray ( VOID ) { + UINT16 MajorRevision; + UINT16 MinorRevision; + // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) { CopyMem ( @@ -58,6 +65,16 @@ RngInitAvailableAlgoArray ( mAvailableAlgoArrayCount++; } =20 + // Raw algorithm (Trng) + if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &gEfiRngAlgorithmRaw, + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + mAvailableAlgoArrayInit =3D TRUE; } =20 @@ -127,6 +144,11 @@ FoundAlgo: return Status; } =20 + // Raw algorithm (Trng) + if (CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmRaw)) { + return GenerateEntropy (RNGValueLength, RNGValue); + } + // // Other algorithms are unsupported by this driver. // diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c b/SecurityP= kg/RandomNumberGenerator/RngDxe/ArmTrng.c new file mode 100644 index 000000000000..6100e02b32b0 --- /dev/null +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c @@ -0,0 +1,71 @@ +/** @file + RNG Driver to produce the UEFI Random Number Generator protocol. + + The driver implements the EFI_RNG_ALGORITHM_RAW using the FW-TRNG + interface to provide entropy. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +#include "RngDxeInternals.h" + +/** + Generate high-quality entropy source using a TRNG or through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy da= ta. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +EFI_STATUS +EFIAPI +GenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ) +{ + EFI_STATUS Status; + UINTN CollectedEntropyBits; + UINTN RequiredEntropyBits; + UINTN EntropyBits; + UINTN Index; + UINTN MaxBits; + + ZeroMem (Entropy, Length); + + RequiredEntropyBits =3D (Length << 3); + Index =3D 0; + CollectedEntropyBits =3D 0; + MaxBits =3D GetTrngMaxSupportedEntropyBits (); + while (CollectedEntropyBits < RequiredEntropyBits) { + EntropyBits =3D MIN ((RequiredEntropyBits - CollectedEntropyBits), Max= Bits); + Status =3D GetTrngEntropy ( + EntropyBits, + (Length - Index), + &Entropy[Index] + ); + if (EFI_ERROR (Status)) { + // Discard the collected bits. + ZeroMem (Entropy, Length); + return Status; + } + + CollectedEntropyBits +=3D EntropyBits; + Index +=3D (EntropyBits >> 3); + } // while + + return Status; +} diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 60efb5562ee0..6c3d42066804 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -42,8 +42,10 @@ [Sources.IA32, Sources.X64] =20 [Sources.AARCH64] AArch64/RngDxe.c + ArmTrng.c =20 [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec SecurityPkg/SecurityPkg.dec =20 @@ -56,6 +58,9 @@ [LibraryClasses] TimerLib RngLib =20 +[LibraryClasses.AARCH64] + TrngLib + [Guids] gEfiRngAlgorithmSp80090Hash256Guid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG gEfiRngAlgorithmSp80090Hmac256Guid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index d883747474e4..490076542a33 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -3,6 +3,7 @@ # # Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
# (C) Copyright 2015-2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -87,6 +88,12 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] =20 ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf =20 + # Arm FW-TRNG interface library. + TrngLib|ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf + ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf + ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf + ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf + [LibraryClasses.ARM] RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =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 (#90867): https://edk2.groups.io/g/devel/message/90867 Mute This Topic: https://groups.io/mt/92066752/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 17 07:07:51 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+90868+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+90868+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515090; cv=none; d=zohomail.com; s=zohoarc; b=dFGHdpr/QqzEcXUR7GKKR1GhdWwhadIwA6w4nRd0yrtOt/K2gG6HWpJTAWIOJwVnLrRl1U0XJ+LoCaEYkwylu2yWOrpB69srflhe6KOjZlYJJ+cYGRlUaUm//Bg+gMf9C/C88HCYIwkiEFIf9pkBILE6Dw0yhghBE/GnwKCWrTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515090; 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=Fjn09WK4trn+bnf7ebumbjTmX3Jr2PfvbglSAFyaBx4=; b=MqhRdDJ3Q52hnJ4BNUse0RimMBrLlFtAbHzwJHej1gCw5LYnlziwiJUjCpeAXAGqeBM1h1BbHHRqk+fCnPX0pr0cTwliaAk6KXEglEzinNlD+lJZHvm70jBp7YkPD3TmFQ5qejQLC+PJj+YKlmR0hahl0Etv3IH5iEnsouVAMuI= 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+90868+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 1656515090353828.4609968005963; Wed, 29 Jun 2022 08:04:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kz1hYY1788612xw7XE1kWP5j; Wed, 29 Jun 2022 08:04:50 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.12652.1656515089245170719 for ; Wed, 29 Jun 2022 08:04:49 -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 2A140176C; Wed, 29 Jun 2022 08:04:49 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE8493F792; Wed, 29 Jun 2022 08:04:46 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 17/22] SecurityPkg/RngDxe: Check before advertising Cpu Rng algo Date: Wed, 29 Jun 2022 17:02:32 +0200 Message-Id: <20220629150241.2597898-24-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: pNDRsIwNqbn029h6eEUwJaTzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515090; bh=1yrMZyx2Qk9cMXyOytk4BuKSDLJqff/yXAOGemi/sso=; h=Cc:Date:From:Reply-To:Subject:To; b=nEQ8OQUZDCDBlGCipGXiMX59yArckxyifzZV9rqFaRIMkXwDLGLntsosX9h3VrfnaxD A5CbOj/rpHBgLsTnCx2ZQOxj53zWiVAk1hPF3qZ8x7N51hsoNoo/zleAZG/IpEEFevdfq dOANv6gXh5vPcdvuWD2rx9E11toQGlGGxNo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515091624100031 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois RngGetBytes() relies on the RngLib. The RngLib might use the RNDR instruction if the FEAT_RNG feature is present. Check RngGetBytes() is working before advertising it via RngGetInfo(). To only check this one time, create a static array that is shared between RngGetInfo and RngGetRNG. This array contains GUIDs. The Rng algorithm with the lowest GUID and that has been checked will be the default Rng algorithm. This patch also prevents from having PcdCpuRngSupportedAlgorithm let to a zero GUID, but let the possibility to have no valid Rng algorithm in such case. Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/RngDxe.c | 77 +++++++++++++++++-- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index f9c740d761ff..d8b696bbea5f 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -23,10 +23,44 @@ #include #include #include +#include #include =20 #include "RngDxeInternals.h" =20 +// +// Static array containing the validated Rng algorithm. +// This array is used by RngGetInfo and RngGetRNG and needs to be +// populated only once. +// The valid entry with the lowest index will be the default algorithm. +// +#define RNG_AVAILABLE_ALGO_MAX 1 +STATIC BOOLEAN mAvailableAlgoArrayInit =3D FALSE; +STATIC UINTN mAvailableAlgoArrayCount; +STATIC EFI_RNG_ALGORITHM mAvailableAlgoArray[RNG_AVAILABLE_ALGO_MAX]; + +/** Initialize mAvailableAlgoArray with the available Rng algorithms. +**/ +STATIC +VOID +EFIAPI +RngInitAvailableAlgoArray ( + VOID + ) +{ + // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. + if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + PcdGetPtr (PcdCpuRngSupportedAlgorithm), + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + + mAvailableAlgoArrayInit =3D TRUE; +} + /** Produces and returns an RNG value using either the default or specified = RNG algorithm. =20 @@ -59,18 +93,35 @@ RngGetRNG ( ) { EFI_STATUS Status; + UINTN Index; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 + if (!mAvailableAlgoArrayInit) { + RngInitAvailableAlgoArray (); + } + if (RNGAlgorithm =3D=3D NULL) { // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - RNGAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); + for (Index =3D 0; Index < RNG_AVAILABLE_ALGO_MAX; Index++) { + if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { + RNGAlgorithm =3D &mAvailableAlgoArray[Index]; + goto FoundAlgo; + } + } + + if (Index =3D=3D RNG_AVAILABLE_ALGO_MAX) { + // No algorithm available. + ASSERT (Index !=3D RNG_AVAILABLE_ALGO_MAX); + return EFI_DEVICE_ERROR; + } } =20 +FoundAlgo: if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)))= { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; @@ -113,24 +164,34 @@ RngGetInfo ( OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { - UINTN RequiredSize; - EFI_RNG_ALGORITHM *CpuRngSupportedAlgorithm; - - RequiredSize =3D sizeof (EFI_RNG_ALGORITHM); + UINTN RequiredSize; =20 if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } =20 + if (!mAvailableAlgoArrayInit) { + RngInitAvailableAlgoArray (); + } + + RequiredSize =3D mAvailableAlgoArrayCount * sizeof (EFI_RNG_ALGORITHM); + + if (RequiredSize =3D=3D 0) { + // No supported algorithms found. + return EFI_UNSUPPORTED; + } + if (*RNGAlgorithmListSize < RequiredSize) { *RNGAlgorithmListSize =3D RequiredSize; return EFI_BUFFER_TOO_SMALL; } =20 - CpuRngSupportedAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); - - CopyMem (&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof (EFI_RNG= _ALGORITHM)); + if (RNGAlgorithmList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } =20 + // There is no gap in the array, so copy the block. + CopyMem (RNGAlgorithmList, mAvailableAlgoArray, RequiredSize); *RNGAlgorithmListSize =3D RequiredSize; return EFI_SUCCESS; } --=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 (#90868): https://edk2.groups.io/g/devel/message/90868 Mute This Topic: https://groups.io/mt/92066753/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 17 07:07:51 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+90869+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+90869+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515093; cv=none; d=zohomail.com; s=zohoarc; b=LzveT5NF1+qHxpvQbkL7JNFr+CzlQmxO9n4DcOW5a2hovV5zbnHv1S38KMIlRD6iHjwx2bQVITPEI6pwgkZTQwqPYsnkkfniDwq630KHc2JI01eb1PVeHp/ixZXQ0pm4IafBXiMkthMToLf/m8JiXvL/RhqamMdjvm0+U4RQ3zc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515093; 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=UKqO6EUiPDGazEyAzGI4G2YLLmK5myZgxKN+vY64JCE=; b=Ls0pOojtPk4Sm+BKy+9jc5sGWZlEHBA01IwkJgOoKeZ+qxBYXnnR3cOXXlUtkT6afQ+5UcTuuMYnPfVf0xqgP0vUn64hzMWWczThXIaSER1ZBl7VI+jd8zpN43DNkQdMLbH1y9AuFbmPsTMUhx33ukvuV49jaGe+toFtSKvfjbQ= 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+90869+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 1656515093196597.9783409778223; Wed, 29 Jun 2022 08:04:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4g1JYY1788612x54FH8T1twc; Wed, 29 Jun 2022 08:04:52 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12739.1656515091604400850 for ; Wed, 29 Jun 2022 08:04:51 -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 816811764; Wed, 29 Jun 2022 08:04:51 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 419263F792; Wed, 29 Jun 2022 08:04:49 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 18/22] SecurityPkg/RngDxe: Add AArch64 RawAlgorithm support through TrngLib Date: Wed, 29 Jun 2022 17:02:33 +0200 Message-Id: <20220629150241.2597898-25-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: HHsJQIZJqQ7kYhoJ6miky78nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515092; bh=O596F18s3wP1Dw3Xr3FngosR/NqYUSgmy0fn4WCYcoo=; h=Cc:Date:From:Reply-To:Subject:To; b=e8U3bKpQOKtLbGT9rUGRY6tDrJRC6btSCtk9BXFZRTFtev/wI9wF1QSud1mw2YyaeCW 1fGXpTjbSlnQlB+S3upzR01yEmMRKMZgMnDOujNYezKLM9SvZxjlIg4osUz/ztIaA/66r syr7+1jSUb7qOEWVmGJZ/mDWT/fJ2Lc/TkA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515093618100035 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) RawAlgorithm is used to provide access to entropy that is suitable for cryptographic applications. Therefore, add RawAlgorithm support that provides access to entropy using the TrngLib. Also remove unused UefiBootServicesTableLib library inclusion and Status variable. Signed-off-by: Sami Mujawar --- .../RngDxe/AArch64/RngDxe.c | 28 +++++++- .../RandomNumberGenerator/RngDxe/ArmTrng.c | 71 +++++++++++++++++++ .../RandomNumberGenerator/RngDxe/RngDxe.inf | 5 ++ SecurityPkg/SecurityPkg.dsc | 7 ++ 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index d8b696bbea5f..ee3f1ee78434 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -1,11 +1,13 @@ /** @file RNG Driver to produce the UEFI Random Number Generator protocol. =20 - The driver will use the RNDR instruction to produce random numbers. + The driver can use RNDR instruction (through the RngLib and if FEAT_RNG = is + present) to produce random numbers. It also uses the Arm FW-TRNG interfa= ce + to implement EFI_RNG_ALGORITHM_RAW. =20 RNG Algorithms defined in UEFI 2.4: - EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID - - EFI_RNG_ALGORITHM_RAW - Unsupported + - EFI_RNG_ALGORITHM_RAW - EFI_RNG_ALGORITHM_SP800_90_HMAC_256_GUID - EFI_RNG_ALGORITHM_SP800_90_HASH_256_GUID - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - Unsupported @@ -24,6 +26,8 @@ #include #include #include +#include +#include #include =20 #include "RngDxeInternals.h" @@ -34,7 +38,7 @@ // populated only once. // The valid entry with the lowest index will be the default algorithm. // -#define RNG_AVAILABLE_ALGO_MAX 1 +#define RNG_AVAILABLE_ALGO_MAX 2 STATIC BOOLEAN mAvailableAlgoArrayInit =3D FALSE; STATIC UINTN mAvailableAlgoArrayCount; STATIC EFI_RNG_ALGORITHM mAvailableAlgoArray[RNG_AVAILABLE_ALGO_MAX]; @@ -48,6 +52,9 @@ RngInitAvailableAlgoArray ( VOID ) { + UINT16 MajorRevision; + UINT16 MinorRevision; + // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) { CopyMem ( @@ -58,6 +65,16 @@ RngInitAvailableAlgoArray ( mAvailableAlgoArrayCount++; } =20 + // Raw algorithm (Trng) + if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &gEfiRngAlgorithmRaw, + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + mAvailableAlgoArrayInit =3D TRUE; } =20 @@ -127,6 +144,11 @@ FoundAlgo: return Status; } =20 + // Raw algorithm (Trng) + if (CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmRaw)) { + return GenerateEntropy (RNGValueLength, RNGValue); + } + // // Other algorithms are unsupported by this driver. // diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c b/SecurityP= kg/RandomNumberGenerator/RngDxe/ArmTrng.c new file mode 100644 index 000000000000..6100e02b32b0 --- /dev/null +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c @@ -0,0 +1,71 @@ +/** @file + RNG Driver to produce the UEFI Random Number Generator protocol. + + The driver implements the EFI_RNG_ALGORITHM_RAW using the FW-TRNG + interface to provide entropy. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +#include "RngDxeInternals.h" + +/** + Generate high-quality entropy source using a TRNG or through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy da= ta. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +EFI_STATUS +EFIAPI +GenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ) +{ + EFI_STATUS Status; + UINTN CollectedEntropyBits; + UINTN RequiredEntropyBits; + UINTN EntropyBits; + UINTN Index; + UINTN MaxBits; + + ZeroMem (Entropy, Length); + + RequiredEntropyBits =3D (Length << 3); + Index =3D 0; + CollectedEntropyBits =3D 0; + MaxBits =3D GetTrngMaxSupportedEntropyBits (); + while (CollectedEntropyBits < RequiredEntropyBits) { + EntropyBits =3D MIN ((RequiredEntropyBits - CollectedEntropyBits), Max= Bits); + Status =3D GetTrngEntropy ( + EntropyBits, + (Length - Index), + &Entropy[Index] + ); + if (EFI_ERROR (Status)) { + // Discard the collected bits. + ZeroMem (Entropy, Length); + return Status; + } + + CollectedEntropyBits +=3D EntropyBits; + Index +=3D (EntropyBits >> 3); + } // while + + return Status; +} diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 60efb5562ee0..6c3d42066804 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -42,8 +42,10 @@ [Sources.IA32, Sources.X64] =20 [Sources.AARCH64] AArch64/RngDxe.c + ArmTrng.c =20 [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec SecurityPkg/SecurityPkg.dec =20 @@ -56,6 +58,9 @@ [LibraryClasses] TimerLib RngLib =20 +[LibraryClasses.AARCH64] + TrngLib + [Guids] gEfiRngAlgorithmSp80090Hash256Guid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG gEfiRngAlgorithmSp80090Hmac256Guid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index d883747474e4..490076542a33 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -3,6 +3,7 @@ # # Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
# (C) Copyright 2015-2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -87,6 +88,12 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] =20 ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf =20 + # Arm FW-TRNG interface library. + TrngLib|ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf + ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf + ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf + ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf + [LibraryClasses.ARM] RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =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 (#90869): https://edk2.groups.io/g/devel/message/90869 Mute This Topic: https://groups.io/mt/92066754/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 17 07:07:51 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+90870+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+90870+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515096; cv=none; d=zohomail.com; s=zohoarc; b=UIoeer7zLR+7c5jYpDaCRdeO9S1JJ8aXT/xEbDinDgHuEwCjyS+0B7yZ4d3sqHEhdXI6tiXFMkzKgRSkigOcmmksr3fgpxgQxliH+IT++FeuiVzGbjvX1dPKYo4cWvP8xLQUoUaaBUrEEmR4CjoZ1KMkFKxg/mzZeJCk908zLXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515096; 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=fMEY15sQMqGgJKHstnwmdeHIMJVP4u3619tNQf1/Jw4=; b=WwG0IPwbQBPlNfxaIGkZoGIx3AxymJeDqZeF/7bkngvAWqPtt9Y6/slYgdAGDE6YPRCSw9xxNH5XX57smutQC8ENvcTc3e31zjkpq/RH2cxNsoZPfdsLI8txh1/fiKRLSXawbGDxI8z7phP5Vj5J6VO4w971D7rUHo7A91diC6Q= 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+90870+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 1656515095948990.9508070013469; Wed, 29 Jun 2022 08:04:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qZJBYY1788612xHDJpfvPKOO; Wed, 29 Jun 2022 08:04:54 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12724.1656515094270228188 for ; Wed, 29 Jun 2022 08:04:54 -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 30A6B19F0; Wed, 29 Jun 2022 08:04:54 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A773B3F792; Wed, 29 Jun 2022 08:04:51 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 18/21] SecurityPkg/RngDxe: Add debug warning for NULL PcdCpuRngSupportedAlgorithm Date: Wed, 29 Jun 2022 17:02:34 +0200 Message-Id: <20220629150241.2597898-26-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: A7jHaWIf3CIoMPT7xRwEYbmzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515094; bh=XvyYFMIe/xsCk55vd45GkkAf8doDr3y1FGUqvVIyfeQ=; h=Cc:Date:From:Reply-To:Subject:To; b=MY+Sh8wQiT1ZMPE6ZrJ8xYtne/swddalDL5HNfGuxYRgV1TYwrEs3vrMxyzLP6zxzSQ PdNWpDTEzJxck8Mk1kXzkPZFXshm9rMqJaoMTxrVk8PapnYeakqbkqOZBE2a4cRP5S4Dn G3aSOt5LZLnQ5DaosdmthVP8dAdOLAAb4eI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515097573100003 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois PcdCpuRngSupportedAlgorithm should allow to identify the the algorithm used by the RNDR CPU instruction to generate a random number. Add a debug warning if the Pcd is not set. Signed-off-by: Pierre Gondois --- .../RandomNumberGenerator/RngDxe/AArch64/RngDxe.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index ee3f1ee78434..ffa32a29dc6a 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -63,6 +63,16 @@ RngInitAvailableAlgoArray ( sizeof (EFI_RNG_ALGORITHM) ); mAvailableAlgoArrayCount++; + + DEBUG_CODE_BEGIN (); + if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { + DEBUG (( + DEBUG_WARN, + "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" + )); + } + + DEBUG_CODE_END (); } =20 // Raw algorithm (Trng) --=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 (#90870): https://edk2.groups.io/g/devel/message/90870 Mute This Topic: https://groups.io/mt/92066755/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 17 07:07:51 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+90872+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+90872+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515100; cv=none; d=zohomail.com; s=zohoarc; b=ZAurLbEnMYCPXpArU6N073zFOVCq9OUGUSjfNS9NtkHJsEgMp1+upENIYM/F8+Sf7Zw5n0QbJvreonkGNZOaC7iz42aIjPX0PgVorqe3iYEcAyoLVkaYmMSXTRN3HJ/9T9rs1bJ+KSgQT0SP8aFpNRvsSVO5h7LRlkjBx7LHZ7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515100; 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=FXvECbFY3r5tEHyMriCVy8LvgxCxld7E3boUKSLGV5s=; b=lR0SRq63TOPmmoaXj+xJi3lVJvx8cHc1eYl0MN6tcrsaqVoMkEUUvp81JhaXeZ6zw5RJWYvD50o4XMyZEddlyrVFCd5KFyQ/gVtKKcnhOfHvwNGC9pHlMUzNWNZ7M306tqJ6O8k+GgNDkJSQCfatvHtGeX/pF6AX7eIAarffGvE= 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+90872+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 1656515100414843.351684522748; Wed, 29 Jun 2022 08:05:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YyljYY1788612xmKsTzcYkzE; Wed, 29 Jun 2022 08:05:00 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12727.1656515099422144099 for ; Wed, 29 Jun 2022 08:04:59 -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 4CD9919F0; Wed, 29 Jun 2022 08:04:59 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DE2973F792; Wed, 29 Jun 2022 08:04:56 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 19/21] SecurityPkg/RngDxe: Rename AArch64/RngDxe.c Date: Wed, 29 Jun 2022 17:02:36 +0200 Message-Id: <20220629150241.2597898-28-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: 0G1KO4LUFIXJJM3wlQS0mBV7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515100; bh=1x8I+TyZ6sUSTIWW4Lh7Glo+Xg2ww+ZavG0clEQz4Cc=; h=Cc:Date:From:Reply-To:Subject:To; b=UDhazTDobeGsj7XwVKWcaYDrdCdoSRWyrvoYr1/YBOLGs6xs0XTClIDGEnwVAmMTyz+ B5PRcHamo63kw3C3ynYG2ramaiLvzVFBZ9mODlMuD2E1NcPgUhKWuXKTbQ3lAnda+Qokf OVYPRj7GHUfpcMkbo5V15CEMoNKI/htKud8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515101598100011 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois To re-use the AArch64/RngDxe.c for an Arm implementation, rename AArch64/RngDxe.c to ArmRngDxe.c. Signed-off-by: Pierre Gondois --- .../RngDxe/{AArch64/RngDxe.c =3D> ArmRngDxe.c} | 0 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename SecurityPkg/RandomNumberGenerator/RngDxe/{AArch64/RngDxe.c =3D> Arm= RngDxe.c} (100%) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c similarity index 100% rename from SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c rename to SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 6c3d42066804..d2d0ff9ebb98 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -41,7 +41,7 @@ [Sources.IA32, Sources.X64] Rand/AesCore.h =20 [Sources.AARCH64] - AArch64/RngDxe.c + ArmRngDxe.c ArmTrng.c =20 [Packages] --=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 (#90872): https://edk2.groups.io/g/devel/message/90872 Mute This Topic: https://groups.io/mt/92066758/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 17 07:07:51 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+90871+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+90871+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515097; cv=none; d=zohomail.com; s=zohoarc; b=F8KOH274IY+MhRsO+xsJPQZSD6bqlZL/bkpDavxiROnSqiWPZv35TAO4ffiPuops0lJ1CmvjT0V+isC0Me0kiPLFnFceJ6ObxYrJYVDUpO5UEWP17TGWVy8J+4glQTaDXOdZxe8/5fPyY+SMvorE1NbSEXU+CJFq2SgXQx/O3XI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515097; 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=fnRmwlShFgV7rplbaQv9wt2v/b+hq37a8/H2D+o6ejo=; b=HRZaGaMWqQvaUmNwrJwsFfny+1W+YDtP7wVaJML7EnMbGlyd0dguPo8KGOJLfAHezDeCcZftVxEOQ8NjzXn+W1VB/rhFTG5ZMcrNJpEjk1kPsHKXXwMNo4F7rsA8i5vpo6AcyEOWP0+mEbA99VBdCC+unwH7twv0WsbgtbPgApg= 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+90871+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 1656515097721259.9542420011901; Wed, 29 Jun 2022 08:04:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3vTpYY1788612xKpd0fSYn2g; Wed, 29 Jun 2022 08:04:57 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.12648.1656515096785573797 for ; Wed, 29 Jun 2022 08:04:56 -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 B86211764; Wed, 29 Jun 2022 08:04:56 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 552FB3F792; Wed, 29 Jun 2022 08:04:54 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 19/22] SecurityPkg/RngDxe: Add debug warning for NULL PcdCpuRngSupportedAlgorithm Date: Wed, 29 Jun 2022 17:02:35 +0200 Message-Id: <20220629150241.2597898-27-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: oNXNluA9g3UBARZLxPwnteNfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515097; bh=iNnQu9OXPyw7KBQASrZDa1OzBVUoW7zx5WM+NxkCcjo=; h=Cc:Date:From:Reply-To:Subject:To; b=VB3V0VN32PQ/S9ih6zzwsh+pN3gmZSsi8ckLfQ7264Ueuu2k7yf7iW+/kEIujGDUbPX O+BH0h8+mU4IPKQJQwlKqxpsIy6tKfX1QHOCChrpZs1fMOmzc4j/kp1RKV1lNrVJWmok3 n5noYf5bkyS7pdjyjur2Gk3tyqjxN+j0E7o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515099567100007 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois PcdCpuRngSupportedAlgorithm should allow to identify the the algorithm used by the RNDR CPU instruction to generate a random number. Add a debug warning if the Pcd is not set. Signed-off-by: Pierre Gondois --- .../RandomNumberGenerator/RngDxe/AArch64/RngDxe.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index ee3f1ee78434..ffa32a29dc6a 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -63,6 +63,16 @@ RngInitAvailableAlgoArray ( sizeof (EFI_RNG_ALGORITHM) ); mAvailableAlgoArrayCount++; + + DEBUG_CODE_BEGIN (); + if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { + DEBUG (( + DEBUG_WARN, + "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" + )); + } + + DEBUG_CODE_END (); } =20 // Raw algorithm (Trng) --=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 (#90871): https://edk2.groups.io/g/devel/message/90871 Mute This Topic: https://groups.io/mt/92066756/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 17 07:07:51 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+90873+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+90873+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515102; cv=none; d=zohomail.com; s=zohoarc; b=LxLOow9XbVvC5UUdSUTdIcZvrLMbt6UwJd/70/1AOxWebBw5CqxDfN2Qg5feWSi9g7OH83QaRtAjSCt6gZ0wxLdD3tFxa4MDq0manWsw2XyWHRIasOesj0ZvVNhZCjuat8mxRCjfpNnDwwHCBxQYSlUNFNlcAWQy5V504VBjMM0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515102; 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=czJ5UUf7q6wfndgPNHm+Mr1C0IhqmRLpREBsG37Cuj0=; b=DOaioQMtSCyJ9pzo/KZySbiWmMKp7l18DEYUNDCQzedbUq/Osg0Vw/XiMLZbzQQMW9Rz5gxgDwxAOJ+zQdoWZ+cMKGNhbpem/fk6EjwjxyxD95VAsQMLH4g5RPIUaU0L1ex7SUzmJJw79cWnizMHdIMNvszWhGYtEf7YFlK3vfk= 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+90873+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 1656515102967219.4212189744086; Wed, 29 Jun 2022 08:05:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id klWTYY1788612xSmMfewLcho; Wed, 29 Jun 2022 08:05:02 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.12575.1656515101897231123 for ; Wed, 29 Jun 2022 08:05:02 -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 BBE951764; Wed, 29 Jun 2022 08:05:01 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 726FF3F792; Wed, 29 Jun 2022 08:04:59 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 20/21] SecurityPkg/RngDxe: Add Arm support of RngDxe Date: Wed, 29 Jun 2022 17:02:37 +0200 Message-Id: <20220629150241.2597898-29-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: I6qWgCu2NSvcvMEZqEdHDhePx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515102; bh=ia2bzYEb1sOw5+CMFNiw7MMR7SWl9835qM6yCuM2qu4=; h=Cc:Date:From:Reply-To:Subject:To; b=RqWD0kjtlbv74If0TTug1EV/jBOX8iklsA8IOG9BjyEyXg9WSLR7WNWOwEnfQnoiQ84 gc/RGwVecaiCGeh7i4iVzfUCqWrvW+dv9fS/oG9Z/R74vm+ZFZxhgzhiL1gJMmgnirSQ3 QOpSdjAzAU+Q1z10SDRc/t26IhfY1SAPYYw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515103622100013 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) Add RngDxe support for Arm. This implementation uses the TrngLib to support the RawAlgorithm and doens't support the RNDR instruction. Signed-off-by: Pierre Gondois --- SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c | 8 ++++++-- SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 9 ++++++--- SecurityPkg/SecurityPkg.dsc | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index ffa32a29dc6a..4775252d30b6 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -22,6 +22,7 @@ =20 **/ =20 +#include #include #include #include @@ -55,8 +56,9 @@ RngInitAvailableAlgoArray ( UINT16 MajorRevision; UINT16 MinorRevision; =20 - // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. - if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) { + #ifdef MDE_CPU_AARCH64 + // Check FEAT_RNG before advertising PcdCpuRngSupportedAlgorithm. + if (ArmHasRngExt ()) { CopyMem ( &mAvailableAlgoArray[mAvailableAlgoArrayCount], PcdGetPtr (PcdCpuRngSupportedAlgorithm), @@ -75,6 +77,8 @@ RngInitAvailableAlgoArray ( DEBUG_CODE_END (); } =20 + #endif + // Raw algorithm (Trng) if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { CopyMem ( diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index d2d0ff9ebb98..599a3085102d 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -27,7 +27,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 ARM # =20 [Sources.common] @@ -40,7 +40,7 @@ [Sources.IA32, Sources.X64] Rand/AesCore.c Rand/AesCore.h =20 -[Sources.AARCH64] +[Sources.AARCH64, Sources.ARM] ArmRngDxe.c ArmTrng.c =20 @@ -49,6 +49,9 @@ [Packages] MdePkg/MdePkg.dec SecurityPkg/SecurityPkg.dec =20 +[Packages.AARCH64, Packages.ARM] + ArmPkg/ArmPkg.dec + [LibraryClasses] UefiLib UefiBootServicesTableLib @@ -58,7 +61,7 @@ [LibraryClasses] TimerLib RngLib =20 -[LibraryClasses.AARCH64] +[LibraryClasses.AARCH64, LibraryClasses.ARM] TrngLib =20 [Guids] diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 490076542a33..882d639489ea 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -292,7 +292,7 @@ [Components.IA32, Components.X64, Components.ARM, Compo= nents.AARCH64] SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDef= aultKeysDxe.inf =20 -[Components.IA32, Components.X64, Components.AARCH64] +[Components.IA32, Components.X64, Components.AARCH64, Components.ARM] # # Random Number Generator # --=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 (#90873): https://edk2.groups.io/g/devel/message/90873 Mute This Topic: https://groups.io/mt/92066759/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 17 07:07:51 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+90874+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+90874+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515105; cv=none; d=zohomail.com; s=zohoarc; b=kdXnwV9BFeNt2JekbJrLt5mwkqFV/rHOPTOlaCYDJ6ANngmgqIX0NVgpl8kDI/yvVQEjNsfiM9lPuP1T+Qoj9qczHT5sm+/2n8b69J+ZUHQuZz4PCLplKSwqj48oYTQAwO8BYrJiWoUd3rpsJOyZAC9ahB+RuObDd2I5hHZLXig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515105; 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=mJIaAXiALU3R+1dspyK6OPzzX/Fm9cJZ3RIQM1Dq6Do=; b=nCM/n22m08emztfB2fZX7GWEhncsTt2r1x5rLM+Tb7qTdYPTCui5uYBMs9E2PCiRjDWib1cj7Nq8mhs0hOTarlwpd3v+11tGgZ/kVoEkT6t2ws3kb3uB40OkjXuhA8eUMrA2SAWJpxkmbNmGqLqmbMoXLdz4fLHm85ZxYeY0wO8= 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+90874+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 16565151055911003.5645385629241; Wed, 29 Jun 2022 08:05:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hg39YY1788612xQd8LwGs5wi; Wed, 29 Jun 2022 08:05:05 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.12658.1656515104502353168 for ; Wed, 29 Jun 2022 08:05:04 -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 6A17D1A00; Wed, 29 Jun 2022 08:05:04 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E28143F792; Wed, 29 Jun 2022 08:05:01 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 20/22] SecurityPkg/RngDxe: Rename AArch64/RngDxe.c Date: Wed, 29 Jun 2022 17:02:38 +0200 Message-Id: <20220629150241.2597898-30-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: 6MPk40LAoMqkvjIglf75aT4rx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515105; bh=OUwPFjnHZg8/Q3gZRjh1hlYsfb2+fumuwWxTk8Y46/E=; h=Cc:Date:From:Reply-To:Subject:To; b=C5MBOUO7zHpNSSfxzZejAohTVAxMbVKAbeX5+jKwOr4fnlw4xOLl8DWfHY70OqU8NKp SoCJzMOgZtLfAo5Mkor+ateFI0HZSaB3S0jtM0oBcESzz4kIzRDgZhTXSa3k58VQeR+Ka vyBHKkyscdGlBelB2nFiC8JILH63vcoffxA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515107618100019 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois To re-use the AArch64/RngDxe.c for an Arm implementation, rename AArch64/RngDxe.c to ArmRngDxe.c. Signed-off-by: Pierre Gondois --- .../RngDxe/{AArch64/RngDxe.c =3D> ArmRngDxe.c} | 0 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename SecurityPkg/RandomNumberGenerator/RngDxe/{AArch64/RngDxe.c =3D> Arm= RngDxe.c} (100%) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c similarity index 100% rename from SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c rename to SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 6c3d42066804..d2d0ff9ebb98 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -41,7 +41,7 @@ [Sources.IA32, Sources.X64] Rand/AesCore.h =20 [Sources.AARCH64] - AArch64/RngDxe.c + ArmRngDxe.c ArmTrng.c =20 [Packages] --=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 (#90874): https://edk2.groups.io/g/devel/message/90874 Mute This Topic: https://groups.io/mt/92066760/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 17 07:07:51 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+90875+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+90875+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515108; cv=none; d=zohomail.com; s=zohoarc; b=SGe3OEBGOu8ulTX/D6B4h3JpgzRgFUARwNGIMzf0Ispg+tK7z0eO8f6EtrTXjLWuIVdFQFATJgvG7rx21tRr+HqegWbo98wfkNwV+nxDNYz0CQmZ0kWYbC/HBAPxdqfZUf547XMquLMaFwXjB4EWL+UBtkgJ1QYD+O4IHstfPqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515108; 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=kBIMyRIyHJ6II8dtgaQ21Gfhi9QfRQ77dghKvwVkgLY=; b=I6RvemP7m5eaagVXzy8scY8B0sc6ivxRDn6ltQIzqZ7LQdRi3638zagbAm5qEK/FBlkzAT11Ia86IdjO0T9c7+Md0F4Ju6FIhlkOlCzxg2nkWRhe6Uc0+4IndOSGdApLtILZ2u9VE+sg3oW+TC91exX3rCBeNpAnzMNmDeFTB/M= 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+90875+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 1656515108081897.4424794568238; Wed, 29 Jun 2022 08:05:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dMWJYY1788612xSRkLr6pDzy; Wed, 29 Jun 2022 08:05:07 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.12650.1656515107083266267 for ; Wed, 29 Jun 2022 08:05:07 -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 006A61764; Wed, 29 Jun 2022 08:05:07 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 92EB13F792; Wed, 29 Jun 2022 08:05:04 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 21/21] ArmVirtPkg: Kvmtool: Add RNG support using FW-TRNG interface Date: Wed, 29 Jun 2022 17:02:39 +0200 Message-Id: <20220629150241.2597898-31-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: eLEa818vL2HCEKSV2BP24BZvx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515107; bh=8NuQ+eRFWGKm6Zbd9+Lq9+5OIThBEJtLYdjm51c0GLo=; h=Cc:Date:From:Reply-To:Subject:To; b=i/nHUuB0UxyZRZF6eEoz35i1g7Ofm39Vi+TiyvVfBuN90oKvf3TrJkIiIX2NurBL1TP fdqpYItk26bJhpwHk/eENPvSe4KUyjLmbMpUjZzXPWyjq1QU91JQF/bH2gcRQCn42jzY4 RDC2XKQs+7nurYzW+rweRfrjWzEdJU4yQH8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515109714100023 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The EFI_RNG_PROTOCOL published by RngDxe has been updated to implement the EFI_RNG_ALGORITHM_RAW using the Arm FW-TRNG interface to provide access to entropy. Therefore, enable EFI_RNG_PROTOCOL for the Kvmtool guest/virtual firmware. Signed-off-by: Sami Mujawar --- ArmVirtPkg/ArmVirtKvmTool.dsc | 10 ++++++++++ ArmVirtPkg/ArmVirtKvmTool.fdf | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 3bd3ebd6e0b3..847dbdd2af2b 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -81,6 +81,9 @@ [LibraryClasses.common] HwInfoParserLib|DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoPar= serLib.inf DynamicPlatRepoLib|DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Dy= namicPlatRepoLib.inf =20 + ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf + TrngLib|ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf + [LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE, LibraryClasses= .common.PEIM] PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf PlatformHookLib|ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt165= 50SerialPortHookLib.inf @@ -112,6 +115,8 @@ [PcdsFeatureFlag.common] # Use MMIO for accessing RTC controller registers. gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio|TRUE =20 + gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE + [PcdsFixedAtBuild.common] gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F =20 @@ -362,6 +367,11 @@ [Components.common] OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf OvmfPkg/Virtio10Dxe/Virtio10.inf =20 + # + # Rng Support + # + SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf + !if $(ARCH) =3D=3D AARCH64 # # ACPI Support diff --git a/ArmVirtPkg/ArmVirtKvmTool.fdf b/ArmVirtPkg/ArmVirtKvmTool.fdf index 9e006e83ee5c..4b5c99ef6700 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.fdf +++ b/ArmVirtPkg/ArmVirtKvmTool.fdf @@ -224,6 +224,11 @@ [FV.FvMain] # INF MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf =20 + # + # Rng Support + # + INF SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf + [FV.FVMAIN_COMPACT] FvAlignment =3D 16 ERASE_POLARITY =3D 1 --=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 (#90875): https://edk2.groups.io/g/devel/message/90875 Mute This Topic: https://groups.io/mt/92066761/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 17 07:07:51 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+90876+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+90876+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515111; cv=none; d=zohomail.com; s=zohoarc; b=jD+4zpZqy94MOw1h5NMECtMKM3vxa/ltOqgtqIuWpfnTd0ctKsjIwofynNQl/4y3NRXWNctpxODGDVa3kHuBYYb4X6oyJ5YuJUx3k+zwqL+GqMBnONfdfMSNpEEPzj0wwc+mNYemFgP6zppnvYbX82dCA6pvk7MVsRTs92Xfpzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515111; 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=JsiJMh4N5KDQwp8JA/hMLEvCai2Zu4bPUm1lW0qnvdM=; b=CYMW8odIc/7kdvgIZIjs0BP33yJCfnwBX7cgFooyF9Ink4BZ9XYwbYeYMru2trOhMjEB+KzOSLqo6If+qE0XYYySe9q0CHivK/3nk7EUGBzuOGVi5AQm3XoMc7y2S+MlX0/u5/HaCTFwhr4I4H3f4tcl+RF0nJwCL9ChkYtpQxs= 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+90876+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 1656515111027962.7250224165839; Wed, 29 Jun 2022 08:05:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ep9GYY1788612xWcriF8xLcP; Wed, 29 Jun 2022 08:05:10 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.12729.1656515109879590768 for ; Wed, 29 Jun 2022 08:05:10 -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 B9DDA19F0; Wed, 29 Jun 2022 08:05:09 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2ACA73F792; Wed, 29 Jun 2022 08:05:06 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 21/22] SecurityPkg/RngDxe: Add Arm support of RngDxe Date: Wed, 29 Jun 2022 17:02:40 +0200 Message-Id: <20220629150241.2597898-32-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: lmwlvcKLoqrCkv0RJvBzTXQNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515110; bh=vP+fHRDEiO8LIT2HSj/RuNzCMpK9fi4QSsdg1KFsLm0=; h=Cc:Date:From:Reply-To:Subject:To; b=GQSk6WTVWe8W7Cdi6j0YdgccDOLANWY8cGuIlLu7DQJWqOUQ9RAwmo1LPeDDP17nRmu Hag+6Z7C45WN2V4Rg+uGeJdzrNg7hzPIIbI20PIcY3feyJRsdNpddJ34z/DBTi/nu7aVF Tl70bwJsWGjWvzFkAAkNDPFR3RgsirDfCck= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515111666100025 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) Add RngDxe support for Arm. This implementation uses the TrngLib to support the RawAlgorithm and doens't support the RNDR instruction. Signed-off-by: Pierre Gondois --- SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c | 8 ++++++-- SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 10 +++++++--- SecurityPkg/SecurityPkg.dsc | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index ffa32a29dc6a..4775252d30b6 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -22,6 +22,7 @@ =20 **/ =20 +#include #include #include #include @@ -55,8 +56,9 @@ RngInitAvailableAlgoArray ( UINT16 MajorRevision; UINT16 MinorRevision; =20 - // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. - if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) { + #ifdef MDE_CPU_AARCH64 + // Check FEAT_RNG before advertising PcdCpuRngSupportedAlgorithm. + if (ArmHasRngExt ()) { CopyMem ( &mAvailableAlgoArray[mAvailableAlgoArrayCount], PcdGetPtr (PcdCpuRngSupportedAlgorithm), @@ -75,6 +77,8 @@ RngInitAvailableAlgoArray ( DEBUG_CODE_END (); } =20 + #endif + // Raw algorithm (Trng) if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { CopyMem ( diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index d2d0ff9ebb98..20752e71ac4e 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -27,7 +27,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 ARM # =20 [Sources.common] @@ -40,7 +40,7 @@ [Sources.IA32, Sources.X64] Rand/AesCore.c Rand/AesCore.h =20 -[Sources.AARCH64] +[Sources.AARCH64, Sources.ARM] ArmRngDxe.c ArmTrng.c =20 @@ -49,6 +49,9 @@ [Packages] MdePkg/MdePkg.dec SecurityPkg/SecurityPkg.dec =20 +[Packages.AARCH64, Packages.ARM] + ArmPkg/ArmPkg.dec + [LibraryClasses] UefiLib UefiBootServicesTableLib @@ -58,7 +61,8 @@ [LibraryClasses] TimerLib RngLib =20 -[LibraryClasses.AARCH64] +[LibraryClasses.AARCH64, LibraryClasses.ARM] + ArmLib TrngLib =20 [Guids] diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 490076542a33..779aa2a061a0 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -94,6 +94,9 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf ArmHvcLib|ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf =20 + # RngDxe dependencies + ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf + [LibraryClasses.ARM] RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 @@ -292,7 +295,7 @@ [Components.IA32, Components.X64, Components.ARM, Compo= nents.AARCH64] SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDef= aultKeysDxe.inf =20 -[Components.IA32, Components.X64, Components.AARCH64] +[Components.IA32, Components.X64, Components.AARCH64, Components.ARM] # # Random Number Generator # --=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 (#90876): https://edk2.groups.io/g/devel/message/90876 Mute This Topic: https://groups.io/mt/92066763/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 17 07:07:51 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+90877+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+90877+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656515114; cv=none; d=zohomail.com; s=zohoarc; b=RnFMv8lW3ZLCsK1Shc3QKUj11+HY1zFwfIriGQn+ubSUQh1N0a1MqKG/He33yvtkZh39iuLgaI1Pg3DlOIz5HCQ17tEmYUnwjcFtmC7whANVM9AYhe7CVZvt9VC8D1Qw1xTlH7SEyP6KN+zslvi32345tkyMxHJEmN9wyRGfn64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656515114; 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=t+UXKWxFjo7lmtG2lps7CBsEVPUPCnS8XjSQwsZED4Q=; b=npM8YiY71jWG5Q/CjYbw0D4hRtpR3SBA9v/yNO8ZVMzHUMWL1gxaRsFWN1DvfjnfGBiAPqIyzDkJYJw7sGTSgTCS7QAPxHhqdIsHqQFB4wiOhNhx+pHEQ0cZWAcfnu0z87yb+/pVVbfyhz73gRxplMnIOkbT5mlKgQlHNnpEaRU= 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+90877+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 1656515114152929.1634259658352; Wed, 29 Jun 2022 08:05:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id JyFAYY1788612xkJ1naVlXCX; Wed, 29 Jun 2022 08:05:13 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.12744.1656515112514558858 for ; Wed, 29 Jun 2022 08:05: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 6A4BD1764; Wed, 29 Jun 2022 08:05:12 -0700 (PDT) X-Received: from pierre123.arm.com (unknown [10.57.42.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D2FAF3F792; Wed, 29 Jun 2022 08:05:09 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v3 22/22] ArmVirtPkg: Kvmtool: Add RNG support using FW-TRNG interface Date: Wed, 29 Jun 2022 17:02:41 +0200 Message-Id: <20220629150241.2597898-33-Pierre.Gondois@arm.com> In-Reply-To: <20220629150241.2597898-1-Pierre.Gondois@arm.com> References: <20220629150241.2597898-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: Y5Z50eS7d7aiYM7IPBSOpuCix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656515113; bh=dWoQk8MzcQdXqqNsPxVUBfO4wx6Qn0HsWgM6LDW44yE=; h=Cc:Date:From:Reply-To:Subject:To; b=eDUckfCUz6BvzarSg0uKPhCh45vwM+XhudsCaeJJkx4Ib93bHibM+WfoxHzlITOZKnl dxAPYv/pINFtW+pUzR2DrLhzJyHEBQ2HgVV/bJQbiz9I24NhkpeY4TE49LCyeCvSQ5LcA xGe4VQnXEPaV7ewJOXmFnEwzHF1SJeWlLOk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656515115658100031 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The EFI_RNG_PROTOCOL published by RngDxe has been updated to implement the EFI_RNG_ALGORITHM_RAW using the Arm FW-TRNG interface to provide access to entropy. Therefore, enable EFI_RNG_PROTOCOL for the Kvmtool guest/virtual firmware. Signed-off-by: Sami Mujawar --- ArmVirtPkg/ArmVirtKvmTool.dsc | 10 ++++++++++ ArmVirtPkg/ArmVirtKvmTool.fdf | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 3bd3ebd6e0b3..847dbdd2af2b 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -81,6 +81,9 @@ [LibraryClasses.common] HwInfoParserLib|DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoPar= serLib.inf DynamicPlatRepoLib|DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Dy= namicPlatRepoLib.inf =20 + ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf + TrngLib|ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf + [LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE, LibraryClasses= .common.PEIM] PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf PlatformHookLib|ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt165= 50SerialPortHookLib.inf @@ -112,6 +115,8 @@ [PcdsFeatureFlag.common] # Use MMIO for accessing RTC controller registers. gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio|TRUE =20 + gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE + [PcdsFixedAtBuild.common] gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F =20 @@ -362,6 +367,11 @@ [Components.common] OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf OvmfPkg/Virtio10Dxe/Virtio10.inf =20 + # + # Rng Support + # + SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf + !if $(ARCH) =3D=3D AARCH64 # # ACPI Support diff --git a/ArmVirtPkg/ArmVirtKvmTool.fdf b/ArmVirtPkg/ArmVirtKvmTool.fdf index 9e006e83ee5c..4b5c99ef6700 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.fdf +++ b/ArmVirtPkg/ArmVirtKvmTool.fdf @@ -224,6 +224,11 @@ [FV.FvMain] # INF MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf =20 + # + # Rng Support + # + INF SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf + [FV.FVMAIN_COMPACT] FvAlignment =3D 16 ERASE_POLARITY =3D 1 --=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 (#90877): https://edk2.groups.io/g/devel/message/90877 Mute This Topic: https://groups.io/mt/92066765/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-