From a11e1b0548bc8cb68214c6df8918d1bfa9ed32c5 Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Fri, 11 Aug 2023 16:33:10 +0200 Subject: [PATCH] [CHERRY-PICK] SecurityPkg/RngDxe: Simplify Rng algorithm selection for Arm The first element of mAvailableAlgoArray is defined as the default Rng algorithm to use. Don't go through the array at each RngGetRNG() call and just return the first element of the array. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar Acked-by: Ard Biesheuvel Acked-by: Jiewen Yao Tested-by: Kun Qin (cherry picked from commit ff7ddc02b273f9159ef46fdb67d99062f8e598d9) --- .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index 78a18c5e11..7a42e3cbe3 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -77,7 +77,6 @@ RngGetRNG ( ) { EFI_STATUS Status; - UINTN Index; GUID RngGuid; if ((This == NULL) || (RNGValueLength == 0) || (RNGValue == NULL)) { @@ -88,21 +87,13 @@ RngGetRNG ( // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - for (Index = 0; Index < mAvailableAlgoArrayCount; Index++) { - if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { - RNGAlgorithm = &mAvailableAlgoArray[Index]; - goto FoundAlgo; - } - } - - if (Index == mAvailableAlgoArrayCount) { - // No algorithm available. - ASSERT (Index != mAvailableAlgoArrayCount); - return EFI_DEVICE_ERROR; + if (mAvailableAlgoArrayCount != 0) { + RNGAlgorithm = &mAvailableAlgoArray[0]; + } else { + return EFI_UNSUPPORTED; } } -FoundAlgo: Status = GetRngGuid (&RngGuid); if (!EFI_ERROR (Status) && CompareGuid (RNGAlgorithm, &RngGuid))