app/crypto-perf: set AAD after the crypto operation
[dpdk.git] / app / test-crypto-perf / cperf_ops.c
index d718278..5be20d9 100644 (file)
@@ -307,6 +307,8 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,
                uint16_t iv_offset)
 {
        uint16_t i;
+       uint16_t aad_offset = iv_offset +
+                       RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16);
 
        for (i = 0; i < nb_ops; i++) {
                struct rte_crypto_sym_op *sym_op = ops[i]->sym;
@@ -318,11 +320,12 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,
 
                /* AEAD parameters */
                sym_op->aead.data.length = options->test_buffer_size;
-               sym_op->aead.data.offset =
-                               RTE_ALIGN_CEIL(options->aead_aad_sz, 16);
+               sym_op->aead.data.offset = 0;
 
-               sym_op->aead.aad.data = rte_pktmbuf_mtod(bufs_in[i], uint8_t *);
-               sym_op->aead.aad.phys_addr = rte_pktmbuf_mtophys(bufs_in[i]);
+               sym_op->aead.aad.data = rte_crypto_op_ctod_offset(ops[i],
+                                       uint8_t *, aad_offset);
+               sym_op->aead.aad.phys_addr = rte_crypto_op_ctophys_offset(ops[i],
+                                       aad_offset);
 
                if (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
                        sym_op->aead.digest.data = test_vector->digest.data;
@@ -360,6 +363,11 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,
 
                        memcpy(iv_ptr, test_vector->aead_iv.data,
                                        test_vector->aead_iv.length);
+
+                       /* Copy AAD after the IV */
+                       memcpy(ops[i]->sym->aead.aad.data,
+                               test_vector->aad.data,
+                               test_vector->aad.length);
                }
        }
 
@@ -367,7 +375,8 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,
 }
 
 static struct rte_cryptodev_sym_session *
-cperf_create_session(uint8_t dev_id,
+cperf_create_session(struct rte_mempool *sess_mp,
+       uint8_t dev_id,
        const struct cperf_options *options,
        const struct cperf_test_vector *test_vector,
        uint16_t iv_offset)
@@ -377,6 +386,7 @@ cperf_create_session(uint8_t dev_id,
        struct rte_crypto_sym_xform aead_xform;
        struct rte_cryptodev_sym_session *sess = NULL;
 
+       sess = rte_cryptodev_sym_session_create(sess_mp);
        /*
         * cipher only
         */
@@ -401,7 +411,8 @@ cperf_create_session(uint8_t dev_id,
                        cipher_xform.cipher.iv.length = 0;
                }
                /* create crypto session */
-               sess = rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
+               rte_cryptodev_sym_session_init(dev_id, sess, &cipher_xform,
+                               sess_mp);
        /*
         *  auth only
         */
@@ -427,7 +438,8 @@ cperf_create_session(uint8_t dev_id,
                        auth_xform.auth.iv.length = 0;
                }
                /* create crypto session */
-               sess =  rte_cryptodev_sym_session_create(dev_id, &auth_xform);
+               rte_cryptodev_sym_session_init(dev_id, sess, &auth_xform,
+                               sess_mp);
        /*
         * cipher and auth
         */
@@ -483,13 +495,13 @@ cperf_create_session(uint8_t dev_id,
                if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
                        cipher_xform.next = &auth_xform;
                        /* create crypto session */
-                       sess = rte_cryptodev_sym_session_create(dev_id,
-                                               &cipher_xform);
+                       rte_cryptodev_sym_session_init(dev_id,
+                                       sess, &cipher_xform, sess_mp);
                } else { /* auth then cipher */
                        auth_xform.next = &cipher_xform;
                        /* create crypto session */
-                       sess = rte_cryptodev_sym_session_create(dev_id,
-                                       &auth_xform);
+                       rte_cryptodev_sym_session_init(dev_id,
+                                       sess, &auth_xform, sess_mp);
                }
        } else { /* options->op_type == CPERF_AEAD */
                aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
@@ -505,11 +517,12 @@ cperf_create_session(uint8_t dev_id,
                aead_xform.aead.iv.length = test_vector->aead_iv.length;
 
                aead_xform.aead.digest_length = options->digest_sz;
-               aead_xform.aead.add_auth_data_length =
+               aead_xform.aead.aad_length =
                                        options->aead_aad_sz;
 
                /* Create crypto session */
-               sess = rte_cryptodev_sym_session_create(dev_id, &aead_xform);
+               rte_cryptodev_sym_session_init(dev_id,
+                                       sess, &aead_xform, sess_mp);
        }
 
        return sess;