]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: add null version of RngLib
authorJian J Wang <jian.j.wang@intel.com>
Tue, 12 Nov 2019 08:45:48 +0000 (16:45 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 14 Nov 2019 01:32:15 +0000 (01:32 +0000)
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1871

This is null version of RngLib which should be used with modules that
inherit an (indirect) dependency on the RngLib class, but never actually
call RngLib APIs for consuming randomness.

To be more specific, if following components or functionalities are used
in a platform, the BaseRngLibNull should *not* be used. Instead, a non-Null
version of RngLib must be used (like BaseRngLib for IA32/X64, or future
DxeRngLibRngProtocol for all ARCHs).

- HddPasswordDxe.inf
- AES, TLS (TlsDxe.inf, TlsLib.inf), RSA_OAEP, RSA_PK1
- (If BaseRngLibNull interface ASSERTed at boot time)

Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c [new file with mode: 0644]
MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf [new file with mode: 0644]
MdePkg/Library/BaseRngLibNull/BaseRngLibNull.uni [new file with mode: 0644]
MdePkg/MdePkg.dsc

diff --git a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c b/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c
new file mode 100644 (file)
index 0000000..cad3059
--- /dev/null
@@ -0,0 +1,94 @@
+/** @file\r
+  Null version of Random number generator services.\r
+\r
+Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/RngLib.h>\r
+\r
+/**\r
+  Generates a 16-bit random number.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out] Rand     Buffer pointer to store the 16-bit random value.\r
+\r
+  @retval TRUE         Random number generated successfully.\r
+  @retval FALSE        Failed to generate the random number.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+GetRandomNumber16 (\r
+  OUT     UINT16                    *Rand\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Generates a 32-bit random number.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out] Rand     Buffer pointer to store the 32-bit random value.\r
+\r
+  @retval TRUE         Random number generated successfully.\r
+  @retval FALSE        Failed to generate the random number.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+GetRandomNumber32 (\r
+  OUT     UINT32                    *Rand\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Generates a 64-bit random number.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out] Rand     Buffer pointer to store the 64-bit random value.\r
+\r
+  @retval TRUE         Random number generated successfully.\r
+  @retval FALSE        Failed to generate the random number.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+GetRandomNumber64 (\r
+  OUT     UINT64                    *Rand\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Generates a 128-bit random number.\r
+\r
+  if Rand is NULL, then ASSERT().\r
+\r
+  @param[out] Rand     Buffer pointer to store the 128-bit random value.\r
+\r
+  @retval TRUE         Random number generated successfully.\r
+  @retval FALSE        Failed to generate the random number.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+GetRandomNumber128 (\r
+  OUT     UINT64                    *Rand\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return FALSE;\r
+}\r
diff --git a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf b/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf
new file mode 100644 (file)
index 0000000..f21e20a
--- /dev/null
@@ -0,0 +1,30 @@
+## @file\r
+#  Null instance of RNG (Random Number Generator) Library.\r
+#\r
+#  Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010029\r
+  BASE_NAME                      = BaseRngLibNull\r
+  MODULE_UNI_FILE                = BaseRngLibNull.uni\r
+  FILE_GUID                      = CD8991F8-2061-4084-8C9E-9C6F352DC58D\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = RngLib\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64 EBC\r
+#\r
+\r
+[Sources]\r
+  BaseRngLibNull.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
diff --git a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.uni b/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.uni
new file mode 100644 (file)
index 0000000..f32be6a
--- /dev/null
@@ -0,0 +1,14 @@
+// /** @file\r
+// Null Instance of RNG (Random Number Generator) Library.\r
+//\r
+// Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// SPDX-License-Identifier: BSD-2-Clause-Patent\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "Null Instance of RNG Library"\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "This library instance should be used with modules that inherit an (indirect) dependency on the RngLib class, but never actually call RngLib APIs for consuming randomness."\r
+\r
index c1278e79070d00b9cad5effb2fc15bcbf1383d07..0aeafaaaccaae66ae35899cca979da51a621b951 100644 (file)
@@ -61,6 +61,7 @@
   MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.inf\r
   MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf\r
   MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf\r
+  MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf\r
 \r
   MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
   MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf\r