From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web12.1058.1666290930610733653 for ; Thu, 20 Oct 2022 11:35:31 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=DoB1Xsaj; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: michael.d.kinney@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666290931; x=1697826931; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0C2Znsggx40F+2AxvgEl81Z2fGJTqxfjlnhUR0Sl/R8=; b=DoB1XsajfRhOaipmcSzJXsM4umkGzyX4k7XWQVkhQB3s9v3f4wgH5jET RHEvJCprsADFm+u/9SFOoaxuYK8eO3XTNDagNxtgvNnThliuCQ+F/g5gV bjZHg/hv6p+5KohlwENj6pfNiDamgqlt0cvd+FHIGDz0VLrKVzNFQfriF PigI/3/UfV8q5NECKD3IRxVoF3FHdtiaRdYJsXWvdgU+evBp/Ez4XN/2h l1az11ymHi/d1bTwVk4S+82bt+YaSMe0m3vHGCuC8pbPEHJTYQAsopUAp D4do3a6+Oc9EVnsRD+kYTxPnD83MkS4qaEd+n8YTnoRK3YqwiIPAVCZyM A==; X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="286523530" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="286523530" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 11:35:31 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="632427764" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="632427764" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.212.188.143]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 11:35:31 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Xiaoyu Lu , Guomin Jiang , Christopher Zurcher Subject: [Patch v2 03/16] CryptoPkg/Library/BaseCryptLib: Update internal functions/variables Date: Thu, 20 Oct 2022 11:34:57 -0700 Message-Id: <20221020183510.1799-4-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20221020183510.1799-1-michael.d.kinney@intel.com> References: <20221020183510.1799-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit * Update BaseCryptLib internal worker functions to be 'STATIC' * Update BaseCryptLib internal working functions to not use EFIAPI * Add GLOBAL_REMOVE_IF_UNREFERENCED to BaseCryptLib global variables Cc: Jiewen Yao Cc: Jian J Wang Cc: Xiaoyu Lu Cc: Guomin Jiang Cc: Christopher Zurcher Signed-off-by: Michael D Kinney --- CryptoPkg/CryptoPkg.ci.yaml | 3 +- .../Library/BaseCryptLib/Hmac/CryptHmac.c | 7 +++ .../Library/BaseCryptLib/Kdf/CryptHkdf.c | 5 ++- .../BaseCryptLib/Pk/CryptAuthenticode.c | 2 +- .../BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c | 3 +- .../BaseCryptLib/Pk/CryptPkcs7VerifyEku.c | 3 ++ CryptoPkg/Library/BaseCryptLib/Pk/CryptTs.c | 44 +++++++++++++------ 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/CryptoPkg/CryptoPkg.ci.yaml b/CryptoPkg/CryptoPkg.ci.yaml index 2fa3a3d5ee05..ca129d6ae56c 100644 --- a/CryptoPkg/CryptoPkg.ci.yaml +++ b/CryptoPkg/CryptoPkg.ci.yaml @@ -24,7 +24,8 @@ "ExceptionList": [ "8001", "IsLeap", "8001", "OBJ_get0_data", - "8001", "OBJ_length" + "8001", "OBJ_length", + "5005", "X509PopCertificate" ], ## Both file path and directory path are accepted. "IgnoreFiles": [ diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmac.c b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmac.c index 2786267a0be1..1ae33b6709cb 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmac.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmac.c @@ -16,6 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent If the allocations fails, HmacMdNew() returns NULL. **/ +STATIC VOID * HmacMdNew ( VOID @@ -33,6 +34,7 @@ HmacMdNew ( @param[in] HmacMdCtx Pointer to the HMAC_CTX context to be released. **/ +STATIC VOID HmacMdFree ( IN VOID *HmacMdCtx @@ -59,6 +61,7 @@ HmacMdFree ( @retval FALSE The Key is set unsuccessfully. **/ +STATIC BOOLEAN HmacMdSetKey ( IN CONST EVP_MD *Md, @@ -94,6 +97,7 @@ HmacMdSetKey ( @retval FALSE HMAC-MD context copy failed. **/ +STATIC BOOLEAN HmacMdDuplicate ( IN CONST VOID *HmacMdContext, @@ -132,6 +136,7 @@ HmacMdDuplicate ( @retval FALSE HMAC-MD data digest failed. **/ +STATIC BOOLEAN HmacMdUpdate ( IN OUT VOID *HmacMdContext, @@ -183,6 +188,7 @@ HmacMdUpdate ( @retval FALSE HMAC-MD digest computation failed. **/ +STATIC BOOLEAN HmacMdFinal ( IN OUT VOID *HmacMdContext, @@ -233,6 +239,7 @@ HmacMdFinal ( @retval FALSE This interface is not supported. **/ +STATIC BOOLEAN HmacMdAll ( IN CONST EVP_MD *Md, diff --git a/CryptoPkg/Library/BaseCryptLib/Kdf/CryptHkdf.c b/CryptoPkg/Library/BaseCryptLib/Kdf/CryptHkdf.c index ffaf5fb131ac..34e81246ed0d 100644 --- a/CryptoPkg/Library/BaseCryptLib/Kdf/CryptHkdf.c +++ b/CryptoPkg/Library/BaseCryptLib/Kdf/CryptHkdf.c @@ -6,7 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include +#include "InternalCryptLib.h" #include #include @@ -27,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent @retval FALSE Hkdf generation failed. **/ +STATIC BOOLEAN HkdfMdExtractAndExpand ( IN CONST EVP_MD *Md, @@ -95,6 +96,7 @@ HkdfMdExtractAndExpand ( @retval false Hkdf generation failed. **/ +STATIC BOOLEAN HkdfMdExtract ( IN CONST EVP_MD *Md, @@ -174,6 +176,7 @@ HkdfMdExtract ( @retval FALSE Hkdf generation failed. **/ +STATIC BOOLEAN HkdfMdExpand ( IN CONST EVP_MD *Md, diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c index aa4a33364d92..6b0dddd4af55 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptAuthenticode.c @@ -23,7 +23,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // OID ASN.1 Value for SPC_INDIRECT_DATA_OBJID // -UINT8 mSpcIndirectOidValue[] = { +GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 mSpcIndirectOidValue[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04 }; diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c index f8028181e47f..4e5a14e35210 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyCommon.c @@ -22,7 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include -UINT8 mOidValue[9] = { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02 }; +GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 mOidValue[9] = { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02 }; /** Check input P7Data is a wrapped ContentInfo structure or not. If not construct @@ -145,6 +145,7 @@ WrapPkcs7Data ( @retval FALSE The pop operation failed. **/ +STATIC BOOLEAN X509PopCertificate ( IN VOID *X509Stack, diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyEku.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyEku.c index 833b29ae9755..63cd49434e71 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyEku.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyEku.c @@ -62,6 +62,7 @@ @retval EFI_NOT_FOUND The number of signers found was not 1. **/ +STATIC EFI_STATUS GetSignerCertificate ( IN CONST PKCS7 *CertChain, @@ -132,6 +133,7 @@ GetSignerCertificate ( @retval EFI_NOT_FOUND One or more EKU's were not found in the signature. **/ +STATIC EFI_STATUS IsEkuInCertificate ( IN CONST X509 *Cert, @@ -255,6 +257,7 @@ IsEkuInCertificate ( @retval EFI_INVALID_PARAMETER A parameter was invalid. @retval EFI_NOT_FOUND One or more EKU's were not found in the signature. **/ +STATIC EFI_STATUS CheckEKUs ( IN CONST X509 *SignerCert, diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptTs.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptTs.c index f118f2e9d6aa..027dbb6842dc 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptTs.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptTs.c @@ -21,7 +21,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // OID ASN.1 Value for SPC_RFC3161_OBJID ("1.3.6.1.4.1.311.3.3.1") // -UINT8 mSpcRFC3161OidValue[] = { +GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 mSpcRFC3161OidValue[] = { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x03, 0x03, 0x01 }; @@ -43,11 +43,17 @@ typedef struct { // // ASN.1 Functions for TS_MESSAGE_IMPRINT // -DECLARE_ASN1_FUNCTIONS (TS_MESSAGE_IMPRINT) -ASN1_SEQUENCE (TS_MESSAGE_IMPRINT) = { +GLOBAL_REMOVE_IF_UNREFERENCED +DECLARE_ASN1_FUNCTIONS ( + TS_MESSAGE_IMPRINT + ) +ASN1_SEQUENCE (TS_MESSAGE_IMPRINT) = +{ ASN1_SIMPLE (TS_MESSAGE_IMPRINT, HashAlgorithm, X509_ALGOR), ASN1_SIMPLE (TS_MESSAGE_IMPRINT, HashedMessage, ASN1_OCTET_STRING) -} ASN1_SEQUENCE_END (TS_MESSAGE_IMPRINT) +} + +ASN1_SEQUENCE_END (TS_MESSAGE_IMPRINT) IMPLEMENT_ASN1_FUNCTIONS (TS_MESSAGE_IMPRINT) /// @@ -68,12 +74,18 @@ typedef struct { // // ASN.1 Functions for TS_ACCURACY // -DECLARE_ASN1_FUNCTIONS (TS_ACCURACY) -ASN1_SEQUENCE (TS_ACCURACY) = { +GLOBAL_REMOVE_IF_UNREFERENCED +DECLARE_ASN1_FUNCTIONS ( + TS_ACCURACY + ) +ASN1_SEQUENCE (TS_ACCURACY) = +{ ASN1_OPT (TS_ACCURACY, Seconds, ASN1_INTEGER), ASN1_IMP_OPT (TS_ACCURACY, Millis, ASN1_INTEGER, 0), ASN1_IMP_OPT (TS_ACCURACY, Micros, ASN1_INTEGER, 1) -} ASN1_SEQUENCE_END (TS_ACCURACY) +} + +ASN1_SEQUENCE_END (TS_ACCURACY) IMPLEMENT_ASN1_FUNCTIONS (TS_ACCURACY) /// @@ -114,8 +126,12 @@ typedef struct { // // ASN.1 Functions for TS_TST_INFO // -DECLARE_ASN1_FUNCTIONS (TS_TST_INFO) -ASN1_SEQUENCE (TS_TST_INFO) = { +GLOBAL_REMOVE_IF_UNREFERENCED +DECLARE_ASN1_FUNCTIONS ( + TS_TST_INFO + ) +ASN1_SEQUENCE (TS_TST_INFO) = +{ ASN1_SIMPLE (TS_TST_INFO, Version, ASN1_INTEGER), ASN1_SIMPLE (TS_TST_INFO, Policy, ASN1_OBJECT), ASN1_SIMPLE (TS_TST_INFO, MessageImprint, TS_MESSAGE_IMPRINT), @@ -126,7 +142,9 @@ ASN1_SEQUENCE (TS_TST_INFO) = { ASN1_OPT (TS_TST_INFO, Nonce, ASN1_INTEGER), ASN1_EXP_OPT (TS_TST_INFO, Tsa, GENERAL_NAME, 0), ASN1_IMP_SEQUENCE_OF_OPT (TS_TST_INFO, Extensions, X509_EXTENSION, 1) -} ASN1_SEQUENCE_END (TS_TST_INFO) +} + +ASN1_SEQUENCE_END (TS_TST_INFO) IMPLEMENT_ASN1_FUNCTIONS (TS_TST_INFO) /** @@ -139,8 +157,8 @@ IMPLEMENT_ASN1_FUNCTIONS (TS_TST_INFO) @retval FALSE Invalid parameters. **/ +STATIC BOOLEAN -EFIAPI ConvertAsn1TimeToEfiTime ( IN ASN1_TIME *Asn1Time, OUT EFI_TIME *EfiTime @@ -222,8 +240,8 @@ ConvertAsn1TimeToEfiTime ( @retval FALSE Invalid TimeStamp Token Information. **/ +STATIC BOOLEAN -EFIAPI CheckTSTInfo ( IN CONST TS_TST_INFO *TstInfo, IN CONST UINT8 *TimestampedData, @@ -352,8 +370,8 @@ CheckTSTInfo ( @retval FALSE Invalid timestamp token. **/ +STATIC BOOLEAN -EFIAPI TimestampTokenVerify ( IN CONST UINT8 *TSToken, IN UINTN TokenSize, -- 2.37.1.windows.1