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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseCryptLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/HashLib.h>
25 The function set SHA512 to digest list.
27 @param DigestList digest list
28 @param Sha512Digest SHA512 digest
31 Tpm2SetSha512ToDigestList (
32 IN TPML_DIGEST_VALUES
*DigestList
,
33 IN UINT8
*Sha512Digest
36 DigestList
->count
= 1;
37 DigestList
->digests
[0].hashAlg
= TPM_ALG_SHA512
;
39 DigestList
->digests
[0].digest
.sha512
,
48 @param HashHandle Hash handle.
50 @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.
51 @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.
56 OUT HASH_HANDLE
*HashHandle
62 CtxSize
= Sha512GetContextSize ();
63 Sha512Ctx
= AllocatePool (CtxSize
);
64 ASSERT (Sha512Ctx
!= NULL
);
66 Sha512Init (Sha512Ctx
);
68 *HashHandle
= (HASH_HANDLE
)Sha512Ctx
;
74 Update hash sequence data.
76 @param HashHandle Hash handle.
77 @param DataToHash Data to be hashed.
78 @param DataToHashLen Data size.
80 @retval EFI_SUCCESS Hash sequence updated.
85 IN HASH_HANDLE HashHandle
,
87 IN UINTN DataToHashLen
92 Sha512Ctx
= (VOID
*)HashHandle
;
93 Sha512Update (Sha512Ctx
, DataToHash
, DataToHashLen
);
99 Complete hash sequence complete.
101 @param HashHandle Hash handle.
102 @param DigestList Digest list.
104 @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.
109 IN HASH_HANDLE HashHandle
,
110 OUT TPML_DIGEST_VALUES
*DigestList
113 UINT8 Digest
[SHA512_DIGEST_SIZE
];
116 Sha512Ctx
= (VOID
*)HashHandle
;
117 Sha512Final (Sha512Ctx
, Digest
);
119 FreePool (Sha512Ctx
);
121 Tpm2SetSha512ToDigestList (DigestList
, Digest
);
126 HASH_INTERFACE mSha512InternalHashInstance
= {
127 HASH_ALGORITHM_SHA512_GUID
,
134 The function register SHA512 instance.
136 @retval EFI_SUCCESS SHA512 instance is registered, or system dose not surpport registr SHA512 instance
140 HashInstanceLibSha512Constructor (
146 Status
= RegisterHashInterfaceLib (&mSha512InternalHashInstance
);
147 if ((Status
== EFI_SUCCESS
) || (Status
== EFI_UNSUPPORTED
)) {
149 // Unsupported means platform policy does not need this instance enabled.