public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: <devel@edk2.groups.io>
Cc: Sami Mujawar <sami.mujawar@arm.com>, <ardb+tianocore@kernel.org>,
	<leif@nuviainc.com>, <rebecca@bsdio.com>, <kraxel@redhat.com>,
	<michael.d.kinney@intel.com>, <gaoliming@byosoft.com.cn>,
	<zhiguang.liu@intel.com>, <jiewen.yao@intel.com>,
	<jian.j.wang@intel.com>, <Matteo.Carlini@arm.com>,
	<Akanksha.Jain2@arm.com>, <Ben.Adderson@arm.com>, <nd@arm.com>
Subject: [PATCH v1 5/9] MdePkg: Add NULL instance of TRNG Library
Date: Thu, 30 Sep 2021 16:40:40 +0100	[thread overview]
Message-ID: <20210930154044.37336-6-sami.mujawar@arm.com> (raw)
In-Reply-To: <20210930154044.37336-1-sami.mujawar@arm.com>

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

The True Random Number Generator (TRNG) library defines an
interface to access the entropy source on a platform. On
platforms that do not have access to an entropy source, a
NULL instance of the TRNG library may be useful to satisfy
the build dependency.

Therefore, add a NULL instance of the TRNG library.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c   | 111 ++++++++++++++++++++
 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf |  30 ++++++
 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni |  12 +++
 MdePkg/MdePkg.dsc                                  |   1 +
 4 files changed, 154 insertions(+)

diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c
new file mode 100644
index 0000000000000000000000000000000000000000..0511df2d99176f97d353f7b5a0a00562960e8165
--- /dev/null
+++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c
@@ -0,0 +1,111 @@
+/** @file
+  Null version of TRNG (True Random Number Generator) services.
+
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+    - TRNG - True Random Number Generator
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/TrngLib.h>
+
+/** Get the TRNG version.
+
+  A TRNG may be implemented by the system firmware, in which case this
+  function shall return the version information for the TRNG implementation.
+  Returning version information is optional and if not implemented,
+  EFI_UNSUPPORTED shall be returned.
+
+  @param [out]  MajorRevision     Major revision.
+  @param [out]  MinorRevision     Minor revision.
+
+  @retval  EFI_SUCCESS            The function completed successfully.
+  @retval  EFI_INVALID_PARAMETER  Invalid parameter.
+  @retval  EFI_UNSUPPORTED        Function not implemented.
+**/
+EFI_STATUS
+EFIAPI
+GetTrngVersion (
+  OUT UINT16  * CONST MajorRevision,
+  OUT UINT16  * CONST MinorRevision
+  )
+{
+  ASSERT (FALSE);
+  return EFI_UNSUPPORTED;
+}
+
+/** Get the UUID of the TRNG backend.
+
+  A TRNG may be implemented by the system firmware, in which case this
+  function shall return the UUID for the TRNG implementation.
+  Returning the TRNG UUID is optional and if not implemented, EFI_UNSUPPORTED
+  shall be returned.
+
+  @param [out]  Guid              UUID of the TRNG backend.
+
+  @retval  EFI_SUCCESS            The function completed successfully.
+  @retval  EFI_INVALID_PARAMETER  Invalid parameter.
+  @retval  EFI_UNSUPPORTED        Function not implemented.
+**/
+EFI_STATUS
+EFIAPI
+GetTrngUuid (
+  OUT GUID  * CONST Guid
+  )
+{
+  ASSERT (FALSE);
+  return EFI_UNSUPPORTED;
+}
+
+/** Returns maximum number of entropy bits that can be returned in a single
+    call.
+
+  @return Returns the maximum number of Entropy bits that can be returned
+          in a single call to GetEntropy().
+**/
+UINTN
+EFIAPI
+GetTrngMaxSupportedEntropyBits (
+  VOID
+  )
+{
+  ASSERT (FALSE);
+  return 0;
+}
+
+/** Returns N bits of conditioned entropy.
+
+  See [3] Section 2.3.1 GetEntropy: An Interface to the Entropy Source
+    GetEntropy
+      Input:
+        bits_of_entropy: the requested amount of entropy
+      Output:
+        entropy_bitstring: The string that provides the requested entropy.
+      status: A Boolean value that is TRUE if the request has been satisfied,
+              and is FALSE otherwise.
+    Note: In this implementation this function returns a status code instead
+          of a boolean value.
+
+  @param  [in]   EntropyBits  Number of entropy bits requested.
+  @param  [out]  Buffer       Buffer to return the entropy bits.
+  @param  [in]   BufferSize   Size of the Buffer in bytes.
+
+  @retval  EFI_SUCCESS            The function completed successfully.
+  @retval  EFI_INVALID_PARAMETER  Invalid parameter.
+  @retval  EFI_UNSUPPORTED        Function not implemented.
+  @retval  EFI_BAD_BUFFER_SIZE    Buffer size is too small.
+  @retval  EFI_NOT_READY          No Entropy available.
+**/
+EFI_STATUS
+EFIAPI
+GetEntropy (
+  IN  CONST UINTN                 EntropyBits,
+  OUT       UINT8       * CONST   Buffer,
+  IN  CONST UINTN                 BufferSize
+  )
+{
+  ASSERT (FALSE);
+  return EFI_UNSUPPORTED;
+}
diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf
new file mode 100644
index 0000000000000000000000000000000000000000..a700cf66f457f8898d5c51a7b9c0b3d7643ff7f9
--- /dev/null
+++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf
@@ -0,0 +1,30 @@
+## @file
+#  Null instance of TRNG (True Random Number Generator) Library.
+#
+#  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = BaseTrngLibNull
+  MODULE_UNI_FILE                = BaseTrngLibNull.uni
+  FILE_GUID                      = ABDE1C87-4F50-4B82-9133-7A79E13F69AB
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = TrngLib
+
+#
+#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+  BaseTrngLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  DebugLib
diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni
new file mode 100644
index 0000000000000000000000000000000000000000..1ec7def522e5975e9621eb280776251b1e5502ca
--- /dev/null
+++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni
@@ -0,0 +1,12 @@
+// /** @file
+// Null Instance of TRNG (True Random Number Generator) Library.
+//
+//  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT             #language en-US "Null instance of TRNG Library"
+
+#string STR_MODULE_DESCRIPTION          #language en-US "This library instance should be used with modules that inherit an (indirect) dependency on the TrngLib class, but never actually call TrngLib APIs for consuming Entropy."
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index a94959169b2fd9d4b5bf7ad903bf5ce06566c60e..f83753e132e9b9eb4152927fc182701fb1e70ca4 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -67,6 +67,7 @@ [Components]
   MdePkg/Library/DxeRngLib/DxeRngLib.inf
   MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf
   MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf
+  MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf
 
   MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
   MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


  parent reply	other threads:[~2021-09-30 15:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30 15:40 [PATCH v1 0/9] Add Raw algorithm support using Arm FW-TRNG interface Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 1/9] MdePkg: Definition for TRNG library class interface Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 2/9] ArmPkg: PCD to select conduit for monitor calls Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 3/9] ArmPkg: Add Arm Firmware TRNG library Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 4/9] MdePkg: Add definition for NULL GUID Sami Mujawar
2021-09-30 15:40 ` Sami Mujawar [this message]
2021-09-30 15:40 ` [PATCH v1 6/9] SecurityPkg: Rename RdRandGenerateEntropy to common name Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 7/9] SecurityPkg: Restructure checks in RngGetInfo Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 8/9] SecurityPkg: Add RawAlgorithm support using TRNG library Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 9/9] ArmVirtPkg: Kvmtool: Add RNG support using FW-TRNG interface Sami Mujawar
2021-10-01 17:47   ` [edk2-devel] " Joey Gouly
2021-10-08  5:35 ` 回复: [PATCH v1 0/9] Add Raw algorithm support using Arm " gaoliming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210930154044.37336-6-sami.mujawar@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox