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 D2585941A2B for ; Thu, 30 Nov 2023 19:32:53 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=mIw4JZVF1OlPy3Gs+ETrYZC+5OA/zNBkXXU4ydWMDDo=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1701372772; v=1; b=FL62zklknm2RAk0Gy1RFXanWOld08p3zcrMwL4i815VOLrJCgEJ2+8GC3kwenqjEYkrWfHzF nzCqk6LZpwD8IlVwojBgWQhHdKumPHSEtgGGQpWn80eYmS83tn3lwprlNkjJdA7chX9ZvCinTQm TcfA36uLwx+xvbxbW96wdIkc= X-Received: by 127.0.0.2 with SMTP id JXrNYY7687511xiFf0A4YHYg; Thu, 30 Nov 2023 11:32:52 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.3154.1701372771787352365 for ; Thu, 30 Nov 2023 11:32:52 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="381574" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="381574" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 11:32:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="835504881" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="835504881" X-Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga008.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 30 Nov 2023 11:32:43 -0800 X-Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 30 Nov 2023 11:32:43 -0800 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Thu, 30 Nov 2023 11:32:42 -0800 X-Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Thu, 30 Nov 2023 11:32:41 -0800 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Thu, 30 Nov 2023 11:32:41 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A2Ucgew/50rNrQReZ1t14HQ9++w6lVVTMWC04qZfliJ+UkuH630sjmEbshvgqPMPg/CuuRBmXUVWXlcECM4/Ex+d6UqvOtElcjP8Ad1vsMwHGWMbmvhf/cFvihVLMYFbYa2mr8uDD2xy8QB3YYg9BcYiXDVwjhRskNGavNRZwiti7x2uqVFQ+brM4XcHKcvNOVlnqANfjivVKbJrMXki2ydvo3JKpjgc7jMvECIE/wmUMQuHI/jwo/9yPtGuPqk4w2mBF5kWszd2xJjNBfw5FQpTPmA1KmtU38J0FNR96tGjQxH8DhVpmYt2ZIbDXv3FFDqBUe2Eb4LnL7rEYn3iAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UeLh67dgNQGRYH3JH9lPsZh8BACXBaOsQRbPsEg+W78=; b=Mu/EYQa5IFZpjbWJOYJdin7VN8N2Oz+5EBGOJtvUXo0veit1WnveX5AVkeXONKdiAtkHn/fdyAMgNnUiA6HjZcm/mV6IDVmSru2euMNt1HOWDMlvJyPKBLOIOmKagrCaNsZwkAUWa7wmTgb4KNB61zWPiEIx1HMeWSxnsIuLxZgz7ddPfIoBmpzQ26g/xcGfPy4bGZnIc8klv1FFMhqbFyez2AFjtZfDGmHNyVPBVTwpzZIZiBuR5SDZG0g7wcLjbAPjKva1oLzyKdlVWfS5ea3H/ZOKK365c1Y0fkroCCT6kMQ44hZWMDPlHb8ILiMehH0MJtArdvCf+URK+/5r7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from CO1PR11MB4929.namprd11.prod.outlook.com (2603:10b6:303:6d::19) by SA3PR11MB8024.namprd11.prod.outlook.com (2603:10b6:806:300::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Thu, 30 Nov 2023 19:32:38 +0000 X-Received: from CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::4382:5b03:f13:88ff]) by CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::4382:5b03:f13:88ff%5]) with mapi id 15.20.7046.023; Thu, 30 Nov 2023 19:32:38 +0000 From: "Michael D Kinney" To: Pedro Falcato , "devel@edk2.groups.io" CC: Savva Mitrofanov , "Gao, Liming" , "Liu, Zhiguang" , "Kinney, Michael D" Subject: Re: [edk2-devel] [PATCH 1/2] MdePkg/BaseLib: Fix CRC16-ANSI calculation Thread-Topic: [PATCH 1/2] MdePkg/BaseLib: Fix CRC16-ANSI calculation Thread-Index: AQHaIzdtuilYKCLtz0qDjaBmsAONrbCTQX3Q Date: Thu, 30 Nov 2023 19:32:38 +0000 Message-ID: References: <20231130024611.67135-1-pedro.falcato@gmail.com> <20231130024611.67135-2-pedro.falcato@gmail.com> In-Reply-To: <20231130024611.67135-2-pedro.falcato@gmail.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CO1PR11MB4929:EE_|SA3PR11MB8024:EE_ x-ms-office365-filtering-correlation-id: 79f53a8f-e891-4ce4-b07b-08dbf1db1c80 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: P9jZ4cefR5nbc3t+JdzXmRBDpYd868JYyxv0y+PCMxIbSehUdSAoUKpszO1R9E/THmpC8F5M4AB441ik5TlsQVECw2DM1ug6KvDBl+UZChK0UerfQEp7yi6XHmGvJ2Zga+7GjTjf3Dntz3HKkA/WLfdo8Fonhba3ib1r5QgBhbsQe03rwPYo6X1wUY0TdYt8zlTKEyGI4xRIFwgM9PqP7VU5DjF0SkteV0pmvy0CLv+HHGNN6tmfPVmsTE3ro/aMoJrcwGICxekRBbwhP5IDlJc9y5ToUYVGuO7DsdYBVjyd/LpXiRFNUGVy7OGixxQVxbTBJ3yAOh0l2nXw1lXNwitcuh0jYtc2IJv4dxsRo3oAwQ7jWYlzi41V2J8qqc2qt+28n/9CNnp0rgsw+DhldCtxI1hE5aih5DXfRNHgIxY2GKZhJECoUgb6/GVDjyLI8AZJTvk2QpIQkWSOEvAW6dezT8sd2FqcsSNnldiVn2pMiY1HABuSiqvjeK1aJFPlsPy8uygqda/Uixv0KdqfbMdbEti2BODR1kUqVQWAY+LgGiaC6jPenCzpwyOP6GLo315es4EZ2uvF/DtgCtoHTCpzNtBk8IQZAS1xI+nhuRE= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?JoWtHxlV8dv+nO/iVDf8f2hW+AqYB+z/sDcwz4oZi0/ytgX889q4EyDISRXN?= =?us-ascii?Q?dfpcemkCzul89kp+6ZwBdqiECOdVrgops3cSAJq/Kmv7BnmKycLGVEchJyGl?= =?us-ascii?Q?qEAmVB00u4AkN4qYJas7hdvaxzJLlaHZDrniT2zg/1mnsUiewqOQ4Ki6ecZg?= =?us-ascii?Q?rPbkWdF+EhOpV3jQHHQ8U4jvrL8UgXx0/OFzIz4zgfqmU9FrG/EDMIVZzdMH?= =?us-ascii?Q?UWKlYqiMPK5GKXM+N9y/N0vb6JIBorTmWPACMrMKZ+bJ3ZrpryfxwQAyd99g?= =?us-ascii?Q?JkcUqXISRdsFk5kd2m/Zzwa/TWrL5fqmZxNRjR9v9kzy66c5bMwhud1ljTQ9?= =?us-ascii?Q?lN6+B6+acJz6PeEeOlorV+WTIPEyB7GfU1/QmvyItqHlqExuiGruXndTFz1m?= =?us-ascii?Q?8gees2T4ekK70ZstgdXlv6kU2l14t5yjUURsgNQ/dvrtas4mDO93sMGpV4Af?= =?us-ascii?Q?z5YYSgdg2uHBMprqTqakqmVYMG5cKL898w3ZBvZbZ3V4y0JeIM55EaoRX3jd?= =?us-ascii?Q?s7st9vYP/ldznS5jqHUQ7IRmugnvFYLI9BRZufbhPmbAQoiQ0kr2a3k3r2EU?= =?us-ascii?Q?TQrLCT+I9Kxcwn5NTrVWhRhE4wyrHfadliMBtgvlkXcjqYZ/8St35skLBmmE?= =?us-ascii?Q?dz7TH5KfXPnU8cF9kKfXLoV64sQa3RQtpfRFgm3Hf/LB84i/aR/vBAfuS49S?= =?us-ascii?Q?FiFawWkrSw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+xBKkrzdbnA050BRJ9AHBwNt71?= =?us-ascii?Q?NQ=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4929.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 79f53a8f-e891-4ce4-b07b-08dbf1db1c80 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Nov 2023 19:32:38.1271 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: xhm9FRGHTOfmZTupzsUJBm+p0ZxOHgDYbdWynRtjsAc9QlRgR9YMwKI+jQyvWx6MsMekX5c5WYlJiFhXqqpIB6XP9uvOtjBU/i6s4S1r3fA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR11MB8024 X-OriginatorOrg: intel.com 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,michael.d.kinney@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 6ReCCIJArbcCPmTepdDANIQZx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" 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=FL62zklk; 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 Reviewed-by: Michael D Kinney > -----Original Message----- > From: Pedro Falcato > Sent: Wednesday, November 29, 2023 6:46 PM > To: devel@edk2.groups.io > Cc: Savva Mitrofanov ; Pedro Falcato > ; Gao, Liming ; Kinney= , > Michael D ; Liu, Zhiguang > > Subject: [PATCH 1/2] MdePkg/BaseLib: Fix CRC16-ANSI calculation >=20 > The current CalculateCrc16Ansi implementation does the following: > 1) Invert the passed checksum > 2) Calculate the new checksum by going through data and using the > lookup table > 3) Invert it back again >=20 > This emulated my design for CalculateCrc32c, where 0 is > passed as the initial checksum, and it inverts in the end. > However, CRC16 does not invert the checksum on input and output. > So this is incorrect. >=20 > Fix the problem by not inverting input checksums nor output checksums. > Callers should now pass CRC16ANSI_INIT as the initial value instead of > "0". This is a breaking change. >=20 > This problem was found out-of-list when older ext4 filesystems > (that use crc16 checksums) failed to mount with "corruption". >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4609 > Signed-off-by: Pedro Falcato > Cc: Liming Gao > Cc: Michael D Kinney > Cc: Zhiguang Liu > --- > MdePkg/Include/Library/BaseLib.h | 5 +++++ > MdePkg/Library/BaseLib/CheckSum.c | 4 ++-- > 2 files changed, 7 insertions(+), 2 deletions(-) >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 5d7067ee854e..728e89d2bf44 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -4599,6 +4599,11 @@ CalculateCrc16Ansi ( > IN UINT16 InitialValue > ); >=20 > +// > +// Initial value for the CRC16-ANSI algorithm, when no prior checksum ha= s > been calculated. > +// > +#define CRC16ANSI_INIT 0xffff > + > /** > Calculates the CRC32c checksum of the given buffer. >=20 > diff --git a/MdePkg/Library/BaseLib/CheckSum.c > b/MdePkg/Library/BaseLib/CheckSum.c > index b6a076573191..57d324c82b22 100644 > --- a/MdePkg/Library/BaseLib/CheckSum.c > +++ b/MdePkg/Library/BaseLib/CheckSum.c > @@ -678,13 +678,13 @@ CalculateCrc16Ansi ( >=20 > Buf =3D Buffer; >=20 > - Crc =3D ~InitialValue; > + Crc =3D InitialValue; >=20 > while (Length-- !=3D 0) { > Crc =3D mCrc16LookupTable[(Crc & 0xFF) ^ *(Buf++)] ^ (Crc >> 8); > } >=20 > - return ~Crc; > + return Crc; > } >=20 > GLOBAL_REMOVE_IF_UNREFERENCED STATIC CONST UINT32 mCrc32cLookupTable[25= 6] > =3D { > -- > 2.43.0 -=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 (#111912): https://edk2.groups.io/g/devel/message/111912 Mute This Topic: https://groups.io/mt/102886793/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-