]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Application/Cryptest/RandVerify.c
Update CryptoPkg for new ciphers (HMAC, Block Cipher, etc) supports.
[mirror_edk2.git] / CryptoPkg / Application / Cryptest / RandVerify.c
diff --git a/CryptoPkg/Application/Cryptest/RandVerify.c b/CryptoPkg/Application/Cryptest/RandVerify.c
new file mode 100644 (file)
index 0000000..c9e7341
--- /dev/null
@@ -0,0 +1,69 @@
+/** @file  \r
+  Application for Pseudorandom Number Generator Validation.\r
+\r
+Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "Cryptest.h"\r
+\r
+#define  RANDOM_NUMBER_SIZE  256\r
+\r
+CONST  UINT8  SeedString[] = "This is the random seed for PRNG verification.";\r
+\r
+UINT8  PreviousRandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };\r
+\r
+UINT8  RandomBuffer[RANDOM_NUMBER_SIZE] = { 0x0 };\r
+\r
+/**\r
+  Validate UEFI-OpenSSL pseudorandom number generator interfaces.\r
+\r
+  @retval  EFI_SUCCESS  Validation succeeded.\r
+  @retval  EFI_ABORTED  Validation failed.\r
+\r
+**/\r
+EFI_STATUS\r
+ValidateCryptPrng (\r
+  VOID\r
+  )\r
+{\r
+  UINTN    Index;\r
+  BOOLEAN  Status;\r
+\r
+  Print (L" \nUEFI-OpenSSL PRNG Engine Testing:\n");\r
+\r
+  Print (L"- Random Generation...");\r
+\r
+  Status = RandomSeed (SeedString, sizeof (SeedString));\r
+  if (!Status) {\r
+    Print (L"[Fail]");\r
+    return EFI_ABORTED;\r
+  }\r
+\r
+  for (Index = 0; Index < 10; Index ++) {\r
+    Status = RandomBytes (RandomBuffer, RANDOM_NUMBER_SIZE);\r
+    if (!Status) {\r
+      Print (L"[Fail]");\r
+      return EFI_ABORTED;\r
+    }\r
+\r
+    if (CompareMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE) == 0) {\r
+      Print (L"[Fail]");\r
+      return EFI_ABORTED;\r
+    }\r
+\r
+    CopyMem (PreviousRandomBuffer, RandomBuffer, RANDOM_NUMBER_SIZE);\r
+  }\r
+\r
+  Print (L"[Pass]\n");\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r