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 F1B1E45BC3 for ; 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 E606643477; Thu, 24 Oct 2024 15:17:32 +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 3778340265 for ; Thu, 24 Oct 2024 15:17:30 +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-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-228-vn9o9nYuNBmXYlrb4rN9qg-1; Thu, 24 Oct 2024 09:17:28 -0400 X-MC-Unique: vn9o9nYuNBmXYlrb4rN9qg-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-539ea3d778dso686021e87.1 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=pwJj9UCJ4Gmcr0EDbETp2P6NDYYy3DnkHL8rnwK3T2atnWIFsjhl6/CZdzwRX/dn7W tkMqX0Ulix+CHlcQEqYxVptDR1qSl1oflqfE3JLKCfZM33Si3IJyRnhp5jGEvZYeqnT2 cxdjFtX4Z7xMU9oiGpTsmER2QLaQJDuIs1ZkaCB7hO8xa+5OJt2cwuhyC6QPlTrrgaoE 0bZC8BO1zM9g442j7bFpajT4iyJFHk09p2tOo/cnsioZvbaFzlx90TdhmNu1LNmcryMt aBO9xGaqqgkKZSuLr3fpQGNfOEn2DgmeEkoDvOQP4CyewdrL9SakE8ZsXP2Kli1hDXIm geEQ== X-Forwarded-Encrypted: i=1; AJvYcCXQ4WC55fChqmMBioAZq/Ji0PRdtN1h2FNYKy/CI1tsRfDE6Zy6DoKwAHMvYB3quDXcQXfzetw=@dpdk.org X-Gm-Message-State: AOJu0YxjgQ6FrxGiHPQlz0JNtMUAkjZvirFCcp6uVkBB57+zJG5OaxZF KiqzPLsVH+UuXED5jMo/n2+r5xoknxYxYAbrAPv3pP+72vSvRi3yyvTMmq14HvJejlHriocBtmU khx7EByMmv4W37ydUtqD5HhMqLn3PUC3ZDhhd71Ofb//bO3PJUvnl4TxbjTkYpbwghkcU/L9qD/ 1A1NVpsgDAnR02MGAfnFI= X-Received: by 2002:a05:6512:b81:b0:52e:7448:e137 with SMTP id 2adb3069b0e04-53b1a2f4e80mr3887661e87.6.1729775846113; 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: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-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