From nobody Mon Sep 15 21:14:25 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99EDDC54EBE for ; Tue, 10 Jan 2023 13:52:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbjAJNwI (ORCPT ); Tue, 10 Jan 2023 08:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbjAJNvD (ORCPT ); Tue, 10 Jan 2023 08:51:03 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEB08CC5; Tue, 10 Jan 2023 05:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1673358659; x=1704894659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TG79sBPQXvKwaZ2EoZ5EqQSwgfOpv/hMs1+X6I6t1ts=; b=NZyte1ViAxLyCInRm2Pq3J4l7ZdoA86ieq0Ffq598yeGaDpDR12uDL+U I+Gxl73y+gUUkVV+nX3mvfNmfyg4fnF8O/TpgSmpw19GNvtfKyAP2w2Jh GhMEkn6InvQxPI61fG3u9XIRGM5IXoJLfFMRBUAcTMCukfyg0L7ij+fyT TR36Ve78Cg/7FijK5+dtmbQ1xuJRxb1a9r/mUsJnXcozlwiQ7mP3uUena XbgD01moGQ8AYM/KODhKndeKRZWON9mSMOtb+td5xerIONhZKn0QtKxEY 3uAa9qQmqYeyYA6fWYUOCAklY/XixS4pdNbUq+QSeuyADtDS8MXFYRo7P w==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , Subject: [PATCH 10/12] crypto: axis - fix XTS unaligned block size handling Date: Tue, 10 Jan 2023 14:50:40 +0100 Message-ID: <20230110135042.2940847-11-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com> References: <20230110135042.2940847-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The hardware does not implement ciphertext stealing so fallback to software if the data length is not aligned to the block size. Fixes this kind of errors with CRYPTO_MANAGER_EXTRA_TESTS: alg: skcipher: artpec6-xts-aes encryption test failed (wrong result) on test vector "random: len=3D151 klen=3D64", cfg=3D"random: inplace_two_sgli= sts use_digest nosimd src_divs=3D[96.95%@+1949, 3.5%@+30]" Signed-off-by: Vincent Whitchurch --- drivers/crypto/axis/artpec6_crypto.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/art= pec6_crypto.c index 3b47faa06606..5eccb5a3a52e 100644 --- a/drivers/crypto/axis/artpec6_crypto.c +++ b/drivers/crypto/axis/artpec6_crypto.c @@ -1309,6 +1309,24 @@ static int artpec6_crypto_ctr_decrypt(struct skciphe= r_request *req) return artpec6_crypto_ctr_crypt(req, false); } =20 +static int artpec6_crypto_xts_encrypt(struct skcipher_request *req) +{ + /* Hardware does not implement ciphertext stealing */ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return artpec6_crypto_crypt_fallback(req, true); + + return artpec6_crypto_encrypt(req); +} + +static int artpec6_crypto_xts_decrypt(struct skcipher_request *req) +{ + /* Hardware does not implement ciphertext stealing */ + if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE)) + return artpec6_crypto_crypt_fallback(req, false); + + return artpec6_crypto_decrypt(req); +} + /* * AEAD functions */ @@ -2928,8 +2946,8 @@ static struct skcipher_alg crypto_algos[] =3D { .max_keysize =3D 2*AES_MAX_KEY_SIZE, .ivsize =3D 16, .setkey =3D artpec6_crypto_xts_set_key, - .encrypt =3D artpec6_crypto_encrypt, - .decrypt =3D artpec6_crypto_decrypt, + .encrypt =3D artpec6_crypto_xts_encrypt, + .decrypt =3D artpec6_crypto_xts_decrypt, .init =3D artpec6_crypto_aes_xts_init, .exit =3D artpec6_crypto_aes_exit, }, --=20 2.34.1