lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230110135042.2940847-11-vincent.whitchurch@axis.com>
Date:   Tue, 10 Jan 2023 14:50:40 +0100
From:   Vincent Whitchurch <vincent.whitchurch@...s.com>
To:     <herbert@...dor.apana.org.au>, <davem@...emloft.net>,
        <jesper.nilsson@...s.com>, <lars.persson@...s.com>
CC:     <kernel@...s.com>,
        Vincent Whitchurch <vincent.whitchurch@...s.com>,
        <linux-crypto@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH 10/12] crypto: axis - fix XTS unaligned block size handling

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%@...49, 3.5%@+30]"

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@...s.com>
---
 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,
 	},
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ