diff options
Diffstat (limited to 'SecurityPkg/Library/HashLibBaseCryptoRouter')
4 files changed, 117 insertions, 108 deletions
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c index aec874a9e0..1013380844 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.c @@ -16,16 +16,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Protocol/Tcg2Protocol.h>
typedef struct {
- EFI_GUID Guid;
- UINT32 Mask;
+ EFI_GUID Guid;
+ UINT32 Mask;
} TPM2_HASH_MASK;
-TPM2_HASH_MASK mTpm2HashMask[] = {
- {HASH_ALGORITHM_SHA1_GUID, HASH_ALG_SHA1},
- {HASH_ALGORITHM_SHA256_GUID, HASH_ALG_SHA256},
- {HASH_ALGORITHM_SHA384_GUID, HASH_ALG_SHA384},
- {HASH_ALGORITHM_SHA512_GUID, HASH_ALG_SHA512},
- {HASH_ALGORITHM_SM3_256_GUID, HASH_ALG_SM3_256},
+TPM2_HASH_MASK mTpm2HashMask[] = {
+ { HASH_ALGORITHM_SHA1_GUID, HASH_ALG_SHA1 },
+ { HASH_ALGORITHM_SHA256_GUID, HASH_ALG_SHA256 },
+ { HASH_ALGORITHM_SHA384_GUID, HASH_ALG_SHA384 },
+ { HASH_ALGORITHM_SHA512_GUID, HASH_ALG_SHA512 },
+ { HASH_ALGORITHM_SM3_256_GUID, HASH_ALG_SM3_256 },
};
/**
@@ -42,11 +42,13 @@ Tpm2GetHashMaskFromAlgo ( )
{
UINTN Index;
- for (Index = 0; Index < sizeof(mTpm2HashMask)/sizeof(mTpm2HashMask[0]); Index++) {
+
+ for (Index = 0; Index < sizeof (mTpm2HashMask)/sizeof (mTpm2HashMask[0]); Index++) {
if (CompareGuid (HashGuid, &mTpm2HashMask[Index].Guid)) {
return mTpm2HashMask[Index].Mask;
}
}
+
return 0;
}
@@ -59,14 +61,14 @@ Tpm2GetHashMaskFromAlgo ( VOID
EFIAPI
Tpm2SetHashToDigestList (
- IN OUT TPML_DIGEST_VALUES *DigestList,
- IN TPML_DIGEST_VALUES *Digest
+ IN OUT TPML_DIGEST_VALUES *DigestList,
+ IN TPML_DIGEST_VALUES *Digest
)
{
CopyMem (
&DigestList->digests[DigestList->count],
&Digest->digests[0],
- sizeof(Digest->digests[0])
+ sizeof (Digest->digests[0])
);
- DigestList->count ++;
+ DigestList->count++;
}
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h index 0736358da8..987d794028 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterCommon.h @@ -31,8 +31,8 @@ Tpm2GetHashMaskFromAlgo ( VOID
EFIAPI
Tpm2SetHashToDigestList (
- IN OUT TPML_DIGEST_VALUES *DigestList,
- IN TPML_DIGEST_VALUES *Digest
+ IN OUT TPML_DIGEST_VALUES *DigestList,
+ IN TPML_DIGEST_VALUES *Digest
);
#endif
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c index 7a0f61efbb..59639d0538 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterDxe.c @@ -19,11 +19,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "HashLibBaseCryptoRouterCommon.h"
-HASH_INTERFACE mHashInterface[HASH_COUNT] = {{{0}, NULL, NULL, NULL}};
-UINTN mHashInterfaceCount = 0;
+HASH_INTERFACE mHashInterface[HASH_COUNT] = {
+ {
+ { 0 }, NULL, NULL, NULL
+ }
+};
+UINTN mHashInterfaceCount = 0;
-UINT32 mSupportedHashMaskLast = 0;
-UINT32 mSupportedHashMaskCurrent = 0;
+UINT32 mSupportedHashMaskLast = 0;
+UINT32 mSupportedHashMaskCurrent = 0;
/**
Check mismatch of supported HashMask between modules
@@ -57,7 +61,7 @@ CheckSupportedHashMaskMismatch ( EFI_STATUS
EFIAPI
HashStart (
- OUT HASH_HANDLE *HashHandle
+ OUT HASH_HANDLE *HashHandle
)
{
HASH_HANDLE *HashCtx;
@@ -70,7 +74,7 @@ HashStart ( CheckSupportedHashMaskMismatch ();
- HashCtx = AllocatePool (sizeof(*HashCtx) * mHashInterfaceCount);
+ HashCtx = AllocatePool (sizeof (*HashCtx) * mHashInterfaceCount);
ASSERT (HashCtx != NULL);
for (Index = 0; Index < mHashInterfaceCount; Index++) {
@@ -97,9 +101,9 @@ HashStart ( EFI_STATUS
EFIAPI
HashUpdate (
- IN HASH_HANDLE HashHandle,
- IN VOID *DataToHash,
- IN UINTN DataToHashLen
+ IN HASH_HANDLE HashHandle,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen
)
{
HASH_HANDLE *HashCtx;
@@ -138,18 +142,18 @@ HashUpdate ( EFI_STATUS
EFIAPI
HashCompleteAndExtend (
- IN HASH_HANDLE HashHandle,
- IN TPMI_DH_PCR PcrIndex,
- IN VOID *DataToHash,
- IN UINTN DataToHashLen,
- OUT TPML_DIGEST_VALUES *DigestList
+ IN HASH_HANDLE HashHandle,
+ IN TPMI_DH_PCR PcrIndex,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen,
+ OUT TPML_DIGEST_VALUES *DigestList
)
{
- TPML_DIGEST_VALUES Digest;
- HASH_HANDLE *HashCtx;
- UINTN Index;
- EFI_STATUS Status;
- UINT32 HashMask;
+ TPML_DIGEST_VALUES Digest;
+ HASH_HANDLE *HashCtx;
+ UINTN Index;
+ EFI_STATUS Status;
+ UINT32 HashMask;
if (mHashInterfaceCount == 0) {
return EFI_UNSUPPORTED;
@@ -158,7 +162,7 @@ HashCompleteAndExtend ( CheckSupportedHashMaskMismatch ();
HashCtx = (HASH_HANDLE *)HashHandle;
- ZeroMem (DigestList, sizeof(*DigestList));
+ ZeroMem (DigestList, sizeof (*DigestList));
for (Index = 0; Index < mHashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&mHashInterface[Index].HashGuid);
@@ -191,14 +195,14 @@ HashCompleteAndExtend ( EFI_STATUS
EFIAPI
HashAndExtend (
- IN TPMI_DH_PCR PcrIndex,
- IN VOID *DataToHash,
- IN UINTN DataToHashLen,
- OUT TPML_DIGEST_VALUES *DigestList
+ IN TPMI_DH_PCR PcrIndex,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen,
+ OUT TPML_DIGEST_VALUES *DigestList
)
{
- HASH_HANDLE HashHandle;
- EFI_STATUS Status;
+ HASH_HANDLE HashHandle;
+ EFI_STATUS Status;
if (mHashInterfaceCount == 0) {
return EFI_UNSUPPORTED;
@@ -225,12 +229,12 @@ HashAndExtend ( EFI_STATUS
EFIAPI
RegisterHashInterfaceLib (
- IN HASH_INTERFACE *HashInterface
+ IN HASH_INTERFACE *HashInterface
)
{
- UINTN Index;
- UINT32 HashMask;
- EFI_STATUS Status;
+ UINTN Index;
+ UINT32 HashMask;
+ EFI_STATUS Status;
//
// Check allow
@@ -240,7 +244,7 @@ RegisterHashInterfaceLib ( return EFI_UNSUPPORTED;
}
- if (mHashInterfaceCount >= sizeof(mHashInterface)/sizeof(mHashInterface[0])) {
+ if (mHashInterfaceCount >= sizeof (mHashInterface)/sizeof (mHashInterface[0])) {
return EFI_OUT_OF_RESOURCES;
}
@@ -258,11 +262,11 @@ RegisterHashInterfaceLib ( // Record hash algorithm bitmap of CURRENT module which consumes HashLib.
//
mSupportedHashMaskCurrent = PcdGet32 (PcdTcg2HashAlgorithmBitmap) | HashMask;
- Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, mSupportedHashMaskCurrent);
+ Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, mSupportedHashMaskCurrent);
ASSERT_EFI_ERROR (Status);
- CopyMem (&mHashInterface[mHashInterfaceCount], HashInterface, sizeof(*HashInterface));
- mHashInterfaceCount ++;
+ CopyMem (&mHashInterface[mHashInterfaceCount], HashInterface, sizeof (*HashInterface));
+ mHashInterfaceCount++;
return EFI_SUCCESS;
}
@@ -283,7 +287,7 @@ HashLibBaseCryptoRouterDxeConstructor ( IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Record hash algorithm bitmap of LAST module which also consumes HashLib.
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c index 42cb562f67..e21103d371 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c @@ -24,7 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define HASH_LIB_PEI_ROUTER_GUID \
{ 0x84681c08, 0x6873, 0x46f3, { 0x8b, 0xb7, 0xab, 0x66, 0x18, 0x95, 0xa1, 0xb3 } }
-EFI_GUID mHashLibPeiRouterGuid = HASH_LIB_PEI_ROUTER_GUID;
+EFI_GUID mHashLibPeiRouterGuid = HASH_LIB_PEI_ROUTER_GUID;
typedef struct {
//
@@ -34,10 +34,10 @@ typedef struct { // If gEfiCallerIdGuid, HashInterfaceCount, HashInterface and SupportedHashMask
// are the hash interface information of CURRENT module which consumes HashLib.
//
- EFI_GUID Identifier;
- UINTN HashInterfaceCount;
- HASH_INTERFACE HashInterface[HASH_COUNT];
- UINT32 SupportedHashMask;
+ EFI_GUID Identifier;
+ UINTN HashInterfaceCount;
+ HASH_INTERFACE HashInterface[HASH_COUNT];
+ UINT32 SupportedHashMask;
} HASH_INTERFACE_HOB;
/**
@@ -49,7 +49,7 @@ typedef struct { **/
HASH_INTERFACE_HOB *
InternalGetHashInterfaceHob (
- EFI_GUID *Identifier
+ EFI_GUID *Identifier
)
{
EFI_PEI_HOB_POINTERS Hob;
@@ -64,9 +64,11 @@ InternalGetHashInterfaceHob ( //
return HashInterfaceHob;
}
+
Hob.Raw = GET_NEXT_HOB (Hob);
Hob.Raw = GetNextGuidHob (&mHashLibPeiRouterGuid, Hob.Raw);
}
+
return NULL;
}
@@ -79,14 +81,14 @@ InternalGetHashInterfaceHob ( **/
HASH_INTERFACE_HOB *
InternalCreateHashInterfaceHob (
- EFI_GUID *Identifier
+ EFI_GUID *Identifier
)
{
- HASH_INTERFACE_HOB LocalHashInterfaceHob;
+ HASH_INTERFACE_HOB LocalHashInterfaceHob;
- ZeroMem (&LocalHashInterfaceHob, sizeof(LocalHashInterfaceHob));
+ ZeroMem (&LocalHashInterfaceHob, sizeof (LocalHashInterfaceHob));
CopyGuid (&LocalHashInterfaceHob.Identifier, Identifier);
- return BuildGuidDataHob (&mHashLibPeiRouterGuid, &LocalHashInterfaceHob, sizeof(LocalHashInterfaceHob));
+ return BuildGuidDataHob (&mHashLibPeiRouterGuid, &LocalHashInterfaceHob, sizeof (LocalHashInterfaceHob));
}
/**
@@ -98,16 +100,17 @@ InternalCreateHashInterfaceHob ( **/
VOID
CheckSupportedHashMaskMismatch (
- IN HASH_INTERFACE_HOB *HashInterfaceHobCurrent
+ IN HASH_INTERFACE_HOB *HashInterfaceHobCurrent
)
{
- HASH_INTERFACE_HOB *HashInterfaceHobLast;
+ HASH_INTERFACE_HOB *HashInterfaceHobLast;
HashInterfaceHobLast = InternalGetHashInterfaceHob (&gZeroGuid);
ASSERT (HashInterfaceHobLast != NULL);
if ((HashInterfaceHobLast->SupportedHashMask != 0) &&
- (HashInterfaceHobCurrent->SupportedHashMask != HashInterfaceHobLast->SupportedHashMask)) {
+ (HashInterfaceHobCurrent->SupportedHashMask != HashInterfaceHobLast->SupportedHashMask))
+ {
DEBUG ((
DEBUG_WARN,
"WARNING: There is mismatch of supported HashMask (0x%x - 0x%x) between modules\n",
@@ -129,13 +132,13 @@ CheckSupportedHashMaskMismatch ( EFI_STATUS
EFIAPI
HashStart (
- OUT HASH_HANDLE *HashHandle
+ OUT HASH_HANDLE *HashHandle
)
{
- HASH_INTERFACE_HOB *HashInterfaceHob;
- HASH_HANDLE *HashCtx;
- UINTN Index;
- UINT32 HashMask;
+ HASH_INTERFACE_HOB *HashInterfaceHob;
+ HASH_HANDLE *HashCtx;
+ UINTN Index;
+ UINT32 HashMask;
HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);
if (HashInterfaceHob == NULL) {
@@ -148,7 +151,7 @@ HashStart ( CheckSupportedHashMaskMismatch (HashInterfaceHob);
- HashCtx = AllocatePool (sizeof(*HashCtx) * HashInterfaceHob->HashInterfaceCount);
+ HashCtx = AllocatePool (sizeof (*HashCtx) * HashInterfaceHob->HashInterfaceCount);
ASSERT (HashCtx != NULL);
for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
@@ -175,15 +178,15 @@ HashStart ( EFI_STATUS
EFIAPI
HashUpdate (
- IN HASH_HANDLE HashHandle,
- IN VOID *DataToHash,
- IN UINTN DataToHashLen
+ IN HASH_HANDLE HashHandle,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen
)
{
- HASH_INTERFACE_HOB *HashInterfaceHob;
- HASH_HANDLE *HashCtx;
- UINTN Index;
- UINT32 HashMask;
+ HASH_INTERFACE_HOB *HashInterfaceHob;
+ HASH_HANDLE *HashCtx;
+ UINTN Index;
+ UINT32 HashMask;
HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);
if (HashInterfaceHob == NULL) {
@@ -222,19 +225,19 @@ HashUpdate ( EFI_STATUS
EFIAPI
HashCompleteAndExtend (
- IN HASH_HANDLE HashHandle,
- IN TPMI_DH_PCR PcrIndex,
- IN VOID *DataToHash,
- IN UINTN DataToHashLen,
- OUT TPML_DIGEST_VALUES *DigestList
+ IN HASH_HANDLE HashHandle,
+ IN TPMI_DH_PCR PcrIndex,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen,
+ OUT TPML_DIGEST_VALUES *DigestList
)
{
- TPML_DIGEST_VALUES Digest;
- HASH_INTERFACE_HOB *HashInterfaceHob;
- HASH_HANDLE *HashCtx;
- UINTN Index;
- EFI_STATUS Status;
- UINT32 HashMask;
+ TPML_DIGEST_VALUES Digest;
+ HASH_INTERFACE_HOB *HashInterfaceHob;
+ HASH_HANDLE *HashCtx;
+ UINTN Index;
+ EFI_STATUS Status;
+ UINT32 HashMask;
HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);
if (HashInterfaceHob == NULL) {
@@ -248,7 +251,7 @@ HashCompleteAndExtend ( CheckSupportedHashMaskMismatch (HashInterfaceHob);
HashCtx = (HASH_HANDLE *)HashHandle;
- ZeroMem (DigestList, sizeof(*DigestList));
+ ZeroMem (DigestList, sizeof (*DigestList));
for (Index = 0; Index < HashInterfaceHob->HashInterfaceCount; Index++) {
HashMask = Tpm2GetHashMaskFromAlgo (&HashInterfaceHob->HashInterface[Index].HashGuid);
@@ -281,15 +284,15 @@ HashCompleteAndExtend ( EFI_STATUS
EFIAPI
HashAndExtend (
- IN TPMI_DH_PCR PcrIndex,
- IN VOID *DataToHash,
- IN UINTN DataToHashLen,
- OUT TPML_DIGEST_VALUES *DigestList
+ IN TPMI_DH_PCR PcrIndex,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen,
+ OUT TPML_DIGEST_VALUES *DigestList
)
{
- HASH_INTERFACE_HOB *HashInterfaceHob;
- HASH_HANDLE HashHandle;
- EFI_STATUS Status;
+ HASH_INTERFACE_HOB *HashInterfaceHob;
+ HASH_HANDLE HashHandle;
+ EFI_STATUS Status;
HashInterfaceHob = InternalGetHashInterfaceHob (&gEfiCallerIdGuid);
if (HashInterfaceHob == NULL) {
@@ -321,13 +324,13 @@ HashAndExtend ( EFI_STATUS
EFIAPI
RegisterHashInterfaceLib (
- IN HASH_INTERFACE *HashInterface
+ IN HASH_INTERFACE *HashInterface
)
{
- UINTN Index;
- HASH_INTERFACE_HOB *HashInterfaceHob;
- UINT32 HashMask;
- EFI_STATUS Status;
+ UINTN Index;
+ HASH_INTERFACE_HOB *HashInterfaceHob;
+ UINT32 HashMask;
+ EFI_STATUS Status;
//
// Check allow
@@ -363,11 +366,11 @@ RegisterHashInterfaceLib ( // Record hash algorithm bitmap of CURRENT module which consumes HashLib.
//
HashInterfaceHob->SupportedHashMask = PcdGet32 (PcdTcg2HashAlgorithmBitmap) | HashMask;
- Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, HashInterfaceHob->SupportedHashMask);
+ Status = PcdSet32S (PcdTcg2HashAlgorithmBitmap, HashInterfaceHob->SupportedHashMask);
ASSERT_EFI_ERROR (Status);
- CopyMem (&HashInterfaceHob->HashInterface[HashInterfaceHob->HashInterfaceCount], HashInterface, sizeof(*HashInterface));
- HashInterfaceHob->HashInterfaceCount ++;
+ CopyMem (&HashInterfaceHob->HashInterface[HashInterfaceHob->HashInterfaceCount], HashInterface, sizeof (*HashInterface));
+ HashInterfaceHob->HashInterfaceCount++;
return EFI_SUCCESS;
}
@@ -385,12 +388,12 @@ RegisterHashInterfaceLib ( EFI_STATUS
EFIAPI
HashLibBaseCryptoRouterPeiConstructor (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN CONST EFI_PEI_SERVICES **PeiServices
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
)
{
- EFI_STATUS Status;
- HASH_INTERFACE_HOB *HashInterfaceHob;
+ EFI_STATUS Status;
+ HASH_INTERFACE_HOB *HashInterfaceHob;
HashInterfaceHob = InternalGetHashInterfaceHob (&gZeroGuid);
if (HashInterfaceHob == NULL) {
@@ -420,7 +423,7 @@ HashLibBaseCryptoRouterPeiConstructor ( //
ZeroMem (&HashInterfaceHob->HashInterface, sizeof (HashInterfaceHob->HashInterface));
HashInterfaceHob->HashInterfaceCount = 0;
- HashInterfaceHob->SupportedHashMask = 0;
+ HashInterfaceHob->SupportedHashMask = 0;
}
//
|