MLK-14611 Fix CBC mode support by returning a correct IV
authorRadu Solea <radu.solea@nxp.com>
Thu, 13 Apr 2017 12:22:41 +0000 (15:22 +0300)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:22:00 +0000 (15:22 -0500)
Current CBC mode does not return the last cyphertext block
as IV for operation chaining. CTS fails because of incorrect IV.

Signed-off-by: Radu Solea <radu.solea@nxp.com>
drivers/crypto/caam/caamalg.c

index 7ca01d8..1340ce6 100644 (file)
@@ -2042,7 +2042,10 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
        struct ablkcipher_request *req = context;
        struct ablkcipher_edesc *edesc;
        struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
+       struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
+       int bsize = crypto_ablkcipher_blocksize(ablkcipher);
        int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
+       size_t ivcopy = min_t(size_t, bsize, ivsize);
 
 #ifdef DEBUG
        dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
@@ -2074,6 +2077,12 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
 
        kfree(edesc);
 
+       /* Pass IV along for cbc */
+       if ((ctx->class1_alg_type & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC) {
+               scatterwalk_map_and_copy(req->info, req->dst,
+                                        req->nbytes - bsize, ivcopy, 0);
+       }
+
        ablkcipher_request_complete(req, err);
 }