blob: c9e7341c3a0e2f52dac318a398efbfed5dffe24c [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @file
2 Application for Pseudorandom Number Generator Validation.
3
4Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5This program and the accompanying materials
6are licensed and made available under the terms and conditions of the BSD License
7which accompanies this distribution. The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14
15#include "Cryptest.h"
16
17#define RANDOM_NUMBER_SIZE 256
18
19CONST UINT8 SeedString[] = "This is the random seed for PRNG verification.";
20
21UINT8 PreviousRandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };
22
23UINT8 RandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };
24
25/**
26 Validate UEFI-OpenSSL pseudorandom number generator interfaces.
27
28 @retval EFI_SUCCESS Validation succeeded.
29 @retval EFI_ABORTED Validation failed.
30
31**/
32EFI_STATUS
33ValidateCryptPrng (
34 VOID
35 )
36{
37 UINTN Index;
38 BOOLEAN Status;
39
40 Print (L" \nUEFI-OpenSSL PRNG Engine Testing:\n");
41
42 Print (L"- Random Generation...");
43
44 Status = RandomSeed (SeedString, sizeof (SeedString));
45 if (!Status) {
46 Print (L"[Fail]");
47 return EFI_ABORTED;
48 }
49
50 for (Index = 0; Index < 10; Index ++) {
51 Status = RandomBytes (RandomBuffer, RANDOM_NUMBER_SIZE);
52 if (!Status) {
53 Print (L"[Fail]");
54 return EFI_ABORTED;
55 }
56
57 if (CompareMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE) == 0) {
58 Print (L"[Fail]");
59 return EFI_ABORTED;
60 }
61
62 CopyMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE);
63 }
64
65 Print (L"[Pass]\n");
66
67 return EFI_SUCCESS;
68
69}