From: Kent Yoder <key@linux.vnet.ibm.com>
Subject: drivers/crypto/nx: fix init race, alignmasks and GCM bug
Patch-mainline: 3.10-rc3
Git-commit: 1ad936e850a896bc16e0d72a56be432f9954ad7e
References: bnc#812137

 Fixes a race on driver init with registering algorithms where the
driver status flag wasn't being set before self testing started.

Added the cra_alignmask field for CBC and ECB modes.

Fixed a bug in GCM where AES block size was being used instead of
authsize.

Signed-off-by: Kent Yoder <key@linux.vnet.ibm.com>
Acked-by: Torsten Duwe <duwe@suse.de>

diff -x '*.orig' -pburN linux-3.0.65-0.9.3/drivers/crypto/nx/nx-aes-cbc.c linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx-aes-cbc.c
--- linux-3.0.65-0.9.3/drivers/crypto/nx/nx-aes-cbc.c	2013-02-25 01:21:23.000000000 -0600
+++ linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx-aes-cbc.c	2013-03-01 11:19:06.000000000 -0600
@@ -126,6 +126,7 @@ struct crypto_alg nx_cbc_aes_alg = {
 	.cra_blocksize   = AES_BLOCK_SIZE,
 	.cra_ctxsize     = sizeof(struct nx_crypto_ctx),
 	.cra_type        = &crypto_blkcipher_type,
+	.cra_alignmask   = 0xf,
 	.cra_module      = THIS_MODULE,
 	.cra_list        = LIST_HEAD_INIT(nx_cbc_aes_alg.cra_list),
 	.cra_init        = nx_crypto_ctx_aes_cbc_init,
diff -x '*.orig' -pburN linux-3.0.65-0.9.3/drivers/crypto/nx/nx-aes-ecb.c linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx-aes-ecb.c
--- linux-3.0.65-0.9.3/drivers/crypto/nx/nx-aes-ecb.c	2013-02-25 01:21:23.000000000 -0600
+++ linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx-aes-ecb.c	2013-03-01 11:19:06.000000000 -0600
@@ -123,6 +123,7 @@ struct crypto_alg nx_ecb_aes_alg = {
 	.cra_priority    = 300,
 	.cra_flags       = CRYPTO_ALG_TYPE_BLKCIPHER,
 	.cra_blocksize   = AES_BLOCK_SIZE,
+	.cra_alignmask   = 0xf,
 	.cra_ctxsize     = sizeof(struct nx_crypto_ctx),
 	.cra_type        = &crypto_blkcipher_type,
 	.cra_module      = THIS_MODULE,
diff -x '*.orig' -pburN linux-3.0.65-0.9.3/drivers/crypto/nx/nx-aes-gcm.c linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx-aes-gcm.c
--- linux-3.0.65-0.9.3/drivers/crypto/nx/nx-aes-gcm.c	2013-02-25 01:21:23.000000000 -0600
+++ linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx-aes-gcm.c	2013-03-01 11:19:06.000000000 -0600
@@ -219,7 +219,7 @@ static int gcm_aes_nx_crypt(struct aead_
 	if (enc)
 		NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT;
 	else
-		nbytes -= AES_BLOCK_SIZE;
+		nbytes -= crypto_aead_authsize(crypto_aead_reqtfm(req));
 
 	csbcpb->cpb.aes_gcm.bit_length_data = nbytes * 8;
 
diff -x '*.orig' -pburN linux-3.0.65-0.9.3/drivers/crypto/nx/nx.c linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx.c
--- linux-3.0.65-0.9.3/drivers/crypto/nx/nx.c	2013-02-25 01:21:23.000000000 -0600
+++ linux-3.0.65-0.9.3-nx/drivers/crypto/nx/nx.c	2013-03-01 11:19:06.000000000 -0600
@@ -456,6 +456,8 @@ static int nx_register_algs(void)
 	if (rc)
 		goto out;
 
+	nx_driver.of.status = NX_OKAY;
+
 	rc = crypto_register_alg(&nx_ecb_aes_alg);
 	if (rc)
 		goto out;
@@ -500,8 +502,6 @@ static int nx_register_algs(void)
 	if (rc)
 		goto out_unreg_s512;
 
-	nx_driver.of.status = NX_OKAY;
-
 	goto out;
 
 out_unreg_s512:
