From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.52.1678209396703085264 for ; Tue, 07 Mar 2023 09:16:36 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) 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 0013A1C2B; Tue, 7 Mar 2023 09:17:19 -0800 (PST) Received: from cam-smtp0.cambridge.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 88B043F67D; Tue, 7 Mar 2023 09:16:34 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, leif@nuviainc.com, sami.mujawar@arm.com, Jiewen Yao , Jian J Wang Subject: [PATCH v4 1/2] SecurityPkg/RngDxe: Simplify Rng algorithm selection for Arm Date: Tue, 7 Mar 2023 18:15:49 +0100 Message-Id: <20230307171550.555541-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230307171550.555541-1-pierre.gondois@arm.com> References: <20230307171550.555541-1-pierre.gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pierre Gondois The default algorithm to use is the first element of mAvailableAlgoArray. There is no need to iterate through the array to find a valid algorithm. Simplify the Rng algorithm selection by returning the first element of mAvailableAlgoArray. Signed-off-by: Pierre Gondois --- .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index ce49ff7ae661..b8a343e3d397 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -77,7 +77,6 @@ RngGetRNG ( ) { EFI_STATUS Status; - UINTN Index; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D= NULL)) { return EFI_INVALID_PARAMETER; @@ -87,21 +86,13 @@ RngGetRNG ( // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - for (Index =3D 0; Index < mAvailableAlgoArrayCount; Index++) { - if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { - RNGAlgorithm =3D &mAvailableAlgoArray[Index]; - goto FoundAlgo; - } - } - - if (Index =3D=3D mAvailableAlgoArrayCount) { - // No algorithm available. - ASSERT (Index !=3D mAvailableAlgoArrayCount); - return EFI_DEVICE_ERROR; + if (mAvailableAlgoArrayCount !=3D 0) { + RNGAlgorithm =3D &mAvailableAlgoArray[0]; + } else { + return EFI_UNSUPPORTED; } } =20 -FoundAlgo: if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)= )) { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; --=20 2.25.1