TianoCore EDK2 master
Loading...
Searching...
No Matches
RandTests.c
Go to the documentation of this file.
1
9#include "TestBaseCryptLib.h"
10
11#define RANDOM_NUMBER_SIZE 256
12
13CONST UINT8 SeedString[] = "This is the random seed for PRNG verification.";
14
15UINT8 PreviousRandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };
16
17UINT8 RandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };
18
20EFIAPI
21TestVerifyPrngGeneration (
22 UNIT_TEST_CONTEXT Context
23 )
24{
25 UINTN Index;
26 BOOLEAN Status;
27
28 Status = RandomSeed (SeedString, sizeof (SeedString));
29 UT_ASSERT_TRUE (Status);
30
31 for (Index = 0; Index < 10; Index++) {
32 Status = RandomBytes (RandomBuffer, RANDOM_NUMBER_SIZE);
33 UT_ASSERT_TRUE (Status);
34
35 Status = (CompareMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE) == 0);
36 UT_ASSERT_FALSE (Status);
37
38 CopyMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE);
39 }
40
41 return UNIT_TEST_PASSED;
42}
43
44TEST_DESC mPrngTest[] = {
45 //
46 // -----Description--------------------------------Class--------------------Function----------------Pre---Post--Context
47 //
48 { "TestVerifyPrngGeneration()", "CryptoPkg.BaseCryptLib.Prng", TestVerifyPrngGeneration, NULL, NULL, NULL },
49};
50
51UINTN mPrngTestNum = ARRAY_SIZE (mPrngTest);
UINT64 UINTN
BOOLEAN EFIAPI RandomBytes(OUT UINT8 *Output, IN UINTN Size)
Definition: CryptRand.c:76
BOOLEAN EFIAPI RandomSeed(IN CONST UINT8 *Seed OPTIONAL, IN UINTN SeedSize)
Definition: CryptRand.c:36
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
VOID * UNIT_TEST_CONTEXT
Definition: UnitTestLib.h:54
#define UT_ASSERT_TRUE(Expression)
Definition: UnitTestLib.h:350
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16
#define UT_ASSERT_FALSE(Expression)
Definition: UnitTestLib.h:362