crypto/aesni_mb: fix CCM digest size check
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Fri, 9 Oct 2020 12:05:19 +0000 (12:05 +0000)
committerAkhil Goyal <akhil.goyal@nxp.com>
Wed, 14 Oct 2020 20:22:06 +0000 (22:22 +0200)
Digest size for CCM was being checked for other algorithms
apart from CCM.

Fixes: c4c0c312a823 ("crypto/aesni_mb: check for invalid digest size")
Cc: stable@dpdk.org
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c

index 34a39ca..ba2882d 100644 (file)
@@ -661,6 +661,14 @@ aesni_mb_set_session_aead_parameters(const MB_MGR *mb_mgr,
                return -EINVAL;
        }
 
+       /* Set IV parameters */
+       sess->iv.offset = xform->aead.iv.offset;
+       sess->iv.length = xform->aead.iv.length;
+
+       /* Set digest sizes */
+       sess->auth.req_digest_len = xform->aead.digest_length;
+       sess->auth.gen_digest_len = sess->auth.req_digest_len;
+
        switch (xform->aead.algo) {
        case RTE_CRYPTO_AEAD_AES_CCM:
                sess->cipher.mode = CCM;
@@ -679,6 +687,13 @@ aesni_mb_set_session_aead_parameters(const MB_MGR *mb_mgr,
                        return -EINVAL;
                }
 
+               /* CCM digests must be between 4 and 16 and an even number */
+               if (sess->auth.req_digest_len < AES_CCM_DIGEST_MIN_LEN ||
+                               sess->auth.req_digest_len > AES_CCM_DIGEST_MAX_LEN ||
+                               (sess->auth.req_digest_len & 1) == 1) {
+                       AESNI_MB_LOG(ERR, "Invalid digest size\n");
+                       return -EINVAL;
+               }
                break;
 
        case RTE_CRYPTO_AEAD_AES_GCM:
@@ -713,20 +728,6 @@ aesni_mb_set_session_aead_parameters(const MB_MGR *mb_mgr,
                return -ENOTSUP;
        }
 
-       /* Set IV parameters */
-       sess->iv.offset = xform->aead.iv.offset;
-       sess->iv.length = xform->aead.iv.length;
-
-       sess->auth.req_digest_len = xform->aead.digest_length;
-       /* CCM digests must be between 4 and 16 and an even number */
-       if (sess->auth.req_digest_len < AES_CCM_DIGEST_MIN_LEN ||
-                       sess->auth.req_digest_len > AES_CCM_DIGEST_MAX_LEN ||
-                       (sess->auth.req_digest_len & 1) == 1) {
-               AESNI_MB_LOG(ERR, "Invalid digest size\n");
-               return -EINVAL;
-       }
-       sess->auth.gen_digest_len = sess->auth.req_digest_len;
-
        return 0;
 }