From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.1989.1576705848243615303 for ; Wed, 18 Dec 2019 13:50:48 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, 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="240930679" 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 2/6] SecurityPkg/HashApiInstanceSha1: Implement API registration mechanism for SHA1 Date: Wed, 18 Dec 2019 14:50:33 -0700 Message-Id: <20191218215037.1630-3-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 SHA1 which registers the SHA1 hash library in CryptoPkg with BaseHashLib based on whether a platform supp= orts SHA1 hash algorithm (provided by PcdTpm2HashMask). Signed-off-by: Sukerkar, Amol N --- SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.c | 128 ++++= ++++++++++++++++ SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.inf | 40 ++++= ++ SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.uni | 16 +++ SecurityPkg/SecurityPkg.dsc | 5 + 4 files changed, 189 insertions(+) diff --git a/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.c = b/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.c new file mode 100644 index 000000000000..06e88f00d70b --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.c @@ -0,0 +1,128 @@ +/** @file=0D + This library is BaseCrypto SHA1 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 +Sha1_Init (=0D + OUT HASH_HANDLE *HashHandle=0D + )=0D +{=0D + VOID *Sha1Ctx;=0D + UINTN CtxSize;=0D +=0D + CtxSize =3D Sha1GetContextSize ();=0D + Sha1Ctx =3D AllocatePool (CtxSize);=0D + ASSERT (Sha1Ctx !=3D NULL);=0D +=0D + Sha1Init (Sha1Ctx);=0D +=0D + *HashHandle =3D (HASH_HANDLE)Sha1Ctx;=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 +Sha1_Update (=0D + IN HASH_HANDLE HashHandle,=0D + IN VOID *DataToHash,=0D + IN UINTN DataToHashLen=0D + )=0D +{=0D + VOID *Sha1Ctx;=0D +=0D + Sha1Ctx =3D (VOID *)HashHandle;=0D + Sha1Update (Sha1Ctx, 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 +Sha1_Final (=0D + IN HASH_HANDLE HashHandle,=0D + OUT UINT8 **Digest=0D + )=0D +{=0D + UINT8 Sha1Digest[SHA1_DIGEST_SIZE];=0D + VOID *Sha1Ctx;=0D +=0D + Sha1Ctx =3D (VOID *)HashHandle;=0D + Sha1Final (Sha1Ctx, Sha1Digest);=0D +=0D + CopyMem (*Digest, Sha1Digest, SHA1_DIGEST_SIZE);=0D +=0D + FreePool (Sha1Ctx);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +HASH_INTERFACE_UNIFIED_API mSha1InternalHashApiInstance =3D {=0D + HASH_ALGORITHM_SHA1_GUID,=0D + Sha1_Init,=0D + Sha1_Update,=0D + Sha1_Final,=0D +};=0D +=0D +/**=0D + The function register SHA1 instance.=0D +=0D + @retval EFI_SUCCESS SHA1 instance is registered, or system dose not su= rpport registr SHA1 instance=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +HashApiInstanceSha1Constructor (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D RegisterHashApiLib (&mSha1InternalHashApiInstance);=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 SHA1 is registered\n"= ));=0D + return EFI_SUCCESS;=0D + }=0D + return Status;=0D +}=0D diff --git a/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.in= f b/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.inf new file mode 100644 index 000000000000..b59c4d883439 --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.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 HashApiInstanceSha1=0D + MODULE_UNI_FILE =3D HashApiInstanceSha1.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 HashApiInstanceSha1Constructor=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 + HashApiInstanceSha1.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/HashApiInstanceSha1/HashApiInstanceSha1.un= i b/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.uni new file mode 100644 index 000000000000..716369d2fb8a --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.uni @@ -0,0 +1,16 @@ +// /** @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 - 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 SHA1 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 9ae134ffee53..6c0832d48e88 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -241,6 +241,11 @@ [Components.IA32, Components.X64, Components.ARM, Comp= onents.AARCH64] [Components.IA32, Components.X64]=0D SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDx= e.inf=0D =0D + #=0D + # Hash API=0D + #=0D + SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.inf=0D +=0D #=0D # TPM=0D #=0D --=20 2.16.2.windows.1