From nobody Fri Apr 26 23:29:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53207+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53207+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1578983190; cv=none; d=zohomail.com; s=zohoarc; b=LzCn+xJ3BSOH4roqrxgPKGj2KLjglNAobtOmqmswopkvSFB6bElRR7Kf4gwVIWOwp1fUt0TMaEAc8N5QpM7E8ZpKALERYt6N6yqsXz/lQtYlIfNWMIBb2+7X2K7WIFGH5+sVqW0z7vT/a2rx+VP4JQxmE0iaLGPIAkpQiFGHETU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578983190; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=rH0gNnlWRVoXycdiSD+rrDeNFTQiTXZDctwFE9ANJFg=; b=NTFYAz+wz8s27pT8ZdTxuPSmfK9iZnpCaP3Xzq4jWSavdZM0WoFiKkES2Vil91PSDDhKHZ/LLx67IkiT10HSLF5K1QbBOYohOATZIK1EcAFTSwWNji4Y0HjqZZDAQCluoQt7YaEBi/RNByQIGGG67hPqZBxnBwGz4U0tVsfzNx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53207+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1578983190870487.5246443620682; Mon, 13 Jan 2020 22:26:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SyHBYY1788612xMGalAZ7tMq; Mon, 13 Jan 2020 22:26:30 -0800 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.7131.1578983189261336758 for ; Mon, 13 Jan 2020 22:26:29 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jan 2020 22:26:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,431,1571727600"; d="scan'208";a="423049926" X-Received: from unknown (HELO shwdeopensfp777.ccr.corp.intel.com) ([10.239.158.78]) by fmsmga005.fm.intel.com with ESMTP; 13 Jan 2020 22:26:27 -0800 From: "Wang, Jian J" To: devel@edk2.groups.io Cc: Xiaoyu Lu , Laszlo Ersek Subject: [edk2-devel] [PATCH v2] CryptoPkg/BaseCryptLib: remove HmacXxxGetContextSize interface Date: Tue, 14 Jan 2020 14:26:26 +0800 Message-Id: <20200114062626.1248-1-jian.j.wang@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,jian.j.wang@intel.com X-Gm-Message-State: 4JalFkAfRQNjswcQ7bs1saqxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1578983190; bh=XcrEIGPaf7g7JLtlZ3HnAZErmCs6zjg0AXVnWrppiP4=; h=Cc:Date:From:Reply-To:Subject:To; b=tCNUB4YddX0xl7bc56Z716hClMWnI3nCnq5Bnz7w+l8dQAQOK0WFTGwh7sv8wa9CbzY qUgyqme6LVmk5PQfyxwL6E7N4R8jgLa0mCJm0qvHIu1HrVYjxRNZhse7LgtflHm+JUmRf hs4WcerzYyEywElLKhjxZhHLauSbYZM1h+s= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" > v2 changes: > - change HmacXxxInit to HmacXxxSetKey > - remove calling to HMAC_CTX_reset() since HmacXxxNew() has done it > already and user-supplied context is not supported any longer. > - update comments affected by above change REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1792 Hmac(Md5|Sha1|Sha256)GetContextSize() use a deprecated macro HMAC_MAX_MD_CBLOCK defined in openssl. They should be dropped to avoid misuses in the future. For context allocation and release, use HmacXxxNew() and HmacXxxFree() instead. Considering that HmacXxxInit() has no use cases, remove the calling to memset() and HMAC_CTX_reset() to drop the support of user supplied context buffer. The only functionality left is to set user supplied key for HMAC. To avoid confusion, change the the its name to HmacXxxSetKey. Cc: Xiaoyu Lu Cc: Laszlo Ersek Signed-off-by: Jian J Wang --- CryptoPkg/Include/Library/BaseCryptLib.h | 111 +++++------------- .../Library/BaseCryptLib/Hmac/CryptHmacMd5.c | 58 ++------- .../BaseCryptLib/Hmac/CryptHmacMd5Null.c | 28 +---- .../Library/BaseCryptLib/Hmac/CryptHmacSha1.c | 59 ++-------- .../BaseCryptLib/Hmac/CryptHmacSha1Null.c | 28 +---- .../BaseCryptLib/Hmac/CryptHmacSha256.c | 58 ++------- .../BaseCryptLib/Hmac/CryptHmacSha256Null.c | 28 +---- .../BaseCryptLibNull/Hmac/CryptHmacMd5Null.c | 20 ---- .../BaseCryptLibNull/Hmac/CryptHmacSha1Null.c | 20 ---- .../Hmac/CryptHmacSha256Null.c | 20 ---- 10 files changed, 72 insertions(+), 358 deletions(-) diff --git a/CryptoPkg/Include/Library/BaseCryptLib.h b/CryptoPkg/Include/L= ibrary/BaseCryptLib.h index 8fe303a0b3..b93f1b9009 100644 --- a/CryptoPkg/Include/Library/BaseCryptLib.h +++ b/CryptoPkg/Include/Library/BaseCryptLib.h @@ -1025,23 +1025,6 @@ Sm3HashAll ( // MAC (Message Authentication Code) Primitive //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-MD= 5 operations. - (NOTE: This API is deprecated. - Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.) - - If this interface is not supported, then return zero. - - @return The size, in bytes, of the context buffer required for HMAC-MD5= operations. - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacMd5GetContextSize ( - VOID - ); - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 u= se. =20 @@ -1073,24 +1056,24 @@ HmacMd5Free ( ); =20 /** - Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 c= ontext for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacMd5Update(). =20 If HmacMd5Context is NULL, then return FALSE. If this interface is not supported, then return FALSE. =20 - @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initializ= ed. + @param[out] HmacMd5Context Pointer to HMAC-MD5 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 - @retval TRUE HMAC-MD5 context initialization succeeded. - @retval FALSE HMAC-MD5 context initialization failed. + @retval TRUE Key is set succeefully. + @retval FALSE Key is set unsucceefully. @retval FALSE This interface is not supported. =20 **/ BOOLEAN EFIAPI -HmacMd5Init ( +HmacMd5SetKey ( OUT VOID *HmacMd5Context, IN CONST UINT8 *Key, IN UINTN KeySize @@ -1123,8 +1106,8 @@ HmacMd5Duplicate ( =20 This function performs HMAC-MD5 digest on a data buffer of the specified= size. It can be called multiple times to compute the digest of long or discont= inuous data streams. - HMAC-MD5 context should be already correctly initialized by HmacMd5Init(= ), and should not be - finalized by HmacMd5Final(). Behavior with invalid context is undefined. + HMAC-MD5 context should be initialized by HmacMd5New(), and should not b= e finalized by + HmacMd5Final(). Behavior with invalid context is undefined. =20 If HmacMd5Context is NULL, then return FALSE. If this interface is not supported, then return FALSE. @@ -1152,8 +1135,8 @@ HmacMd5Update ( This function completes HMAC-MD5 hash computation and retrieves the dige= st value into the specified memory. After this function has been called, the HMAC-MD5 = context cannot be used again. - HMAC-MD5 context should be already correctly initialized by HmacMd5Init(= ), and should not be - finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is u= ndefined. + HMAC-MD5 context should be initialized by HmacMd5New(), and should not b= e finalized by + HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined. =20 If HmacMd5Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE. @@ -1175,23 +1158,6 @@ HmacMd5Final ( OUT UINT8 *HmacValue ); =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A1 operations. - (NOTE: This API is deprecated. - Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operatio= ns.) - - If this interface is not supported, then return zero. - - @return The size, in bytes, of the context buffer required for HMAC-SHA= 1 operations. - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacSha1GetContextSize ( - VOID - ); - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 = use. =20 @@ -1223,24 +1189,24 @@ HmacSha1Free ( ); =20 /** - Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1= context for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacSha1Update(). =20 If HmacSha1Context is NULL, then return FALSE. If this interface is not supported, then return FALSE. =20 - @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initial= ized. + @param[out] HmacSha1Context Pointer to HMAC-SHA1 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 - @retval TRUE HMAC-SHA1 context initialization succeeded. - @retval FALSE HMAC-SHA1 context initialization failed. + @retval TRUE The Key is set succeefully. + @retval FALSE The Key is set unsucceefully. @retval FALSE This interface is not supported. =20 **/ BOOLEAN EFIAPI -HmacSha1Init ( +HmacSha1SetKey ( OUT VOID *HmacSha1Context, IN CONST UINT8 *Key, IN UINTN KeySize @@ -1273,8 +1239,8 @@ HmacSha1Duplicate ( =20 This function performs HMAC-SHA1 digest on a data buffer of the specifie= d size. It can be called multiple times to compute the digest of long or discont= inuous data streams. - HMAC-SHA1 context should be already correctly initialized by HmacSha1Ini= t(), and should not - be finalized by HmacSha1Final(). Behavior with invalid context is undefi= ned. + HMAC-SHA1 context should be initialized by HmacSha1New(), and should not= be finalized by + HmacSha1Final(). Behavior with invalid context is undefined. =20 If HmacSha1Context is NULL, then return FALSE. If this interface is not supported, then return FALSE. @@ -1302,8 +1268,8 @@ HmacSha1Update ( This function completes HMAC-SHA1 hash computation and retrieves the dig= est value into the specified memory. After this function has been called, the HMAC-SHA1= context cannot be used again. - HMAC-SHA1 context should be already correctly initialized by HmacSha1Ini= t(), and should - not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 con= text is undefined. + HMAC-SHA1 context should be initialized by HmacSha1New(), and should not= be finalized + by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined. =20 If HmacSha1Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE. @@ -1325,23 +1291,6 @@ HmacSha1Final ( OUT UINT8 *HmacValue ); =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A256 operations. - (NOTE: This API is deprecated. - Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context op= erations.) - - If this interface is not supported, then return zero. - - @return The size, in bytes, of the context buffer required for HMAC-SHA= 256 operations. - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacSha256GetContextSize ( - VOID - ); - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA25= 6 use. =20 @@ -1368,24 +1317,24 @@ HmacSha256Free ( ); =20 /** - Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SH= A256 context for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacSha256Update(). =20 If HmacSha256Context is NULL, then return FALSE. If this interface is not supported, then return FALSE. =20 - @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being ini= tialized. + @param[out] HmacSha256Context Pointer to HMAC-SHA256 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 - @retval TRUE HMAC-SHA256 context initialization succeeded. - @retval FALSE HMAC-SHA256 context initialization failed. + @retval TRUE The Key is set succeefully. + @retval FALSE The Key is set unsucceefully. @retval FALSE This interface is not supported. =20 **/ BOOLEAN EFIAPI -HmacSha256Init ( +HmacSha256SetKey ( OUT VOID *HmacSha256Context, IN CONST UINT8 *Key, IN UINTN KeySize @@ -1418,8 +1367,8 @@ HmacSha256Duplicate ( =20 This function performs HMAC-SHA256 digest on a data buffer of the specif= ied size. It can be called multiple times to compute the digest of long or discont= inuous data streams. - HMAC-SHA256 context should be already correctly initialized by HmacSha25= 6Init(), and should not - be finalized by HmacSha256Final(). Behavior with invalid context is unde= fined. + HMAC-SHA256 context should be initialized by HmacSha256New(), and should= not be finalized + by HmacSha256Final(). Behavior with invalid context is undefined. =20 If HmacSha256Context is NULL, then return FALSE. If this interface is not supported, then return FALSE. @@ -1447,8 +1396,8 @@ HmacSha256Update ( This function completes HMAC-SHA256 hash computation and retrieves the d= igest value into the specified memory. After this function has been called, the HMAC-SHA2= 56 context cannot be used again. - HMAC-SHA256 context should be already correctly initialized by HmacSha25= 6Init(), and should - not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256= context is undefined. + HMAC-SHA256 context should be initialized by HmacSha256New(), and should= not be finalized + by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undef= ined. =20 If HmacSha256Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE. diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c b/CryptoPkg= /Library/BaseCryptLib/Hmac/CryptHmacMd5.c index 19e9fbeae6..f0609e61d7 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c @@ -9,37 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "InternalCryptLib.h" #include =20 -// -// NOTE: OpenSSL redefines the size of HMAC_CTX at crypto/hmac/hmac_lcl.h -// #define HMAC_MAX_MD_CBLOCK_SIZE 144 -// -#define HMAC_MD5_CTX_SIZE (sizeof(void *) * 4 + sizeof(unsigned int) + \ - sizeof(unsigned char) * 144) - -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-MD= 5 operations. - (NOTE: This API is deprecated. - Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.) - - @return The size, in bytes, of the context buffer required for HMAC-MD5= operations. - -**/ -UINTN -EFIAPI -HmacMd5GetContextSize ( - VOID - ) -{ - // - // Retrieves the OpenSSL HMAC-MD5 Context Size - // NOTE: HMAC_CTX object was made opaque in openssl-1.1.x, here we just = use the - // fixed size as a workaround to make this API work for compatibil= ity. - // We should retire HmacMd5GetContextSize() in future, and use Hma= cMd5New() - // and HmacMd5Free() for context allocation and release. - // - return (UINTN) HMAC_MD5_CTX_SIZE; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 u= se. =20 @@ -78,22 +47,22 @@ HmacMd5Free ( } =20 /** - Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 c= ontext for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacMd5Update(). =20 If HmacMd5Context is NULL, then return FALSE. =20 - @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initializ= ed. + @param[out] HmacMd5Context Pointer to HMAC-MD5 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 - @retval TRUE HMAC-MD5 context initialization succeeded. - @retval FALSE HMAC-MD5 context initialization failed. + @retval TRUE Key is set succeefully. + @retval FALSE Key is set unsucceefully. =20 **/ BOOLEAN EFIAPI -HmacMd5Init ( +HmacMd5SetKey ( OUT VOID *HmacMd5Context, IN CONST UINT8 *Key, IN UINTN KeySize @@ -106,13 +75,6 @@ HmacMd5Init ( return FALSE; } =20 - // - // OpenSSL HMAC-MD5 Context Initialization - // - memset(HmacMd5Context, 0, HMAC_MD5_CTX_SIZE); - if (HMAC_CTX_reset ((HMAC_CTX *)HmacMd5Context) !=3D 1) { - return FALSE; - } if (HMAC_Init_ex ((HMAC_CTX *)HmacMd5Context, Key, (UINT32) KeySize, EVP= _md5(), NULL) !=3D 1) { return FALSE; } @@ -159,8 +121,8 @@ HmacMd5Duplicate ( =20 This function performs HMAC-MD5 digest on a data buffer of the specified= size. It can be called multiple times to compute the digest of long or discont= inuous data streams. - HMAC-MD5 context should be already correctly initialized by HmacMd5Init(= ), and should not be - finalized by HmacMd5Final(). Behavior with invalid context is undefined. + HMAC-MD5 context should be initialized by HmacMd5New(), and should not b= e finalized by + HmacMd5Final(). Behavior with invalid context is undefined. =20 If HmacMd5Context is NULL, then return FALSE. =20 @@ -210,8 +172,8 @@ HmacMd5Update ( This function completes HMAC-MD5 digest computation and retrieves the di= gest value into the specified memory. After this function has been called, the HMAC-MD5 = context cannot be used again. - HMAC-MD5 context should be already correctly initialized by HmacMd5Init(= ), and should not be - finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is u= ndefined. + HMAC-MD5 context should be initialized by HmacMd5New(), and should not b= e finalized by + HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined. =20 If HmacMd5Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE. diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5Null.c b/Crypt= oPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5Null.c index 3aafed874b..9da132eeee 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5Null.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5Null.c @@ -8,26 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "InternalCryptLib.h" =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-MD= 5 operations. - (NOTE: This API is deprecated. - Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.) - - Return zero to indicate this interface is not supported. - - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacMd5GetContextSize ( - VOID - ) -{ - ASSERT (FALSE); - return 0; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 u= se. =20 @@ -65,12 +45,12 @@ HmacMd5Free ( } =20 /** - Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 c= ontext for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacMd5Update(). =20 Return FALSE to indicate this interface is not supported. =20 - @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initializ= ed. + @param[out] HmacMd5Context Pointer to HMAC-MD5 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 @@ -79,7 +59,7 @@ HmacMd5Free ( **/ BOOLEAN EFIAPI -HmacMd5Init ( +HmacMd5SetKey ( OUT VOID *HmacMd5Context, IN CONST UINT8 *Key, IN UINTN KeySize diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1.c b/CryptoPk= g/Library/BaseCryptLib/Hmac/CryptHmacSha1.c index 7d7df9640e..1bb5edfbd1 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1.c @@ -9,38 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "InternalCryptLib.h" #include =20 -// -// NOTE: OpenSSL redefines the size of HMAC_CTX at crypto/hmac/hmac_lcl.h -// #define HMAC_MAX_MD_CBLOCK_SIZE 144 -// -// -#define HMAC_SHA1_CTX_SIZE (sizeof(void *) * 4 + sizeof(unsigned int) += \ - sizeof(unsigned char) * 144) - -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A1 operations. - (NOTE: This API is deprecated. - Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operatio= ns.) - - @return The size, in bytes, of the context buffer required for HMAC-SHA= 1 operations. - -**/ -UINTN -EFIAPI -HmacSha1GetContextSize ( - VOID - ) -{ - // - // Retrieves the OpenSSL HMAC-SHA1 Context Size - // NOTE: HMAC_CTX object was made opaque in openssl-1.1.x, here we just = use the - // fixed size as a workaround to make this API work for compatibil= ity. - // We should retire HmacSha15GetContextSize() in future, and use H= macSha1New() - // and HmacSha1Free() for context allocation and release. - // - return (UINTN) HMAC_SHA1_CTX_SIZE; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 = use. =20 @@ -79,22 +47,22 @@ HmacSha1Free ( } =20 /** - Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1= context for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacSha1Update(). =20 If HmacSha1Context is NULL, then return FALSE. =20 - @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initial= ized. + @param[out] HmacSha1Context Pointer to HMAC-SHA1 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 - @retval TRUE HMAC-SHA1 context initialization succeeded. - @retval FALSE HMAC-SHA1 context initialization failed. + @retval TRUE The Key is set succeefully. + @retval FALSE The Key is set unsucceefully. =20 **/ BOOLEAN EFIAPI -HmacSha1Init ( +HmacSha1SetKey ( OUT VOID *HmacSha1Context, IN CONST UINT8 *Key, IN UINTN KeySize @@ -107,13 +75,6 @@ HmacSha1Init ( return FALSE; } =20 - // - // OpenSSL HMAC-SHA1 Context Initialization - // - memset(HmacSha1Context, 0, HMAC_SHA1_CTX_SIZE); - if (HMAC_CTX_reset ((HMAC_CTX *)HmacSha1Context) !=3D 1) { - return FALSE; - } if (HMAC_Init_ex ((HMAC_CTX *)HmacSha1Context, Key, (UINT32) KeySize, EV= P_sha1(), NULL) !=3D 1) { return FALSE; } @@ -160,8 +121,8 @@ HmacSha1Duplicate ( =20 This function performs HMAC-SHA1 digest on a data buffer of the specifie= d size. It can be called multiple times to compute the digest of long or discont= inuous data streams. - HMAC-SHA1 context should be already correctly initialized by HmacSha1Ini= t(), and should not - be finalized by HmacSha1Final(). Behavior with invalid context is undefi= ned. + HMAC-SHA1 context should be initialized by HmacSha1New(), and should not= be finalized by + HmacSha1Final(). Behavior with invalid context is undefined. =20 If HmacSha1Context is NULL, then return FALSE. =20 @@ -211,8 +172,8 @@ HmacSha1Update ( This function completes HMAC-SHA1 digest computation and retrieves the d= igest value into the specified memory. After this function has been called, the HMAC-SHA1= context cannot be used again. - HMAC-SHA1 context should be already correctly initialized by HmacSha1Ini= t(), and should - not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 con= text is undefined. + HMAC-SHA1 context should be initialized by HmacSha1New(), and should not= be finalized by + HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined. =20 If HmacSha1Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE. diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1Null.c b/Cryp= toPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1Null.c index 547aa484ea..2c26e9d514 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1Null.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha1Null.c @@ -8,26 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "InternalCryptLib.h" =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A1 operations. - (NOTE: This API is deprecated. - Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operatio= ns.) - - Return zero to indicate this interface is not supported. - - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacSha1GetContextSize ( - VOID - ) -{ - ASSERT (FALSE); - return 0; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 = use. =20 @@ -65,12 +45,12 @@ HmacSha1Free ( } =20 /** - Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1= context for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacSha1Update(). =20 Return FALSE to indicate this interface is not supported. =20 - @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initial= ized. + @param[out] HmacSha1Context Pointer to HMAC-SHA1 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 @@ -79,7 +59,7 @@ HmacSha1Free ( **/ BOOLEAN EFIAPI -HmacSha1Init ( +HmacSha1SetKey ( OUT VOID *HmacSha1Context, IN CONST UINT8 *Key, IN UINTN KeySize diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256.c b/Crypto= Pkg/Library/BaseCryptLib/Hmac/CryptHmacSha256.c index f24443e745..930248e39f 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256.c @@ -9,37 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "InternalCryptLib.h" #include =20 -// -// NOTE: OpenSSL redefines the size of HMAC_CTX at crypto/hmac/hmac_lcl.h -// #define HMAC_MAX_MD_CBLOCK_SIZE 144 -// -#define HMAC_SHA256_CTX_SIZE (sizeof(void *) * 4 + sizeof(unsigned int)= + \ - sizeof(unsigned char) * 144) - -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A256 operations. - (NOTE: This API is deprecated. - Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context op= erations.) - - @return The size, in bytes, of the context buffer required for HMAC-SHA= 256 operations. - -**/ -UINTN -EFIAPI -HmacSha256GetContextSize ( - VOID - ) -{ - // - // Retrieves the OpenSSL HMAC-SHA256 Context Size - // NOTE: HMAC_CTX object was made opaque in openssl-1.1.x, here we just = use the - // fixed size as a workaround to make this API work for compatibil= ity. - // We should retire HmacSha256GetContextSize() in future, and use = HmacSha256New() - // and HmacSha256Free() for context allocation and release. - // - return (UINTN)HMAC_SHA256_CTX_SIZE; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA25= 6 use. =20 @@ -78,22 +47,22 @@ HmacSha256Free ( } =20 /** - Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SH= A256 context for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacSha256Update(). =20 If HmacSha256Context is NULL, then return FALSE. =20 - @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being ini= tialized. + @param[out] HmacSha256Context Pointer to HMAC-SHA256 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 - @retval TRUE HMAC-SHA256 context initialization succeeded. - @retval FALSE HMAC-SHA256 context initialization failed. + @retval TRUE The Key is set succeefully. + @retval FALSE The Key is set unsucceefully. =20 **/ BOOLEAN EFIAPI -HmacSha256Init ( +HmacSha256SetKey ( OUT VOID *HmacSha256Context, IN CONST UINT8 *Key, IN UINTN KeySize @@ -106,13 +75,6 @@ HmacSha256Init ( return FALSE; } =20 - // - // OpenSSL HMAC-SHA256 Context Initialization - // - memset(HmacSha256Context, 0, HMAC_SHA256_CTX_SIZE); - if (HMAC_CTX_reset ((HMAC_CTX *)HmacSha256Context) !=3D 1) { - return FALSE; - } if (HMAC_Init_ex ((HMAC_CTX *)HmacSha256Context, Key, (UINT32) KeySize, = EVP_sha256(), NULL) !=3D 1) { return FALSE; } @@ -159,8 +121,8 @@ HmacSha256Duplicate ( =20 This function performs HMAC-SHA256 digest on a data buffer of the specif= ied size. It can be called multiple times to compute the digest of long or discont= inuous data streams. - HMAC-SHA256 context should be already correctly initialized by HmacSha25= 6Init(), and should not - be finalized by HmacSha256Final(). Behavior with invalid context is unde= fined. + HMAC-SHA256 context should be initialized by HmacSha256New(), and should= not be finalized + by HmacSha256Final(). Behavior with invalid context is undefined. =20 If HmacSha256Context is NULL, then return FALSE. =20 @@ -210,8 +172,8 @@ HmacSha256Update ( This function completes HMAC-SHA256 hash computation and retrieves the d= igest value into the specified memory. After this function has been called, the HMAC-SHA2= 56 context cannot be used again. - HMAC-SHA256 context should be already correctly initialized by HmacSha25= 6Init(), and should - not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256= context is undefined. + HMAC-SHA256 context should be initialized by HmacSha256New(), and should= not be finalized + by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undef= ined. =20 If HmacSha256Context is NULL, then return FALSE. If HmacValue is NULL, then return FALSE. diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256Null.c b/Cr= yptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256Null.c index f0a4420e27..1af625ec9f 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256Null.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256Null.c @@ -8,26 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "InternalCryptLib.h" =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A256 operations. - (NOTE: This API is deprecated. - Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context op= erations.) - - Return zero to indicate this interface is not supported. - - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacSha256GetContextSize ( - VOID - ) -{ - ASSERT (FALSE); - return 0; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA25= 6 use. =20 @@ -65,12 +45,12 @@ HmacSha256Free ( } =20 /** - Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SH= A256 context for - subsequent use. + Set user-supplied key for subsequent use. It must be done before any + calling to HmacSha256Update(). =20 Return FALSE to indicate this interface is not supported. =20 - @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being ini= tialized. + @param[out] HmacSha256Context Pointer to HMAC-SHA256 context. @param[in] Key Pointer to the user-supplied key. @param[in] KeySize Key size in bytes. =20 @@ -79,7 +59,7 @@ HmacSha256Free ( **/ BOOLEAN EFIAPI -HmacSha256Init ( +HmacSha256SetKey ( OUT VOID *HmacSha256Context, IN CONST UINT8 *Key, IN UINTN KeySize diff --git a/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacMd5Null.c b/C= ryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacMd5Null.c index 3aafed874b..205dc9e474 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacMd5Null.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacMd5Null.c @@ -8,26 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "InternalCryptLib.h" =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-MD= 5 operations. - (NOTE: This API is deprecated. - Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.) - - Return zero to indicate this interface is not supported. - - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacMd5GetContextSize ( - VOID - ) -{ - ASSERT (FALSE); - return 0; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 u= se. =20 diff --git a/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha1Null.c b/= CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha1Null.c index 547aa484ea..542350f15a 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha1Null.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha1Null.c @@ -8,26 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "InternalCryptLib.h" =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A1 operations. - (NOTE: This API is deprecated. - Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operatio= ns.) - - Return zero to indicate this interface is not supported. - - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacSha1GetContextSize ( - VOID - ) -{ - ASSERT (FALSE); - return 0; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 = use. =20 diff --git a/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha256Null.c = b/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha256Null.c index f0a4420e27..f8074cc617 100644 --- a/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha256Null.c +++ b/CryptoPkg/Library/BaseCryptLibNull/Hmac/CryptHmacSha256Null.c @@ -8,26 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "InternalCryptLib.h" =20 -/** - Retrieves the size, in bytes, of the context buffer required for HMAC-SH= A256 operations. - (NOTE: This API is deprecated. - Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context op= erations.) - - Return zero to indicate this interface is not supported. - - @retval 0 This interface is not supported. - -**/ -UINTN -EFIAPI -HmacSha256GetContextSize ( - VOID - ) -{ - ASSERT (FALSE); - return 0; -} - /** Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA25= 6 use. =20 --=20 2.24.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#53207): https://edk2.groups.io/g/devel/message/53207 Mute This Topic: https://groups.io/mt/69689481/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-