From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 180FA7803D0 for ; Wed, 30 Aug 2023 08:24:21 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=GfD7Z2Tl5SXc5j4hUiEc48LXjZ/tIKOlHVxj4wys+KI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1693383860; v=1; b=HcVpz4rOU/lapUv65gOdJDRKrWuYt8dEnII1EAEy9gHGz5Tn60wbrMMu/V9bVUUiQoGmC8zv ZF4smwu4fTei6PvRLzH1vyghgoaMTIEGFm8DgGdpKynPN3buCSFuZer3xqFzUETiv71T68F4GIm b13Q0GjE5ZiURC941dwKj3mY= X-Received: by 127.0.0.2 with SMTP id bFxxYY7687511xcfQfycPGg5; Wed, 30 Aug 2023 01:24:20 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.9325.1693383851049649440 for ; Wed, 30 Aug 2023 01:24:20 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10817"; a="461957423" X-IronPort-AV: E=Sophos;i="6.02,213,1688454000"; d="scan'208";a="461957423" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2023 01:24:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10817"; a="829147832" X-IronPort-AV: E=Sophos;i="6.02,213,1688454000"; d="scan'208";a="829147832" X-Received: from shwdejointd777.ccr.corp.intel.com ([10.239.58.116]) by FMSMGA003.fm.intel.com with ESMTP; 30 Aug 2023 01:24:14 -0700 From: "Wenxing Hou" To: devel@edk2.groups.io Cc: Jiewen Yao , Yi Li , Xiaoyu Lu , Guomin Jiang Subject: [edk2-devel] [PATCH 3/9] CryptoPkg: Add HMAC functions based on Mbedtls Date: Wed, 30 Aug 2023 16:23:59 +0800 Message-Id: <20230830082405.2148-4-wenxing.hou@intel.com> In-Reply-To: <20230830082405.2148-1-wenxing.hou@intel.com> References: <20230830082405.2148-1-wenxing.hou@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,wenxing.hou@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Ysg8bSzjg1QscAKOIryHPxlpx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=HcVpz4rO; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Add HMAC APIS. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4177 Cc: Jiewen Yao cc: Yi Li Cc: Xiaoyu Lu Cc: Guomin Jiang Signed-off-by: Wenxing Hou --- .../BaseCryptLibMbedTls/Hmac/CryptHmac.c | 620 ++++++++++++++++++ .../BaseCryptLibMbedTls/Hmac/CryptHmacNull.c | 359 ++++++++++ 2 files changed, 979 insertions(+) create mode 100644 CryptoPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmac.c create mode 100644 CryptoPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmacNul= l.c diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmac.c b/Crypt= oPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmac.c new file mode 100644 index 0000000000..8f998bf2fa --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmac.c @@ -0,0 +1,620 @@ +/** @file=0D + HMAC-SHA256 Wrapper Implementation over MbedTLS.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "InternalCryptLib.h"=0D +#include =0D +=0D +/**=0D + Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD us= e.=0D +=0D + @return Pointer to the HMAC_CTX context that has been initialized.=0D + If the allocations fails, HmacShaMdNew() returns NULL.=0D +=0D +**/=0D +STATIC=0D +VOID *=0D +HmacMdNew (=0D + VOID=0D + )=0D +{=0D + VOID *HmacMdCtx;=0D +=0D + HmacMdCtx =3D AllocateZeroPool (sizeof (mbedtls_md_context_t));=0D + if (HmacMdCtx =3D=3D NULL) {=0D + return NULL;=0D + }=0D +=0D + return HmacMdCtx;=0D +}=0D +=0D +/**=0D + Release the specified HMAC_CTX context.=0D +=0D + @param[in] HmacMdCtx Pointer to the HMAC_CTX context to be released.=0D +=0D +**/=0D +VOID=0D +HmacMdFree (=0D + IN VOID *HmacMdCtx=0D + )=0D +{=0D + mbedtls_md_free (HmacMdCtx);=0D + if (HmacMdCtx !=3D NULL) {=0D + FreePool (HmacMdCtx);=0D + }=0D +}=0D +=0D +/**=0D + Set user-supplied key for subsequent use. It must be done before any=0D + calling to HmacMdUpdate().=0D +=0D + If HmacMdContext is NULL, then return FALSE.=0D +=0D + @param[in] MdType Message Digest Type.=0D + @param[out] HmacMdContext Pointer to HMAC-MD context.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D +=0D + @retval TRUE The Key is set successfully.=0D + @retval FALSE The Key is set unsuccessfully.=0D +=0D +**/=0D +STATIC=0D +BOOLEAN=0D +HmacMdSetKey (=0D + IN mbedtls_md_type_t MdType,=0D + OUT VOID *HmacMdContext,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize=0D + )=0D +{=0D + const mbedtls_md_info_t *md_info;=0D + INT32 Ret;=0D +=0D + if ((HmacMdContext =3D=3D NULL) || (KeySize > INT_MAX)) {=0D + return FALSE;=0D + }=0D +=0D + ZeroMem (HmacMdContext, sizeof (mbedtls_md_context_t));=0D + mbedtls_md_init (HmacMdContext);=0D +=0D + md_info =3D mbedtls_md_info_from_type (MdType);=0D + ASSERT (md_info !=3D NULL);=0D +=0D + Ret =3D mbedtls_md_setup (HmacMdContext, md_info, 1);=0D + if (Ret !=3D 0) {=0D + return FALSE;=0D + }=0D +=0D + Ret =3D mbedtls_md_hmac_starts (HmacMdContext, Key, KeySize);=0D + if (Ret !=3D 0) {=0D + return FALSE;=0D + }=0D +=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Makes a copy of an existing HMAC-MD context.=0D +=0D + If HmacMdContext is NULL, then return FALSE.=0D + If NewHmacMdContext is NULL, then return FALSE.=0D +=0D + @param[in] HmacMdContext Pointer to HMAC-MD context being copied.=0D + @param[out] NewHmacMdContext Pointer to new HMAC-MD context.=0D +=0D + @retval TRUE HMAC-MD context copy succeeded.=0D + @retval FALSE HMAC-MD context copy failed.=0D +=0D +**/=0D +STATIC=0D +BOOLEAN=0D +HmacMdDuplicate (=0D + IN CONST VOID *HmacMdContext,=0D + OUT VOID *NewHmacMdContext=0D + )=0D +{=0D + INT32 Ret;=0D +=0D + if ((HmacMdContext =3D=3D NULL) || (NewHmacMdContext =3D=3D NULL)) {=0D + return FALSE;=0D + }=0D +=0D + Ret =3D mbedtls_md_clone (NewHmacMdContext, HmacMdContext);=0D + if (Ret !=3D 0) {=0D + return FALSE;=0D + }=0D +=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Digests the input data and updates HMAC-MD context.=0D +=0D + This function performs HMAC-MD digest on a data buffer of the specified = size.=0D + It can be called multiple times to compute the digest of long or discont= inuous data streams.=0D + HMAC-MD context should be initialized by HmacMdNew(), and should not be = finalized=0D + by HmacMdFinal(). Behavior with invalid context is undefined.=0D +=0D + If HmacMdContext is NULL, then return FALSE.=0D +=0D + @param[in, out] HmacMdContext Pointer to the HMAC-MD context.=0D + @param[in] Data Pointer to the buffer containing the = data to be digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval TRUE HMAC-MD data digest succeeded.=0D + @retval FALSE HMAC-MD data digest failed.=0D +=0D +**/=0D +STATIC=0D +BOOLEAN=0D +HmacMdUpdate (=0D + IN OUT VOID *HmacMdContext,=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize=0D + )=0D +{=0D + INT32 Ret;=0D +=0D + if (HmacMdContext =3D=3D NULL) {=0D + return FALSE;=0D + }=0D +=0D + if ((Data =3D=3D NULL) && (DataSize !=3D 0)) {=0D + return FALSE;=0D + }=0D +=0D + if (DataSize > INT_MAX) {=0D + return FALSE;=0D + }=0D +=0D + Ret =3D mbedtls_md_hmac_update (HmacMdContext, Data, DataSize);=0D + if (Ret !=3D 0) {=0D + return FALSE;=0D + }=0D +=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Completes computation of the HMAC-MD digest value.=0D +=0D + This function completes HMAC-MD hash computation and retrieves the diges= t value into=0D + the specified memory. After this function has been called, the HMAC-MD c= ontext cannot=0D + be used again.=0D + HMAC-MD context should be initialized by HmacMdNew(), and should not be = finalized=0D + by HmacMdFinal(). Behavior with invalid HMAC-MD context is undefined.=0D +=0D + If HmacMdContext is NULL, then return FALSE.=0D + If HmacValue is NULL, then return FALSE.=0D +=0D + @param[in, out] HmacMdContext Pointer to the HMAC-MD context.=0D + @param[out] HmacValue Pointer to a buffer that receives th= e HMAC-MD digest=0D + value.=0D +=0D + @retval TRUE HMAC-MD digest computation succeeded.=0D + @retval FALSE HMAC-MD digest computation failed.=0D +=0D +**/=0D +STATIC=0D +BOOLEAN=0D +HmacMdFinal (=0D + IN OUT VOID *HmacMdContext,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + INT32 Ret;=0D +=0D + if ((HmacMdContext =3D=3D NULL) || (HmacValue =3D=3D NULL)) {=0D + return FALSE;=0D + }=0D +=0D + Ret =3D mbedtls_md_hmac_finish (HmacMdContext, HmacValue);=0D + mbedtls_md_free (HmacMdContext);=0D + if (Ret !=3D 0) {=0D + return FALSE;=0D + }=0D +=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Computes the HMAC-MD digest of a input data buffer.=0D +=0D + This function performs the HMAC-MD digest of a given data buffer, and pl= aces=0D + the digest value into the specified memory.=0D +=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in] MdType Message Digest Type.=0D + @param[in] Data Pointer to the buffer containing the data to be= digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D + @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD d= igest=0D + value.=0D +=0D + @retval TRUE HMAC-MD digest computation succeeded.=0D + @retval FALSE HMAC-MD digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +STATIC=0D +BOOLEAN=0D +HmacMdAll (=0D + IN mbedtls_md_type_t MdType,=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + const mbedtls_md_info_t *md_info;=0D + INT32 Ret;=0D +=0D + md_info =3D mbedtls_md_info_from_type (MdType);=0D + ASSERT (md_info !=3D NULL);=0D +=0D + Ret =3D mbedtls_md_hmac (md_info, Key, KeySize, Data, DataSize, HmacValu= e);=0D + if (Ret !=3D 0) {=0D + return FALSE;=0D + }=0D +=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA25= 6 use.=0D +=0D + @return Pointer to the HMAC_CTX context that has been initialized.=0D + If the allocations fails, HmacSha256New() returns NULL.=0D +=0D +**/=0D +VOID *=0D +EFIAPI=0D +HmacSha256New (=0D + VOID=0D + )=0D +{=0D + return HmacMdNew ();=0D +}=0D +=0D +/**=0D + Release the specified HMAC_CTX context.=0D +=0D + @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be release= d.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +HmacSha256Free (=0D + IN VOID *HmacSha256Ctx=0D + )=0D +{=0D + HmacMdFree (HmacSha256Ctx);=0D +}=0D +=0D +/**=0D + Set user-supplied key for subsequent use. It must be done before any=0D + calling to HmacSha256Update().=0D +=0D + If HmacSha256Context is NULL, then return FALSE.=0D +=0D + @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D +=0D + @retval TRUE The Key is set successfully.=0D + @retval FALSE The Key is set unsuccessfully.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256SetKey (=0D + OUT VOID *HmacSha256Context,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize=0D + )=0D +{=0D + return HmacMdSetKey (MBEDTLS_MD_SHA256, HmacSha256Context, Key, KeySize)= ;=0D +}=0D +=0D +/**=0D + Makes a copy of an existing HMAC-SHA256 context.=0D +=0D + If HmacSha256Context is NULL, then return FALSE.=0D + If NewHmacSha256Context is NULL, then return FALSE.=0D +=0D + @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being c= opied.=0D + @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.=0D +=0D + @retval TRUE HMAC-SHA256 context copy succeeded.=0D + @retval FALSE HMAC-SHA256 context copy failed.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256Duplicate (=0D + IN CONST VOID *HmacSha256Context,=0D + OUT VOID *NewHmacSha256Context=0D + )=0D +{=0D + return HmacMdDuplicate (HmacSha256Context, NewHmacSha256Context);=0D +}=0D +=0D +/**=0D + Digests the input data and updates HMAC-SHA256 context.=0D +=0D + This function performs HMAC-SHA256 digest on a data buffer of the specif= ied size.=0D + It can be called multiple times to compute the digest of long or discont= inuous data streams.=0D + HMAC-SHA256 context should be initialized by HmacSha256New(), and should= not be finalized=0D + by HmacSha256Final(). Behavior with invalid context is undefined.=0D +=0D + If HmacSha256Context is NULL, then return FALSE.=0D +=0D + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.=0D + @param[in] Data Pointer to the buffer containing the = data to be digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval TRUE HMAC-SHA256 data digest succeeded.=0D + @retval FALSE HMAC-SHA256 data digest failed.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256Update (=0D + IN OUT VOID *HmacSha256Context,=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize=0D + )=0D +{=0D + return HmacMdUpdate (HmacSha256Context, Data, DataSize);=0D +}=0D +=0D +/**=0D + Completes computation of the HMAC-SHA256 digest value.=0D +=0D + This function completes HMAC-SHA256 hash computation and retrieves the d= igest value into=0D + the specified memory. After this function has been called, the HMAC-SHA2= 56 context cannot=0D + be used again.=0D + HMAC-SHA256 context should be initialized by HmacSha256New(), and should= not be finalized=0D + by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undef= ined.=0D +=0D + If HmacSha256Context is NULL, then return FALSE.=0D + If HmacValue is NULL, then return FALSE.=0D +=0D + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.= =0D + @param[out] HmacValue Pointer to a buffer that receives th= e HMAC-SHA256 digest=0D + value (32 bytes).=0D +=0D + @retval TRUE HMAC-SHA256 digest computation succeeded.=0D + @retval FALSE HMAC-SHA256 digest computation failed.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256Final (=0D + IN OUT VOID *HmacSha256Context,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + return HmacMdFinal (HmacSha256Context, HmacValue);=0D +}=0D +=0D +/**=0D + Computes the HMAC-SHA256 digest of a input data buffer.=0D +=0D + This function performs the HMAC-SHA256 digest of a given data buffer, an= d places=0D + the digest value into the specified memory.=0D +=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in] Data Pointer to the buffer containing the data to be= digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA2= 56 digest=0D + value (32 bytes).=0D +=0D + @retval TRUE HMAC-SHA256 digest computation succeeded.=0D + @retval FALSE HMAC-SHA256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256All (=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + return HmacMdAll (MBEDTLS_MD_SHA256, Data, DataSize, Key, KeySize, HmacV= alue);=0D +}=0D +=0D +/**=0D + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA38= 4 use.=0D +=0D + @return Pointer to the HMAC_CTX context that has been initialized.=0D + If the allocations fails, HmacSha384New() returns NULL.=0D +=0D +**/=0D +VOID *=0D +EFIAPI=0D +HmacSha384New (=0D + VOID=0D + )=0D +{=0D + return HmacMdNew ();=0D +}=0D +=0D +/**=0D + Release the specified HMAC_CTX context.=0D +=0D + @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be release= d.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +HmacSha384Free (=0D + IN VOID *HmacSha384Ctx=0D + )=0D +{=0D + HmacMdFree (HmacSha384Ctx);=0D +}=0D +=0D +/**=0D + Set user-supplied key for subsequent use. It must be done before any=0D + calling to HmacSha384Update().=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D +=0D + @retval TRUE The Key is set successfully.=0D + @retval FALSE The Key is set unsuccessfully.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384SetKey (=0D + OUT VOID *HmacSha384Context,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize=0D + )=0D +{=0D + return HmacMdSetKey (MBEDTLS_MD_SHA384, HmacSha384Context, Key, KeySize)= ;=0D +}=0D +=0D +/**=0D + Makes a copy of an existing HMAC-SHA384 context.=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If NewHmacSha384Context is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being c= opied.=0D + @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.=0D +=0D + @retval TRUE HMAC-SHA384 context copy succeeded.=0D + @retval FALSE HMAC-SHA384 context copy failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384Duplicate (=0D + IN CONST VOID *HmacSha384Context,=0D + OUT VOID *NewHmacSha384Context=0D + )=0D +{=0D + return HmacMdDuplicate (HmacSha384Context, NewHmacSha384Context);=0D +}=0D +=0D +/**=0D + Digests the input data and updates HMAC-SHA384 context.=0D +=0D + This function performs HMAC-SHA384 digest on a data buffer of the specif= ied size.=0D + It can be called multiple times to compute the digest of long or discont= inuous data streams.=0D + HMAC-SHA384 context should be initialized by HmacSha384New(), and should= not be finalized=0D + by HmacSha384Final(). Behavior with invalid context is undefined.=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.=0D + @param[in] Data Pointer to the buffer containing the = data to be digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval TRUE HMAC-SHA384 data digest succeeded.=0D + @retval FALSE HMAC-SHA384 data digest failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384Update (=0D + IN OUT VOID *HmacSha384Context,=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize=0D + )=0D +{=0D + return HmacMdUpdate (HmacSha384Context, Data, DataSize);=0D +}=0D +=0D +/**=0D + Completes computation of the HMAC-SHA384 digest value.=0D +=0D + This function completes HMAC-SHA384 hash computation and retrieves the d= igest value into=0D + the specified memory. After this function has been called, the HMAC-SHA3= 84 context cannot=0D + be used again.=0D + HMAC-SHA384 context should be initialized by HmacSha384New(), and should= not be finalized=0D + by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undef= ined.=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If HmacValue is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.= =0D + @param[out] HmacValue Pointer to a buffer that receives th= e HMAC-SHA384 digest=0D + value (48 bytes).=0D +=0D + @retval TRUE HMAC-SHA384 digest computation succeeded.=0D + @retval FALSE HMAC-SHA384 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384Final (=0D + IN OUT VOID *HmacSha384Context,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + return HmacMdFinal (HmacSha384Context, HmacValue);=0D +}=0D +=0D +/**=0D + Computes the HMAC-SHA384 digest of a input data buffer.=0D +=0D + This function performs the HMAC-SHA384 digest of a given data buffer, an= d places=0D + the digest value into the specified memory.=0D +=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in] Data Pointer to the buffer containing the data to be= digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA3= 84 digest=0D + value (48 bytes).=0D +=0D + @retval TRUE HMAC-SHA384 digest computation succeeded.=0D + @retval FALSE HMAC-SHA384 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384All (=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + return HmacMdAll (MBEDTLS_MD_SHA384, Data, DataSize, Key, KeySize, HmacV= alue);=0D +}=0D diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmacNull.c b/C= ryptoPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmacNull.c new file mode 100644 index 0000000000..37bf3ea486 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/Hmac/CryptHmacNull.c @@ -0,0 +1,359 @@ +/** @file=0D + HMAC-SHA256/SHA384 Wrapper Implementation which does not provide real ca= pabilities.=0D +=0D +Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include "InternalCryptLib.h"=0D +=0D +/**=0D + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA25= 6 use.=0D +=0D + Return NULL to indicate this interface is not supported.=0D +=0D + @return NULL This interface is not supported..=0D +=0D +**/=0D +VOID *=0D +EFIAPI=0D +HmacSha256New (=0D + VOID=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return NULL;=0D +}=0D +=0D +/**=0D + Release the specified HMAC_CTX context.=0D +=0D + This function will do nothing.=0D +=0D + @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be release= d.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +HmacSha256Free (=0D + IN VOID *HmacSha256Ctx=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return;=0D +}=0D +=0D +/**=0D + Set user-supplied key for subsequent use. It must be done before any=0D + calling to HmacSha256Update().=0D +=0D + Return FALSE to indicate this interface is not supported.=0D +=0D + @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D +=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256SetKey (=0D + OUT VOID *HmacSha256Context,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Makes a copy of an existing HMAC-SHA256 context.=0D +=0D + Return FALSE to indicate this interface is not supported.=0D +=0D + @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being c= opied.=0D + @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.=0D +=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256Duplicate (=0D + IN CONST VOID *HmacSha256Context,=0D + OUT VOID *NewHmacSha256Context=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Digests the input data and updates HMAC-SHA256 context.=0D +=0D + Return FALSE to indicate this interface is not supported.=0D +=0D + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.=0D + @param[in] Data Pointer to the buffer containing the = data to be digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256Update (=0D + IN OUT VOID *HmacSha256Context,=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Completes computation of the HMAC-SHA256 digest value.=0D +=0D + Return FALSE to indicate this interface is not supported.=0D +=0D + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.= =0D + @param[out] HmacValue Pointer to a buffer that receives th= e HMAC-SHA256 digest=0D + value (32 bytes).=0D +=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256Final (=0D + IN OUT VOID *HmacSha256Context,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Computes the HMAC-SHA256 digest of a input data buffer.=0D +=0D + This function performs the HMAC-SHA256 digest of a given data buffer, an= d places=0D + the digest value into the specified memory.=0D +=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in] Data Pointer to the buffer containing the data to be= digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA2= 56 digest=0D + value (32 bytes).=0D +=0D + @retval TRUE HMAC-SHA256 digest computation succeeded.=0D + @retval FALSE HMAC-SHA256 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha256All (=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA38= 4 use.=0D +=0D + @return Pointer to the HMAC_CTX context that has been initialized.=0D + If the allocations fails, HmacSha384New() returns NULL.=0D +=0D +**/=0D +VOID *=0D +EFIAPI=0D +HmacSha384New (=0D + VOID=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return NULL;=0D +}=0D +=0D +/**=0D + Release the specified HMAC_CTX context.=0D +=0D + @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be release= d.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +HmacSha384Free (=0D + IN VOID *HmacSha384Ctx=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return;=0D +}=0D +=0D +/**=0D + Set user-supplied key for subsequent use. It must be done before any=0D + calling to HmacSha384Update().=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D +=0D + @retval TRUE The Key is set successfully.=0D + @retval FALSE The Key is set unsuccessfully.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384SetKey (=0D + OUT VOID *HmacSha384Context,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Makes a copy of an existing HMAC-SHA384 context.=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If NewHmacSha384Context is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being c= opied.=0D + @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.=0D +=0D + @retval TRUE HMAC-SHA384 context copy succeeded.=0D + @retval FALSE HMAC-SHA384 context copy failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384Duplicate (=0D + IN CONST VOID *HmacSha384Context,=0D + OUT VOID *NewHmacSha384Context=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Digests the input data and updates HMAC-SHA384 context.=0D +=0D + This function performs HMAC-SHA384 digest on a data buffer of the specif= ied size.=0D + It can be called multiple times to compute the digest of long or discont= inuous data streams.=0D + HMAC-SHA384 context should be initialized by HmacSha384New(), and should= not be finalized=0D + by HmacSha384Final(). Behavior with invalid context is undefined.=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.=0D + @param[in] Data Pointer to the buffer containing the = data to be digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D +=0D + @retval TRUE HMAC-SHA384 data digest succeeded.=0D + @retval FALSE HMAC-SHA384 data digest failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384Update (=0D + IN OUT VOID *HmacSha384Context,=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Completes computation of the HMAC-SHA384 digest value.=0D +=0D + This function completes HMAC-SHA384 hash computation and retrieves the d= igest value into=0D + the specified memory. After this function has been called, the HMAC-SHA3= 84 context cannot=0D + be used again.=0D + HMAC-SHA384 context should be initialized by HmacSha384New(), and should= not be finalized=0D + by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undef= ined.=0D +=0D + If HmacSha384Context is NULL, then return FALSE.=0D + If HmacValue is NULL, then return FALSE.=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.= =0D + @param[out] HmacValue Pointer to a buffer that receives th= e HMAC-SHA384 digest=0D + value (48 bytes).=0D +=0D + @retval TRUE HMAC-SHA384 digest computation succeeded.=0D + @retval FALSE HMAC-SHA384 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384Final (=0D + IN OUT VOID *HmacSha384Context,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Computes the HMAC-SHA384 digest of a input data buffer.=0D +=0D + This function performs the HMAC-SHA384 digest of a given data buffer, an= d places=0D + the digest value into the specified memory.=0D +=0D + If this interface is not supported, then return FALSE.=0D +=0D + @param[in] Data Pointer to the buffer containing the data to be= digested.=0D + @param[in] DataSize Size of Data buffer in bytes.=0D + @param[in] Key Pointer to the user-supplied key.=0D + @param[in] KeySize Key size in bytes.=0D + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA3= 84 digest=0D + value (48 bytes).=0D +=0D + @retval TRUE HMAC-SHA384 digest computation succeeded.=0D + @retval FALSE HMAC-SHA384 digest computation failed.=0D + @retval FALSE This interface is not supported.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +HmacSha384All (=0D + IN CONST VOID *Data,=0D + IN UINTN DataSize,=0D + IN CONST UINT8 *Key,=0D + IN UINTN KeySize,=0D + OUT UINT8 *HmacValue=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return FALSE;=0D +}=0D --=20 2.26.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#108133): https://edk2.groups.io/g/devel/message/108133 Mute This Topic: https://groups.io/mt/101048352/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-