public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
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 v5 12/21] SecurityPkg/RngDxe: Rename RdRandGenerateEntropy to generic name
Date: Mon, 19 Sep 2022 21:21:58 +0200	[thread overview]
Message-ID: <20220919192207.637786-13-Pierre.Gondois@arm.com> (raw)
In-Reply-To: <20220919192207.637786-1-Pierre.Gondois@arm.com>

From: Sami Mujawar <sami.mujawar@arm.com>

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

Rename RdRandGenerateEntropy() to GenerateEntropy() to provide a
common interface to generate entropy on other architectures.
GenerateEntropy() is intended to generate high quality entropy.

Also move the definition to RngDxeInternals.h

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 .../RngDxe/Rand/RdRand.c                      | 14 ++++--
 .../RngDxe/Rand/RdRand.h                      | 43 -------------------
 .../RngDxe/Rand/RngDxe.c                      |  7 ++-
 .../RandomNumberGenerator/RngDxe/RngDxe.inf   |  2 +-
 .../RngDxe/RngDxeInternals.h                  | 19 ++++++++
 5 files changed, 36 insertions(+), 49 deletions(-)
 delete mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c
index 5b6644138231..4b011c7e8e49 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c
@@ -1,15 +1,23 @@
 /** @file
-  Support routines for RDRAND instruction access.
+  Support routines for RDRAND instruction access, which will leverage
+  Intel Secure Key technology to provide high-quality random numbers for use
+  in applications, or entropy for seeding other random number generators.
+  Refer to http://software.intel.com/en-us/articles/intel-digital-random-number
+  -generator-drng-software-implementation-guide/ for more information about Intel
+  Secure Key technology.
 
+Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR>
 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
 #include <Library/RngLib.h>
+#include <Library/TimerLib.h>
 
 #include "AesCore.h"
-#include "RdRand.h"
 #include "RngDxeInternals.h"
 
 /**
@@ -87,7 +95,7 @@ RdRandGetSeed128 (
 **/
 EFI_STATUS
 EFIAPI
-RdRandGenerateEntropy (
+GenerateEntropy (
   IN UINTN   Length,
   OUT UINT8  *Entropy
   )
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h
deleted file mode 100644
index 7fdb6891bd63..000000000000
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/** @file
-  Header for the RDRAND APIs used by RNG DXE driver.
-
-  Support API definitions for RDRAND instruction access, which will leverage
-  Intel Secure Key technology to provide high-quality random numbers for use
-  in applications, or entropy for seeding other random number generators.
-  Refer to http://software.intel.com/en-us/articles/intel-digital-random-number
-  -generator-drng-software-implementation-guide/ for more information about Intel
-  Secure Key technology.
-
-Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef __RD_RAND_H__
-#define __RD_RAND_H__
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/TimerLib.h>
-#include <Protocol/Rng.h>
-
-/**
-  Generate high-quality entropy source through RDRAND.
-
-  @param[in]   Length        Size of the buffer, in bytes, to fill with.
-  @param[out]  Entropy       Pointer to the buffer to store the entropy data.
-
-  @retval EFI_SUCCESS        Entropy generation succeeded.
-  @retval EFI_NOT_READY      Failed to request random data.
-
-**/
-EFI_STATUS
-EFIAPI
-RdRandGenerateEntropy (
-  IN UINTN   Length,
-  OUT UINT8  *Entropy
-  );
-
-#endif // __RD_RAND_H__
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
index 2df4ed44329a..8d44f0636c3d 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
@@ -14,13 +14,16 @@
    - EFI_RNG_ALGORITHM_X9_31_3DES_GUID        - Unsupported
    - EFI_RNG_ALGORITHM_X9_31_AES_GUID         - Unsupported
 
+  Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR>
   Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include "RdRand.h"
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+
 #include "RngDxeInternals.h"
 
 /**
@@ -88,7 +91,7 @@ RngGetRNG (
       return EFI_INVALID_PARAMETER;
     }
 
-    Status = RdRandGenerateEntropy (RNGValueLength, RNGValue);
+    Status = GenerateEntropy (RNGValueLength, RNGValue);
     return Status;
   }
 
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
index f3300971993f..60efb5562ee0 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
@@ -10,6 +10,7 @@
 #
 #  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
 #  (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+#  Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.<BR>
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -36,7 +37,6 @@ [Sources.common]
 [Sources.IA32, Sources.X64]
   Rand/RngDxe.c
   Rand/RdRand.c
-  Rand/RdRand.h
   Rand/AesCore.c
   Rand/AesCore.h
 
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
index 224d8bd4ea5f..48d2d27c1608 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
@@ -10,6 +10,8 @@
 #ifndef RNGDXE_INTERNALS_H_
 #define RNGDXE_INTERNALS_H_
 
+#include <Protocol/Rng.h>
+
 /**
   Returns information about the random number generation implementation.
 
@@ -114,4 +116,21 @@ RngGetBytes (
   OUT UINT8  *RandBuffer
   );
 
+/**
+  Generate high-quality entropy source using a TRNG or through RDRAND.
+
+  @param[in]   Length        Size of the buffer, in bytes, to fill with.
+  @param[out]  Entropy       Pointer to the buffer to store the entropy data.
+
+  @retval EFI_SUCCESS        Entropy generation succeeded.
+  @retval EFI_NOT_READY      Failed to request random data.
+
+**/
+EFI_STATUS
+EFIAPI
+GenerateEntropy (
+  IN UINTN   Length,
+  OUT UINT8  *Entropy
+  );
+
 #endif // RNGDXE_INTERNALS_H_
-- 
2.25.1


  parent reply	other threads:[~2022-09-19 19:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19 19:21 [PATCH v5 00/21] Add Raw algorithm support using Arm FW-TRNG interface PierreGondois
2022-09-19 19:21 ` [PATCH v5 01/21] ArmPkg: PCD to select conduit for monitor calls PierreGondois
2022-09-27 18:59   ` Leif Lindholm
2022-09-19 19:21 ` [PATCH v5 02/21] ArmPkg/ArmMonitorLib: Definition for ArmMonitorLib library class PierreGondois
2022-09-19 19:21 ` [PATCH v5 03/21] ArmPkg/ArmMonitorLib: Add ArmMonitorLib PierreGondois
2022-09-27 18:51   ` Leif Lindholm
2022-09-27 19:00   ` [edk2-devel] " Rebecca Cran
2022-09-27 19:10   ` Rebecca Cran
2022-09-19 19:21 ` [PATCH v5 04/21] ArmPkg/ArmHvcNullLib: Add NULL instance of ArmHvcLib PierreGondois
2022-09-27 18:55   ` Leif Lindholm
2022-09-19 19:21 ` [PATCH v5 05/21] MdePkg/TrngLib: Definition for TRNG library class interface PierreGondois
2022-09-27 19:00   ` Leif Lindholm
2022-09-19 19:21 ` [PATCH v5 06/21] MdePkg/TrngLib: Add NULL instance of TRNG Library PierreGondois
2022-09-27 19:02   ` Leif Lindholm
2022-09-19 19:21 ` [PATCH v5 07/21] ArmPkg: Add FID definitions for Firmware TRNG PierreGondois
2022-09-27 19:04   ` Leif Lindholm
2022-09-19 19:21 ` [PATCH v5 08/21] ArmPkg/TrngLib: Add Arm Firmware TRNG library PierreGondois
2022-09-19 19:21 ` [PATCH v5 09/21] MdePkg/BaseRngLib: Rename ArmReadIdIsar0() to ArmGetFeatRng() PierreGondois
2022-09-27 21:44   ` [edk2-devel] " Rebecca Cran
2022-09-28 17:10   ` Leif Lindholm
2022-09-29 16:21     ` PierreGondois
2022-09-29 17:09       ` Leif Lindholm
2022-09-19 19:21 ` [PATCH v5 10/21] ArmPkg/ArmLib: Add ArmReadIdIsar0() helper PierreGondois
2022-09-19 19:21 ` [PATCH v5 11/21] ArmPkg/ArmLib: Add ArmHasRngExt() PierreGondois
2022-09-19 19:21 ` PierreGondois [this message]
2022-09-19 19:21 ` [PATCH v5 13/21] SecurityPkg/RngDxe: Replace Pcd with Sp80090Ctr256Guid PierreGondois
2022-09-19 19:22 ` [PATCH v5 14/21] SecurityPkg/RngDxe: Remove ArchGetSupportedRngAlgorithms() PierreGondois
2022-09-19 19:22 ` [PATCH v5 15/21] SecurityPkg/RngDxe: Documentation/include/parameter cleanup PierreGondois
2022-09-19 19:22 ` [PATCH v5 16/21] SecurityPkg/RngDxe: Check before advertising Cpu Rng algo PierreGondois
2022-09-19 19:22 ` [PATCH v5 17/21] SecurityPkg/RngDxe: Add AArch64 RawAlgorithm support through TrngLib PierreGondois
2022-09-19 19:22 ` [PATCH v5 18/21] SecurityPkg/RngDxe: Add debug warning for NULL PcdCpuRngSupportedAlgorithm PierreGondois
2022-09-19 19:22 ` [PATCH v5 19/21] SecurityPkg/RngDxe: Rename AArch64/RngDxe.c PierreGondois
2022-09-19 19:22 ` [PATCH v5 20/21] SecurityPkg/RngDxe: Add Arm support of RngDxe PierreGondois
2022-09-19 19:22 ` [PATCH v5 21/21] ArmVirtPkg: Kvmtool: Add RNG support using FW-TRNG interface PierreGondois

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=20220919192207.637786-13-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