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 8059745BC0; Thu, 24 Oct 2024 15:10:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 73F9A40281; Thu, 24 Oct 2024 15:10:18 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 4ED6640265 for ; Thu, 24 Oct 2024 15:10:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729775416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p0F0ReBcfdumzGJWIBpA9ncK6Ayi3pGzURVoo34rpQs=; b=DTg4afez6wFu9UhNFuoyAZucmNj9RCaAeC+fGYnKxCfAMIaThyXtoOnYljdu+yNtZ+yqnS NCOC+takrjRPQiw5iDez7ocWNRq1qxbWqcuxP/0KLlZRKG/uQAVinCT8O5htnwafDuLUZW Ru+UBQDex51hIefCFrWqOtHq2ShHQXc= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-I5Sq8Kz_OQuw3LkCmEPkUQ-1; Thu, 24 Oct 2024 09:10:15 -0400 X-MC-Unique: I5Sq8Kz_OQuw3LkCmEPkUQ-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-539eaa055feso697212e87.1 for ; Thu, 24 Oct 2024 06:10:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729775414; x=1730380214; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p0F0ReBcfdumzGJWIBpA9ncK6Ayi3pGzURVoo34rpQs=; b=ea5Ip5dSFB081lLo3KjXluvqRDIB2bK1sYP+PjzgEinOpx5ekP6fZ3rDhxiJDiwDUt jIO9ygyzVN8awc5d8CHkRCxHhhF80euLgmnKZWvN8e5qIP218C9DOgrSmfZsHbxhwrsP i9t2Q1wohkLZQmHKndeBqcGwAjbGTrmr0ccltljjNOjnfFwNkLg5Epaol1WSLHdc12ox pCpyqWYoKQz9z1jNcP4YR7Own2D9lDLurtZO5uKTTZizOSj92klVnm3VO9uzqWy0Fy0I VovFQXY/7IfCj1BiBsOJU+w9VD/44hHA2hsxoRTEJbrer4kEUS3n98FAbZTE+Sbrc+/M hLGw== X-Gm-Message-State: AOJu0YzHfqfKCBC9huOtGS3mEs+gsvFFkgUBBIhsjQZYtPeG6OzhgUJV 8JPwmX/eukebKNB6UMv+ce4MEEcqIXQR3N49/c2P0rhGuHxkFiOAN8jCvbkj1/+IfBR8tZV8+Vi 4NMij8XrlWvDmtoB5aaPc5vhBjeX3MOrKSY52Ql/FP/ljuNgOtaa+BEGLOtPigUCcC19z8DmhWj be7+aSDzdsulLkDKE= X-Received: by 2002:a05:6512:308b:b0:536:53a9:96d5 with SMTP id 2adb3069b0e04-53b1a3084c0mr3287599e87.17.1729775414104; Thu, 24 Oct 2024 06:10:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXMC673txeTDFeR0fkhUp1Da8lcBBsORSS09aDK9Efbhdbsy7tX8XYQvnUn/Dtwhm5R9tHDN3ihwApvxjTUBU= X-Received: by 2002:a05:6512:308b:b0:536:53a9:96d5 with SMTP id 2adb3069b0e04-53b1a3084c0mr3287576e87.17.1729775413731; Thu, 24 Oct 2024 06:10:13 -0700 (PDT) MIME-Version: 1.0 References: <20241024120535.2722316-1-david.marchand@redhat.com> <20241024120535.2722316-5-david.marchand@redhat.com> <98CBD80474FA8B44BF855DF32C47DC35E9F816@smartserver.smartshare.dk> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F816@smartserver.smartshare.dk> From: David Marchand Date: Thu, 24 Oct 2024 15:10:01 +0200 Message-ID: Subject: Re: [PATCH 4/6] crypto/openssl: fix 3DES-CTR with big endian CPUs To: =?UTF-8?Q?Morten_Br=C3=B8rup?= Cc: dev@dpdk.org, thomas@monjalon.net, ferruh.yigit@amd.com, stephen@networkplumber.org, mattias.ronnblom@ericsson.com, stable@dpdk.org, Kai Ji , Slawomir Mrozowicz , Tomasz Kulasek , Daniel Mrzyglod , Pablo de Lara , Michal Kobylinski X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Thu, Oct 24, 2024 at 2:55=E2=80=AFPM Morten Br=C3=B8rup wrote: > > > From: David Marchand [mailto:david.marchand@redhat.com] > > Sent: Thursday, 24 October 2024 14.06 > > > > Caught by code review. > > > > 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; > > > > - *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. Or declare ctr as a uint64_t in process_openssl_cipher_des3ctr directly, and remove this casting. --=20 David Marchand