Skip to content

Commit

Permalink
MdePkg/DxeRngLib: Request raw algorithm instead of default
Browse files Browse the repository at this point in the history
The DxeRngLib tries to generate a random number using the 3 NIST
SP 800-90 compliant DRBG algorithms, i.e. 256-bits CTR, HASH and HMAC.
If none of the call is successful, the fallback option is the default
RNG algorithm of the EFI_RNG_PROTOCOL. This default algorithm might
be an unsafe implementation.

Try requesting the Raw algorithm before requesting the default one.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Kun Qin <kun.qin@microsoft.com>
  • Loading branch information
pierregondois authored and mergify[bot] committed Sep 8, 2023
1 parent 65b5dd8 commit bd1f0ee
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MdePkg/Library/DxeRngLib/DxeRngLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ GenerateRandomNumberViaNist800Algorithm (
return Status;
}

Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmRaw, BufferSize, Buffer);
DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Raw - Status = %r\n", __func__, Status));
if (!EFI_ERROR (Status)) {
return Status;
}

// If all the other methods have failed, use the default method from the RngProtocol
Status = RngProtocol->GetRNG (RngProtocol, NULL, BufferSize, Buffer);
DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status = %r\n", __func__, Status));
DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm default - Status = %r\n", __func__, Status));
if (!EFI_ERROR (Status)) {
return Status;
}
Expand Down

0 comments on commit bd1f0ee

Please sign in to comment.