cryptodev: remove unused cryptodev session structure
[dpdk.git] / drivers / crypto / snow3g / rte_snow3g_pmd.c
index b21691f..0c65b2d 100644 (file)
@@ -47,6 +47,8 @@
 #define SNOW3G_MAX_BURST 8
 #define BYTE_LEN 8
 
+static uint8_t cryptodev_driver_id;
+
 /** Get xform chain order. */
 static enum snow3g_operation
 snow3g_get_mode(const struct rte_crypto_sym_xform *xform)
@@ -121,7 +123,7 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
                        SNOW3G_LOG_ERR("Wrong IV length");
                        return -EINVAL;
                }
-               sess->iv_offset = cipher_xform->cipher.iv.offset;
+               sess->cipher_iv_offset = cipher_xform->cipher.iv.offset;
 
                /* Initialize key */
                sso_snow3g_init_key_sched(cipher_xform->cipher.key.data,
@@ -132,7 +134,20 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
                /* Only SNOW 3G UIA2 supported */
                if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_SNOW3G_UIA2)
                        return -EINVAL;
+
+               if (auth_xform->auth.digest_length != SNOW3G_DIGEST_LENGTH) {
+                       SNOW3G_LOG_ERR("Wrong digest length");
+                       return -EINVAL;
+               }
+
                sess->auth_op = auth_xform->auth.op;
+
+               if (auth_xform->auth.iv.length != SNOW3G_IV_LENGTH) {
+                       SNOW3G_LOG_ERR("Wrong IV length");
+                       return -EINVAL;
+               }
+               sess->auth_iv_offset = auth_xform->auth.iv.offset;
+
                /* Initialize key */
                sso_snow3g_init_key_sched(auth_xform->auth.key.data,
                                &sess->pKeySched_hash);
@@ -151,13 +166,13 @@ snow3g_get_session(struct snow3g_qp *qp, struct rte_crypto_op *op)
        struct snow3g_session *sess;
 
        if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-               if (unlikely(op->sym->session->dev_type !=
-                               RTE_CRYPTODEV_SNOW3G_PMD))
+               if (unlikely(op->sym->session->driver_id !=
+                               cryptodev_driver_id))
                        return NULL;
 
                sess = (struct snow3g_session *)op->sym->session->_private;
        } else  {
-               struct rte_cryptodev_session *c_sess = NULL;
+               struct rte_cryptodev_sym_session *c_sess = NULL;
 
                if (rte_mempool_get(qp->sess_mp, (void **)&c_sess))
                        return NULL;
@@ -193,7 +208,7 @@ process_snow3g_cipher_op(struct rte_crypto_op **ops,
                        rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
                                (ops[i]->sym->cipher.data.offset >> 3);
                iv[i] = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
-                               session->iv_offset);
+                               session->cipher_iv_offset);
                num_bytes[i] = ops[i]->sym->cipher.data.length >> 3;
 
                processed_ops++;
@@ -223,7 +238,7 @@ process_snow3g_cipher_op_bit(struct rte_crypto_op *op,
        }
        dst = rte_pktmbuf_mtod(op->sym->m_dst, uint8_t *);
        iv = rte_crypto_op_ctod_offset(op, uint8_t *,
-                               session->iv_offset);
+                               session->cipher_iv_offset);
        length_in_bits = op->sym->cipher.data.length;
 
        sso_snow3g_f8_1_buffer_bit(&session->pKeySched_cipher, iv,
@@ -242,20 +257,9 @@ process_snow3g_hash_op(struct rte_crypto_op **ops,
        uint8_t processed_ops = 0;
        uint8_t *src, *dst;
        uint32_t length_in_bits;
+       uint8_t *iv;
 
        for (i = 0; i < num_ops; i++) {
-               if (unlikely(ops[i]->sym->auth.aad.length != SNOW3G_IV_LENGTH)) {
-                       ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
-                       SNOW3G_LOG_ERR("aad");
-                       break;
-               }
-
-               if (unlikely(ops[i]->sym->auth.digest.length != SNOW3G_DIGEST_LENGTH)) {
-                       ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
-                       SNOW3G_LOG_ERR("digest");
-                       break;
-               }
-
                /* Data must be byte aligned */
                if ((ops[i]->sym->auth.data.offset % BYTE_LEN) != 0) {
                        ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
@@ -267,27 +271,29 @@ process_snow3g_hash_op(struct rte_crypto_op **ops,
 
                src = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
                                (ops[i]->sym->auth.data.offset >> 3);
+               iv = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
+                               session->auth_iv_offset);
 
                if (session->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
                        dst = (uint8_t *)rte_pktmbuf_append(ops[i]->sym->m_src,
-                                       ops[i]->sym->auth.digest.length);
+                                       SNOW3G_DIGEST_LENGTH);
 
                        sso_snow3g_f9_1_buffer(&session->pKeySched_hash,
-                                       ops[i]->sym->auth.aad.data, src,
+                                       iv, src,
                                        length_in_bits, dst);
                        /* Verify digest. */
                        if (memcmp(dst, ops[i]->sym->auth.digest.data,
-                                       ops[i]->sym->auth.digest.length) != 0)
+                                       SNOW3G_DIGEST_LENGTH) != 0)
                                ops[i]->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
 
                        /* Trim area used for digest from mbuf. */
                        rte_pktmbuf_trim(ops[i]->sym->m_src,
-                                       ops[i]->sym->auth.digest.length);
+                                       SNOW3G_DIGEST_LENGTH);
                } else  {
                        dst = ops[i]->sym->auth.digest.data;
 
                        sso_snow3g_f9_1_buffer(&session->pKeySched_hash,
-                                       ops[i]->sym->auth.aad.data, src,
+                                       iv, src,
                                        length_in_bits, dst);
                }
                processed_ops++;
@@ -558,7 +564,7 @@ cryptodev_snow3g_create(const char *name,
                goto init_error;
        }
 
-       dev->dev_type = RTE_CRYPTODEV_SNOW3G_PMD;
+       dev->driver_id = cryptodev_driver_id;
        dev->dev_ops = rte_snow3g_pmd_ops;
 
        /* Register RX/TX burst functions for data path. */
@@ -642,3 +648,4 @@ RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_SNOW3G_PMD,
        "max_nb_queue_pairs=<int> "
        "max_nb_sessions=<int> "
        "socket_id=<int>");
+RTE_PMD_REGISTER_CRYPTO_DRIVER(cryptodev_snow3g_pmd_drv, cryptodev_driver_id);