]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
crypto: caam/qi - properly set IV after {en,de}crypt
authorHoria Geantă <horia.geanta@nxp.com>
Mon, 10 Jul 2017 05:40:30 +0000 (08:40 +0300)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 28 Sep 2017 14:34:54 +0000 (10:34 -0400)
BugLink: http://bugs.launchpad.net/bugs/1720154
commit a68a193805224d90bedd94e9e8ac287600f07b78 upstream.

caam/qi needs a fix similar to what was done for caam/jr in
commit "crypto: caam/qi - properly set IV after {en,de}crypt",
to allow for ablkcipher/skcipher chunking/streaming.

Fixes: b189817cf789 ("crypto: caam/qi - add ablkcipher and authenc algorithms")
Suggested-by: David Gstir <david@sigma-star.at>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
drivers/crypto/caam/caamalg_qi.c

index 058be8f094ee127d85c1aca979597d5c9c579a6c..fe0185ceac161b52b846906426c70d74b1a4ff7b 100644 (file)
@@ -776,9 +776,9 @@ static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status)
        struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
        struct caam_ctx *caam_ctx = crypto_ablkcipher_ctx(ablkcipher);
        struct device *qidev = caam_ctx->qidev;
-#ifdef DEBUG
        int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
 
+#ifdef DEBUG
        dev_err(qidev, "%s %d: status 0x%x\n", __func__, __LINE__, status);
 #endif
 
@@ -799,6 +799,13 @@ static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status)
        ablkcipher_unmap(qidev, edesc, req);
        qi_cache_free(edesc);
 
+       /*
+        * The crypto API expects us to set the IV (req->info) to the last
+        * ciphertext block. This is used e.g. by the CTS mode.
+        */
+       scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize,
+                                ivsize, 0);
+
        ablkcipher_request_complete(req, status);
 }