All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gonglei <arei.gonglei@huawei.com>
To: qemu-devel@nongnu.org, virtio-dev@lists.oasis-open.org
Cc: luonengjun@huawei.com, mst@redhat.com, stefanha@redhat.com,
	pbonzini@redhat.com, berrange@redhat.com,
	weidong.huang@huawei.com, wu.wubin@huawei.com,
	mike.caraman@nxp.com, agraf@suse.de, xin.zeng@intel.com,
	claudio.fontana@huawei.com, nmorey@kalray.eu,
	vincent.jardin@6wind.com, jianjay.zhou@huawei.com,
	hanweidong@huawei.com, peter.huangpeng@huawei.com,
	Gonglei <arei.gonglei@huawei.com>
Subject: [Qemu-devel] [PATCH v4 02/13] cryptodev: add symmetric algorithm operation stuff
Date: Wed, 28 Sep 2016 16:25:41 +0800	[thread overview]
Message-ID: <1475051152-400276-3-git-send-email-arei.gonglei@huawei.com> (raw)
In-Reply-To: <1475051152-400276-1-git-send-email-arei.gonglei@huawei.com>

This patch add session operation and crypto operation
stuff in the cryptodev backend, including function
pointers and correpsonding structures.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 backends/cryptodev.c       |  45 +++++++++++++++
 include/sysemu/cryptodev.h | 133 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 178 insertions(+)

diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index a15904b..8963019 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -74,6 +74,51 @@ void qcrypto_cryptodev_backend_cleanup(
     backend->ready = 0;
 }
 
+int64_t qcrypto_cryptodev_backend_sym_create_session(
+           QCryptoCryptoDevBackend *backend,
+           QCryptoCryptoDevBackendSymSessionInfo *sess_info,
+           uint32_t queue_index, Error **errp)
+{
+    QCryptoCryptoDevBackendClass *bc =
+                      QCRYPTO_CRYPTODEV_BACKEND_GET_CLASS(backend);
+
+    if (bc->create_session) {
+        return bc->create_session(backend, sess_info, queue_index, errp);
+    }
+
+    return -1;
+}
+
+int qcrypto_cryptodev_backend_sym_close_session(
+           QCryptoCryptoDevBackend *backend,
+           uint64_t session_id,
+           uint32_t queue_index, Error **errp)
+{
+    QCryptoCryptoDevBackendClass *bc =
+                      QCRYPTO_CRYPTODEV_BACKEND_GET_CLASS(backend);
+
+    if (bc->close_session) {
+        return bc->close_session(backend, session_id, queue_index, errp);
+    }
+
+    return -1;
+}
+
+int qcrypto_cryptodev_backend_sym_operation(
+                 QCryptoCryptoDevBackend *backend,
+                 QCryptoCryptoDevBackendSymOpInfo *op_info,
+                 uint32_t queue_index, Error **errp)
+{
+    QCryptoCryptoDevBackendClass *bc =
+                      QCRYPTO_CRYPTODEV_BACKEND_GET_CLASS(backend);
+
+    if (bc->do_sym_op) {
+        return bc->do_sym_op(backend, op_info, queue_index, errp);
+    }
+
+    return -1;
+}
+
 static void
 qcrypto_cryptodev_backend_get_queues(Object *obj, Visitor *v, const char *name,
                              void *opaque, Error **errp)
diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h
index cc3c3be..ea5e1bb 100644
--- a/include/sysemu/cryptodev.h
+++ b/include/sysemu/cryptodev.h
@@ -56,12 +56,95 @@ typedef struct QCryptoCryptoDevBackendClientState
                      QCryptoCryptoDevBackendClientState;
 typedef struct QCryptoCryptoDevBackend QCryptoCryptoDevBackend;
 
+enum QCryptoCryptoDevBackendAlgType {
+    QCRYPTO_CRYPTODEV_BACKEND_ALG_SYM,
+    QCRYPTO_CRYPTODEV_BACKEND_ALG__MAX,
+};
+
+/**
+ * QCryptoCryptoDevBackendSymSessionInfo:
+ *
+ * @op_code: operation code (refer to virtio_crypto.h)
+ * @cipher_alg: algorithm type of CIPHER
+ * @key_len: byte length of cipher key
+ * @hash_alg: algorithm type of HASH/MAC
+ * @hash_result_len: byte length of HASH operation result
+ * @auth_key_len: byte length of authenticated key
+ * @add_len: byte length of additional authenticated data
+ * @op_type: operation type (refer to virtio_crypto.h)
+ * @direction: encryption or direction for CIPHER
+ * @hash_mode: HASH mode for HASH operation (refer to virtio_crypto.h)
+ * @alg_chain_order: order of algorithm chaining (CIPHER then HASH,
+ *                   or HASH then CIPHER)
+ * @cipher_key: pointer to a key of CIPHER
+ * @auth_key: pointer to an authenticated key of MAC
+ *
+ */
+typedef struct QCryptoCryptoDevBackendSymSessionInfo {
+    /* corresponding with virtio crypto spec */
+    uint32_t op_code;
+    uint32_t cipher_alg;
+    uint32_t key_len;
+    uint32_t hash_alg;
+    uint32_t hash_result_len;
+    uint32_t auth_key_len;
+    uint32_t add_len;
+    uint8_t op_type;
+    uint8_t direction;
+    uint8_t hash_mode;
+    uint8_t alg_chain_order;
+    uint8_t *cipher_key;
+    uint8_t *auth_key;
+} QCryptoCryptoDevBackendSymSessionInfo;
+
+/**
+ * QCryptoCryptoDevBackendSymOpInfo:
+ *
+ * @session_id: session index which was previously
+ *              created by qcrypto_cryptodev_backend_sym_create_session()
+ * @aad_len: byte length of additional authenticated data
+ * @iv_len: byte length of initialization vector or counter
+ * @src_len: byte length of source data
+ * @dst_len: byte length of destination data, which is equal to
+ *           src_len + hash_result_len if HASH alg configured
+ * @op_type: operation type (refer to virtio_crypto.h)
+ * @iv: pointer to the initialization vector or counter
+ * @src: pointer to the source data
+ * @dst: pointer to the destination data
+ * @dst: pointer to the additional authenticated data
+ * @data[0]: pointer to the extensional memory by one memory allocation
+ *
+ */
+typedef struct QCryptoCryptoDevBackendSymOpInfo {
+    uint64_t session_id;
+    uint32_t aad_len;
+    uint32_t iv_len;
+    uint32_t src_len;
+    /* dst_len is equal to src_len + hash_result_len if hash alg configured */
+    uint32_t dst_len;
+    uint8_t op_type; /* cipher or algo chainning */
+    uint8_t *iv;
+    uint8_t *src;
+    uint8_t *dst;
+    uint8_t *aad_data; /* additional auth data */
+    uint8_t data[0];
+} QCryptoCryptoDevBackendSymOpInfo;
 
 typedef struct QCryptoCryptoDevBackendClass {
     ObjectClass parent_class;
 
     void (*init)(QCryptoCryptoDevBackend *backend, Error **errp);
     void (*cleanup)(QCryptoCryptoDevBackend *backend, Error **errp);
+
+    int64_t (*create_session)(QCryptoCryptoDevBackend *backend,
+                       QCryptoCryptoDevBackendSymSessionInfo *sess_info,
+                       uint32_t queue_index, Error **errp);
+    int (*close_session)(QCryptoCryptoDevBackend *backend,
+                           uint64_t session_id,
+                           uint32_t queue_index, Error **errp);
+    int (*do_sym_op)(QCryptoCryptoDevBackend *backend,
+                     QCryptoCryptoDevBackendSymOpInfo *op_info,
+                     uint32_t queue_index, Error **errp);
 } QCryptoCryptoDevBackendClass;
 
 
@@ -142,4 +225,54 @@ void qcrypto_cryptodev_backend_cleanup(
            QCryptoCryptoDevBackend *backend,
            Error **errp);
 
+/**
+ * qcrypto_cryptodev_backend_sym_create_session:
+ * @backend: the cryptodev backend object
+ * @sess_info: parameters needed by session creating
+ * @queue_index: queue index of cryptodev backend client
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Create a session for symmetric algorithms
+ *
+ * Returns: session id on success, or -1 on error
+ */
+int64_t qcrypto_cryptodev_backend_sym_create_session(
+           QCryptoCryptoDevBackend *backend,
+           QCryptoCryptoDevBackendSymSessionInfo *sess_info,
+           uint32_t queue_index, Error **errp);
+
+/**
+ * qcrypto_cryptodev_backend_sym_close_session:
+ * @backend: the cryptodev backend object
+ * @session_id: the session id
+ * @queue_index: queue index of cryptodev backend client
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Close a session for symmetric algorithms which was previously
+ * created by qcrypto_cryptodev_backend_sym_create_session()
+ *
+ * Returns: 0 on success, or Negative on error
+ */
+int qcrypto_cryptodev_backend_sym_close_session(
+           QCryptoCryptoDevBackend *backend,
+           uint64_t session_id,
+           uint32_t queue_index, Error **errp);
+
+/**
+ * qcrypto_cryptodev_backend_sym_operation:
+ * @backend: the cryptodev backend object
+ * @op_info: parameters needed by symmetric crypto operation
+ * @queue_index: queue index of cryptodev backend client
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Do symmetric crypto operation, such as encryption and
+ * decryption
+ *
+ * Returns: 0 on success, or Negative on error
+ */
+int qcrypto_cryptodev_backend_sym_operation(
+                 QCryptoCryptoDevBackend *backend,
+                 QCryptoCryptoDevBackendSymOpInfo *op_info,
+                 uint32_t queue_index, Error **errp);
+
 #endif /* QCRYPTO_CRYPTODEV_H */
-- 
1.7.12.4

  parent reply	other threads:[~2016-09-28  8:30 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-28  8:25 [Qemu-devel] [PATCH v4 00/13] virtio-crypto: introduce framework and device emulation Gonglei
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 01/13] cryptodev: introduce cryptodev backend interface Gonglei
2016-10-03 16:10   ` Stefan Hajnoczi
2016-10-03 16:15     ` Daniel P. Berrange
2016-10-05  3:06     ` Gonglei (Arei)
2016-09-28  8:25 ` Gonglei [this message]
2016-10-03 16:13   ` [Qemu-devel] [PATCH v4 02/13] cryptodev: add symmetric algorithm operation stuff Stefan Hajnoczi
2016-10-05  3:07     ` [Qemu-devel] [virtio-dev] " Gonglei (Arei)
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 03/13] virtio-crypto: introduce virtio_crypto.h Gonglei
2016-10-03 16:14   ` Stefan Hajnoczi
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 04/13] cryptodev: introduce a new cryptodev backend Gonglei
2016-10-03 16:31   ` Stefan Hajnoczi
2016-10-05  3:19     ` Gonglei (Arei)
2016-10-05 12:53       ` Stefan Hajnoczi
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 05/13] virtio-crypto: add virtio crypto device emulation Gonglei
2016-10-04  9:38   ` Stefan Hajnoczi
2016-10-05  3:26     ` Gonglei (Arei)
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 06/13] virtio-crypto-pci: add virtio crypto pci support Gonglei
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 07/13] virtio-crypto: set capacity of algorithms supported Gonglei
2016-10-04  9:46   ` Stefan Hajnoczi
2016-10-05  3:30     ` [Qemu-devel] [virtio-dev] " Gonglei (Arei)
2016-10-05 12:55       ` Stefan Hajnoczi
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 08/13] virtio-crypto: add control queue handler Gonglei
2016-10-04 10:09   ` Stefan Hajnoczi
2016-10-05  3:38     ` Gonglei (Arei)
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 09/13] virtio-crypto: add data queue processing handler Gonglei
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 10/13] cryptodev: introduce an unified wrapper for crypto operation Gonglei
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 11/13] virtio-crypto: emulate virtio crypto as a legacy device by default Gonglei
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 12/13] virtio-crypto-test: add qtest case for virtio-crypto Gonglei
2016-09-28  8:25 ` [Qemu-devel] [PATCH v4 13/13] virtio-crypto: add myself as virtio-crypto and cryptodev backends maintainer Gonglei
2016-09-28  9:14 ` [Qemu-devel] [PATCH v4 00/13] virtio-crypto: introduce framework and device emulation no-reply
2016-09-28  9:18   ` Gonglei (Arei)
2016-10-03 12:02 ` Gonglei (Arei)
2016-10-04 10:13 ` Stefan Hajnoczi
2016-10-05  3:42   ` [Qemu-devel] [virtio-dev] " Gonglei (Arei)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475051152-400276-3-git-send-email-arei.gonglei@huawei.com \
    --to=arei.gonglei@huawei.com \
    --cc=agraf@suse.de \
    --cc=berrange@redhat.com \
    --cc=claudio.fontana@huawei.com \
    --cc=hanweidong@huawei.com \
    --cc=jianjay.zhou@huawei.com \
    --cc=luonengjun@huawei.com \
    --cc=mike.caraman@nxp.com \
    --cc=mst@redhat.com \
    --cc=nmorey@kalray.eu \
    --cc=pbonzini@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vincent.jardin@6wind.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=weidong.huang@huawei.com \
    --cc=wu.wubin@huawei.com \
    --cc=xin.zeng@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.