lkml.org 
[lkml]   [2023]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 11/12] crypto: axis - handle zero cryptlen
Date
Succeed zero length operations to prevent hangs/failures with various
CRYPTO_MANAGER_EXTRA_TESTS such as:

artpec6-ecb-aes "random: len=0 klen=32" encryption random:
inplace_two_sglists may_sleep use_finup src_divs=[100.0%@+2743]
key_offset=93

For XTS, sizes lesser than the block size need to be explicitly rejected
to prevent errors like this:

alg: skcipher: artpec6-xts-aes encryption unexpectedly succeeded on test
vector "random: len=0 klen=64"; expected_error=-22, cfg="rando m:
use_final nosimd src_divs=[<reimport>100.0%@+3991]
dst_divs=[73.80%@+4003, 26.20%@+16] iv_offset=68"

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
drivers/crypto/axis/artpec6_crypto.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c
index 5eccb5a3a52e..938faf3afa69 100644
--- a/drivers/crypto/axis/artpec6_crypto.c
+++ b/drivers/crypto/axis/artpec6_crypto.c
@@ -1097,6 +1097,9 @@ static int __artpec6_crypto_encrypt(struct skcipher_request *req)
void (*complete)(struct crypto_async_request *req);
int ret;

+ if (!req->cryptlen)
+ return 0;
+
req_ctx = skcipher_request_ctx(req);

switch (ctx->crypto_type) {
@@ -1145,6 +1148,9 @@ static int __artpec6_crypto_decrypt(struct skcipher_request *req)
struct artpec6_crypto_request_context *req_ctx = NULL;
void (*complete)(struct crypto_async_request *req);

+ if (!req->cryptlen)
+ return 0;
+
req_ctx = skcipher_request_ctx(req);

switch (ctx->crypto_type) {
@@ -1311,6 +1317,9 @@ static int artpec6_crypto_ctr_decrypt(struct skcipher_request *req)

static int artpec6_crypto_xts_encrypt(struct skcipher_request *req)
{
+ if (req->cryptlen < AES_BLOCK_SIZE)
+ return -EINVAL;
+
/* Hardware does not implement ciphertext stealing */
if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE))
return artpec6_crypto_crypt_fallback(req, true);
@@ -1320,6 +1329,9 @@ static int artpec6_crypto_xts_encrypt(struct skcipher_request *req)

static int artpec6_crypto_xts_decrypt(struct skcipher_request *req)
{
+ if (req->cryptlen < AES_BLOCK_SIZE)
+ return -EINVAL;
+
/* Hardware does not implement ciphertext stealing */
if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE))
return artpec6_crypto_crypt_fallback(req, false);
--
2.34.1
\
 
 \ /
  Last update: 2023-03-26 23:34    [W:0.058 / U:0.520 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site