cryptodev: remove crypto device type enumeration
[dpdk.git] / drivers / crypto / kasumi / rte_kasumi_pmd.c
index 810699f..6c8da17 100644 (file)
@@ -48,6 +48,8 @@
 #define KASUMI_MAX_BURST 4
 #define BYTE_LEN 8
 
+static uint8_t cryptodev_driver_id;
+
 /** Get xform chain order. */
 static enum kasumi_operation
 kasumi_get_mode(const struct rte_crypto_sym_xform *xform)
@@ -117,7 +119,7 @@ kasumi_set_session_parameters(struct kasumi_session *sess,
                if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_KASUMI_F8)
                        return -EINVAL;
 
-               sess->iv_offset = cipher_xform->cipher.iv.offset;
+               sess->cipher_iv_offset = cipher_xform->cipher.iv.offset;
                if (cipher_xform->cipher.iv.length != KASUMI_IV_LENGTH) {
                        KASUMI_LOG_ERR("Wrong IV length");
                        return -EINVAL;
@@ -132,7 +134,20 @@ kasumi_set_session_parameters(struct kasumi_session *sess,
                /* Only KASUMI F9 supported */
                if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_KASUMI_F9)
                        return -EINVAL;
+
+               if (auth_xform->auth.digest_length != KASUMI_DIGEST_LENGTH) {
+                       KASUMI_LOG_ERR("Wrong digest length");
+                       return -EINVAL;
+               }
+
                sess->auth_op = auth_xform->auth.op;
+
+               sess->auth_iv_offset = auth_xform->auth.iv.offset;
+               if (auth_xform->auth.iv.length != KASUMI_IV_LENGTH) {
+                       KASUMI_LOG_ERR("Wrong IV length");
+                       return -EINVAL;
+               }
+
                /* Initialize key */
                sso_kasumi_init_f9_key_sched(auth_xform->auth.key.data,
                                &sess->pKeySched_hash);
@@ -151,8 +166,8 @@ kasumi_get_session(struct kasumi_qp *qp, struct rte_crypto_op *op)
        struct kasumi_session *sess;
 
        if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
-               if (unlikely(op->sym->session->dev_type !=
-                               RTE_CRYPTODEV_KASUMI_PMD))
+               if (unlikely(op->sym->session->driver_id !=
+                               cryptodev_driver_id))
                        return NULL;
 
                sess = (struct kasumi_session *)op->sym->session->_private;
@@ -194,7 +209,7 @@ process_kasumi_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_ptr = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
-                               session->iv_offset);
+                               session->cipher_iv_offset);
                iv[i] = *((uint64_t *)(iv_ptr));
                num_bytes[i] = ops[i]->sym->cipher.data.length >> 3;
 
@@ -227,7 +242,7 @@ process_kasumi_cipher_op_bit(struct rte_crypto_op *op,
        }
        dst = rte_pktmbuf_mtod(op->sym->m_dst, uint8_t *);
        iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
-                       session->iv_offset);
+                       session->cipher_iv_offset);
        iv = *((uint64_t *)(iv_ptr));
        length_in_bits = op->sym->cipher.data.length;
 
@@ -246,6 +261,7 @@ process_kasumi_hash_op(struct rte_crypto_op **ops,
        unsigned i;
        uint8_t processed_ops = 0;
        uint8_t *src, *dst;
+       uint8_t *iv_ptr;
        uint32_t length_in_bits;
        uint32_t num_bytes;
        uint32_t shift_bits;
@@ -253,18 +269,6 @@ process_kasumi_hash_op(struct rte_crypto_op **ops,
        uint8_t direction;
 
        for (i = 0; i < num_ops; i++) {
-               if (unlikely(ops[i]->sym->auth.aad.length != KASUMI_IV_LENGTH)) {
-                       ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
-                       KASUMI_LOG_ERR("aad");
-                       break;
-               }
-
-               if (unlikely(ops[i]->sym->auth.digest.length != KASUMI_DIGEST_LENGTH)) {
-                       ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
-                       KASUMI_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;
@@ -276,8 +280,9 @@ process_kasumi_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 from AAD */
-               iv = *((uint64_t *)(ops[i]->sym->auth.aad.data));
+               iv_ptr = rte_crypto_op_ctod_offset(ops[i], uint8_t *,
+                               session->auth_iv_offset);
+               iv = *((uint64_t *)(iv_ptr));
                /* Direction from next bit after end of message */
                num_bytes = (length_in_bits >> 3) + 1;
                shift_bits = (BYTE_LEN - 1 - length_in_bits) % BYTE_LEN;
@@ -285,19 +290,19 @@ process_kasumi_hash_op(struct rte_crypto_op **ops,
 
                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);
+                                       KASUMI_DIGEST_LENGTH);
 
                        sso_kasumi_f9_1_buffer_user(&session->pKeySched_hash,
                                        iv, src,
                                        length_in_bits, dst, direction);
                        /* Verify digest. */
                        if (memcmp(dst, ops[i]->sym->auth.digest.data,
-                                       ops[i]->sym->auth.digest.length) != 0)
+                                       KASUMI_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);
+                                       KASUMI_DIGEST_LENGTH);
                } else  {
                        dst = ops[i]->sym->auth.digest.data;
 
@@ -577,7 +582,7 @@ cryptodev_kasumi_create(const char *name,
                goto init_error;
        }
 
-       dev->dev_type = RTE_CRYPTODEV_KASUMI_PMD;
+       dev->driver_id = cryptodev_driver_id;
        dev->dev_ops = rte_kasumi_pmd_ops;
 
        /* Register RX/TX burst functions for data path. */
@@ -661,3 +666,4 @@ RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_KASUMI_PMD,
        "max_nb_queue_pairs=<int> "
        "max_nb_sessions=<int> "
        "socket_id=<int>");
+RTE_PMD_REGISTER_CRYPTO_DRIVER(cryptodev_kasumi_pmd_drv, cryptodev_driver_id);