From nobody Mon Feb 9 17:24:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+52380+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+52380+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1576707400; cv=none; d=zohomail.com; s=zohoarc; b=Rnx8WfytQxl/Z7teTaXo7UKVvHSngh+a2iGFD++Bl56lBcJTyRG1wC2VlBr1SmYMm/iTD8gA5dOwf3FWO5e9TFciQmVkPWEhQjgwIHM8CWuQQj5mTJ3dbNhQFiK28lwm4I7ivb0wDKFMVFVWeZRmMyghdJdBQHmKr+StQBJcCIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576707400; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=oTabB9M5KbcXbbhLYICXH25sVsQwvorc/E/G6qarKVI=; b=P025Q408mZPqU+NrZiOuHlRrE3mO88ZTgr8ciEllkO4EraYlXF1Jj6gRMng1XE6RIE7TYUDPFDmBPmk0+tdSScR0N/BSqWkpB3w+zLCzEJU851AwfGIwJwK+NPnB/Co9oifZQuB5BDaarhWC81o+fA0jG4c1dUbmPhpoHxylilI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+52380+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1576707400447329.46232703201315; Wed, 18 Dec 2019 14:16:40 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id tgQUYY1788612xkUhHgWLsCv; Wed, 18 Dec 2019 14:16:40 -0800 X-Received: from mga14.intel.com (mga14.intel.com []) by mx.groups.io with SMTP id smtpd.web10.1987.1576705847293132972 for ; Wed, 18 Dec 2019 13:50:49 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2019 13:50:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="240930696" X-Received: from ansukerk-mobl.amr.corp.intel.com ([10.78.16.174]) by fmsmga004.fm.intel.com with ESMTP; 18 Dec 2019 13:50:48 -0800 From: "Sukerkar, Amol N" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, sachin.agrawal@intel.com, self, Subash Lakkimsetti Subject: [edk2-devel] [PATCH v1 6/6] SecurityPkg/HashApiInstanceSM3: Implement API registration mechanism for SM3 Date: Wed, 18 Dec 2019 14:50:37 -0700 Message-Id: <20191218215037.1630-7-amol.n.sukerkar@intel.com> In-Reply-To: <20191218215037.1630-1-amol.n.sukerkar@intel.com> References: <20191218215037.1630-1-amol.n.sukerkar@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,amol.n.sukerkar@intel.com X-Gm-Message-State: e1cSsowQkyVeNJndNdYTgP0nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1576707400; bh=YkNlt94XSOwkUd9Qt+Ph7iFiNbXX2Ck1Kn1ZvfsrkRI=; h=Cc:Date:From:Reply-To:Subject:To; b=LyQgjiG2TEF2rT8z8CQYwl/OTsU2O6RkloXqWOUDK5YpXfGEPKO4yOELUgieJpFSFH4 Hyga0DhClemFJEIfO3Aay7EQ4F7oifb/+nxGOLfztD76+e8XGYGWAcK7ClAKWdMfI7/5F P41rhsDb32plkf4tcFg4e0+N45omb0aHrOY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This is the HashApiInstance implementation for SM3 which registers the SM3 hash library in CryptoPkg with BaseHashLib based on whether a platform supp= orts SM3 hash algorithm. Signed-off-by: Subash Lakkimsetti Signed-off-by: Sukerkar, Amol N --- SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.c | 128 ++++++= ++++++++++++++ SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.inf | 40 ++++++ SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.uni | 16 +++ 3 files changed, 184 insertions(+) diff --git a/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.c b/= SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.c new file mode 100644 index 000000000000..391f482c1520 --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.c @@ -0,0 +1,128 @@ +/** @file + This library is BaseCrypto Sm3 hash instance. + It can be registered to BaseCrypto router, to serve as hash engine. + +Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +/** + Start hash sequence. + + @param HashHandle Hash handle. + + @retval EFI_SUCCESS Hash sequence start and HandleHandle return= ed. + @retval EFI_OUT_OF_RESOURCES No enough resource to start hash. +**/ +EFI_STATUS +EFIAPI +Sm3_Init ( + OUT HASH_HANDLE *HashHandle + ) +{ + VOID *Sm3Ctx; + UINTN CtxSize; + + CtxSize =3D Sm3GetContextSize (); + Sm3Ctx =3D AllocatePool (CtxSize); + ASSERT (Sm3Ctx !=3D NULL); + + Sm3Init (Sm3Ctx); + + *HashHandle =3D (HASH_HANDLE)Sm3Ctx; + + return EFI_SUCCESS; +} + +/** + Update hash sequence data. + + @param HashHandle Hash handle. + @param DataToHash Data to be hashed. + @param DataToHashLen Data size. + + @retval EFI_SUCCESS Hash sequence updated. +**/ +EFI_STATUS +EFIAPI +Sm3_Update ( + IN HASH_HANDLE HashHandle, + IN VOID *DataToHash, + IN UINTN DataToHashLen + ) +{ + VOID *Sm3Ctx; + + Sm3Ctx =3D (VOID *)HashHandle; + Sm3Update (Sm3Ctx, DataToHash, DataToHashLen); + + return EFI_SUCCESS; +} + +/** + Complete hash sequence complete. + + @param HashHandle Hash handle. + @param DigestList Digest list. + + @retval EFI_SUCCESS Hash sequence complete and DigestList is returne= d. +**/ +EFI_STATUS +EFIAPI +Sm3_Final ( + IN HASH_HANDLE HashHandle, + OUT UINT8 **Digest + ) +{ + UINT8 Sm3Digest[SM3_256_DIGEST_SIZE]; + VOID *Sm3Ctx; + + Sm3Ctx =3D (VOID *)HashHandle; + Sm3Final (Sm3Ctx, Sm3Digest); + + CopyMem (*Digest, Sm3Digest, SM3_256_DIGEST_SIZE); + + FreePool (Sm3Ctx); + + return EFI_SUCCESS; +} + +HASH_INTERFACE_UNIFIED_API mSm3InternalHashApiInstance =3D { + HASH_ALGORITHM_SM3_256_GUID, + Sm3_Init, + Sm3_Update, + Sm3_Final, +}; + +/** + The function register Sm3 instance. + + @retval EFI_SUCCESS Sm3 instance is registered, or system dose not sur= pport registr Sm3 instance +**/ +EFI_STATUS +EFIAPI +HashApiInstanceSm3Constructor ( + VOID + ) +{ + EFI_STATUS Status; + + Status =3D RegisterHashApiLib (&mSm3InternalHashApiInstance); + if ((Status =3D=3D EFI_SUCCESS) || (Status =3D=3D EFI_UNSUPPORTED)) { + // + // Unsupported means platform policy does not need this instance enabl= ed. + // + DEBUG ((DEBUG_ERROR, "[ansukerk]: Hash Interface Sm3 is registered\n")= ); + return EFI_SUCCESS; + } + return Status; +} diff --git a/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.inf = b/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.inf new file mode 100644 index 000000000000..ae328bfbf41f --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.inf @@ -0,0 +1,40 @@ +## @file +# Provides BaseCrypto SM3 hash service +# +# This library can be registered to BaseCrypto router, to serve as hash e= ngine. +# +# Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D HashApiInstanceSm3 + MODULE_UNI_FILE =3D HashApiInstanceSm3.uni + FILE_GUID =3D 9A7A6AB4-9DA6-4aa4-90CB-6D4B79EDA7B9 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NULL + CONSTRUCTOR =3D HashApiInstanceSm3Constructor + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + HashApiInstanceSm3.c + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec + CryptoPkg/CryptoPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + BaseCryptLib diff --git a/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.uni = b/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.uni new file mode 100644 index 000000000000..8f9712b1520e --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSm3/HashApiInstanceSm3.uni @@ -0,0 +1,16 @@ +// /** @file +// Provides BaseCrypto SM3 hash service +// +// This library can be registered to BaseCrypto router, to serve as hash e= ngine. +// +// Copyright (c) 2019, Intel Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Provides BaseCryp= to SM3 hash service API" + +#string STR_MODULE_DESCRIPTION #language en-US "This library can = be registered to Base Hash API, to serve as hash engine." + --=20 2.16.2.windows.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 (#52380): https://edk2.groups.io/g/devel/message/52380 Mute This Topic: https://groups.io/mt/68808201/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-