2 This library is BaseCrypto SHA1 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 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/Tpm2CommandLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseCryptLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/HashLib.h>
26 The function set SHA1 to digest list.
28 @param DigestList digest list
29 @param Sha1Digest SHA1 digest
32 Tpm2SetSha1ToDigestList (
33 IN TPML_DIGEST_VALUES
*DigestList
,
37 DigestList
->count
= 1;
38 DigestList
->digests
[0].hashAlg
= TPM_ALG_SHA1
;
40 DigestList
->digests
[0].digest
.sha1
,
49 @param HashHandle Hash handle.
51 @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.
52 @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.
57 OUT HASH_HANDLE
*HashHandle
63 CtxSize
= Sha1GetContextSize ();
64 Sha1Ctx
= AllocatePool (CtxSize
);
65 ASSERT (Sha1Ctx
!= NULL
);
69 *HashHandle
= (HASH_HANDLE
)Sha1Ctx
;
75 Update hash sequence data.
77 @param HashHandle Hash handle.
78 @param DataToHash Data to be hashed.
79 @param DataToHashLen Data size.
81 @retval EFI_SUCCESS Hash sequence updated.
86 IN HASH_HANDLE HashHandle
,
88 IN UINTN DataToHashLen
93 Sha1Ctx
= (VOID
*)HashHandle
;
94 Sha1Update (Sha1Ctx
, DataToHash
, DataToHashLen
);
100 Complete hash sequence complete.
102 @param HashHandle Hash handle.
103 @param DigestList Digest list.
105 @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.
110 IN HASH_HANDLE HashHandle
,
111 OUT TPML_DIGEST_VALUES
*DigestList
114 UINT8 Digest
[SHA1_DIGEST_SIZE
];
117 Sha1Ctx
= (VOID
*)HashHandle
;
118 Sha1Final (Sha1Ctx
, Digest
);
122 Tpm2SetSha1ToDigestList (DigestList
, Digest
);
127 HASH_INTERFACE mSha1InternalHashInstance
= {
128 HASH_ALGORITHM_SHA1_GUID
,
135 The function register SHA1 instance.
137 @retval EFI_SUCCESS SHA1 instance is registered, or system dose not surpport registr SHA1 instance
141 HashInstanceLibSha1Constructor (
147 Status
= RegisterHashInterfaceLib (&mSha1InternalHashInstance
);
148 if ((Status
== EFI_SUCCESS
) || (Status
== EFI_UNSUPPORTED
)) {
150 // Unsupported means platform policy does not need this instance enabled.