From nobody Tue Feb 10 06:59:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90902+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90902+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1656530375; cv=none; d=zohomail.com; s=zohoarc; b=joGMZXj/oM8FycHiU2tc3W8+UgMEPQE6hgQvHD3G/m7Syzb/E4sK94zdGAaWcLufuYRs/0TP3R7I8Wjdc4S2xP7anFt9/CmxjOph1ZzyBrqkjOaGBofiFxANpQb/APWsaxJJ9zAOHwYygJGj6y6CmKMezgae1vfFTpo/4Bgq1f8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656530375; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=YZ0FEV86gMFbM/2LiPyjT8YVvwVca3/c9H3ZYToiTEQ=; b=eyCr1qS1nPafHg8frjuGpbpSDyvntN/VKIukkNU5mfGn4aiPlsxoR3amTt2QQAnDK/M98YSPwkNrRmBZsds6LLTd2C3KSfSI7ktPqUzqLnWxvNhAccCiDpquhztoD3KAtjYkOd21ZCLIFY/17IsUiC2lBetiuu3mEJ3cxRGE36k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90902+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1656530375699318.1832381860605; Wed, 29 Jun 2022 12:19:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1qgBYY1788612xksG7bVln1C; Wed, 29 Jun 2022 12:19:34 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.15827.1656530373964459523 for ; Wed, 29 Jun 2022 12:19:34 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE60414BF; Wed, 29 Jun 2022 12:19:33 -0700 (PDT) X-Received: from pierre123.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 72ABD3F792; Wed, 29 Jun 2022 12:19:31 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH RESEND v1 4/9] MdePkg/DrbgLib: Add Get_entropy_input() implementation Date: Wed, 29 Jun 2022 21:18:41 +0200 Message-Id: <20220629191848.2619317-5-Pierre.Gondois@arm.com> In-Reply-To: <20220629191848.2619317-1-Pierre.Gondois@arm.com> References: <20220629191848.2619317-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: sg31x2SzimI5GmlMtzXTrd66x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1656530374; bh=yjsokSHA9kEaIr4sRYZ2sQmJCiYuE/igTvY0KGl82ts=; h=Cc:Date:From:Reply-To:Subject:To; b=fJ1OMjA0h67mbYoqoUuia71AFkR+Wbj+XdoNMhrJO+pOScO39EOTfpLKCfebNHh/+XJ fAwnpol6WWDSj5kqe973EqAFW3zzKsDobR5Q0+PH3QIZVpy2kF98TdbcRLHb0sQErkSeK HllpGVlsJ2Q7MHbHmVfHlNDSBsRnpvWKWZ0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1656530376147100006 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois NIST Special Publication 800-90C, s10.3.3 'Get_entropy_input Constructions for Accessing Entropy Sources' specifies multiple way to implement the Get_entropy_input() function. Implement s10.3.3.1 'Construction When a Conditioning Function is not Used' in a separate file to let room for other potential implementations. Signed-off-by: Pierre Gondois --- MdePkg/Library/DrbgLib/GetEntropyInput.c | 72 ++++++++++++++++++++++++ MdePkg/Library/DrbgLib/GetEntropyInput.h | 48 ++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 MdePkg/Library/DrbgLib/GetEntropyInput.c create mode 100644 MdePkg/Library/DrbgLib/GetEntropyInput.h diff --git a/MdePkg/Library/DrbgLib/GetEntropyInput.c b/MdePkg/Library/Drbg= Lib/GetEntropyInput.c new file mode 100644 index 000000000000..6257bc9093dd --- /dev/null +++ b/MdePkg/Library/DrbgLib/GetEntropyInput.c @@ -0,0 +1,72 @@ +/** @file + GetEntropyInput function implementation. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] NIST Special Publication 800-90A Revision 1, June 2015, Recommenda= tion + for Random Number Generation Using Deterministic Random Bit Genera= tors. + (https://csrc.nist.gov/publications/detail/sp/800-90a/rev-1/final) + - [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) + - [3] (Second Draft) NIST Special Publication 800-90C, Recommendation for + Random Bit Generator (RBG) Constructions. + (https://csrc.nist.gov/publications/detail/sp/800-90c/draft) + + @par Glossary: + - TRNG - True Random Number Generator + - Sec - Security + - DRBG - Deterministic Random Bits Generator + - CTR - Counter +**/ + +#include +#include + +#include "Common.h" + +/** GetEntropyInput implementation (no conditionning function). + + Cf. [3] 10.3.3.1 Construction When a Conditioning Function is not Used + + @param [in] DrbgHandle The Drbg hanble. + @param [in] MinEntropy Minimum entropy. + @param [out] EntropyBitsStream Stream containing the generated entropy. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Out of resources. +**/ +EFI_STATUS +EFIAPI +GetEntropyInputNoCondFn ( + IN DRBG_HANDLE DrbgHandle, + IN UINTN MinEntropy, + OUT BIT_STREAM **EntropyBitsStream + ) +{ + EFI_STATUS Status; + + if ((DrbgHandle =3D=3D NULL) || + (EntropyBitsStream =3D=3D NULL) || + (*EntropyBitsStream !=3D NULL)) + { + ASSERT (DrbgHandle !=3D NULL); + ASSERT (EntropyBitsStream !=3D NULL); + ASSERT (*EntropyBitsStream =3D=3D NULL); + return EFI_INVALID_PARAMETER; + } + + // 1. (status, entropy_bitstring) =3D Get_Entropy(min_entropy, max_lengt= h). + // 2. If (status !=3D SUCCESS), then return (status, Null). + // 3. Return SUCCESS, entropy_bitstring. + Status =3D GetEntropy (DrbgHandle, MinEntropy, EntropyBitsStream); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + // Fall through. + } + + return Status; +} diff --git a/MdePkg/Library/DrbgLib/GetEntropyInput.h b/MdePkg/Library/Drbg= Lib/GetEntropyInput.h new file mode 100644 index 000000000000..336fbc3826c0 --- /dev/null +++ b/MdePkg/Library/DrbgLib/GetEntropyInput.h @@ -0,0 +1,48 @@ +/** @file + GetEntropyInput function implementation. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] NIST Special Publication 800-90A Revision 1, June 2015, Recommenda= tion + for Random Number Generation Using Deterministic Random Bit Genera= tors. + (https://csrc.nist.gov/publications/detail/sp/800-90a/rev-1/final) + - [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) + - [3] (Second Draft) NIST Special Publication 800-90C, Recommendation for + Random Bit Generator (RBG) Constructions. + (https://csrc.nist.gov/publications/detail/sp/800-90c/draft) + + @par Glossary: + - TRNG - True Random Number Generator + - Sec - Security + - DRBG - Deterministic Random Bits Generator + - CTR - Counter +**/ + +#ifndef GET_ENTROPY_INPUT_H_ +#define GET_ENTROPY_INPUT_H_ + +/** GetEntropyInput implementation (no conditionning function). + + Cf. [3] 10.3.3.1 Construction When a Conditioning Function is not Used + + @param [in] DrbgHandle The Drbg hanble. + @param [in] MinEntropy Minimum entropy. + @param [out] EntropyBitsStream Stream containing the generated entropy. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_OUT_OF_RESOURCES Out of resources. +**/ +EFI_STATUS +EFIAPI +GetEntropyInputNoCondFn ( + IN DRBG_HANDLE DrbgHandle, + IN UINTN MinEntropy, + OUT BIT_STREAM **EntropyBitsStream + ); + +#endif // GET_ENTROPY_INPUT_H_ --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#90902): https://edk2.groups.io/g/devel/message/90902 Mute This Topic: https://groups.io/mt/92072290/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-