From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 72128203BBBBD for ; Tue, 22 May 2018 23:11:43 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2018 23:11:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,432,1520924400"; d="scan'208";a="51462788" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by FMSMGA003.fm.intel.com with ESMTP; 22 May 2018 23:11:41 -0700 Received: from fmsmsx118.amr.corp.intel.com (10.18.116.18) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 22 May 2018 23:11:34 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx118.amr.corp.intel.com (10.18.116.18) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 22 May 2018 23:11:32 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.79]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.40]) with mapi id 14.03.0319.002; Wed, 23 May 2018 14:10:47 +0800 From: "Zeng, Star" To: "Ni, Ruiyu" , "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Gao, Liming" , "Long, Qin" , "Zeng, Star" Thread-Topic: [edk2] [PATCH] MdePkg/BaseLib: Add GenerateGuid() to BaseLib Thread-Index: AQHT8lesvr385T/2CE6mIMAPgb1gwKQ8Sz+AgACI85A= Date: Wed, 23 May 2018 06:10:46 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BAEE851@shsmsx102.ccr.corp.intel.com> References: <20180523053348.175228-1-ruiyu.ni@intel.com> <734D49CCEBEEF84792F5B80ED585239D5BCA57E7@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5BCA57E7@SHSMSX104.ccr.corp.intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYWYzYzU0ZjktZWIyYy00ZjU4LTk5MTgtNDQ5NWM5NWExNDViIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSVduUk5ZVWxUUEJaVWpvVzVEa2JHSFJoZzgwMjkxcmJ3VjR4ZU1TUU43MXArVzRwZXpkQzNFaG1CeGpzM0FcLzQifQ== dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdePkg/BaseLib: Add GenerateGuid() to BaseLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 May 2018 06:11:43 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ray, Two points need be noticed. 1. BaseLib.inf forgets to include RngLib. 2. This patch will include RngLib dependency to BaseLib, that may break man= y platforms that do not declare RngLib in their platform dsc. Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ni, = Ruiyu Sent: Wednesday, May 23, 2018 1:58 PM To: Ni, Ruiyu ; edk2-devel@lists.01.org Cc: Kinney, Michael D ; Gao, Liming ; Long, Qin Subject: Re: [edk2] [PATCH] MdePkg/BaseLib: Add GenerateGuid() to BaseLib Sorry, I forgot to include Long Qin. Thanks/Ray > -----Original Message----- > From: edk2-devel On Behalf Of Ruiyu=20 > Ni > Sent: Wednesday, May 23, 2018 1:34 PM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Gao, Liming=20 > > Subject: [edk2] [PATCH] MdePkg/BaseLib: Add GenerateGuid() to BaseLib >=20 > Per RFC4122, there are five versions of UUID (GUID). > The version 4 only depends on truly random or pseudo-random number=20 > generation. > So GenerateGuid () can be added to BaseLib. It uses the > GetRandomNumber128() services exposed from MdePkg/RngLib. > This API can be used by some EFI utilities which needs the guidgen=20 > services, > e.g.: utility that partitions the disk in GPT format needs to fill the=20 > generated GUID in partition table. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni > Cc: Liming Gao > Cc: Michael D Kinney > Cc: Qin Long > --- > MdePkg/Include/Library/BaseLib.h | 18 ++++++++- > MdePkg/Library/BaseLib/BaseLibInternals.h | 3 +- > MdePkg/Library/BaseLib/GenerateGuid.c | 64 > +++++++++++++++++++++++++++++++ > 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644=20 > MdePkg/Library/BaseLib/GenerateGuid.c >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index eb2899f852..272596d64c 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -2,7 +2,7 @@ > Provides string functions, linked list functions, math functions,=20 > synchronization > functions, file path functions, and CPU architecture-specific function= s. >=20 > -Copyright (c) 2006 - 2017, Intel Corporation. All rights=20 > reserved.
> +Copyright (c) 2006 - 2018, Intel Corporation. All rights=20 > +reserved.
> Portions copyright (c) 2008 - 2009, Apple Inc. All rights=20 > reserved.
This program and the accompanying materials are=20 > licensed and made available under the terms and conditions of the BSD=20 > License @@ -5104,6 +5104,22 @@ EFIAPI CpuDeadLoop ( > VOID > ); > + > +/** > + Generate a raw 128-bit (16-byte) GUID. > + > + If Guid is NULL, then ASSERT(). > + > + @param Guid Receive the 128-bit (16-byte) GUID. > + > + @retval TRUE The GUID is generated successfully. > + @retval FALSE The GUID is not generated. > +**/ > +BOOLEAN > +EFIAPI > +GenerateGuid ( > + OUT GUID *Guid > + ); >=20 > #if defined (MDE_CPU_IPF) >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h > b/MdePkg/Library/BaseLib/BaseLibInternals.h > index 9dca97a0dc..427eb44eba 100644 > --- a/MdePkg/Library/BaseLib/BaseLibInternals.h > +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h > @@ -1,7 +1,7 @@ > /** @file > Declaration of internal functions in BaseLib. >=20 > - Copyright (c) 2006 - 2017, Intel Corporation. All rights=20 > reserved.
> + Copyright (c) 2006 - 2018, Intel Corporation. All rights=20 > + reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of=20 > the BSD License > which accompanies this distribution. The full text of the license=20 > may be found at @@ -20,6 +20,7 @@ #include =20 > #include #include > +#include >=20 > // > // Math functions > diff --git a/MdePkg/Library/BaseLib/GenerateGuid.c > b/MdePkg/Library/BaseLib/GenerateGuid.c > new file mode 100644 > index 0000000000..b90f7c5a83 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/GenerateGuid.c > @@ -0,0 +1,64 @@ > +/** @file > + Generate GUID implementation. > + > + Copyright (c) 2018, Intel Corporation. All rights reserved.
=20 > + This program and the accompanying materials are licensed and made=20 > + available under the terms and conditions of the BSD License which=20 > + accompanies this distribution. The full text of the license may be=20 > + found at http://opensource.org/licenses/bsd-license.php. > + > + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > +**/ > + > +#include "BaseLibInternals.h" > + > +/** > + Generate a raw 128-bit (16-byte) GUID. > + > + If Guid is NULL, then ASSERT(). > + > + @param Guid Receive the generated 128-bit (16-byte) GUID. > + > + @retval TRUE The GUID is generated successfully. > + @retval FALSE The GUID is not generated. > +**/ > +BOOLEAN > +EFIAPI > +GenerateGuid ( > + OUT GUID *Guid > + ) > +{ > + ASSERT (Guid !=3D NULL); > + > + // > + // A GUID is encoded as a 128-bit object as follows: > + // 0 1 2 3 > + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 > + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > + // | time_low | > + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > + // | time_mid | time_hi_and_version | > + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > + // |clk_seq_hi_res | clk_seq_low | node (0-1) | > + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > + // | node (2-5) | > + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > + // The below algorithm generates version 4 GUID from truly-random=20 > + or > pseudo-random numbers. > + // The algorithm is as follows (per RFC 4122): > + // > Set all the bits to randomly (or pseudo-randomly) values. > + // > Set the two most significant bits (bits 6 and 7) of=20 > + clk_seq_hi_res field > to zero and one, respectively. > + // > Set the four most significant bits (bits 12 through 15) of > time_hi_and_version field to 4 (4-bit version number). > + // > + if (!GetRandomNumber128 ((UINT64 *)Guid)) { > + return FALSE; > + } > + > + // > + // Version 4 (Random GUID) > + // > + Guid->Data4[0] =3D BitFieldWrite8 (Guid->Data4[0], 6, 7, 0b10); > + Guid->Data3 =3D BitFieldWrite16 (Guid->Data3, 12, 15, 4); > +} > + > -- > 2.16.1.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel