2 This library is BaseCrypto SHA512 hash instance.
3 It can be registered to BaseCrypto router, to serve as hash engine.
5 Copyright (c) 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/DebugLib.h>
14 #include <Library/BaseCryptLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/HashLib.h>
19 The function set SHA512 to digest list.
21 @param DigestList digest list
22 @param Sha512Digest SHA512 digest
25 Tpm2SetSha512ToDigestList (
26 IN TPML_DIGEST_VALUES
*DigestList
,
27 IN UINT8
*Sha512Digest
30 DigestList
->count
= 1;
31 DigestList
->digests
[0].hashAlg
= TPM_ALG_SHA512
;
33 DigestList
->digests
[0].digest
.sha512
,
42 @param HashHandle Hash handle.
44 @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.
45 @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.
50 OUT HASH_HANDLE
*HashHandle
56 CtxSize
= Sha512GetContextSize ();
57 Sha512Ctx
= AllocatePool (CtxSize
);
58 ASSERT (Sha512Ctx
!= NULL
);
60 Sha512Init (Sha512Ctx
);
62 *HashHandle
= (HASH_HANDLE
)Sha512Ctx
;
68 Update hash sequence data.
70 @param HashHandle Hash handle.
71 @param DataToHash Data to be hashed.
72 @param DataToHashLen Data size.
74 @retval EFI_SUCCESS Hash sequence updated.
79 IN HASH_HANDLE HashHandle
,
81 IN UINTN DataToHashLen
86 Sha512Ctx
= (VOID
*)HashHandle
;
87 Sha512Update (Sha512Ctx
, DataToHash
, DataToHashLen
);
93 Complete hash sequence complete.
95 @param HashHandle Hash handle.
96 @param DigestList Digest list.
98 @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.
103 IN HASH_HANDLE HashHandle
,
104 OUT TPML_DIGEST_VALUES
*DigestList
107 UINT8 Digest
[SHA512_DIGEST_SIZE
];
110 Sha512Ctx
= (VOID
*)HashHandle
;
111 Sha512Final (Sha512Ctx
, Digest
);
113 FreePool (Sha512Ctx
);
115 Tpm2SetSha512ToDigestList (DigestList
, Digest
);
120 HASH_INTERFACE mSha512InternalHashInstance
= {
121 HASH_ALGORITHM_SHA512_GUID
,
128 The function register SHA512 instance.
130 @retval EFI_SUCCESS SHA512 instance is registered, or system dose not surpport registr SHA512 instance
134 HashInstanceLibSha512Constructor (
140 Status
= RegisterHashInterfaceLib (&mSha512InternalHashInstance
);
141 if ((Status
== EFI_SUCCESS
) || (Status
== EFI_UNSUPPORTED
)) {
143 // Unsupported means platform policy does not need this instance enabled.