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0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
81 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f, 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
86(EFIAPI *EFI_HMAC_NEW)(
92(EFIAPI *EFI_HMAC_FREE)(
98(EFIAPI *EFI_HMAC_INIT)(
99 IN OUT VOID *HashContext,
106(EFIAPI *EFI_HMAC_DUP)(
108 OUT VOID *NewHashContext
113(EFIAPI *EFI_HMAC_UPDATE)(
114 IN OUT VOID *HashContext,
121(EFIAPI *EFI_HMAC_FINAL)(
122 IN OUT VOID *HashContext,
128(EFIAPI *EFI_HMAC_ALL)(
138 EFI_HMAC_NEW HmacNew;
139 EFI_HMAC_FREE HmacFree;
140 EFI_HMAC_INIT HmacInit;
141 EFI_HMAC_DUP HmacDup;
142 EFI_HMAC_UPDATE HmacUpdate;
143 EFI_HMAC_FINAL HmacFinal;
144 EFI_HMAC_ALL HmacAll;
151HMAC_TEST_CONTEXT mHmacSha256TestCtx = {
SHA256_DIGEST_SIZE,
HmacSha256New,
HmacSha256Free,
HmacSha256SetKey,
HmacSha256Duplicate,
HmacSha256Update,
HmacSha256Final,
HmacSha256All, HmacSha256Key,
sizeof (HmacSha256Key), HmacSha256Digest };
152HMAC_TEST_CONTEXT mHmacSha384TestCtx = {
SHA384_DIGEST_SIZE,
HmacSha384New,
HmacSha384Free,
HmacSha384SetKey,
HmacSha384Duplicate,
HmacSha384Update,
HmacSha384Final,
HmacSha384All, HmacSha384Key,
sizeof (HmacSha384Key), HmacSha384Digest };
156TestVerifyHmacPreReq (
162 HmacTestContext = Context;
163 HmacTestContext->HmacCtx = HmacTestContext->HmacNew ();
164 if (HmacTestContext->HmacCtx ==
NULL) {
165 return UNIT_TEST_ERROR_TEST_FAILED;
168 return UNIT_TEST_PASSED;
173TestVerifyHmacCleanUp (
179 HmacTestContext = Context;
180 if (HmacTestContext->HmacCtx !=
NULL) {
181 HmacTestContext->HmacFree (HmacTestContext->HmacCtx);
191 UINT8 Digest[MAX_DIGEST_SIZE];
192 UINT8 DigestCopy[MAX_DIGEST_SIZE];
193 UINT8 DigestByAll[MAX_DIGEST_SIZE];
194 VOID *HmacCopyContext;
198 HmacTestContext = Context;
200 ZeroMem (Digest, MAX_DIGEST_SIZE);
201 ZeroMem (DigestCopy, MAX_DIGEST_SIZE);
202 ZeroMem (DigestByAll, MAX_DIGEST_SIZE);
204 HmacCopyContext = HmacTestContext->HmacNew ();
206 Status = HmacTestContext->HmacInit (HmacTestContext->HmacCtx, HmacTestContext->Key, HmacTestContext->KeySize);
209 Status = HmacTestContext->HmacInit (HmacCopyContext, HmacTestContext->Key, HmacTestContext->KeySize);
212 Status = HmacTestContext->HmacUpdate (HmacTestContext->HmacCtx, HmacData, 8);
215 Status = HmacTestContext->HmacDup (HmacTestContext->HmacCtx, HmacCopyContext);
218 Status = HmacTestContext->HmacFinal (HmacTestContext->HmacCtx, Digest);
221 Status = HmacTestContext->HmacFinal (HmacCopyContext, DigestCopy);
224 Status = HmacTestContext->HmacAll (HmacData, 8, HmacTestContext->Key, HmacTestContext->KeySize, DigestByAll);
231 return UNIT_TEST_PASSED;
238 {
"TestVerifyHmacSha256()",
"CryptoPkg.BaseCryptLib.Hmac", TestVerifyHmac, TestVerifyHmacPreReq, TestVerifyHmacCleanUp, &mHmacSha256TestCtx },
239 {
"TestVerifyHmacSha384()",
"CryptoPkg.BaseCryptLib.Hmac", TestVerifyHmac, TestVerifyHmacPreReq, TestVerifyHmacCleanUp, &mHmacSha384TestCtx },
BOOLEAN EFIAPI HmacSha384Update(IN OUT VOID *HmacSha384Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI HmacSha384SetKey(OUT VOID *HmacSha384Context, IN CONST UINT8 *Key, IN UINTN KeySize)
VOID *EFIAPI HmacSha256New(VOID)
BOOLEAN EFIAPI HmacSha256Duplicate(IN CONST VOID *HmacSha256Context, OUT VOID *NewHmacSha256Context)
VOID *EFIAPI HmacSha384New(VOID)
BOOLEAN EFIAPI HmacSha384All(IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
VOID EFIAPI HmacSha384Free(IN VOID *HmacSha384Ctx)
VOID EFIAPI HmacSha256Free(IN VOID *HmacSha256Ctx)
BOOLEAN EFIAPI HmacSha384Duplicate(IN CONST VOID *HmacSha384Context, OUT VOID *NewHmacSha384Context)
#define SHA256_DIGEST_SIZE
BOOLEAN EFIAPI HmacSha384Final(IN OUT VOID *HmacSha384Context, OUT UINT8 *HmacValue)
BOOLEAN EFIAPI HmacSha256SetKey(OUT VOID *HmacSha256Context, IN CONST UINT8 *Key, IN UINTN KeySize)
BOOLEAN EFIAPI HmacSha256Update(IN OUT VOID *HmacSha256Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI HmacSha256All(IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
BOOLEAN EFIAPI HmacSha256Final(IN OUT VOID *HmacSha256Context, OUT UINT8 *HmacValue)
#define SHA384_DIGEST_SIZE
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define ARRAY_SIZE(Array)
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length)
#define UT_ASSERT_TRUE(Expression)