From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CB8B445BC0; Thu, 24 Oct 2024 14:55:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 944CE40281; Thu, 24 Oct 2024 14:55:02 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 6A0E64003C; Thu, 24 Oct 2024 14:55:01 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 3BF8A2027D; Thu, 24 Oct 2024 14:55:01 +0200 (CEST) Content-class: urn:content-classes:message Subject: RE: [PATCH 4/6] crypto/openssl: fix 3DES-CTR with big endian CPUs MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Thu, 24 Oct 2024 14:54:59 +0200 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9F816@smartserver.smartshare.dk> X-MimeOLE: Produced By Microsoft Exchange V6.5 In-Reply-To: <20241024120535.2722316-5-david.marchand@redhat.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH 4/6] crypto/openssl: fix 3DES-CTR with big endian CPUs Thread-Index: AdsmDSArmqSp5wh8RrO55GHJDFnDfwAAhRBA References: <20241024120535.2722316-1-david.marchand@redhat.com> <20241024120535.2722316-5-david.marchand@redhat.com> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "David Marchand" , Cc: , , , , , "Kai Ji" , "Slawomir Mrozowicz" , "Tomasz Kulasek" , "Daniel Mrzyglod" , "Pablo de Lara" , "Michal Kobylinski" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: David Marchand [mailto:david.marchand@redhat.com] > Sent: Thursday, 24 October 2024 14.06 >=20 > Caught by code review. >=20 > Don't byte swap unconditionally (assuming that CPU is little endian is > wrong). Instead, convert from big endian to cpu and vice versa. Yes looks like a bug. I wonder if this PMD has more similar bugs... grep bswap drivers/crypto/openssl/* says no. > @@ -110,9 +111,9 @@ ctr_inc(uint8_t *ctr) > { > uint64_t *ctr64 =3D (uint64_t *)ctr; >=20 > - *ctr64 =3D __builtin_bswap64(*ctr64); > + *ctr64 =3D rte_be_to_cpu_64(*ctr64); > (*ctr64)++; > - *ctr64 =3D __builtin_bswap64(*ctr64); > + *ctr64 =3D rte_cpu_to_be_64(*ctr64); > } But that's not all. There may be an alignment bug too; the way it is used in = process_openssl_cipher_des3ctr(), "ctr" is not guaranteed to be uint64_t = aligned. How about this instead: ctr_inc(void *ctr) { uint64_t ctr64 =3D rte_be_to_cpu_64(*(unaligned_uint64_t *)ctr); ctr64++; *(unaligned_uint64_t *)ctr =3D rte_cpu_to_be_64(ctr64); } Or this: ctr_inc(void *ctr) { uint64_t ctr64; memcpy(&ctr64, ctr, sizeof(uint64_t)); ctr64 =3D rte_be_to_cpu_64(ctr64); ctr64++; ctr64 =3D rte_cpu_to_be_64(ctr64); memcpy(ctr, &ctr64, sizeof(uint64_t)); } Or use a union in process_openssl_cipher_des3ctr() to ensure it's = uint64_t aligned.