linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher
@ 2019-05-14 21:53 Hook, Gary
  2019-05-14 21:53 ` [PATCH 2/3] crypto: ccp - fix AES CFB error exposed by new test vectors Hook, Gary
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hook, Gary @ 2019-05-14 21:53 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

CFB mode should be treated as a stream cipher, not block.

Fixes: 63b945091a07 ('crypto: ccp - CCP device driver and interface support')

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-ops.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index 267a367bd076..3ecadeab919c 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -1,7 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AMD Cryptographic Coprocessor (CCP) driver
  *
- * Copyright (C) 2013,2018 Advanced Micro Devices, Inc.
+ * Copyright (C) 2013-2019 Advanced Micro Devices, Inc.
  *
  * Author: Tom Lendacky <thomas.lendacky@amd.com>
  * Author: Gary R Hook <gary.hook@amd.com>
@@ -893,8 +894,7 @@ static int ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
 		return -EINVAL;
 
 	if (((aes->mode == CCP_AES_MODE_ECB) ||
-	     (aes->mode == CCP_AES_MODE_CBC) ||
-	     (aes->mode == CCP_AES_MODE_CFB)) &&
+	     (aes->mode == CCP_AES_MODE_CBC)) &&
 	    (aes->src_len & (AES_BLOCK_SIZE - 1)))
 		return -EINVAL;
 


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] crypto: ccp - fix AES CFB error exposed by new test vectors
  2019-05-14 21:53 [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher Hook, Gary
@ 2019-05-14 21:53 ` Hook, Gary
  2019-05-14 21:53 ` [PATCH 3/3] crypto: ccp - Fix 3DES complaint from ccp-crypto module Hook, Gary
  2019-05-23  6:51 ` [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Hook, Gary @ 2019-05-14 21:53 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Updated testmgr will exhibit this error message when loading the
ccp-crypto module:

alg: skcipher: cfb-aes-ccp encryption failed with err -22 on test vector 3, cfg="in-place"

Update the CCP crypto driver to correctly treat CFB as a streaming mode
cipher (instead of block mode). Update the configuration for CFB to
specify the block size as a single byte;

Fixes: 2b789435d7f3 ('crypto: ccp - CCP AES crypto API support')

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-crypto-aes.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-crypto-aes.c b/drivers/crypto/ccp/ccp-crypto-aes.c
index 89291c15015c..3f768699332b 100644
--- a/drivers/crypto/ccp/ccp-crypto-aes.c
+++ b/drivers/crypto/ccp/ccp-crypto-aes.c
@@ -1,7 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * AMD Cryptographic Coprocessor (CCP) AES crypto API support
  *
- * Copyright (C) 2013,2016 Advanced Micro Devices, Inc.
+ * Copyright (C) 2013-2019 Advanced Micro Devices, Inc.
  *
  * Author: Tom Lendacky <thomas.lendacky@amd.com>
  *
@@ -79,8 +80,7 @@ static int ccp_aes_crypt(struct ablkcipher_request *req, bool encrypt)
 		return -EINVAL;
 
 	if (((ctx->u.aes.mode == CCP_AES_MODE_ECB) ||
-	     (ctx->u.aes.mode == CCP_AES_MODE_CBC) ||
-	     (ctx->u.aes.mode == CCP_AES_MODE_CFB)) &&
+	     (ctx->u.aes.mode == CCP_AES_MODE_CBC)) &&
 	    (req->nbytes & (AES_BLOCK_SIZE - 1)))
 		return -EINVAL;
 
@@ -291,7 +291,7 @@ static struct ccp_aes_def aes_algs[] = {
 		.version	= CCP_VERSION(3, 0),
 		.name		= "cfb(aes)",
 		.driver_name	= "cfb-aes-ccp",
-		.blocksize	= AES_BLOCK_SIZE,
+		.blocksize	= 1,
 		.ivsize		= AES_BLOCK_SIZE,
 		.alg_defaults	= &ccp_aes_defaults,
 	},


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] crypto: ccp - Fix 3DES complaint from ccp-crypto module
  2019-05-14 21:53 [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher Hook, Gary
  2019-05-14 21:53 ` [PATCH 2/3] crypto: ccp - fix AES CFB error exposed by new test vectors Hook, Gary
@ 2019-05-14 21:53 ` Hook, Gary
  2019-05-23  6:51 ` [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Hook, Gary @ 2019-05-14 21:53 UTC (permalink / raw)
  To: linux-crypto; +Cc: Lendacky, Thomas, herbert, davem

Crypto self-tests reveal an error:

alg: skcipher: cbc-des3-ccp encryption test failed (wrong output IV) on test vector 0, cfg="in-place"

The offset value should not be recomputed when retrieving the context.
Also, a code path exists which makes decisions based on older (version 3)
hardware; a v3 device deosn't support 3DES so remove this check.

Fixes: 990672d48515 ('crypto: ccp - Enable 3DES function on v5 CCPs')

Signed-off-by: Gary R Hook <gary.hook@amd.com>
---
 drivers/crypto/ccp/ccp-ops.c |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index 3ecadeab919c..b116d62991c6 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -1267,6 +1267,9 @@ static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
 	int ret;
 
 	/* Error checks */
+	if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0))
+		return -EINVAL;
+
 	if (!cmd_q->ccp->vdata->perform->des3)
 		return -EINVAL;
 
@@ -1349,8 +1352,6 @@ static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
 	 * passthru option to convert from big endian to little endian.
 	 */
 	if (des3->mode != CCP_DES3_MODE_ECB) {
-		u32 load_mode;
-
 		op.sb_ctx = cmd_q->sb_ctx;
 
 		ret = ccp_init_dm_workarea(&ctx, cmd_q,
@@ -1366,12 +1367,8 @@ static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
 		if (ret)
 			goto e_ctx;
 
-		if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0))
-			load_mode = CCP_PASSTHRU_BYTESWAP_NOOP;
-		else
-			load_mode = CCP_PASSTHRU_BYTESWAP_256BIT;
 		ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
-				     load_mode);
+				     CCP_PASSTHRU_BYTESWAP_256BIT);
 		if (ret) {
 			cmd->engine_error = cmd_q->cmd_error;
 			goto e_ctx;
@@ -1433,10 +1430,6 @@ static int ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
 		}
 
 		/* ...but we only need the last DES3_EDE_BLOCK_SIZE bytes */
-		if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0))
-			dm_offset = CCP_SB_BYTES - des3->iv_len;
-		else
-			dm_offset = 0;
 		ccp_get_dm_area(&ctx, dm_offset, des3->iv, 0,
 				DES3_EDE_BLOCK_SIZE);
 	}


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher
  2019-05-14 21:53 [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher Hook, Gary
  2019-05-14 21:53 ` [PATCH 2/3] crypto: ccp - fix AES CFB error exposed by new test vectors Hook, Gary
  2019-05-14 21:53 ` [PATCH 3/3] crypto: ccp - Fix 3DES complaint from ccp-crypto module Hook, Gary
@ 2019-05-23  6:51 ` Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2019-05-23  6:51 UTC (permalink / raw)
  To: Hook, Gary; +Cc: linux-crypto, Lendacky, Thomas, davem

On Tue, May 14, 2019 at 09:53:16PM +0000, Hook, Gary wrote:
> CFB mode should be treated as a stream cipher, not block.
> 
> Fixes: 63b945091a07 ('crypto: ccp - CCP device driver and interface support')
> 
> Signed-off-by: Gary R Hook <gary.hook@amd.com>
> ---
>  drivers/crypto/ccp/ccp-ops.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-05-23  6:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-14 21:53 [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher Hook, Gary
2019-05-14 21:53 ` [PATCH 2/3] crypto: ccp - fix AES CFB error exposed by new test vectors Hook, Gary
2019-05-14 21:53 ` [PATCH 3/3] crypto: ccp - Fix 3DES complaint from ccp-crypto module Hook, Gary
2019-05-23  6:51 ` [PATCH 1/3] crypto: ccp - AES CFB mode is a stream cipher Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).