From mboxrd@z Thu Jan 1 00:00:00 1970 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:48 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: amol.n.sukerkar@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False 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:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,330,1571727600"; d="scan'208";a="240930683" Received: from ansukerk-mobl.amr.corp.intel.com ([10.78.16.174]) by fmsmga004.fm.intel.com with ESMTP; 18 Dec 2019 13:50:47 -0800 From: "Sukerkar, Amol N" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, sachin.agrawal@intel.com, self Subject: [PATCH v1 3/6] SecurityPkg/HashApiInstanceSha256: Implement API registration mechanism for SHA256 Date: Wed, 18 Dec 2019 14:50:34 -0700 Message-Id: <20191218215037.1630-4-amol.n.sukerkar@intel.com> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20191218215037.1630-1-amol.n.sukerkar@intel.com> References: <20191218215037.1630-1-amol.n.sukerkar@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable This is the HashApiInstance implementation for SHA256 which registers the SHA256 hash library in CryptoPkg with BaseHashLib based on whether a platfo= rm supports SHA256 hash algorithm (provided by PcdTpm2HashMask). Signed-off-by: Sukerkar, Amol N --- SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.c | 128 = ++++++++++++++++++++ SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.inf | 40 = ++++++ SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.uni | 16 = +++ SecurityPkg/SecurityPkg.dsc | 1 + 4 files changed, 185 insertions(+) diff --git a/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha25= 6.c b/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.c new file mode 100644 index 000000000000..129d60a387fd --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.c @@ -0,0 +1,128 @@ +/** @file=0D + This library is BaseCrypto SHA256 hash instance.=0D + It can be registered to BaseCrypto router, to serve as hash engine.=0D +=0D +Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Start hash sequence.=0D +=0D + @param HashHandle Hash handle.=0D +=0D + @retval EFI_SUCCESS Hash sequence start and HandleHandle return= ed.=0D + @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +Sha256_Init (=0D + OUT HASH_HANDLE *HashHandle=0D + )=0D +{=0D + VOID *Sha256Ctx;=0D + UINTN CtxSize;=0D +=0D + CtxSize =3D Sha256GetContextSize ();=0D + Sha256Ctx =3D AllocatePool (CtxSize);=0D + ASSERT (Sha256Ctx !=3D NULL);=0D +=0D + Sha256Init (Sha256Ctx);=0D +=0D + *HashHandle =3D (HASH_HANDLE)Sha256Ctx;=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Update hash sequence data.=0D +=0D + @param HashHandle Hash handle.=0D + @param DataToHash Data to be hashed.=0D + @param DataToHashLen Data size.=0D +=0D + @retval EFI_SUCCESS Hash sequence updated.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +Sha256_Update (=0D + IN HASH_HANDLE HashHandle,=0D + IN VOID *DataToHash,=0D + IN UINTN DataToHashLen=0D + )=0D +{=0D + VOID *Sha256Ctx;=0D +=0D + Sha256Ctx =3D (VOID *)HashHandle;=0D + Sha256Update (Sha256Ctx, DataToHash, DataToHashLen);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Complete hash sequence complete.=0D +=0D + @param HashHandle Hash handle.=0D + @param DigestList Digest list.=0D +=0D + @retval EFI_SUCCESS Hash sequence complete and DigestList is returne= d.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +Sha256_Final (=0D + IN HASH_HANDLE HashHandle,=0D + OUT UINT8 **Digest=0D + )=0D +{=0D + UINT8 Sha256Digest[SHA256_DIGEST_SIZE];=0D + VOID *Sha256Ctx;=0D +=0D + Sha256Ctx =3D (VOID *)HashHandle;=0D + Sha256Final (Sha256Ctx, Sha256Digest);=0D +=0D + CopyMem (*Digest, Sha256Digest, SHA256_DIGEST_SIZE);=0D +=0D + FreePool (Sha256Ctx);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +HASH_INTERFACE_UNIFIED_API mSha256InternalHashApiInstance =3D {=0D + HASH_ALGORITHM_SHA256_GUID,=0D + Sha256_Init,=0D + Sha256_Update,=0D + Sha256_Final,=0D +};=0D +=0D +/**=0D + The function register SHA256 instance.=0D +=0D + @retval EFI_SUCCESS SHA256 instance is registered, or system dose not = surpport registr SHA256 instance=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +HashApiInstanceSha256Constructor (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D RegisterHashApiLib (&mSha256InternalHashApiInstance);=0D + if ((Status =3D=3D EFI_SUCCESS) || (Status =3D=3D EFI_UNSUPPORTED)) {=0D + //=0D + // Unsupported means platform policy does not need this instance enabl= ed.=0D + //=0D + DEBUG ((DEBUG_ERROR, "[ansukerk]: Hash Interface SHA256 is registered\= n"));=0D + return EFI_SUCCESS;=0D + }=0D + return Status;=0D +}=0D diff --git a/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha25= 6.inf b/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.inf new file mode 100644 index 000000000000..08d802cd69f4 --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.inf @@ -0,0 +1,40 @@ +## @file=0D +# Provides BaseCrypto SHA1 hash service=0D +#=0D +# This library can be registered to BaseCrypto router, to serve as hash e= ngine.=0D +#=0D +# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D HashApiInstanceSha256=0D + MODULE_UNI_FILE =3D HashApiInstanceSha256.uni=0D + FILE_GUID =3D 9A7A6AB4-9DA6-4aa4-90CB-6D4B79EDA7B9= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D NULL=0D + CONSTRUCTOR =3D HashApiInstanceSha256Constructor=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[Sources]=0D + HashApiInstanceSha256.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + SecurityPkg/SecurityPkg.dec=0D + CryptoPkg/CryptoPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + BaseMemoryLib=0D + DebugLib=0D + MemoryAllocationLib=0D + BaseCryptLib=0D diff --git a/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha25= 6.uni b/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.uni new file mode 100644 index 000000000000..b2121464c552 --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.uni @@ -0,0 +1,16 @@ +// /** @file=0D +// Provides BaseCrypto SHA256 hash service=0D +//=0D +// This library can be registered to BaseCrypto router, to serve as hash e= ngine.=0D +//=0D +// Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
= =0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=0D +=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "Provides BaseCryp= to SHA256 hash service API"=0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "This library can = be registered to Base Hash API, to serve as hash engine."=0D +=0D diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 6c0832d48e88..95a5710735e0 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -245,6 +245,7 @@ [Components.IA32, Components.X64] # Hash API=0D #=0D SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.inf=0D + SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.inf=0D =0D #=0D # TPM=0D --=20 2.16.2.windows.1