From patchwork Tue Jan 10 13:50:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 41487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2759236wrt; Tue, 10 Jan 2023 05:57:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXtnMNa8fv0B0bxlnGkpue/KEcTM5r1WJwxMxm/qAwYWXfuW0AeH/lfVmhnSydkH187G0iw7 X-Received: by 2002:a05:6a20:8e10:b0:a4:a73e:d1e2 with SMTP id y16-20020a056a208e1000b000a4a73ed1e2mr99797249pzj.57.1673359044339; Tue, 10 Jan 2023 05:57:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673359044; cv=none; d=google.com; s=arc-20160816; b=MO1esWoseCKUUyZCAztBhzW+m+f2/RrzBeUshJVxlwxGkhlE/UaZ/5slYoGsMcrQrw oCcDL98j1Y+ocY3eoJWvYk09dsF6OowtfdI8I/ZxrQnvnwlufd2ffO9bKYlAY7ICQlxO IA93PfpNwRy1shnR6T3NAeRAsRN4OosHjF558ITpeK/Qqy/BxE7NQxMk4qT0od9ah6OD XwiKCCodxn1kUo034nnUzntRmrbknps9/SDePx55YHnDEZAeny1iihs7lZLTbhwV0OD0 9WdX+R9+eEUqp8Z2JyfTRHTH97BtGSvdncu+BaGSeZUTauGSrgOLxE7KNswQmOQv40g/ F68w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TG79sBPQXvKwaZ2EoZ5EqQSwgfOpv/hMs1+X6I6t1ts=; b=Ovu96yXwdf3+s4DYE3spRH+icFmB6ScG0sHhU4lruUUaztOP/WuMFZXMcxWW3Y+y/K tCb52cpSYtBP4AC70s3uFPhF3diEBspVJLc5nk3fBQ75PNYSnm5WLAvzKEE97TnROgdn a01usbE3hFt58wpXRf9DSY9DJVC9/M/hlfb/ZPP/ZdxfeGEBKOVfTjsFF8XAIi9W9E2H PlbO/3QO4NeITdaJ9X/3pORbT/p/wrqmiS5DA2i3JnlDef8WNLz9islY21ANZ/esxhxD +aCNvL6+CTVHEY8YokEXQYBfIr2V/XryDubNngSlymqcNaM64PRDizgtOW4+JvroF3bX kifQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=NZyte1Vi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a63fb4e000000b00476c770e17asi11400901pgj.764.2023.01.10.05.57.07; Tue, 10 Jan 2023 05:57:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=NZyte1Vi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238613AbjAJNwG (ORCPT + 99 others); Tue, 10 Jan 2023 08:52:06 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754644133423782560?= X-GMAIL-MSGID: =?utf-8?q?1754644133423782560?= 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=151 klen=64", cfg="random: inplace_two_sglists use_digest nosimd src_divs=[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/artpec6_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 skcipher_request *req) return artpec6_crypto_ctr_crypt(req, false); } +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[] = { .max_keysize = 2*AES_MAX_KEY_SIZE, .ivsize = 16, .setkey = artpec6_crypto_xts_set_key, - .encrypt = artpec6_crypto_encrypt, - .decrypt = artpec6_crypto_decrypt, + .encrypt = artpec6_crypto_xts_encrypt, + .decrypt = artpec6_crypto_xts_decrypt, .init = artpec6_crypto_aes_xts_init, .exit = artpec6_crypto_aes_exit, },