crypto: stm32/cryp - update to return iv_out
authorLionel Debieve <lionel.debieve@st.com>
Wed, 24 Apr 2019 13:34:53 +0000 (15:34 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 3 May 2019 06:03:29 +0000 (14:03 +0800)
The kernel crypto API request output the next IV data to
IV buffer for CBC implementation.

Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/stm32/stm32-cryp.c

index eb525669d4eb9ebf3c479b0447988bffe3db568b..cddcc97875b2f7e4e4d178fa441fd68f857e4631 100644 (file)
@@ -393,6 +393,23 @@ static void stm32_cryp_hw_write_iv(struct stm32_cryp *cryp, u32 *iv)
        }
 }
 
+static void stm32_cryp_get_iv(struct stm32_cryp *cryp)
+{
+       struct ablkcipher_request *req = cryp->req;
+       u32 *tmp = req->info;
+
+       if (!tmp)
+               return;
+
+       *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV0LR));
+       *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV0RR));
+
+       if (is_aes(cryp)) {
+               *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV1LR));
+               *tmp++ = cpu_to_be32(stm32_cryp_read(cryp, CRYP_IV1RR));
+       }
+}
+
 static void stm32_cryp_hw_write_key(struct stm32_cryp *c)
 {
        unsigned int i;
@@ -622,6 +639,9 @@ static void stm32_cryp_finish_req(struct stm32_cryp *cryp, int err)
                /* Phase 4 : output tag */
                err = stm32_cryp_read_auth_tag(cryp);
 
+       if (!err && (!(is_gcm(cryp) || is_ccm(cryp))))
+               stm32_cryp_get_iv(cryp);
+
        if (cryp->sgs_copied) {
                void *buf_in, *buf_out;
                int pages, len;