]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/HashInstanceLibSha384/HashInstanceLibSha384.c
QuarkSocPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / SecurityPkg / Library / HashInstanceLibSha384 / HashInstanceLibSha384.c
CommitLineData
3a347533
ZC
1/** @file\r
2 This library is BaseCrypto SHA384 hash instance.\r
3 It can be registered to BaseCrypto router, to serve as hash engine.\r
4\r
5Copyright (c) 2018, Intel Corporation. All rights reserved. <BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <PiPei.h>\r
17\r
18#include <Library/BaseLib.h>\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/BaseCryptLib.h>\r
22#include <Library/MemoryAllocationLib.h>\r
23#include <Library/HashLib.h>\r
24\r
25/**\r
26 The function set SHA384 to digest list.\r
27\r
28 @param DigestList digest list\r
29 @param Sha384Digest SHA384 digest\r
30**/\r
31VOID\r
32Tpm2SetSha384ToDigestList (\r
33 IN TPML_DIGEST_VALUES *DigestList,\r
34 IN UINT8 *Sha384Digest\r
35 )\r
36{\r
37 DigestList->count = 1;\r
38 DigestList->digests[0].hashAlg = TPM_ALG_SHA384;\r
39 CopyMem (\r
40 DigestList->digests[0].digest.sha384,\r
41 Sha384Digest,\r
42 SHA384_DIGEST_SIZE\r
43 );\r
44}\r
45\r
46/**\r
47 Start hash sequence.\r
48\r
49 @param HashHandle Hash handle.\r
50\r
51 @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.\r
52 @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.\r
53**/\r
54EFI_STATUS\r
55EFIAPI\r
56Sha384HashInit (\r
57 OUT HASH_HANDLE *HashHandle\r
58 )\r
59{\r
60 VOID *Sha384Ctx;\r
61 UINTN CtxSize;\r
62\r
63 CtxSize = Sha384GetContextSize ();\r
64 Sha384Ctx = AllocatePool (CtxSize);\r
65 ASSERT (Sha384Ctx != NULL);\r
66\r
67 Sha384Init (Sha384Ctx);\r
68\r
69 *HashHandle = (HASH_HANDLE)Sha384Ctx;\r
70\r
71 return EFI_SUCCESS;\r
72}\r
73\r
74/**\r
75 Update hash sequence data.\r
76\r
77 @param HashHandle Hash handle.\r
78 @param DataToHash Data to be hashed.\r
79 @param DataToHashLen Data size.\r
80\r
81 @retval EFI_SUCCESS Hash sequence updated.\r
82**/\r
83EFI_STATUS\r
84EFIAPI\r
85Sha384HashUpdate (\r
86 IN HASH_HANDLE HashHandle,\r
87 IN VOID *DataToHash,\r
88 IN UINTN DataToHashLen\r
89 )\r
90{\r
91 VOID *Sha384Ctx;\r
92\r
93 Sha384Ctx = (VOID *)HashHandle;\r
94 Sha384Update (Sha384Ctx, DataToHash, DataToHashLen);\r
95\r
96 return EFI_SUCCESS;\r
97}\r
98\r
99/**\r
100 Complete hash sequence complete.\r
101\r
102 @param HashHandle Hash handle.\r
103 @param DigestList Digest list.\r
104\r
105 @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.\r
106**/\r
107EFI_STATUS\r
108EFIAPI\r
109Sha384HashFinal (\r
110 IN HASH_HANDLE HashHandle,\r
111 OUT TPML_DIGEST_VALUES *DigestList\r
112 )\r
113{\r
114 UINT8 Digest[SHA384_DIGEST_SIZE];\r
115 VOID *Sha384Ctx;\r
116\r
117 Sha384Ctx = (VOID *)HashHandle;\r
118 Sha384Final (Sha384Ctx, Digest);\r
119\r
120 FreePool (Sha384Ctx);\r
121\r
122 Tpm2SetSha384ToDigestList (DigestList, Digest);\r
123\r
124 return EFI_SUCCESS;\r
125}\r
126\r
127HASH_INTERFACE mSha384InternalHashInstance = {\r
128 HASH_ALGORITHM_SHA384_GUID,\r
129 Sha384HashInit,\r
130 Sha384HashUpdate,\r
131 Sha384HashFinal,\r
132};\r
133\r
134/**\r
135 The function register SHA384 instance.\r
136\r
137 @retval EFI_SUCCESS SHA384 instance is registered, or system dose not surpport registr SHA384 instance\r
138**/\r
139EFI_STATUS\r
140EFIAPI\r
141HashInstanceLibSha384Constructor (\r
142 VOID\r
143 )\r
144{\r
145 EFI_STATUS Status;\r
146\r
147 Status = RegisterHashInterfaceLib (&mSha384InternalHashInstance);\r
148 if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r
149 //\r
150 // Unsupported means platform policy does not need this instance enabled.\r
151 //\r
152 return EFI_SUCCESS;\r
153 }\r
154 return Status;\r
155}\r