aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/nx/nx.c
diff options
context:
space:
mode:
authorKent Yoder <key@linux.vnet.ibm.com>2013-04-12 13:13:59 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2013-05-24 04:11:10 -0400
commit1ad936e850a896bc16e0d72a56be432f9954ad7e (patch)
treed0108b0f99c61e6779eadbaebf29ed5b6be2e485 /drivers/crypto/nx/nx.c
parent519fe2ecb755b875d9814cdda19778c2e88c6901 (diff)
drivers/crypto/nx: Fixes for multiple races and issues
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. Removed use of blkcipher_walk routines for scatterlist processing. Corner cases in the code prevent us from processing an entire scatterlist at a time and walking the buffers in block sized chunks turns out to be unecessary anyway. Fixed off-by-one error in saving off extra data in the sha code. Fixed accounting error for number of bytes processed in the sha code. Signed-off-by: Kent Yoder <key@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers/crypto/nx/nx.c')
-rw-r--r--drivers/crypto/nx/nx.c38
1 files changed, 7 insertions, 31 deletions
diff --git a/drivers/crypto/nx/nx.c b/drivers/crypto/nx/nx.c
index c767f232e693..bbdab6e5ccf0 100644
--- a/drivers/crypto/nx/nx.c
+++ b/drivers/crypto/nx/nx.c
@@ -211,44 +211,20 @@ int nx_build_sg_lists(struct nx_crypto_ctx *nx_ctx,
211{ 211{
212 struct nx_sg *nx_insg = nx_ctx->in_sg; 212 struct nx_sg *nx_insg = nx_ctx->in_sg;
213 struct nx_sg *nx_outsg = nx_ctx->out_sg; 213 struct nx_sg *nx_outsg = nx_ctx->out_sg;
214 struct blkcipher_walk walk;
215 int rc;
216
217 blkcipher_walk_init(&walk, dst, src, nbytes);
218 rc = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
219 if (rc)
220 goto out;
221 214
222 if (iv) 215 if (iv)
223 memcpy(iv, walk.iv, AES_BLOCK_SIZE); 216 memcpy(iv, desc->info, AES_BLOCK_SIZE);
224 217
225 while (walk.nbytes) { 218 nx_insg = nx_walk_and_build(nx_insg, nx_ctx->ap->sglen, src, 0, nbytes);
226 nx_insg = nx_build_sg_list(nx_insg, walk.src.virt.addr, 219 nx_outsg = nx_walk_and_build(nx_outsg, nx_ctx->ap->sglen, dst, 0, nbytes);
227 walk.nbytes, nx_ctx->ap->sglen);
228 nx_outsg = nx_build_sg_list(nx_outsg, walk.dst.virt.addr,
229 walk.nbytes, nx_ctx->ap->sglen);
230
231 rc = blkcipher_walk_done(desc, &walk, 0);
232 if (rc)
233 break;
234 }
235
236 if (walk.nbytes) {
237 nx_insg = nx_build_sg_list(nx_insg, walk.src.virt.addr,
238 walk.nbytes, nx_ctx->ap->sglen);
239 nx_outsg = nx_build_sg_list(nx_outsg, walk.dst.virt.addr,
240 walk.nbytes, nx_ctx->ap->sglen);
241
242 rc = 0;
243 }
244 220
245 /* these lengths should be negative, which will indicate to phyp that 221 /* these lengths should be negative, which will indicate to phyp that
246 * the input and output parameters are scatterlists, not linear 222 * the input and output parameters are scatterlists, not linear
247 * buffers */ 223 * buffers */
248 nx_ctx->op.inlen = (nx_ctx->in_sg - nx_insg) * sizeof(struct nx_sg); 224 nx_ctx->op.inlen = (nx_ctx->in_sg - nx_insg) * sizeof(struct nx_sg);
249 nx_ctx->op.outlen = (nx_ctx->out_sg - nx_outsg) * sizeof(struct nx_sg); 225 nx_ctx->op.outlen = (nx_ctx->out_sg - nx_outsg) * sizeof(struct nx_sg);
250out: 226
251 return rc; 227 return 0;
252} 228}
253 229
254/** 230/**
@@ -454,6 +430,8 @@ static int nx_register_algs(void)
454 if (rc) 430 if (rc)
455 goto out; 431 goto out;
456 432
433 nx_driver.of.status = NX_OKAY;
434
457 rc = crypto_register_alg(&nx_ecb_aes_alg); 435 rc = crypto_register_alg(&nx_ecb_aes_alg);
458 if (rc) 436 if (rc)
459 goto out; 437 goto out;
@@ -498,8 +476,6 @@ static int nx_register_algs(void)
498 if (rc) 476 if (rc)
499 goto out_unreg_s512; 477 goto out_unreg_s512;
500 478
501 nx_driver.of.status = NX_OKAY;
502
503 goto out; 479 goto out;
504 480
505out_unreg_s512: 481out_unreg_s512: