summaryrefslogtreecommitdiffstats
path: root/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RandTests.c
blob: cc6b2ca46ba1812084648a990eff9fbb1c620fe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/** @file
  Application for Pseudorandom Number Generator Validation.

Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include "TestBaseCryptLib.h"

#define  RANDOM_NUMBER_SIZE  256

CONST  UINT8  SeedString[] = "This is the random seed for PRNG verification.";

UINT8  PreviousRandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };

UINT8  RandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };

UNIT_TEST_STATUS
EFIAPI
TestVerifyPrngGeneration (
  UNIT_TEST_CONTEXT           Context
  )
{
  UINTN    Index;
  BOOLEAN  Status;

  Status = RandomSeed (SeedString, sizeof (SeedString));
  UT_ASSERT_TRUE (Status);

  for (Index = 0; Index < 10; Index ++) {
    Status = RandomBytes (RandomBuffer, RANDOM_NUMBER_SIZE);
    UT_ASSERT_TRUE (Status);

    Status = (CompareMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE) == 0);
    UT_ASSERT_FALSE (Status);

    CopyMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE);
  }

  return UNIT_TEST_PASSED;
}

TEST_DESC mPrngTest[] = {
    //
    // -----Description--------------------------------Class--------------------Function----------------Pre---Post--Context
    //
    {"TestVerifyPrngGeneration()",       "CryptoPkg.BaseCryptLib.Prng",   TestVerifyPrngGeneration,   NULL, NULL, NULL},
};

UINTN mPrngTestNum = ARRAY_SIZE(mPrngTest);