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 49C6845BC0; Thu, 24 Oct 2024 15:17:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CC6F140281; Thu, 24 Oct 2024 15:17:31 +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 AEC0840265 for ; Thu, 24 Oct 2024 15:17:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729775849; 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=2CI+lpWiVaIAbEdEfxyM04OohbdHi/FC/n7qEJtNZ/E=; b=JBLnWNODZyviDmRXvCcKJB/WmseKB9J/16razUmVt6tX/g4TNlhnOx2WPQTC/Pn7OSN2+B CSWouqknfhzfOxoVp2cqIIoRj6x/bnY4rBwOyKOvItogV2KYgB/EoUD6SeGcCnq/tvX14q RyjatkHmQkM0f2kHYZDtRokozIUuSsk= 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-172-yoTunf5yMCaPFUL5nA5RFg-1; Thu, 24 Oct 2024 09:17:27 -0400 X-MC-Unique: yoTunf5yMCaPFUL5nA5RFg-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-539ebb67c28so610280e87.3 for ; Thu, 24 Oct 2024 06:17:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729775846; x=1730380646; 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=2CI+lpWiVaIAbEdEfxyM04OohbdHi/FC/n7qEJtNZ/E=; b=ZvkdC0YOF8qa9kLQ/6iA0xvxoyAo63Rt/4OLTVeN2cbxEmCe/MPEnMNrM7+JJSRYon FTeVmwlZ2u7VTdju3fhbFvcl0QzGDQ3Bun+Fww5f0fKU0suHnOUJpJd5/pXiyu5sR5WD xQQeK8l3klpzn4cFZu7vUacECqN7Q3p2RThsGcc/88d7qESR+hSiCmaGHvzoMkCwbDtY Ei8wIIJNFY4I+68XK6C5o+xrjidO+uhyZZXtHI9QxdBN49oE6a+Q2gjpmbz/gU2Ehv+2 +aeKDgxuQUkjmVFQhG3ViXMQU2sn+7JFcYfwsgPbFR220VqCsjbH3Hds7XccMop1l5L8 GaSw== X-Gm-Message-State: AOJu0Yz5AIcumpH4uBYV/JsOu6Nv7zn2Ph4Ncwh+OJ2d2glBFdKt1r9c GvdaISIgXAMxsDpzeTqMt9r5AwUIRqR6REhaWdisHtSLoQctM2Q/9CDXYXoftAVNApmnQsZupJ3 OBmZdAA/HZGK5c9Sf5PC9tBFvPGovtZ0jjMonkizdBpW0v+lZAGlomagP5w5lP7lc/7h+l6JkGa 4APQzWy8X7hO9Nlho= X-Received: by 2002:a05:6512:b81:b0:52e:7448:e137 with SMTP id 2adb3069b0e04-53b1a2f4e80mr3887666e87.6.1729775846144; Thu, 24 Oct 2024 06:17:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpj73yHKWcY85jjX2a00XowXoeUGO7hDjhVVxcy7h0QY4zDG9Sp5hz+t7b9mgfb/7kyf639cjajJgmw3+thbU= X-Received: by 2002:a05:6512:b81:b0:52e:7448:e137 with SMTP id 2adb3069b0e04-53b1a2f4e80mr3887637e87.6.1729775845604; Thu, 24 Oct 2024 06:17:25 -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: From: David Marchand Date: Thu, 24 Oct 2024 15:17:14 +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 3:10=E2=80=AFPM David Marchand wrote: > > There may be an alignment bug too; the way it is used in process_openss= l_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 uint6= 4_t aligned. > > Or declare ctr as a uint64_t in process_openssl_cipher_des3ctr > directly, and remove this casting. Like: diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c index 9657b70c7a..8e193759b7 100644 --- a/drivers/crypto/openssl/rte_openssl_pmd.c +++ b/drivers/crypto/openssl/rte_openssl_pmd.c @@ -99,22 +99,6 @@ digest_name_get(enum rte_crypto_auth_algorithm algo) static int cryptodev_openssl_remove(struct rte_vdev_device *vdev); -/*------------------------------------------------------------------------= ----*/ - -/** - * Increment counter by 1 - * Counter is 64 bit array, big-endian - */ -static void -ctr_inc(uint8_t *ctr) -{ - uint64_t *ctr64 =3D (uint64_t *)ctr; - - *ctr64 =3D __builtin_bswap64(*ctr64); - (*ctr64)++; - *ctr64 =3D __builtin_bswap64(*ctr64); -} - /* *------------------------------------------------------------------------= ------ * Session Prepare @@ -1192,7 +1176,9 @@ static int process_openssl_cipher_des3ctr(struct rte_mbuf *mbuf_src, uint8_t *dst, int offset, uint8_t *iv, int srclen, EVP_CIPHER_CTX *ctx) { - uint8_t ebuf[8], ctr[8]; + uint8_t ebuf[8]; + uint64_t host_ctr; + uint64_t ctr; int unused, n; struct rte_mbuf *m; uint8_t *src; @@ -1209,14 +1195,16 @@ process_openssl_cipher_des3ctr(struct rte_mbuf *mbuf_src, uint8_t *dst, l =3D rte_pktmbuf_data_len(m) - offset; memcpy(ctr, iv, 8); + host_ctr =3D rte_be_64_to_cpu(ctr); for (n =3D 0; n < srclen; n++) { if (n % 8 =3D=3D 0) { + ctr =3D rte_cpu_to_be_64(host_ctr); if (EVP_EncryptUpdate(ctx, (unsigned char *)&ebuf, &unused, (const unsigned char *)&ctr, 8) <= =3D 0) goto process_cipher_des3ctr_err; - ctr_inc(ctr); + host_ctr++; } dst[n] =3D *(src++) ^ ebuf[n % 8]; --=20 David Marchand