crypto/dpaax_sec: use AES-CTR initial counter as 1
authorVakul Garg <vakul.garg@nxp.com>
Wed, 6 Nov 2019 05:17:30 +0000 (10:47 +0530)
committerAkhil Goyal <akhil.goyal@nxp.com>
Fri, 8 Nov 2019 12:51:16 +0000 (13:51 +0100)
As per RFC3686, the initial aes-ctr counter value should be '1' for use
in ipsec. The patches changes SEC descriptor for using correct counter
value. In addition, it drops a redundant parameter for passing IV while
creating the descriptor.

This patch adds changes for all NXP crypto PMDs

Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
drivers/common/dpaax/caamflib/desc/algo.h
drivers/crypto/caam_jr/caam_jr.c
drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
drivers/crypto/dpaa_sec/dpaa_sec.c

index 83dbb80..345bb5b 100644 (file)
@@ -289,12 +289,12 @@ cnstr_shdsc_snow_f9(uint32_t *descbuf, bool ps, bool swap,
 static inline int
 cnstr_shdsc_blkcipher(uint32_t *descbuf, bool ps, bool swap,
                      enum rta_share_type share,
-                     struct alginfo *cipherdata, uint8_t *iv,
+                     struct alginfo *cipherdata,
                      uint32_t ivlen, uint8_t dir)
 {
        struct program prg;
        struct program *p = &prg;
-       uint32_t iv_off = 0;
+       uint32_t iv_off = 0, counter;
        const bool need_dk = (dir == DIR_DEC) &&
                             (cipherdata->algtype == OP_ALG_ALGSEL_AES) &&
                             (cipherdata->algmode == OP_ALG_AAI_CBC);
@@ -336,12 +336,17 @@ cnstr_shdsc_blkcipher(uint32_t *descbuf, bool ps, bool swap,
        if (cipherdata->algmode == OP_ALG_AAI_CTR)
                iv_off = 16;
 
-       if (iv)
-               /* IV load, convert size */
-               LOAD(p, (uintptr_t)iv, CONTEXT1, iv_off, ivlen, IMMED | COPY);
-       else
-               /* IV is present first before the actual message */
-               SEQLOAD(p, CONTEXT1, iv_off, ivlen, 0);
+       /* IV is present first before the actual message */
+       SEQLOAD(p, CONTEXT1, iv_off, ivlen, 0);
+
+       /* If IV len is less than 16 bytes, set 'counter' as 1 */
+       if (cipherdata->algmode == OP_ALG_AAI_CTR && ivlen < 16) {
+               counter = 1;
+               if (!swap)
+                       counter = swab32(1);
+
+               LOAD(p, counter, CONTEXT1, (iv_off + ivlen), 16 - ivlen, IMMED);
+       }
 
        MATHB(p, SEQINSZ, SUB, MATH2, VSEQINSZ, 4, 0);
        MATHB(p, SEQINSZ, SUB, MATH2, VSEQOUTSZ, 4, 0);
index d1da9a6..8aaa3d4 100644 (file)
@@ -336,7 +336,6 @@ caam_jr_prep_cdb(struct caam_jr_session *ses)
                shared_desc_len = cnstr_shdsc_blkcipher(
                                                cdb->sh_desc, true,
                                                swap, SHR_NEVER, &alginfo_c,
-                                               NULL,
                                                ses->iv.length,
                                                ses->dir);
        } else if (is_auth_only(ses)) {
index c6af3a4..3150ca4 100644 (file)
@@ -1858,7 +1858,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
                cipherdata.algmode = OP_ALG_AAI_CBC;
                session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
                bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
-                                               SHR_NEVER, &cipherdata, NULL,
+                                               SHR_NEVER, &cipherdata,
                                                session->iv.length,
                                                session->dir);
                break;
@@ -1867,7 +1867,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
                cipherdata.algmode = OP_ALG_AAI_CBC;
                session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
                bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
-                                               SHR_NEVER, &cipherdata, NULL,
+                                               SHR_NEVER, &cipherdata,
                                                session->iv.length,
                                                session->dir);
                break;
@@ -1876,7 +1876,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
                cipherdata.algmode = OP_ALG_AAI_CTR;
                session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
                bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
-                                               SHR_NEVER, &cipherdata, NULL,
+                                               SHR_NEVER, &cipherdata,
                                                session->iv.length,
                                                session->dir);
                break;
@@ -1885,7 +1885,7 @@ dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
                cipherdata.algmode = OP_ALG_AAI_CTR;
                session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CTR;
                bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
-                                               SHR_NEVER, &cipherdata, NULL,
+                                               SHR_NEVER, &cipherdata,
                                                session->iv.length,
                                                session->dir);
                break;
index dcd0399..dc528ee 100644 (file)
@@ -478,7 +478,6 @@ dpaa_sec_prep_cdb(dpaa_sec_session *ses)
                        shared_desc_len = cnstr_shdsc_blkcipher(
                                        cdb->sh_desc, true,
                                        swap, SHR_NEVER, &alginfo_c,
-                                       NULL,
                                        ses->iv.length,
                                        ses->dir);
                        break;