TianoCore EDK2 master
Loading...
Searching...
No Matches
BaseHashApiLib.c
Go to the documentation of this file.
1
14#include <Base.h>
16#include <Library/BaseLib.h>
20#include <Library/DebugLib.h>
21#include <Library/PcdLib.h>
22#include <Library/HashApiLib.h>
23
30EFIAPI
32 VOID
33 )
34{
35 switch (PcdGet32 (PcdHashApiLibPolicy)) {
36 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
37 case HASH_ALG_SHA1:
38 return Sha1GetContextSize ();
39 break;
40 #endif
41
42 case HASH_ALG_SHA256:
43 return Sha256GetContextSize ();
44 break;
45
46 case HASH_ALG_SHA384:
47 return Sha384GetContextSize ();
48 break;
49
50 case HASH_ALG_SHA512:
51 return Sha512GetContextSize ();
52 break;
53
54 case HASH_ALG_SM3_256:
55 return Sm3GetContextSize ();
56 break;
57
58 default:
59 ASSERT (FALSE);
60 return 0;
61 break;
62 }
63}
64
73BOOLEAN
74EFIAPI
76 OUT HASH_API_CONTEXT HashContext
77 )
78{
79 switch (PcdGet32 (PcdHashApiLibPolicy)) {
80 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
81 case HASH_ALG_SHA1:
82 return Sha1Init (HashContext);
83 break;
84 #endif
85
86 case HASH_ALG_SHA256:
87 return Sha256Init (HashContext);
88 break;
89
90 case HASH_ALG_SHA384:
91 return Sha384Init (HashContext);
92 break;
93
94 case HASH_ALG_SHA512:
95 return Sha512Init (HashContext);
96 break;
97
98 case HASH_ALG_SM3_256:
99 return Sm3Init (HashContext);
100 break;
101
102 default:
103 ASSERT (FALSE);
104 return FALSE;
105 break;
106 }
107}
108
118BOOLEAN
119EFIAPI
121 IN HASH_API_CONTEXT HashContext,
122 OUT HASH_API_CONTEXT NewHashContext
123 )
124{
125 switch (PcdGet32 (PcdHashApiLibPolicy)) {
126 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
127 case HASH_ALG_SHA1:
128 return Sha1Duplicate (HashContext, NewHashContext);
129 break;
130 #endif
131
132 case HASH_ALG_SHA256:
133 return Sha256Duplicate (HashContext, NewHashContext);
134 break;
135
136 case HASH_ALG_SHA384:
137 return Sha384Duplicate (HashContext, NewHashContext);
138 break;
139
140 case HASH_ALG_SHA512:
141 return Sha512Duplicate (HashContext, NewHashContext);
142 break;
143
144 case HASH_ALG_SM3_256:
145 return Sm3Duplicate (HashContext, NewHashContext);
146 break;
147
148 default:
149 ASSERT (FALSE);
150 return FALSE;
151 break;
152 }
153}
154
165BOOLEAN
166EFIAPI
168 IN HASH_API_CONTEXT HashContext,
169 IN VOID *DataToHash,
170 IN UINTN DataToHashLen
171 )
172{
173 switch (PcdGet32 (PcdHashApiLibPolicy)) {
174 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
175 case HASH_ALG_SHA1:
176 return Sha1Update (HashContext, DataToHash, DataToHashLen);
177 break;
178 #endif
179
180 case HASH_ALG_SHA256:
181 return Sha256Update (HashContext, DataToHash, DataToHashLen);
182 break;
183
184 case HASH_ALG_SHA384:
185 return Sha384Update (HashContext, DataToHash, DataToHashLen);
186 break;
187
188 case HASH_ALG_SHA512:
189 return Sha512Update (HashContext, DataToHash, DataToHashLen);
190 break;
191
192 case HASH_ALG_SM3_256:
193 return Sm3Update (HashContext, DataToHash, DataToHashLen);
194 break;
195
196 default:
197 ASSERT (FALSE);
198 return FALSE;
199 break;
200 }
201}
202
212BOOLEAN
213EFIAPI
215 IN HASH_API_CONTEXT HashContext,
216 OUT UINT8 *Digest
217 )
218{
219 switch (PcdGet32 (PcdHashApiLibPolicy)) {
220 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
221 case HASH_ALG_SHA1:
222 return Sha1Final (HashContext, Digest);
223 break;
224 #endif
225
226 case HASH_ALG_SHA256:
227 return Sha256Final (HashContext, Digest);
228 break;
229
230 case HASH_ALG_SHA384:
231 return Sha384Final (HashContext, Digest);
232 break;
233
234 case HASH_ALG_SHA512:
235 return Sha512Final (HashContext, Digest);
236 break;
237
238 case HASH_ALG_SM3_256:
239 return Sm3Final (HashContext, Digest);
240 break;
241
242 default:
243 ASSERT (FALSE);
244 return FALSE;
245 break;
246 }
247}
248
259BOOLEAN
260EFIAPI
262 IN CONST VOID *DataToHash,
263 IN UINTN DataToHashLen,
264 OUT UINT8 *Digest
265 )
266{
267 switch (PcdGet32 (PcdHashApiLibPolicy)) {
268 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
269 case HASH_ALG_SHA1:
270 return Sha1HashAll (DataToHash, DataToHashLen, Digest);
271 break;
272 #endif
273
274 case HASH_ALG_SHA256:
275 return Sha256HashAll (DataToHash, DataToHashLen, Digest);
276 break;
277
278 case HASH_ALG_SHA384:
279 return Sha384HashAll (DataToHash, DataToHashLen, Digest);
280 break;
281
282 case HASH_ALG_SHA512:
283 return Sha512HashAll (DataToHash, DataToHashLen, Digest);
284 break;
285
286 case HASH_ALG_SM3_256:
287 return Sm3HashAll (DataToHash, DataToHashLen, Digest);
288 break;
289
290 default:
291 ASSERT (FALSE);
292 return FALSE;
293 break;
294 }
295}
UINT64 UINTN
UINTN EFIAPI Sha256GetContextSize(VOID)
Definition: CryptSha256.c:20
UINTN EFIAPI Sha384GetContextSize(VOID)
Definition: CryptSha512.c:20
BOOLEAN EFIAPI Sha512HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha512.c:427
BOOLEAN EFIAPI Sm3Duplicate(IN CONST VOID *Sm3Context, OUT VOID *NewSm3Context)
Definition: CryptSm3.c:79
BOOLEAN EFIAPI Sha512Final(IN OUT VOID *Sha512Context, OUT UINT8 *HashValue)
Definition: CryptSha512.c:389
BOOLEAN EFIAPI Sha384Duplicate(IN CONST VOID *Sha384Context, OUT VOID *NewSha384Context)
Definition: CryptSha512.c:78
UINTN EFIAPI Sm3GetContextSize(VOID)
Definition: CryptSm3.c:20
UINTN EFIAPI Sha512GetContextSize(VOID)
Definition: CryptSha512.c:246
BOOLEAN EFIAPI Sha1Final(IN OUT VOID *Sha1Context, OUT UINT8 *HashValue)
Definition: CryptSha1.c:163
BOOLEAN EFIAPI Sm3Update(IN OUT VOID *Sm3Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSm3.c:116
BOOLEAN EFIAPI Sha512Init(OUT VOID *Sha512Context)
Definition: CryptSha512.c:270
BOOLEAN EFIAPI Sm3Final(IN OUT VOID *Sm3Context, OUT UINT8 *HashValue)
Definition: CryptSm3.c:166
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
Definition: CryptSha256.c:44
BOOLEAN EFIAPI Sha1Duplicate(IN CONST VOID *Sha1Context, OUT VOID *NewSha1Context)
Definition: CryptSha1.c:78
BOOLEAN EFIAPI Sha384HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha512.c:201
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
Definition: CryptSha256.c:161
BOOLEAN EFIAPI Sm3HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSm3.c:206
BOOLEAN EFIAPI Sha384Update(IN OUT VOID *Sha384Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha512.c:115
BOOLEAN EFIAPI Sha256Duplicate(IN CONST VOID *Sha256Context, OUT VOID *NewSha256Context)
Definition: CryptSha256.c:76
BOOLEAN EFIAPI Sm3Init(OUT VOID *Sm3Context)
Definition: CryptSm3.c:44
BOOLEAN EFIAPI Sha1Init(OUT VOID *Sha1Context)
Definition: CryptSha1.c:46
BOOLEAN EFIAPI Sha256HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha256.c:199
BOOLEAN EFIAPI Sha512Duplicate(IN CONST VOID *Sha512Context, OUT VOID *NewSha512Context)
Definition: CryptSha512.c:304
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha256.c:113
BOOLEAN EFIAPI Sha1HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha1.c:201
UINTN EFIAPI Sha1GetContextSize(VOID)
Definition: CryptSha1.c:22
BOOLEAN EFIAPI Sha384Final(IN OUT VOID *Sha384Context, OUT UINT8 *HashValue)
Definition: CryptSha512.c:163
BOOLEAN EFIAPI Sha384Init(OUT VOID *Sha384Context)
Definition: CryptSha512.c:44
BOOLEAN EFIAPI Sha512Update(IN OUT VOID *Sha512Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha512.c:341
BOOLEAN EFIAPI Sha1Update(IN OUT VOID *Sha1Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha1.c:115
BOOLEAN EFIAPI HashApiUpdate(IN HASH_API_CONTEXT HashContext, IN VOID *DataToHash, IN UINTN DataToHashLen)
BOOLEAN EFIAPI HashApiDuplicate(IN HASH_API_CONTEXT HashContext, OUT HASH_API_CONTEXT NewHashContext)
BOOLEAN EFIAPI HashApiFinal(IN HASH_API_CONTEXT HashContext, OUT UINT8 *Digest)
UINTN EFIAPI HashApiGetContextSize(VOID)
BOOLEAN EFIAPI HashApiHashAll(IN CONST VOID *DataToHash, IN UINTN DataToHashLen, OUT UINT8 *Digest)
BOOLEAN EFIAPI HashApiInit(OUT HASH_API_CONTEXT HashContext)
#define CONST
Definition: Base.h:259
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet32(TokenName)
Definition: PcdLib.h:362