1 /** @file
2   Application for Pseudorandom Number Generator Validation.
3 
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT 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 
19 CONST  UINT8  SeedString[] = "This is the random seed for PRNG verification.";
20 
21 UINT8  PreviousRandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };
22 
23 UINT8  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 **/
32 EFI_STATUS
ValidateCryptPrng(VOID)33 ValidateCryptPrng (
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 }
70