2 This library is BaseCrypto SHA256 hash instance.
3 It can be registered to BaseCrypto router, to serve as hash engine.
5 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/Tpm2CommandLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/BaseCryptLib.h>
16 #include <Library/MemoryAllocationLib.h>
17 #include <Library/HashLib.h>
20 The function set SHA256 to digest list.
22 @param DigestList digest list
23 @param Sha256Digest SHA256 digest
26 Tpm2SetSha256ToDigestList (
27 IN TPML_DIGEST_VALUES
*DigestList
,
28 IN UINT8
*Sha256Digest
31 DigestList
->count
= 1;
32 DigestList
->digests
[0].hashAlg
= TPM_ALG_SHA256
;
34 DigestList
->digests
[0].digest
.sha256
,
43 @param HashHandle Hash handle.
45 @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.
46 @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.
51 OUT HASH_HANDLE
*HashHandle
57 CtxSize
= Sha256GetContextSize ();
58 Sha256Ctx
= AllocatePool (CtxSize
);
59 ASSERT (Sha256Ctx
!= NULL
);
61 Sha256Init (Sha256Ctx
);
63 *HashHandle
= (HASH_HANDLE
)Sha256Ctx
;
69 Update hash sequence data.
71 @param HashHandle Hash handle.
72 @param DataToHash Data to be hashed.
73 @param DataToHashLen Data size.
75 @retval EFI_SUCCESS Hash sequence updated.
80 IN HASH_HANDLE HashHandle
,
82 IN UINTN DataToHashLen
87 Sha256Ctx
= (VOID
*)HashHandle
;
88 Sha256Update (Sha256Ctx
, DataToHash
, DataToHashLen
);
94 Complete hash sequence complete.
96 @param HashHandle Hash handle.
97 @param DigestList Digest list.
99 @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.
104 IN HASH_HANDLE HashHandle
,
105 OUT TPML_DIGEST_VALUES
*DigestList
108 UINT8 Digest
[SHA256_DIGEST_SIZE
];
111 Sha256Ctx
= (VOID
*)HashHandle
;
112 Sha256Final (Sha256Ctx
, Digest
);
114 FreePool (Sha256Ctx
);
116 Tpm2SetSha256ToDigestList (DigestList
, Digest
);
121 HASH_INTERFACE mSha256InternalHashInstance
= {
122 HASH_ALGORITHM_SHA256_GUID
,
129 The function register SHA256 instance.
131 @retval EFI_SUCCESS SHA256 instance is registered, or system does not support register SHA256 instance
135 HashInstanceLibSha256Constructor (
141 Status
= RegisterHashInterfaceLib (&mSha256InternalHashInstance
);
142 if ((Status
== EFI_SUCCESS
) || (Status
== EFI_UNSUPPORTED
)) {
144 // Unsupported means platform policy does not need this instance enabled.