summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c')
-rw-r--r--MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c
index 54d29d96f3..980854d67b 100644
--- a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c
+++ b/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c
@@ -11,7 +11,7 @@
#include <Library/DebugLib.h>
#include <Library/TimerLib.h>
-#define DEFAULT_DELAY_TIME_IN_MICROSECONDS 10
+#define DEFAULT_DELAY_TIME_IN_MICROSECONDS 10
/**
Using the TimerLib GetPerformanceCounterProperties() we delay
@@ -26,22 +26,22 @@ CalculateMinimumDecentDelayInMicroseconds (
VOID
)
{
- UINT64 CounterHz;
+ UINT64 CounterHz;
// Get the counter properties
CounterHz = GetPerformanceCounterProperties (NULL, NULL);
// Make sure we won't divide by zero
if (CounterHz == 0) {
- ASSERT(CounterHz != 0); // Assert so the developer knows something is wrong
+ ASSERT (CounterHz != 0); // Assert so the developer knows something is wrong
return DEFAULT_DELAY_TIME_IN_MICROSECONDS;
}
+
// Calculate the minimum delay based on 1.5 microseconds divided by the hertz.
// We calculate the length of a cycle (1/CounterHz) and multiply it by 1.5 microseconds
// This ensures that the performance counter has increased by at least one
- return (UINT32)(MAX (DivU64x64Remainder (1500000,CounterHz, NULL), 1));
+ return (UINT32)(MAX (DivU64x64Remainder (1500000, CounterHz, NULL), 1));
}
-
/**
Generates a 16-bit random number.
@@ -56,11 +56,11 @@ CalculateMinimumDecentDelayInMicroseconds (
BOOLEAN
EFIAPI
GetRandomNumber16 (
- OUT UINT16 *Rand
+ OUT UINT16 *Rand
)
{
UINT32 Index;
- UINT8 *RandPtr;
+ UINT8 *RandPtr;
UINT32 DelayInMicroSeconds;
ASSERT (Rand != NULL);
@@ -68,15 +68,17 @@ GetRandomNumber16 (
if (Rand == NULL) {
return FALSE;
}
+
DelayInMicroSeconds = CalculateMinimumDecentDelayInMicroseconds ();
- RandPtr = (UINT8*)Rand;
+ RandPtr = (UINT8 *)Rand;
// Get 2 bytes of random ish data
- for (Index = 0; Index < sizeof(UINT16); Index ++) {
+ for (Index = 0; Index < sizeof (UINT16); Index++) {
*RandPtr = (UINT8)(GetPerformanceCounter () & 0xFF);
// Delay to give the performance counter a chance to change
MicroSecondDelay (DelayInMicroSeconds);
RandPtr++;
}
+
return TRUE;
}
@@ -94,11 +96,11 @@ GetRandomNumber16 (
BOOLEAN
EFIAPI
GetRandomNumber32 (
- OUT UINT32 *Rand
+ OUT UINT32 *Rand
)
{
UINT32 Index;
- UINT8 *RandPtr;
+ UINT8 *RandPtr;
UINT32 DelayInMicroSeconds;
ASSERT (Rand != NULL);
@@ -107,15 +109,16 @@ GetRandomNumber32 (
return FALSE;
}
- RandPtr = (UINT8 *) Rand;
+ RandPtr = (UINT8 *)Rand;
DelayInMicroSeconds = CalculateMinimumDecentDelayInMicroseconds ();
// Get 4 bytes of random ish data
- for (Index = 0; Index < sizeof(UINT32); Index ++) {
+ for (Index = 0; Index < sizeof (UINT32); Index++) {
*RandPtr = (UINT8)(GetPerformanceCounter () & 0xFF);
// Delay to give the performance counter a chance to change
MicroSecondDelay (DelayInMicroSeconds);
RandPtr++;
}
+
return TRUE;
}
@@ -133,11 +136,11 @@ GetRandomNumber32 (
BOOLEAN
EFIAPI
GetRandomNumber64 (
- OUT UINT64 *Rand
+ OUT UINT64 *Rand
)
{
UINT32 Index;
- UINT8 *RandPtr;
+ UINT8 *RandPtr;
UINT32 DelayInMicroSeconds;
ASSERT (Rand != NULL);
@@ -146,10 +149,10 @@ GetRandomNumber64 (
return FALSE;
}
- RandPtr = (UINT8 *)Rand;
+ RandPtr = (UINT8 *)Rand;
DelayInMicroSeconds = CalculateMinimumDecentDelayInMicroseconds ();
// Get 8 bytes of random ish data
- for (Index = 0; Index < sizeof(UINT64); Index ++) {
+ for (Index = 0; Index < sizeof (UINT64); Index++) {
*RandPtr = (UINT8)(GetPerformanceCounter () & 0xFF);
// Delay to give the performance counter a chance to change
MicroSecondDelay (DelayInMicroSeconds);
@@ -173,7 +176,7 @@ GetRandomNumber64 (
BOOLEAN
EFIAPI
GetRandomNumber128 (
- OUT UINT64 *Rand
+ OUT UINT64 *Rand
)
{
ASSERT (Rand != NULL);