Skip to content

Commit

Permalink
[CHERRY-PICK] SecurityPkg/RngDxe: Simplify Rng algorithm selection fo…
Browse files Browse the repository at this point in the history
…r 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 <pierre.gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
Tested-by: Kun Qin <kun.qin@microsoft.com>
(cherry picked from commit ff7ddc0)
  • Loading branch information
pierregondois authored and makubacki committed Jan 31, 2024
1 parent bce9dd4 commit a11e1b0
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ RngGetRNG (
)
{
EFI_STATUS Status;
UINTN Index;
GUID RngGuid;

if ((This == NULL) || (RNGValueLength == 0) || (RNGValue == NULL)) {
Expand All @@ -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))
Expand Down

0 comments on commit a11e1b0

Please # to comment.