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 724FE941F19 for ; Mon, 18 Mar 2024 23:17:46 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=BN33KfJJ9Jgd6HkR8uzm2sFt2UPQdqBkfqBqFO6xSWU=; c=relaxed/simple; d=groups.io; h=From:To:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Feedback-ID:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1710803865; v=1; b=Y1KHNLkTlth2wED19sQtfV7eSIpakh3UNdfEwORup5jDSpnPg8hofZAYcd6Zar4wC/JG9nSw xe0V8s99JLpOYu75swgiCjicUQjacKJBV93gmvAufCJrYfusS0B7SSUTeX4G4WF9DPCPRlnDFd4 a2wzidJoqDo/2agXLBOGgpwyddF0tTm8jVIBUwah6MZqTQbEalPkbMd2w1Mqa5wzWoEVgC3iYQf vsWg2jzmoPxoMyCLlcLFIJdA7k8S6q6x4D0TXg2ZCBfU1aAs5iyIMmONEhn6xsIrzlXmWZLoyLR laTXcTbtK3ek5Xwtan+RKKUKewYpJiDMfL+14Sspj567g== X-Received: by 127.0.0.2 with SMTP id WXmwYY7687511x6tSJAQcRSd; Mon, 18 Mar 2024 16:17:45 -0700 X-Received: from a2i971.smtp2go.com (a2i971.smtp2go.com [103.47.207.203]) by mx.groups.io with SMTP id smtpd.web10.9989.1710465380410779084 for ; Thu, 14 Mar 2024 18:16:20 -0700 X-Received: from [10.45.79.170] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1rkwBH-gL4ToM-Mz for devel@edk2.groups.io; Fri, 15 Mar 2024 01:16:19 +0000 X-Received: from [10.90.237.184] (helo=gem-name-lb-02.localdomain) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96.1-S2G) (envelope-from ) id 1rkwBH-bMNhSV-0m for devel@edk2.groups.io; Fri, 15 Mar 2024 01:16:19 +0000 From: "Chris Ruffin via groups.io" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH 3/3] CryptoPkg/BaseCryptLibUnitTest: add unit test functions Date: Thu, 14 Mar 2024 21:16:13 -0400 Message-ID: <20240315011613.1512-3-cruffin@millcore.com> In-Reply-To: <20240315011613.1512-1-cruffin@millcore.com> References: <20240315011613.1512-1-cruffin@millcore.com> MIME-Version: 1.0 X-Smtpcorp-Track: 1rkwUHPuNhSV0X.82Fi9P6LKLzJd Feedback-ID: 401384m:401384aZcXcRg:401384sTbmcJQvr6 X-Report-Abuse: Please forward a copy of this message, including all headers, to 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 Resent-Date: Mon, 18 Mar 2024 16:17:44 -0700 Reply-To: devel@edk2.groups.io,cruffin@millcore.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: iGJcfWjG71LGyBaBNduarH31x7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=Y1KHNLkT; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Chris Ruffin Add unit test functions: TestVerifyPkcs1v2Decrypt() TestVerifyTestRsaOaepEncrypt() TestVerifyTestRsaOaepDecrypt() Signed-off-by: Chris Ruffin Cc: Jiewen Yao Cc: Yi Li Cc: Wenxing Hou --- .../Library/BaseCryptLib/OaepEncryptTests.c | 184 +++++++++++++++++- 1 file changed, 182 insertions(+), 2 deletions(-) diff --git a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/OaepEncryptTests.= c b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/OaepEncryptTests.c index 22a4ea7e46..2b5c6d04da 100644 --- a/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/OaepEncryptTests.c +++ b/CryptoPkg/Test/UnitTest/Library/BaseCryptLib/OaepEncryptTests.c @@ -153,9 +153,42 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 PrivateKey[= ] =3D { 0x86, 0x10, 0x09, 0x88, 0x6C, 0x35, 0x60, 0xF2,=0D };=0D =0D +//=0D +// Public Modulus of RSA Key=0D +//=0D +GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 RsaN[] =3D {=0D + 0xBB, 0xF8, 0x2F, 0x09, 0x06, 0x82, 0xCE, 0x9C, 0x23, 0x38, 0xAC, 0x2B, = 0x9D, 0xA8, 0x71, 0xF7,=0D + 0x36, 0x8D, 0x07, 0xEE, 0xD4, 0x10, 0x43, 0xA4, 0x40, 0xD6, 0xB6, 0xF0, = 0x74, 0x54, 0xF5, 0x1F,=0D + 0xB8, 0xDF, 0xBA, 0xAF, 0x03, 0x5C, 0x02, 0xAB, 0x61, 0xEA, 0x48, 0xCE, = 0xEB, 0x6F, 0xCD, 0x48,=0D + 0x76, 0xED, 0x52, 0x0D, 0x60, 0xE1, 0xEC, 0x46, 0x19, 0x71, 0x9D, 0x8A, = 0x5B, 0x8B, 0x80, 0x7F,=0D + 0xAF, 0xB8, 0xE0, 0xA3, 0xDF, 0xC7, 0x37, 0x72, 0x3E, 0xE6, 0xB4, 0xB7, = 0xD9, 0x3A, 0x25, 0x84,=0D + 0xEE, 0x6A, 0x64, 0x9D, 0x06, 0x09, 0x53, 0x74, 0x88, 0x34, 0xB2, 0x45, = 0x45, 0x98, 0x39, 0x4E,=0D + 0xE0, 0xAA, 0xB1, 0x2D, 0x7B, 0x61, 0xA5, 0x1F, 0x52, 0x7A, 0x9A, 0x41, = 0xF6, 0xC1, 0x68, 0x7F,=0D + 0xE2, 0x53, 0x72, 0x98, 0xCA, 0x2A, 0x8F, 0x59, 0x46, 0xF8, 0xE5, 0xFD, = 0x09, 0x1D, 0xBD, 0xCB=0D +};=0D +=0D +//=0D +// Public Exponent of RSA Key=0D +//=0D +GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 RsaE[] =3D { 0x11 };=0D +=0D +//=0D +// Private Exponent of RSA Key=0D +//=0D +GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT8 RsaD[] =3D {=0D + 0xA5, 0xDA, 0xFC, 0x53, 0x41, 0xFA, 0xF2, 0x89, 0xC4, 0xB9, 0x88, 0xDB, = 0x30, 0xC1, 0xCD, 0xF8,=0D + 0x3F, 0x31, 0x25, 0x1E, 0x06, 0x68, 0xB4, 0x27, 0x84, 0x81, 0x38, 0x01, = 0x57, 0x96, 0x41, 0xB2,=0D + 0x94, 0x10, 0xB3, 0xC7, 0x99, 0x8D, 0x6B, 0xC4, 0x65, 0x74, 0x5E, 0x5C, = 0x39, 0x26, 0x69, 0xD6,=0D + 0x87, 0x0D, 0xA2, 0xC0, 0x82, 0xA9, 0x39, 0xE3, 0x7F, 0xDC, 0xB8, 0x2E, = 0xC9, 0x3E, 0xDA, 0xC9,=0D + 0x7F, 0xF3, 0xAD, 0x59, 0x50, 0xAC, 0xCF, 0xBC, 0x11, 0x1C, 0x76, 0xF1, = 0xA9, 0x52, 0x94, 0x44,=0D + 0xE5, 0x6A, 0xAF, 0x68, 0xC5, 0x6C, 0x09, 0x2C, 0xD3, 0x8D, 0xC3, 0xBE, = 0xF5, 0xD2, 0x0A, 0x93,=0D + 0x99, 0x26, 0xED, 0x4F, 0x74, 0xA1, 0x3E, 0xDD, 0xFB, 0xE1, 0xA1, 0xCE, = 0xCC, 0x48, 0x94, 0xAF,=0D + 0x94, 0x28, 0xC2, 0xB7, 0xB8, 0x88, 0x3F, 0xE4, 0x46, 0x3A, 0x4B, 0xC8, = 0x5B, 0x1C, 0xB3, 0xC1=0D +};=0D +=0D UNIT_TEST_STATUS=0D EFIAPI=0D -TestVerifyOaepEncrypt (=0D +TestVerifyPkcs1v2Encrypt (=0D IN UNIT_TEST_CONTEXT Context=0D )=0D {=0D @@ -296,11 +329,158 @@ TestVerifyOaepEncrypt ( return UNIT_TEST_PASSED;=0D }=0D =0D +UNIT_TEST_STATUS=0D +EFIAPI=0D +TestVerifyPkcs1v2Decrypt (=0D + IN UNIT_TEST_CONTEXT Context=0D + )=0D +{=0D + BOOLEAN Status;=0D + UINT8 PlaintextBuffer[4];=0D + UINT8 *EncryptedBuffer;=0D + UINTN EncryptedBufferSize;=0D + UINT8 *DecryptedBuffer;=0D + UINTN DecryptedBufferSize;=0D +=0D + // Create a file and add content '123' in it=0D + PlaintextBuffer[0] =3D '1';=0D + PlaintextBuffer[1] =3D '2';=0D + PlaintextBuffer[2] =3D '3';=0D + PlaintextBuffer[3] =3D 0;=0D +=0D + Status =3D Pkcs1v2Encrypt (=0D + SelfTestCert,=0D + (UINTN)sizeof (SelfTestCert),=0D + PlaintextBuffer,=0D + (UINTN)sizeof (PlaintextBuffer),=0D + NULL,=0D + 0,=0D + &EncryptedBuffer,=0D + (UINTN *)&EncryptedBufferSize=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + Status =3D Pkcs1v2Decrypt (=0D + PrivateKey,=0D + (UINTN)sizeof (PrivateKey),=0D + EncryptedBuffer,=0D + EncryptedBufferSize,=0D + &DecryptedBuffer,=0D + (UINTN *)&DecryptedBufferSize=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + UT_ASSERT_TRUE ((CompareMem (PlaintextBuffer, DecryptedBuffer, Decrypted= BufferSize) =3D=3D 0));=0D +=0D + return UNIT_TEST_PASSED;=0D +}=0D +=0D +UNIT_TEST_STATUS=0D +EFIAPI=0D +TestVerifyRsaOaepEncrypt (=0D + IN UNIT_TEST_CONTEXT Context=0D + )=0D +{=0D + BOOLEAN Status;=0D + UINT8 PlaintextBuffer[4];=0D + UINT8 *EncryptedBuffer;=0D + UINTN EncryptedBufferSize;=0D + VOID *RsaContext =3D NULL;=0D +=0D + // Create a file and add content '123' in it=0D + PlaintextBuffer[0] =3D '1';=0D + PlaintextBuffer[1] =3D '2';=0D + PlaintextBuffer[2] =3D '3';=0D + PlaintextBuffer[3] =3D 0;=0D +=0D + RsaContext =3D RsaNew ();=0D + UT_ASSERT_FALSE (RsaContext =3D=3D NULL);=0D +=0D + Status =3D RsaSetKey (RsaContext, RsaKeyN, RsaN, sizeof (RsaN));=0D + UT_ASSERT_TRUE (Status);=0D +=0D + Status =3D RsaSetKey (RsaContext, RsaKeyE, RsaE, sizeof (RsaE));=0D + UT_ASSERT_TRUE (Status);=0D +=0D + Status =3D RsaOaepEncrypt (=0D + RsaContext,=0D + PlaintextBuffer,=0D + sizeof (PlaintextBuffer),=0D + NULL,=0D + 0,=0D + &EncryptedBuffer,=0D + &EncryptedBufferSize=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + return UNIT_TEST_PASSED;=0D +}=0D +=0D +UNIT_TEST_STATUS=0D +EFIAPI=0D +TestVerifyRsaOaepDecrypt (=0D + IN UNIT_TEST_CONTEXT Context=0D + )=0D +{=0D + BOOLEAN Status;=0D + UINT8 PlaintextBuffer[4];=0D + UINT8 *EncryptedBuffer;=0D + UINTN EncryptedBufferSize;=0D + UINT8 *DecryptedBuffer;=0D + UINTN DecryptedBufferSize;=0D + VOID *RsaContext =3D NULL;=0D +=0D + // Create a file and add content '123' in it=0D + PlaintextBuffer[0] =3D '1';=0D + PlaintextBuffer[1] =3D '2';=0D + PlaintextBuffer[2] =3D '3';=0D + PlaintextBuffer[3] =3D 0;=0D +=0D + RsaContext =3D RsaNew ();=0D + UT_ASSERT_FALSE (RsaContext =3D=3D NULL);=0D +=0D + Status =3D RsaSetKey (RsaContext, RsaKeyN, RsaN, sizeof (RsaN));=0D + UT_ASSERT_TRUE (Status);=0D +=0D + Status =3D RsaSetKey (RsaContext, RsaKeyE, RsaE, sizeof (RsaE));=0D + UT_ASSERT_TRUE (Status);=0D +=0D + Status =3D RsaOaepEncrypt (=0D + RsaContext,=0D + PlaintextBuffer,=0D + sizeof (PlaintextBuffer),=0D + NULL,=0D + 0,=0D + &EncryptedBuffer,=0D + &EncryptedBufferSize=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + Status =3D RsaSetKey (RsaContext, RsaKeyD, RsaD, sizeof (RsaD));=0D + UT_ASSERT_TRUE (Status);=0D +=0D + Status =3D RsaOaepDecrypt (=0D + RsaContext,=0D + EncryptedBuffer,=0D + EncryptedBufferSize,=0D + &DecryptedBuffer,=0D + &DecryptedBufferSize=0D + );=0D + UT_ASSERT_TRUE (Status);=0D +=0D + UT_ASSERT_TRUE ((CompareMem (PlaintextBuffer, DecryptedBuffer, Decrypted= BufferSize) =3D=3D 0));=0D +=0D + return UNIT_TEST_PASSED;=0D +}=0D +=0D TEST_DESC mOaepTest[] =3D {=0D //=0D // -----Description--------------------------------------Class----------= ------------Function-----------------Pre---Post--Context=0D //=0D - { "TestVerifyOaepEncrypt()", "CryptoPkg.BaseCryptLib.Pkcs1v2Encrypt", Te= stVerifyOaepEncrypt, NULL, NULL, NULL },=0D + { "TestVerifyPkcs1v2Encrypt()", "CryptoPkg.BaseCryptLib.Pkcs1v2Encrypt",= TestVerifyPkcs1v2Encrypt, NULL, NULL, NULL },=0D + { "TestVerifyPkcs1v2Decrypt()", "CryptoPkg.BaseCryptLib.Pkcs1v2Decrypt",= TestVerifyPkcs1v2Decrypt, NULL, NULL, NULL },=0D + { "TestVerifyRsaOaepEncrypt()", "CryptoPkg.BaseCryptLib.RsaOaepEncrypt",= TestVerifyRsaOaepEncrypt, NULL, NULL, NULL },=0D + { "TestVerifyRsaOaepDecrypt()", "CryptoPkg.BaseCryptLib.RsaOaepDecrypt",= TestVerifyRsaOaepDecrypt, NULL, NULL, NULL },=0D };=0D =0D UINTN mOaepTestNum =3D ARRAY_SIZE (mOaepTest);=0D --=20 2.44.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116863): https://edk2.groups.io/g/devel/message/116863 Mute This Topic: https://groups.io/mt/105014759/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-