2 BaseCrypto SM3 hash instance library.
3 It can be registered to BaseCrypto router, to serve as hash engine.
5 Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/Tpm2CommandLib.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 SM3 to digest list.
21 @param DigestList digest list
22 @param Sm3Digest SM3 digest
25 Tpm2SetSm3ToDigestList (
26 IN TPML_DIGEST_VALUES
*DigestList
,
30 DigestList
->count
= 1;
31 DigestList
->digests
[0].hashAlg
= TPM_ALG_SM3_256
;
33 DigestList
->digests
[0].digest
.sm3_256
,
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
= Sm3GetContextSize ();
57 Sm3Ctx
= AllocatePool (CtxSize
);
59 return EFI_OUT_OF_RESOURCES
;
64 *HashHandle
= (HASH_HANDLE
)Sm3Ctx
;
70 Update hash sequence data.
72 @param HashHandle Hash handle.
73 @param DataToHash Data to be hashed.
74 @param DataToHashLen Data size.
76 @retval EFI_SUCCESS Hash sequence updated.
81 IN HASH_HANDLE HashHandle
,
83 IN UINTN DataToHashLen
88 Sm3Ctx
= (VOID
*)HashHandle
;
89 Sm3Update (Sm3Ctx
, DataToHash
, DataToHashLen
);
95 Complete hash sequence complete.
97 @param HashHandle Hash handle.
98 @param DigestList Digest list.
100 @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.
105 IN HASH_HANDLE HashHandle
,
106 OUT TPML_DIGEST_VALUES
*DigestList
109 UINT8 Digest
[SM3_256_DIGEST_SIZE
];
112 Sm3Ctx
= (VOID
*)HashHandle
;
113 Sm3Final (Sm3Ctx
, Digest
);
117 Tpm2SetSm3ToDigestList (DigestList
, Digest
);
122 HASH_INTERFACE mSm3InternalHashInstance
= {
123 HASH_ALGORITHM_SM3_256_GUID
,
130 The function register SM3 instance.
132 @retval EFI_SUCCESS SM3 instance is registered, or system dose not support register SM3 instance
136 HashInstanceLibSm3Constructor (
142 Status
= RegisterHashInterfaceLib (&mSm3InternalHashInstance
);
143 if ((Status
== EFI_SUCCESS
) || (Status
== EFI_UNSUPPORTED
)) {
145 // Unsupported means platform policy does not need this instance enabled.