From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web08.8432.1665500682958145987 for ; Tue, 11 Oct 2022 08:04:43 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Uaj9YBVN; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1665500683; x=1697036683; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ErTF5Ei8O7wltfZxyg2LN/k/u0EpFoHHr8cl4VRFtGU=; b=Uaj9YBVNQ4L5GYKTdcijuN0mz+tsa4HzCFbHbnu6jdmgxbKVFcR5vCi9 r1/tEIXkSay/beDY/ylVvwyst44N/oKzflNJhRHewcC8FREO+8uPT4/oN RQlehOYuwC49huJgb3m5OOpDiYrN0bmYjP4lPhjjHwYOx3gIkucNG0fPQ UzxdsVwv2hp2aBEczBEhf/LCY2r55U1rxxEfPzmwqr8cHtcjwcIFkj/w3 COBRun9l3fYAdzNqULyOIweA5X/CAaCzjY/IbZvCBK3ci/Gg6PUlEX1+A fHgnVIHxyXObDggFrdG3K4dVtP1NzAYjlGcUaDTVJvfvAb+QE8qRRUXb/ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10497"; a="305581045" X-IronPort-AV: E=Sophos;i="5.95,176,1661842800"; d="scan'208";a="305581045" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2022 08:04:07 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10497"; a="604172817" X-IronPort-AV: E=Sophos;i="5.95,176,1661842800"; d="scan'208";a="604172817" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.79.249]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2022 08:04:07 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Xiaoyu Lu , Guomin Jiang , Christopher Zurcher Subject: [Patch 04/12] CryptoPkg/Test/UnitTest/Library/BaseCryptLib: Unit test fixes Date: Tue, 11 Oct 2022 08:03:50 -0700 Message-Id: <20221011150358.1332-5-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20221011150358.1332-1-michael.d.kinney@intel.com> References: <20221011150358.1332-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit * Update ImageTimeStampTest to return UNIT_TEST_PASSED instead of Status. On success Status is TRUE(1), which was returning a unit test status of UNIT_TEST_ERROR_PREREQUISITE_NOT_MET. * Update HmacTests to use the *Free() service from the HMAC family instead of FreePool(). Using FreePool() generates ASSERT() because the context being freed was not allocated using AllocatePool(). Cc: Jiewen Yao Cc: Jian J Wang Cc: Xiaoyu Lu Cc: Guomin Jiang Cc: Christopher Zurcher Signed-off-by: Michael D Kinney --- .../UnitTest/Library/BaseCryptLib/HmacTests.c | 17 ++++++++++++----- .../UnitTest/Library/BaseCryptLib/TSTests.c | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/HmacTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/HmacTests.c index 9c5b39410d0f..b347cb4cb4f8 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/HmacTests.c +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/HmacTests.c @@ -87,6 +87,12 @@ VOID * VOID ); +typedef +VOID +(EFIAPI *EFI_HMAC_FREE)( + IN VOID *HashContext + ); + typedef BOOLEAN (EFIAPI *EFI_HMAC_INIT)( @@ -113,6 +119,7 @@ BOOLEAN typedef struct { UINT32 DigestSize; EFI_HMAC_NEW HmacNew; + EFI_HMAC_FREE HmacFree; EFI_HMAC_INIT HmacInit; EFI_HMAC_UPDATE HmacUpdate; EFI_HMAC_FINAL HmacFinal; @@ -123,10 +130,10 @@ typedef struct { } HMAC_TEST_CONTEXT; // These functions have been deprecated but they've been left commented out for future reference -// HMAC_TEST_CONTEXT mHmacMd5TestCtx = {MD5_DIGEST_SIZE, HmacMd5New, HmacMd5SetKey, HmacMd5Update, HmacMd5Final, HmacMd5Key, sizeof(HmacMd5Key), HmacMd5Digest}; -// HMAC_TEST_CONTEXT mHmacSha1TestCtx = {SHA1_DIGEST_SIZE, HmacSha1New, HmacSha1SetKey, HmacSha1Update, HmacSha1Final, HmacSha1Key, sizeof(HmacSha1Key), HmacSha1Digest}; -HMAC_TEST_CONTEXT mHmacSha256TestCtx = { SHA256_DIGEST_SIZE, HmacSha256New, HmacSha256SetKey, HmacSha256Update, HmacSha256Final, HmacSha256Key, sizeof (HmacSha256Key), HmacSha256Digest }; -HMAC_TEST_CONTEXT mHmacSha384TestCtx = { SHA384_DIGEST_SIZE, HmacSha384New, HmacSha384SetKey, HmacSha384Update, HmacSha384Final, HmacSha384Key, sizeof (HmacSha384Key), HmacSha384Digest }; +// HMAC_TEST_CONTEXT mHmacMd5TestCtx = {MD5_DIGEST_SIZE, HmacMd5New, HmacMd5Free, HmacMd5SetKey, HmacMd5Update, HmacMd5Final, HmacMd5Key, sizeof(HmacMd5Key), HmacMd5Digest}; +// HMAC_TEST_CONTEXT mHmacSha1TestCtx = {SHA1_DIGEST_SIZE, HmacSha1New, HmacSha1Free, HmacSha1SetKey, HmacSha1Update, HmacSha1Final, HmacSha1Key, sizeof(HmacSha1Key), HmacSha1Digest}; +HMAC_TEST_CONTEXT mHmacSha256TestCtx = { SHA256_DIGEST_SIZE, HmacSha256New, HmacSha256Free, HmacSha256SetKey, HmacSha256Update, HmacSha256Final, HmacSha256Key, sizeof (HmacSha256Key), HmacSha256Digest }; +HMAC_TEST_CONTEXT mHmacSha384TestCtx = { SHA384_DIGEST_SIZE, HmacSha384New, HmacSha384Free, HmacSha384SetKey, HmacSha384Update, HmacSha384Final, HmacSha384Key, sizeof (HmacSha384Key), HmacSha384Digest }; UNIT_TEST_STATUS EFIAPI @@ -155,7 +162,7 @@ TestVerifyHmacCleanUp ( HmacTestContext = Context; if (HmacTestContext->HmacCtx != NULL) { - FreePool (HmacTestContext->HmacCtx); + HmacTestContext->HmacFree (HmacTestContext->HmacCtx); } } diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TSTests.c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TSTests.c index 225ec3e59746..226e57e66f04 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TSTests.c +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TSTests.c @@ -322,7 +322,7 @@ TestVerifyImageTimestampVerify ( UT_ASSERT_EQUAL (SigningTime.Minute, 50); UT_ASSERT_EQUAL (SigningTime.Second, 3); - return Status; + return UNIT_TEST_PASSED; } TEST_DESC mImageTimestampTest[] = { -- 2.37.1.windows.1