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="240930687" 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 4/6] SecurityPkg/HashApiInstanceSha384: Implement API registration mechanism for SHA384 Date: Wed, 18 Dec 2019 14:50:35 -0700 Message-Id: <20191218215037.1630-5-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 SHA384 which registers the SHA384 hash library in CryptoPkg with BaseHashLib based on whether a platfo= rm supports SHA384 hash algorithm (provided by PcdTpm2HashMask). Signed-off-by: Sukerkar, Amol N --- SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.c | 128 = ++++++++++++++++++++ SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.inf | 40 = ++++++ SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.uni | 16 = +++ SecurityPkg/SecurityPkg.dsc | 1 + 4 files changed, 185 insertions(+) diff --git a/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha38= 4.c b/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.c new file mode 100644 index 000000000000..0d1b8f3e877a --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.c @@ -0,0 +1,128 @@ +/** @file=0D + This library is BaseCrypto SHA384 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 +Sha384_Init (=0D + OUT HASH_HANDLE *HashHandle=0D + )=0D +{=0D + VOID *Sha384Ctx;=0D + UINTN CtxSize;=0D +=0D + CtxSize =3D Sha384GetContextSize ();=0D + Sha384Ctx =3D AllocatePool (CtxSize);=0D + ASSERT (Sha384Ctx !=3D NULL);=0D +=0D + Sha384Init (Sha384Ctx);=0D +=0D + *HashHandle =3D (HASH_HANDLE)Sha384Ctx;=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 +Sha384_Update (=0D + IN HASH_HANDLE HashHandle,=0D + IN VOID *DataToHash,=0D + IN UINTN DataToHashLen=0D + )=0D +{=0D + VOID *Sha384Ctx;=0D +=0D + Sha384Ctx =3D (VOID *)HashHandle;=0D + Sha384Update (Sha384Ctx, 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 +Sha384_Final (=0D + IN HASH_HANDLE HashHandle,=0D + OUT UINT8 **Digest=0D + )=0D +{=0D + UINT8 Sha384Digest[SHA384_DIGEST_SIZE];=0D + VOID *Sha384Ctx;=0D +=0D + Sha384Ctx =3D (VOID *)HashHandle;=0D + Sha384Final (Sha384Ctx, Sha384Digest);=0D +=0D + CopyMem (*Digest, Sha384Digest, SHA384_DIGEST_SIZE);=0D +=0D + FreePool (Sha384Ctx);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +HASH_INTERFACE_UNIFIED_API mSha384InternalHashApiInstance =3D {=0D + HASH_ALGORITHM_SHA384_GUID,=0D + Sha384_Init,=0D + Sha384_Update,=0D + Sha384_Final,=0D +};=0D +=0D +/**=0D + The function register SHA384 instance.=0D +=0D + @retval EFI_SUCCESS SHA384 instance is registered, or system dose not = surpport registr SHA384 instance=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +HashApiInstanceSha384Constructor (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + Status =3D RegisterHashApiLib (&mSha384InternalHashApiInstance);=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 SHA384 is registered\= n"));=0D + return EFI_SUCCESS;=0D + }=0D + return Status;=0D +}=0D diff --git a/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha38= 4.inf b/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.inf new file mode 100644 index 000000000000..ee36a926a8b8 --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.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 HashApiInstanceSha384=0D + MODULE_UNI_FILE =3D HashApiInstanceSha384.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 HashApiInstanceSha384Constructor=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 + HashApiInstanceSha384.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/HashApiInstanceSha384/HashApiInstanceSha38= 4.uni b/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.uni new file mode 100644 index 000000000000..be41375bca7a --- /dev/null +++ b/SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.uni @@ -0,0 +1,16 @@ +// /** @file=0D +// Provides BaseCrypto SHA384 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 SHA384 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 95a5710735e0..c03822872718 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -246,6 +246,7 @@ [Components.IA32, Components.X64] #=0D SecurityPkg/Library/HashApiInstanceSha1/HashApiInstanceSha1.inf=0D SecurityPkg/Library/HashApiInstanceSha256/HashApiInstanceSha256.inf=0D + SecurityPkg/Library/HashApiInstanceSha384/HashApiInstanceSha384.inf=0D =0D #=0D # TPM=0D --=20 2.16.2.windows.1