From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (EUR02-AM0-obe.outbound.protection.outlook.com [40.107.247.62]) by mx.groups.io with SMTP id smtpd.web10.5163.1688034509955067971 for ; Thu, 29 Jun 2023 03:28:30 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=CW3Z41Iu; spf=pass (domain: arm.com, ip: 40.107.247.62, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WOh7Xb9fhZFY5tv8Yuj2BjiVjJXBbn2DCsmBLaNtFsA=; b=CW3Z41IuR/WwJJPG9To2R9p+aEfW0eo9Ct8DlgGJgENEyipOdoogR/mxyFeRcf4hrKjbnzeDCjLqaQjI0NEVQ+MoXKDVCe2gLLd/3cW+JKTExLpnqGSnJi6zfNZUESy6w47nT0Ii8ValJnoRiWrhaxSkjFL1jmchZiMO1KIQtPQ= Received: from AM5PR0101CA0035.eurprd01.prod.exchangelabs.com (2603:10a6:206:16::48) by GV1PR08MB7779.eurprd08.prod.outlook.com (2603:10a6:150:57::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.24; Thu, 29 Jun 2023 10:28:10 +0000 Received: from AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:16:cafe::6b) by AM5PR0101CA0035.outlook.office365.com (2603:10a6:206:16::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.34 via Frontend Transport; Thu, 29 Jun 2023 10:28:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT039.mail.protection.outlook.com (100.127.140.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.22 via Frontend Transport; Thu, 29 Jun 2023 10:28:09 +0000 Received: ("Tessian outbound c08fa2e31830:v142"); Thu, 29 Jun 2023 10:28:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8c243e1a1821b7ac X-CR-MTA-TID: 64aa7808 Received: from b4e0b7b545c3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E2A7F0C2-EAF4-4597-AED2-2995B3A200C5.1; Thu, 29 Jun 2023 10:28:03 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b4e0b7b545c3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 29 Jun 2023 10:28:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TgVLNXmPpEnFHW64P+iLH/5VQ6VZU/qVq2qt5Y7p/y1fSeVimBkId5tG0l9M/o/+LaBd2ItVTAKXuM90HWia1P3237YmHGnpoaXDI1gwQeus3kLYjQSlS/bV2xqEc6+jWI4m9Jnu2n0ddDAywytCBskbTUbMCeUUgHAV3tsCq0KdpkqrOqneCALVz2blJCTdIsQKI+VhF7POBhOH1e8B80IvJ/h8J2L4WkcqmOD+UyunLDr1n2FC3SU3szGH5NwVmi42jBNuzGsccVfP5NLLycDEodcbu1XspmK95ne06qgb96ilsGczdoPipj/sOr/gej6HjaJIFgudzlgIqHuIZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WOh7Xb9fhZFY5tv8Yuj2BjiVjJXBbn2DCsmBLaNtFsA=; b=itZx5RBZvnR20ut/28gf0Igd6tTJIdgGzRB1E6FzWFUQ5WGE6vnyJj1qTchHWTiMOCv5H9l3kESoylsHJsVkkWem44I9E3yhvu6k6ifbVHnW77e1PFHg3PkaAYXB7ezzoDC4Y3/KURjOLzY78jWtDGDZzmXM186VOgySXWHa9jEWYm87NNCaAqkmruStEjnapRifpTta5Ir+lxkL5qIo9fXoI3Dg2wxVENpfQEvdTC8haFHmZhrsvWarHFyc81m+jXdYio3zYPfj74iXENbTPEiUNGCIkSXLt9ypmeV6wJRDpFtC9YuMEFzynJ5v/ZhFUljFo2EyTHIJf2Jh1i8S8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WOh7Xb9fhZFY5tv8Yuj2BjiVjJXBbn2DCsmBLaNtFsA=; b=CW3Z41IuR/WwJJPG9To2R9p+aEfW0eo9Ct8DlgGJgENEyipOdoogR/mxyFeRcf4hrKjbnzeDCjLqaQjI0NEVQ+MoXKDVCe2gLLd/3cW+JKTExLpnqGSnJi6zfNZUESy6w47nT0Ii8ValJnoRiWrhaxSkjFL1jmchZiMO1KIQtPQ= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by DU0PR08MB9050.eurprd08.prod.outlook.com (2603:10a6:10:47a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.26; Thu, 29 Jun 2023 10:28:00 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::8ef4:aa57:6248:7850]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::8ef4:aa57:6248:7850%4]) with mapi id 15.20.6544.019; Thu, 29 Jun 2023 10:27:59 +0000 Message-ID: Date: Thu, 29 Jun 2023 11:27:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v1 5/8] MdePkg/Rng: Add GetRngGuid() to RngLib To: pierre.gondois@arm.com, devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Jose Marinho , Samer El-Haj-Mahmoud , "nd@arm.com" References: <20230509074042.1523428-1-pierre.gondois@arm.com> <20230509074042.1523428-6-pierre.gondois@arm.com> From: "Sami Mujawar" In-Reply-To: <20230509074042.1523428-6-pierre.gondois@arm.com> X-ClientProxiedBy: LNXP265CA0081.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:76::21) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6806:EE_|DU0PR08MB9050:EE_|AM7EUR03FT039:EE_|GV1PR08MB7779:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a870aba-1861-4ecb-a1c2-08db788b8930 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: tyGO4ntAOQbtov63J/oFQ16FPxNm3vVQeYAlq2yyA8xsVZTrIsDSXEUlzmyYK891joL0QazrkQc7DuZAgQ+NDkT8uOdJYtJWcWDnZEm7NvGY417XptfKYRbULvSVxTC4YlpehxgOGzuo2GJdXhgnM54ex7CyCJeAGHYcc/0RTt8U+ogAt66+ZwWHZriROPkTmt9N4lCu99RA1h/eI0eXoKcmZxQSJLpF8JPi55JVagDFMH/XgGz681uFslBbOJew8J6TSJxW7hRevdRPo+Bq+w/3HVUTHLGpSqDRt7LqQAb4oDBFbl6kL0PVaudmyb5Im++2IYKAP4Cbu63DQH9rHEVxA/XR0z4c21tnMqtRKePxSD3u7zV3kdXHDkZjGNKt3yDY/+nPz+Q5d7RpGsU8798Rj54y7NmpZL926Am1XFDJvyQYtaYXS8L0X5PEGTjBkRueqOQDRSy5TqluSBGkx8DTLl93RE6fKPYVsImYfJkS2v0ze5qaUC6bf/dIpoQUQgBt80iYYWIuoq2ko/TCsXARquSCBOEHzVPmsMYmv/jfyDSNjhSPFVrab1SgzfOWVAuAmgzkreM88CqoTV6yc6Jk4FgNRbiMZlABsPJ+9Yyt3IJcRzPN7dzcQQOQdJhBxm0jEjEFldCZ+n/kg32G+w== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB6806.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(396003)(346002)(376002)(136003)(39860400002)(451199021)(26005)(54906003)(2906002)(30864003)(45080400002)(6486002)(186003)(2616005)(38100700002)(83380400001)(53546011)(6506007)(86362001)(19627235002)(31696002)(41300700001)(478600001)(66556008)(66476007)(316002)(4326008)(36756003)(8936002)(66946007)(6512007)(31686004)(44832011)(5660300002)(8676002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9050 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b0d30039-2113-4e6c-3e4b-08db788b8315 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UNP9BrJKA7T5QYyRiAOmdKXCJImCNuSX8tKGQAARdS7YXkPlCVzsv31ixI9PGSVPqBzLwflbdPe/7m5gnjwPUVhW4dy2sT49bS9lcm6OzR4gqZaDn1HxZkIKjgklpX/g6ebWxLitjhBmTdeZKRQRWL0WbjQinXtF6WZRjxdeN23FfLRIDfVplQSJIDQ7eLBuan1Z+0pim7twTPD6jMspzVxU0pY/FLp80eHEYJwESM9q0NJdjYwba0CeMqLz29t+Zn4SUv2yjv+eHGUeXPfLlpE9rm12a3K6Tu4uvt/ziUp+S3nQ2gOQu81yuYnAA/AH7xLcrJzO2aqp3RGvXG/lNy22WygzPa7fwdFd9CPAR77DLyCqtC++7oCg2CEYUrsffI3mnip6l5dQQguuyYpiQBNVqu8EwC2OTCELFvvwkIgvy4MWR9z5mVQe6rNFl83X/4XmYoay3QiPx20iDVmfMCcQcbKqHfV0Di6TJh8HCnxzs8H7+xZQEpL7l2i+zjOVFTbFYkKcBaEQebFBPs5mEq4K6OlUL1WztrM033Ld35Rix5p8BY1CgncncSBomxofXV422Zm5HRzmbHi8EmVDH2EoZ991eaB+uk+jqNecpEg8aGdARZgnyx6mRJ7PGF5X3E2VVtZzACuF3Q6tvZzwRN2zpIWrEGNMXloJZuhPJZ1BzDI0rAEF+Gy2co3Z5XEhHer0MRjwjUtjfU5LT+kg/SP66p9RPSJHdeei8ZGsWmnQj1Zwd1dkWP1dBQDpgFp5BpDvRp1T4n6UYKzGWSIt4w== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199021)(46966006)(40470700004)(36840700001)(26005)(31686004)(5660300002)(316002)(36756003)(70206006)(70586007)(4326008)(8936002)(8676002)(44832011)(478600001)(40460700003)(6512007)(2906002)(31696002)(36860700001)(19627235002)(86362001)(186003)(41300700001)(54906003)(40480700001)(6486002)(82310400005)(45080400002)(82740400003)(30864003)(356005)(53546011)(336012)(6506007)(2616005)(83380400001)(47076005)(81166007)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2023 10:28:09.9728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9a870aba-1861-4ecb-a1c2-08db788b8930 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB7779 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Pierre, Thank you for this patch. Please find my response inline marked [SAMI]. With that addressed, Reviewed-by: Sami Mujawar Regards, Sami Mujawar On 09/05/2023 08:40 am, pierre.gondois@arm.com wrote: > From: Pierre Gondois > > The EFI_RNG_PROTOCOL can use the RngLib. The RngLib has multiple > implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). > To allow the RngDxe to detect when such implementation is used, > add a GetRngGuid() function to the RngLib. > > Signed-off-by: Pierre Gondois > --- > MdePkg/Include/Library/RngLib.h | 17 ++++++++ > MdePkg/Library/BaseRngLib/AArch64/Rndr.c | 42 +++++++++++++++++++ > MdePkg/Library/BaseRngLib/BaseRngLib.inf | 9 ++++ > MdePkg/Library/BaseRngLib/Rand/RdRand.c | 26 ++++++++++++ > .../Library/BaseRngLibNull/BaseRngLibNull.c | 22 ++++++++++ > .../BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 3 ++ > .../Library/BaseRngLibTimerLib/RngLibTimer.c | 28 +++++++++++++ > MdePkg/Library/DxeRngLib/DxeRngLib.c | 28 +++++++++++++ > 8 files changed, 175 insertions(+) > > diff --git a/MdePkg/Include/Library/RngLib.h b/MdePkg/Include/Library/RngLib.h > index 429ed19e287e..945482cd5e56 100644 > --- a/MdePkg/Include/Library/RngLib.h > +++ b/MdePkg/Include/Library/RngLib.h > @@ -1,6 +1,7 @@ > /** @file > Provides random number generator services. > > +Copyright (c) 2023, Arm Limited. All rights reserved.
> Copyright (c) 2015, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -77,4 +78,20 @@ GetRandomNumber128 ( > OUT UINT64 *Rand > ); > > +/** > + Get a GUID identifying the RNG algorithm implementation. > + > + @param [out] RngGuid If success, contains the GUID identifying > + the RNG algorithm implementation. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_UNSUPPORTED Not supported. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > +**/ > +EFI_STATUS > +EFIAPI > +GetRngGuid ( > + GUID *RngGuid > + ); > + > #endif // __RNG_LIB_H__ > diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c > index 20811bf3ebf3..d39db62153ee 100644 > --- a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c > +++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c > @@ -2,6 +2,7 @@ > Random number generator service that uses the RNDR instruction > to provide pseudorandom numbers. > > + Copyright (c) 2023, Arm Limited. All rights reserved.
> Copyright (c) 2021, NUVIA Inc. All rights reserved.
> Copyright (c) 2015, Intel Corporation. All rights reserved.
> > @@ -11,6 +12,7 @@ > > #include > #include > +#include > #include > #include > > @@ -138,3 +140,43 @@ ArchIsRngSupported ( > { > return mRndrSupported; > } > + > +/** > + Get a GUID identifying the RNG algorithm implementation. > + > + @param [out] RngGuid If success, contains the GUID identifying > + the RNG algorithm implementation. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_UNSUPPORTED Not supported. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > +**/ > +EFI_STATUS > +EFIAPI > +GetRngGuid ( > + GUID *RngGuid > + ) > +{ > + GUID *RngLibGuid; > + > + if (RngGuid == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (!mRndrSupported) { > + return EFI_UNSUPPORTED; > + } > + > + // > + // If the platform advertises the algorithm behind RNDR instruction, > + // use it. Otherwise use gEfiRngAlgorithmArmRndr. > + // > + RngLibGuid = PcdGetPtr (PcdCpuRngSupportedAlgorithm); > + if (!IsZeroGuid (RngLibGuid)) { > + CopyMem (RngGuid, RngLibGuid, sizeof (*RngGuid)); > + } else { > + CopyMem (RngGuid, &gEfiRngAlgorithmArmRndr, sizeof (*RngGuid)); > + } > + > + return EFI_SUCCESS; > +} > diff --git a/MdePkg/Library/BaseRngLib/BaseRngLib.inf b/MdePkg/Library/BaseRngLib/BaseRngLib.inf > index 1fcceb941495..a79fbf03d74c 100644 > --- a/MdePkg/Library/BaseRngLib/BaseRngLib.inf > +++ b/MdePkg/Library/BaseRngLib/BaseRngLib.inf > @@ -4,6 +4,7 @@ > # BaseRng Library that uses CPU RNG instructions (e.g. RdRand) to > # provide random numbers. > # > +# Copyright (c) 2023, Arm Limited. All rights reserved.
> # Copyright (c) 2021, NUVIA Inc. All rights reserved.
> # Copyright (c) 2015, Intel Corporation. All rights reserved.
> # > @@ -43,9 +44,17 @@ [Sources.AARCH64] > AArch64/ArmReadIdIsar0.asm | MSFT > AArch64/ArmRng.asm | MSFT > > +[Guids] > + gEfiRngAlgorithmArmRndr > + gEfiRngAlgorithmSp80090Ctr256Guid > + gEfiRngAlgorithmUnSafe [SAMI] Maybe we can split the [Guids] section into [Guids.AARCH64] and [Guids.Ia32, Guids.X64]. Also gEfiRngAlgorithmUnSafe does not appear to be used and can be removed. [/SAMI] > + > [Packages] > MdePkg/MdePkg.dec > > +[Pcd.AARCH64] > + gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm > + > [LibraryClasses] > BaseLib > DebugLib > diff --git a/MdePkg/Library/BaseRngLib/Rand/RdRand.c b/MdePkg/Library/BaseRngLib/Rand/RdRand.c > index 070d41e2555f..9bd68352f9f7 100644 > --- a/MdePkg/Library/BaseRngLib/Rand/RdRand.c > +++ b/MdePkg/Library/BaseRngLib/Rand/RdRand.c > @@ -2,6 +2,7 @@ > Random number generator services that uses RdRand instruction access > to provide high-quality random numbers. > > +Copyright (c) 2023, Arm Limited. All rights reserved.
> Copyright (c) 2021, NUVIA Inc. All rights reserved.
> Copyright (c) 2015, Intel Corporation. All rights reserved.
> > @@ -11,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > #include > #include > +#include > #include > > #include "BaseRngLibInternals.h" > @@ -128,3 +130,27 @@ ArchIsRngSupported ( > */ > return TRUE; > } > + > +/** > + Get a GUID identifying the RNG algorithm implementation. > + > + @param [out] RngGuid If success, contains the GUID identifying > + the RNG algorithm implementation. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_UNSUPPORTED Not supported. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > +**/ > +EFI_STATUS > +EFIAPI > +GetRngGuid ( > + GUID *RngGuid > + ) > +{ > + if (RngGuid == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + CopyMem (RngGuid, &gEfiRngAlgorithmSp80090Ctr256Guid, sizeof (*RngGuid)); > + return EFI_SUCCESS; > +} > diff --git a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c b/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c > index efba5c851ead..af5e8eb8f72a 100644 > --- a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c > +++ b/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c > @@ -1,13 +1,16 @@ > /** @file > Null version of Random number generator services. > > +Copyright (c) 2023, Arm Limited. All rights reserved.
> Copyright (c) 2019, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent > > **/ > > +#include > #include > #include > +#include > > /** > Generates a 16-bit random number. > @@ -92,3 +95,22 @@ GetRandomNumber128 ( > ASSERT (FALSE); > return FALSE; > } > + > +/** > + Get a GUID identifying the RNG algorithm implementation. > + > + @param [out] RngGuid If success, contains the GUID identifying > + the RNG algorithm implementation. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_UNSUPPORTED Not supported. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > +**/ > +EFI_STATUS > +EFIAPI > +GetRngGuid ( > + GUID *RngGuid > + ) > +{ > + return EFI_UNSUPPORTED; > +} > diff --git a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf b/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf > index f857290e823b..13e10141fad0 100644 > --- a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf > +++ b/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf > @@ -30,6 +30,9 @@ [Sources] > [Packages] > MdePkg/MdePkg.dec > > +[Guids] > + gEfiRngAlgorithmUnSafe > + > [LibraryClasses] > BaseLib > DebugLib > diff --git a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c > index 980854d67b72..fc9f7e31a333 100644 > --- a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c > +++ b/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c > @@ -2,14 +2,18 @@ > BaseRng Library that uses the TimerLib to provide reasonably random numbers. > Do not use this on a production system. > > + Copyright (c) 2023, Arm Limited. All rights reserved. > Copyright (c) Microsoft Corporation. > SPDX-License-Identifier: BSD-2-Clause-Patent > **/ > > #include > +#include > #include > +#include > #include > #include > +#include > > #define DEFAULT_DELAY_TIME_IN_MICROSECONDS 10 > > @@ -190,3 +194,27 @@ GetRandomNumber128 ( > // Read second 64 bits > return GetRandomNumber64 (++Rand); > } > + > +/** > + Get a GUID identifying the RNG algorithm implementation. > + > + @param [out] RngGuid If success, contains the GUID identifying > + the RNG algorithm implementation. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_UNSUPPORTED Not supported. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > +**/ > +EFI_STATUS > +EFIAPI > +GetRngGuid ( > + GUID *RngGuid > + ) > +{ > + if (RngGuid == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + CopyMem (RngGuid, &gEfiRngAlgorithmUnSafe, sizeof (*RngGuid)); > + return EFI_SUCCESS; > +} > diff --git a/MdePkg/Library/DxeRngLib/DxeRngLib.c b/MdePkg/Library/DxeRngLib/DxeRngLib.c > index a01b66ad7d20..cd23859e3112 100644 > --- a/MdePkg/Library/DxeRngLib/DxeRngLib.c > +++ b/MdePkg/Library/DxeRngLib/DxeRngLib.c > @@ -1,6 +1,7 @@ > /** @file > Provides an implementation of the library class RngLib that uses the Rng protocol. > > + Copyright (c) 2023, Arm Limited. All rights reserved. > Copyright (c) Microsoft Corporation. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent > > @@ -207,3 +208,30 @@ GetRandomNumber128 ( > > return TRUE; > } > + > +/** > + Get a GUID identifying the RNG algorithm implementation. > + > + @param [out] RngGuid If success, contains the GUID identifying > + the RNG algorithm implementation. > + > + @retval EFI_SUCCESS Success. > + @retval EFI_UNSUPPORTED Not supported. > + @retval EFI_INVALID_PARAMETER Invalid parameter. > +**/ > +EFI_STATUS > +EFIAPI > +GetRngGuid ( > + GUID *RngGuid > + ) > +{ > + /* It is not possible to know beforehand which Rng algorithm will > + be used by this library. > + This API is mainly used by RngDxe. RngDxe relies on the RngLib. > + The RngLib|DxeRngLib.inf implementation locates and uses an installed > + EFI_RNG_PROTOCOL. > + It is thus not possible to have both RngDxe and RngLib|DxeRngLib.inf. > + and it is ok not to support this API. > + */ > + return EFI_UNSUPPORTED; > +}