summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/DxeRngLib/DxeRngLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library/DxeRngLib/DxeRngLib.c')
-rw-r--r--MdePkg/Library/DxeRngLib/DxeRngLib.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/MdePkg/Library/DxeRngLib/DxeRngLib.c b/MdePkg/Library/DxeRngLib/DxeRngLib.c
index 9c3d67b5a6..82129aa445 100644
--- a/MdePkg/Library/DxeRngLib/DxeRngLib.c
+++ b/MdePkg/Library/DxeRngLib/DxeRngLib.c
@@ -37,46 +37,47 @@ GenerateRandomNumberViaNist800Algorithm (
RngProtocol = NULL;
if (Buffer == NULL) {
- DEBUG((DEBUG_ERROR, "%a: Buffer == NULL.\n", __FUNCTION__));
- return EFI_INVALID_PARAMETER;
+ DEBUG ((DEBUG_ERROR, "%a: Buffer == NULL.\n", __FUNCTION__));
+ return EFI_INVALID_PARAMETER;
}
Status = gBS->LocateProtocol (&gEfiRngProtocolGuid, NULL, (VOID **)&RngProtocol);
- if (EFI_ERROR (Status) || RngProtocol == NULL) {
- DEBUG((DEBUG_ERROR, "%a: Could not locate RNG prototocol, Status = %r\n", __FUNCTION__, Status));
- return Status;
+ if (EFI_ERROR (Status) || (RngProtocol == NULL)) {
+ DEBUG ((DEBUG_ERROR, "%a: Could not locate RNG prototocol, Status = %r\n", __FUNCTION__, Status));
+ return Status;
}
Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Ctr256Guid, BufferSize, Buffer);
- DEBUG((DEBUG_INFO, "%a: GetRNG algorithm CTR-256 - Status = %r\n", __FUNCTION__, Status));
+ DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm CTR-256 - Status = %r\n", __FUNCTION__, Status));
if (!EFI_ERROR (Status)) {
return Status;
}
Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Hmac256Guid, BufferSize, Buffer);
- DEBUG((DEBUG_INFO, "%a: GetRNG algorithm HMAC-256 - Status = %r\n", __FUNCTION__, Status));
+ DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm HMAC-256 - Status = %r\n", __FUNCTION__, Status));
if (!EFI_ERROR (Status)) {
return Status;
}
Status = RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmSp80090Hash256Guid, BufferSize, Buffer);
- DEBUG((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status = %r\n", __FUNCTION__, Status));
+ DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status = %r\n", __FUNCTION__, 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", __FUNCTION__, Status));
+ DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status = %r\n", __FUNCTION__, Status));
if (!EFI_ERROR (Status)) {
return Status;
}
+
// If we get to this point, we have failed
- DEBUG((DEBUG_ERROR, "%a: GetRNG() failed, staus = %r\n", __FUNCTION__, Status));
+ DEBUG ((DEBUG_ERROR, "%a: GetRNG() failed, staus = %r\n", __FUNCTION__, Status));
return Status;
}// GenerateRandomNumberViaNist800Algorithm()
-
/**
Generates a 16-bit random number.
@@ -94,17 +95,17 @@ GetRandomNumber16 (
OUT UINT16 *Rand
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
- if (Rand == NULL)
- {
+ if (Rand == NULL) {
return FALSE;
}
- Status = GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, sizeof(UINT16));
+ Status = GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, sizeof (UINT16));
if (EFI_ERROR (Status)) {
return FALSE;
}
+
return TRUE;
}
@@ -122,19 +123,20 @@ GetRandomNumber16 (
BOOLEAN
EFIAPI
GetRandomNumber32 (
- OUT UINT32 *Rand
+ OUT UINT32 *Rand
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (Rand == NULL) {
return FALSE;
}
- Status = GenerateRandomNumberViaNist800Algorithm ((UINT8*)Rand, sizeof(UINT32));
+ Status = GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, sizeof (UINT32));
if (EFI_ERROR (Status)) {
return FALSE;
}
+
return TRUE;
}
@@ -152,19 +154,20 @@ GetRandomNumber32 (
BOOLEAN
EFIAPI
GetRandomNumber64 (
- OUT UINT64 *Rand
+ OUT UINT64 *Rand
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (Rand == NULL) {
return FALSE;
}
- Status = GenerateRandomNumberViaNist800Algorithm ((UINT8*)Rand, sizeof(UINT64));
+ Status = GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, sizeof (UINT64));
if (EFI_ERROR (Status)) {
return FALSE;
}
+
return TRUE;
}
@@ -182,18 +185,19 @@ GetRandomNumber64 (
BOOLEAN
EFIAPI
GetRandomNumber128 (
- OUT UINT64 *Rand
+ OUT UINT64 *Rand
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (Rand == NULL) {
return FALSE;
}
- Status = GenerateRandomNumberViaNist800Algorithm ((UINT8*)Rand, 2 * sizeof(UINT64));
+ Status = GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, 2 * sizeof (UINT64));
if (EFI_ERROR (Status)) {
return FALSE;
}
+
return TRUE;
}