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 46A3345BD2 for ; Fri, 25 Oct 2024 09:05:01 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3863740B90; Fri, 25 Oct 2024 09:05:01 +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 4835A4065A for ; Fri, 25 Oct 2024 09:04:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729839898; 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=9+WyFfzSWDFrLuJ4Dbn07AxzyQYH3PLZBoyUMr2I9F8=; b=D/HZ+APqP9v6ojEJ+5kUll9Smm8csHLlur2Hjtqs0YyH8GdE389UTrWREPp9ABiAjf7jYJ TAyrK+Bh014BU89iTicJdh7hrartxXUnTlZmP6tpRYEI8rSyc5rILlsXmKe0c11AtHznX6 30aF8uwwATSHlIPk9q+uzFjKIyzEuh0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-akWNO_nKPWScy2Uwita_Og-1; Fri, 25 Oct 2024 03:04:53 -0400 X-MC-Unique: akWNO_nKPWScy2Uwita_Og-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 28A381955D91; Fri, 25 Oct 2024 07:04:51 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.57]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1B96719560A2; Fri, 25 Oct 2024 07:04:46 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@amd.com, stephen@networkplumber.org, mattias.ronnblom@ericsson.com, stable@dpdk.org, =?UTF-8?q?Morten=20Br=C3=B8rup?= , Kai Ji , Michal Kobylinski , Slawomir Mrozowicz , Tomasz Kulasek , Daniel Mrzyglod , Pablo de Lara Subject: [PATCH v2 4/6] crypto/openssl: fix 3DES-CTR with big endian CPUs Date: Fri, 25 Oct 2024 09:04:21 +0200 Message-ID: <20241025070424.3916007-5-david.marchand@redhat.com> In-Reply-To: <20241025070424.3916007-1-david.marchand@redhat.com> References: <20241024120535.2722316-1-david.marchand@redhat.com> <20241025070424.3916007-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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. Besides, avoid unaligned accesses and remove the ctr_inc helper that is not used anywhere else. Fixes: d61f70b4c918 ("crypto/libcrypto: add driver for OpenSSL library") Cc: stable@dpdk.org Signed-off-by: David Marchand Acked-by: Morten Brørup --- Changes since v1: - fixed unaligned access, - removed unneeded helper, --- drivers/crypto/openssl/rte_openssl_pmd.c | 28 ++++++++---------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c index 9657b70c7a..0616383921 100644 --- a/drivers/crypto/openssl/rte_openssl_pmd.c +++ b/drivers/crypto/openssl/rte_openssl_pmd.c @@ -2,6 +2,7 @@ * Copyright(c) 2016-2017 Intel Corporation */ +#include #include #include #include @@ -99,22 +100,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 = (uint64_t *)ctr; - - *ctr64 = __builtin_bswap64(*ctr64); - (*ctr64)++; - *ctr64 = __builtin_bswap64(*ctr64); -} - /* *------------------------------------------------------------------------------ * Session Prepare @@ -1192,7 +1177,8 @@ 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 ctr; int unused, n; struct rte_mbuf *m; uint8_t *src; @@ -1208,15 +1194,19 @@ process_openssl_cipher_des3ctr(struct rte_mbuf *mbuf_src, uint8_t *dst, src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset); l = rte_pktmbuf_data_len(m) - offset; - memcpy(ctr, iv, 8); + memcpy(&ctr, iv, 8); for (n = 0; n < srclen; n++) { if (n % 8 == 0) { + uint64_t cpu_ctr; + if (EVP_EncryptUpdate(ctx, (unsigned char *)&ebuf, &unused, (const unsigned char *)&ctr, 8) <= 0) goto process_cipher_des3ctr_err; - ctr_inc(ctr); + cpu_ctr = rte_be_to_cpu_64(ctr); + cpu_ctr++; + ctr = rte_cpu_to_be_64(cpu_ctr); } dst[n] = *(src++) ^ ebuf[n % 8]; -- 2.46.2