9#include "InternalCryptLib.h"
10#include <mbedtls/md.h>
28 if (HmacMdCtx ==
NULL) {
46 mbedtls_md_free (HmacMdCtx);
47 if (HmacMdCtx !=
NULL) {
70 IN mbedtls_md_type_t MdType,
71 OUT VOID *HmacMdContext,
76 const mbedtls_md_info_t *md_info;
79 if ((HmacMdContext ==
NULL) || (KeySize > INT_MAX)) {
83 ZeroMem (HmacMdContext,
sizeof (mbedtls_md_context_t));
84 mbedtls_md_init (HmacMdContext);
86 md_info = mbedtls_md_info_from_type (MdType);
87 ASSERT (md_info !=
NULL);
89 Ret = mbedtls_md_setup (HmacMdContext, md_info, 1);
94 Ret = mbedtls_md_hmac_starts (HmacMdContext, Key, KeySize);
112 mbedtls_md_type_t MdType
116 case MBEDTLS_MD_SHA256:
118 case MBEDTLS_MD_SHA384:
143 IN CONST mbedtls_md_type_t MdType,
145 OUT VOID *NewHmacMdContext
149 CONST mbedtls_md_info_t *md_info;
150 mbedtls_md_context_t *MdContext;
152 if ((HmacMdContext ==
NULL) || (NewHmacMdContext ==
NULL)) {
156 ZeroMem (NewHmacMdContext,
sizeof (mbedtls_md_context_t));
157 mbedtls_md_init (NewHmacMdContext);
158 md_info = mbedtls_md_info_from_type (MdType);
159 ASSERT (md_info !=
NULL);
161 Ret = mbedtls_md_setup (NewHmacMdContext, md_info, 1);
166 MdContext = (mbedtls_md_context_t *)NewHmacMdContext;
168 Ret = mbedtls_md_clone (NewHmacMdContext, HmacMdContext);
170 if (MdContext->md_ctx !=
NULL) {
171 mbedtls_free (MdContext->md_ctx);
174 if (MdContext->hmac_ctx !=
NULL) {
175 mbedtls_free (MdContext->hmac_ctx);
182 ((mbedtls_md_context_t *)NewHmacMdContext)->hmac_ctx,
183 ((
CONST mbedtls_md_context_t *)HmacMdContext)->hmac_ctx,
211 IN OUT VOID *HmacMdContext,
218 if (HmacMdContext ==
NULL) {
222 if ((Data ==
NULL) && (DataSize != 0)) {
226 if (DataSize > INT_MAX) {
230 Ret = mbedtls_md_hmac_update (HmacMdContext, Data, DataSize);
261 IN OUT VOID *HmacMdContext,
267 if ((HmacMdContext ==
NULL) || (HmacValue ==
NULL)) {
271 Ret = mbedtls_md_hmac_finish (HmacMdContext, HmacValue);
276 Ret = mbedtls_md_hmac_reset (HmacMdContext);
308 IN mbedtls_md_type_t MdType,
316 const mbedtls_md_info_t *md_info;
319 md_info = mbedtls_md_info_from_type (MdType);
320 ASSERT (md_info !=
NULL);
322 Ret = mbedtls_md_hmac (md_info, Key, KeySize, Data, DataSize, HmacValue);
355 IN VOID *HmacSha256Ctx
378 OUT VOID *HmacSha256Context,
383 return HmacMdSetKey (MBEDTLS_MD_SHA256, HmacSha256Context, Key, KeySize);
402 IN CONST VOID *HmacSha256Context,
403 OUT VOID *NewHmacSha256Context
406 return HmacMdDuplicate (MBEDTLS_MD_SHA256, HmacSha256Context, NewHmacSha256Context);
430 IN OUT VOID *HmacSha256Context,
435 return HmacMdUpdate (HmacSha256Context, Data, DataSize);
461 IN OUT VOID *HmacSha256Context,
498 return HmacMdAll (MBEDTLS_MD_SHA256, Data, DataSize, Key, KeySize, HmacValue);
526 IN VOID *HmacSha384Ctx
551 OUT VOID *HmacSha384Context,
556 return HmacMdSetKey (MBEDTLS_MD_SHA384, HmacSha384Context, Key, KeySize);
577 IN CONST VOID *HmacSha384Context,
578 OUT VOID *NewHmacSha384Context
581 return HmacMdDuplicate (MBEDTLS_MD_SHA384, HmacSha384Context, NewHmacSha384Context);
607 IN OUT VOID *HmacSha384Context,
612 return HmacMdUpdate (HmacSha384Context, Data, DataSize);
640 IN OUT VOID *HmacSha384Context,
677 return HmacMdAll (MBEDTLS_MD_SHA384, Data, DataSize, Key, KeySize, HmacValue);
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
BOOLEAN EFIAPI HmacSha384Update(IN OUT VOID *HmacSha384Context, IN CONST VOID *Data, IN UINTN DataSize)
STATIC VOID * HmacMdNew(VOID)
BOOLEAN EFIAPI HmacSha384SetKey(OUT VOID *HmacSha384Context, IN CONST UINT8 *Key, IN UINTN KeySize)
STATIC VOID HmacMdFree(IN VOID *HmacMdCtx)
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)
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)
STATIC BOOLEAN HmacMdFinal(IN OUT VOID *HmacMdContext, OUT UINT8 *HmacValue)
BOOLEAN EFIAPI HmacSha256All(IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
STATIC BOOLEAN HmacMdAll(IN CONST EVP_MD *Md, IN CONST VOID *Data, IN UINTN DataSize, IN CONST UINT8 *Key, IN UINTN KeySize, OUT UINT8 *HmacValue)
STATIC BOOLEAN HmacMdDuplicate(IN CONST VOID *HmacMdContext, OUT VOID *NewHmacMdContext)
BOOLEAN EFIAPI HmacSha256Final(IN OUT VOID *HmacSha256Context, OUT UINT8 *HmacValue)
STATIC BOOLEAN HmacMdUpdate(IN OUT VOID *HmacMdContext, IN CONST VOID *Data, IN UINTN DataSize)
STATIC BOOLEAN HmacMdSetKey(IN CONST EVP_MD *Md, OUT VOID *HmacMdContext, IN CONST UINT8 *Key, IN UINTN KeySize)
int HmacMdGetBlockSize(mbedtls_md_type_t MdType)