From: "PierreGondois" <pierre.gondois@arm.com>
To: devel@edk2.groups.io
Cc: Sami Mujawar <sami.mujawar@arm.com>,
Leif Lindholm <quic_llindhol@quicinc.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Rebecca Cran <rebecca@bsdio.com>,
Michael D Kinney <michael.d.kinney@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Jiewen Yao <jiewen.yao@intel.com>,
Jian J Wang <jian.j.wang@intel.com>
Subject: [PATCH v9 07/19] MdePkg/ArmTrngLib: Add NULL instance of Arm TRNG Library
Date: Fri, 28 Oct 2022 17:32:47 +0200 [thread overview]
Message-ID: <20221028153259.397445-8-Pierre.Gondois@arm.com> (raw)
In-Reply-To: <20221028153259.397445-1-Pierre.Gondois@arm.com>
From: Sami Mujawar <sami.mujawar@arm.com>
Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)
The Arm 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 Arm TRNG library.
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
.../BaseArmTrngLibNull/BaseArmTrngLibNull.c | 121 ++++++++++++++++++
.../BaseArmTrngLibNull/BaseArmTrngLibNull.inf | 30 +++++
.../BaseArmTrngLibNull/BaseArmTrngLibNull.uni | 12 ++
MdePkg/MdeLibs.dsc.inc | 1 +
MdePkg/MdePkg.dsc | 1 +
5 files changed, 165 insertions(+)
create mode 100644 MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.c
create mode 100644 MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf
create mode 100644 MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.uni
diff --git a/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.c b/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.c
new file mode 100644
index 000000000000..316d78bf5e83
--- /dev/null
+++ b/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.c
@@ -0,0 +1,121 @@
+/** @file
+ Null version of the Arm TRNG (True Random Number Generator) services
+ (Cf [1]).
+
+ Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+ @par Reference(s):
+ - [1] Arm True Random Number Generator Firmware, Interface 1.0,
+ Platform Design Document.
+ (https://developer.arm.com/documentation/den0098/latest/)
+ - [2] NIST Special Publication 800-90B, Recommendation for the Entropy
+ Sources Used for Random Bit Generation.
+ (https://csrc.nist.gov/publications/detail/sp/800-90b/final)
+
+ @par Glossary:
+ - TRNG - True Random Number Generator
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/ArmTrngLib.h>
+
+/** Get the version of the Arm TRNG backend.
+
+ A TRNG may be implemented by the system firmware, in which case this
+ function shall return the version of the Arm TRNG backend.
+ The implementation must return NOT_SUPPORTED if a Back end is not present.
+
+ @param [out] MajorRevision Major revision.
+ @param [out] MinorRevision Minor revision.
+
+ @retval RETURN_SUCCESS The function completed successfully.
+ @retval RETURN_INVALID_PARAMETER Invalid parameter.
+ @retval RETURN_UNSUPPORTED Backend not present.
+**/
+RETURN_STATUS
+EFIAPI
+GetArmTrngVersion (
+ OUT UINT16 *MajorRevision,
+ OUT UINT16 *MinorRevision
+ )
+{
+ ASSERT (FALSE);
+ return RETURN_UNSUPPORTED;
+}
+
+/** Get the UUID of the Arm TRNG backend.
+
+ A TRNG may be implemented by the system firmware, in which case this
+ function shall return the UUID of the TRNG backend.
+ Returning the Arm TRNG UUID is optional and if not implemented,
+ RETURN_UNSUPPORTED shall be returned.
+
+ Note: The caller must not rely on the returned UUID as a trustworthy Arm TRNG
+ Back end identity
+
+ @param [out] Guid UUID of the Arm TRNG backend.
+
+ @retval RETURN_SUCCESS The function completed successfully.
+ @retval RETURN_INVALID_PARAMETER Invalid parameter.
+ @retval RETURN_UNSUPPORTED Function not implemented.
+**/
+RETURN_STATUS
+EFIAPI
+GetArmTrngUuid (
+ OUT GUID *Guid
+ )
+{
+ ASSERT (FALSE);
+ return RETURN_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 GetArmTrngEntropy().
+**/
+UINTN
+EFIAPI
+GetArmTrngMaxSupportedEntropyBits (
+ VOID
+ )
+{
+ ASSERT (FALSE);
+ return 0;
+}
+
+/** Returns N bits of conditioned entropy.
+
+ See [2] 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.
+
+ @param [in] EntropyBits Number of entropy bits requested.
+ @param [in] BufferSize Size of the Buffer in bytes.
+ @param [out] Buffer Buffer to return the entropy bits.
+
+ @retval RETURN_SUCCESS The function completed successfully.
+ @retval RETURN_INVALID_PARAMETER Invalid parameter.
+ @retval RETURN_UNSUPPORTED Function not implemented.
+ @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small.
+ @retval RETURN_NOT_READY No Entropy available.
+**/
+RETURN_STATUS
+EFIAPI
+GetArmTrngEntropy (
+ IN UINTN EntropyBits,
+ IN UINTN BufferSize,
+ OUT UINT8 *Buffer
+ )
+{
+ ASSERT (FALSE);
+ return RETURN_UNSUPPORTED;
+}
diff --git a/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf b/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf
new file mode 100644
index 000000000000..256df1373eee
--- /dev/null
+++ b/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf
@@ -0,0 +1,30 @@
+## @file
+# Null instance of the Arm TRNG (True Random Number Generator) Library.
+#
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = BaseArmTrngLibNull
+ MODULE_UNI_FILE = BaseArmTrngLibNull.uni
+ FILE_GUID = ABDE1C87-4F50-4B82-9133-7A79E13F69AB
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmTrngLib
+
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 RISCV64
+#
+
+[Sources]
+ BaseArmTrngLibNull.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ DebugLib
diff --git a/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.uni b/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.uni
new file mode 100644
index 000000000000..876764b8bebc
--- /dev/null
+++ b/MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.uni
@@ -0,0 +1,12 @@
+// /** @file
+// Null Instance of the Arm TRNG (True Random Number Generator) Library.
+//
+// Copyright (c) 2021 - 2022, 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 ArmTrngLib class, but never actually call ArmTrngLib APIs for consuming Entropy."
diff --git a/MdePkg/MdeLibs.dsc.inc b/MdePkg/MdeLibs.dsc.inc
index fc6f385b304d..4580481cb580 100644
--- a/MdePkg/MdeLibs.dsc.inc
+++ b/MdePkg/MdeLibs.dsc.inc
@@ -12,6 +12,7 @@
##
[LibraryClasses]
+ ArmTrngLib|MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf
RegisterFilterLib|MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf
CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
SmmCpuRendezvousLib|MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 493a13ec9197..32a852dc466e 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -57,6 +57,7 @@ [Components]
MdePkg/Library/PciSegmentLibSegmentInfo/BasePciSegmentLibSegmentInfo.inf
MdePkg/Library/PciSegmentLibSegmentInfo/DxeRuntimePciSegmentLibSegmentInfo.inf
MdePkg/Library/BaseS3PciSegmentLib/BaseS3PciSegmentLib.inf
+ MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf
MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
--
2.25.1
next prev parent reply other threads:[~2022-10-28 15:33 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 15:32 [PATCH v9 00/19] Add Raw algorithm support using Arm TRNG interface PierreGondois
2022-10-28 15:32 ` [PATCH v9 01/19] ArmPkg: PCD to select conduit for monitor calls PierreGondois
2022-10-28 15:32 ` [PATCH v9 02/19] ArmPkg/ArmMonitorLib: Definition for ArmMonitorLib library class PierreGondois
2022-10-28 15:32 ` [PATCH v9 03/19] ArmPkg/ArmMonitorLib: Add ArmMonitorLib PierreGondois
2022-10-28 15:32 ` [PATCH v9 04/19] ArmPkg: Sort HVC/SMC section alphbetically in ArmPkg.dsc PierreGondois
2022-10-28 15:32 ` [PATCH v9 05/19] ArmPkg/ArmHvcLibNull: Add NULL instance of ArmHvcLib PierreGondois
2022-10-28 15:32 ` [PATCH v9 06/19] MdePkg/ArmTrngLib: Definition for Arm TRNG library class interface PierreGondois
2022-10-28 15:32 ` PierreGondois [this message]
2022-10-28 15:32 ` [PATCH v9 08/19] ArmPkg: Add FID definitions for Arm TRNG PierreGondois
2022-10-28 15:32 ` [PATCH v9 09/19] ArmPkg/ArmTrngLib: Add Arm TRNG library PierreGondois
2022-10-28 15:32 ` [PATCH v9 10/19] SecurityPkg/RngDxe: Rename RdRandGenerateEntropy to generic name PierreGondois
2022-10-28 15:32 ` [PATCH v9 11/19] SecurityPkg/RngDxe: Replace Pcd with Sp80090Ctr256Guid PierreGondois
2022-10-28 15:32 ` [PATCH v9 12/19] SecurityPkg/RngDxe: Remove ArchGetSupportedRngAlgorithms() PierreGondois
2022-10-28 15:32 ` [PATCH v9 13/19] SecurityPkg/RngDxe: Documentation/include/parameter cleanup PierreGondois
2022-10-28 15:32 ` [PATCH v9 14/19] SecurityPkg/RngDxe: Check before advertising Cpu Rng algo PierreGondois
2022-10-28 15:32 ` [PATCH v9 15/19] SecurityPkg/RngDxe: Add AArch64 RawAlgorithm support through ArmTrngLib PierreGondois
2022-10-28 15:32 ` [PATCH v9 16/19] SecurityPkg/RngDxe: Add debug warning for NULL PcdCpuRngSupportedAlgorithm PierreGondois
2022-10-28 15:32 ` [PATCH v9 17/19] SecurityPkg/RngDxe: Rename AArch64/RngDxe.c PierreGondois
2022-10-28 15:32 ` [PATCH v9 18/19] SecurityPkg/RngDxe: Add Arm support of RngDxe PierreGondois
2022-10-28 15:32 ` [PATCH v9 19/19] ArmVirtPkg: Kvmtool: Add RNG support using Arm TRNG interface PierreGondois
2022-11-01 1:10 ` 回复: [PATCH v9 00/19] Add Raw algorithm " gaoliming
2022-11-01 8:55 ` Yao, Jiewen
2022-11-04 1:16 ` 回复: " gaoliming
2022-11-04 17:34 ` [edk2-devel] " Ard Biesheuvel
2022-11-06 16:57 ` Ard Biesheuvel
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=20221028153259.397445-8-Pierre.Gondois@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