]>
Commit | Line | Data |
---|---|---|
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 | |
5 | Copyright (c) 2018, Intel Corporation. All rights reserved. <BR>\r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
10 | #include <PiPei.h>\r | |
11 | \r | |
12 | #include <Library/BaseLib.h>\r | |
13 | #include <Library/BaseMemoryLib.h>\r | |
14 | #include <Library/DebugLib.h>\r | |
15 | #include <Library/BaseCryptLib.h>\r | |
16 | #include <Library/MemoryAllocationLib.h>\r | |
17 | #include <Library/HashLib.h>\r | |
18 | \r | |
19 | /**\r | |
20 | The function set SHA384 to digest list.\r | |
21 | \r | |
22 | @param DigestList digest list\r | |
23 | @param Sha384Digest SHA384 digest\r | |
24 | **/\r | |
25 | VOID\r | |
26 | Tpm2SetSha384ToDigestList (\r | |
27 | IN TPML_DIGEST_VALUES *DigestList,\r | |
28 | IN UINT8 *Sha384Digest\r | |
29 | )\r | |
30 | {\r | |
31 | DigestList->count = 1;\r | |
32 | DigestList->digests[0].hashAlg = TPM_ALG_SHA384;\r | |
33 | CopyMem (\r | |
34 | DigestList->digests[0].digest.sha384,\r | |
35 | Sha384Digest,\r | |
36 | SHA384_DIGEST_SIZE\r | |
37 | );\r | |
38 | }\r | |
39 | \r | |
40 | /**\r | |
41 | Start hash sequence.\r | |
42 | \r | |
43 | @param HashHandle Hash handle.\r | |
44 | \r | |
45 | @retval EFI_SUCCESS Hash sequence start and HandleHandle returned.\r | |
46 | @retval EFI_OUT_OF_RESOURCES No enough resource to start hash.\r | |
47 | **/\r | |
48 | EFI_STATUS\r | |
49 | EFIAPI\r | |
50 | Sha384HashInit (\r | |
51 | OUT HASH_HANDLE *HashHandle\r | |
52 | )\r | |
53 | {\r | |
54 | VOID *Sha384Ctx;\r | |
55 | UINTN CtxSize;\r | |
56 | \r | |
57 | CtxSize = Sha384GetContextSize ();\r | |
58 | Sha384Ctx = AllocatePool (CtxSize);\r | |
59 | ASSERT (Sha384Ctx != NULL);\r | |
60 | \r | |
61 | Sha384Init (Sha384Ctx);\r | |
62 | \r | |
63 | *HashHandle = (HASH_HANDLE)Sha384Ctx;\r | |
64 | \r | |
65 | return EFI_SUCCESS;\r | |
66 | }\r | |
67 | \r | |
68 | /**\r | |
69 | Update hash sequence data.\r | |
70 | \r | |
71 | @param HashHandle Hash handle.\r | |
72 | @param DataToHash Data to be hashed.\r | |
73 | @param DataToHashLen Data size.\r | |
74 | \r | |
75 | @retval EFI_SUCCESS Hash sequence updated.\r | |
76 | **/\r | |
77 | EFI_STATUS\r | |
78 | EFIAPI\r | |
79 | Sha384HashUpdate (\r | |
80 | IN HASH_HANDLE HashHandle,\r | |
81 | IN VOID *DataToHash,\r | |
82 | IN UINTN DataToHashLen\r | |
83 | )\r | |
84 | {\r | |
85 | VOID *Sha384Ctx;\r | |
86 | \r | |
87 | Sha384Ctx = (VOID *)HashHandle;\r | |
88 | Sha384Update (Sha384Ctx, DataToHash, DataToHashLen);\r | |
89 | \r | |
90 | return EFI_SUCCESS;\r | |
91 | }\r | |
92 | \r | |
93 | /**\r | |
94 | Complete hash sequence complete.\r | |
95 | \r | |
96 | @param HashHandle Hash handle.\r | |
97 | @param DigestList Digest list.\r | |
98 | \r | |
99 | @retval EFI_SUCCESS Hash sequence complete and DigestList is returned.\r | |
100 | **/\r | |
101 | EFI_STATUS\r | |
102 | EFIAPI\r | |
103 | Sha384HashFinal (\r | |
104 | IN HASH_HANDLE HashHandle,\r | |
105 | OUT TPML_DIGEST_VALUES *DigestList\r | |
106 | )\r | |
107 | {\r | |
108 | UINT8 Digest[SHA384_DIGEST_SIZE];\r | |
109 | VOID *Sha384Ctx;\r | |
110 | \r | |
111 | Sha384Ctx = (VOID *)HashHandle;\r | |
112 | Sha384Final (Sha384Ctx, Digest);\r | |
113 | \r | |
114 | FreePool (Sha384Ctx);\r | |
115 | \r | |
116 | Tpm2SetSha384ToDigestList (DigestList, Digest);\r | |
117 | \r | |
118 | return EFI_SUCCESS;\r | |
119 | }\r | |
120 | \r | |
121 | HASH_INTERFACE mSha384InternalHashInstance = {\r | |
122 | HASH_ALGORITHM_SHA384_GUID,\r | |
123 | Sha384HashInit,\r | |
124 | Sha384HashUpdate,\r | |
125 | Sha384HashFinal,\r | |
126 | };\r | |
127 | \r | |
128 | /**\r | |
129 | The function register SHA384 instance.\r | |
130 | \r | |
131 | @retval EFI_SUCCESS SHA384 instance is registered, or system does not support register SHA384 instance\r | |
132 | **/\r | |
133 | EFI_STATUS\r | |
134 | EFIAPI\r | |
135 | HashInstanceLibSha384Constructor (\r | |
136 | VOID\r | |
137 | )\r | |
138 | {\r | |
139 | EFI_STATUS Status;\r | |
140 | \r | |
141 | Status = RegisterHashInterfaceLib (&mSha384InternalHashInstance);\r | |
142 | if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {\r | |
143 | //\r | |
144 | // Unsupported means platform policy does not need this instance enabled.\r | |
145 | //\r | |
146 | return EFI_SUCCESS;\r | |
147 | }\r | |
148 | return Status;\r | |
149 | }\r |