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: peter.huangpeng@huawei.com, luonengjun@huawei.com,
	mst@redhat.com, stefanha@redhat.com, pbonzini@redhat.com,
	berrange@redhat.com, weidong.huang@huawei.com,
	mike.caraman@nxp.com, agraf@suse.de, xin.zeng@intel.com,
	claudio.fontana@huawei.com, nmorey@kalray.eu,
	vincent.jardin@6wind.com, Gonglei <arei.gonglei@huawei.com>
Subject: [Qemu-devel] [PATCH v2 04/15] crypto: add symetric algorithms support
Date: Tue, 13 Sep 2016 11:52:10 +0800	[thread overview]
Message-ID: <1473738741-220600-5-git-send-email-arei.gonglei@huawei.com> (raw)
In-Reply-To: <1473738741-220600-1-git-send-email-arei.gonglei@huawei.com>

This patch include three parts, the first is define the
session structure and the second is the opertion structure,
whose properties are needed to finish the symetric algorithms.
The third part defines some function pointers.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 crypto/crypto.c         | 16 +++++++++-
 include/crypto/crypto.h | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 1 deletion(-)

diff --git a/crypto/crypto.c b/crypto/crypto.c
index 3f760fd..958a959 100644
--- a/crypto/crypto.c
+++ b/crypto/crypto.c
@@ -177,7 +177,21 @@ int qemu_deliver_crypto_packet(CryptoClientState *sender,
                               void *header_opqaue,
                               void *opaque)
 {
-    return 0;
+    CryptoClientState *cc = opaque;
+    int ret = -1;
+
+    if (!cc->ready) {
+        return 1;
+    }
+
+    if (flags == QEMU_CRYPTO_PACKET_FLAG_SYM) {
+        CryptoSymOpInfo *op_info = header_opqaue;
+        if (cc->info->do_sym_op) {
+            ret = cc->info->do_sym_op(cc, op_info);
+        }
+    }
+
+    return ret;
 }
 
 int qemu_send_crypto_packet_async(CryptoClientState *sender,
diff --git a/include/crypto/crypto.h b/include/crypto/crypto.h
index 4f0efb7..95cca23 100644
--- a/include/crypto/crypto.h
+++ b/include/crypto/crypto.h
@@ -33,10 +33,50 @@
 
 #define MAX_CRYPTO_QUEUE_NUM  64
 
+#define  QEMU_CRYPTO_PACKET_FLAG_NONE (0)
+#define  QEMU_CRYPTO_PACKET_FLAG_SYM (1 << 0)
+
+typedef struct CryptoSymSessionInfo {
+    uint8_t op_code;
+    uint8_t op_type;
+    uint8_t direction;
+    uint32_t cipher_alg;
+    uint32_t key_len;
+    uint8_t *cipher_key;
+
+    uint32_t hash_alg;
+    uint8_t hash_mode;
+    uint32_t hash_result_len;
+    uint8_t alg_chain_order;
+    uint32_t auth_key_len;
+    uint32_t add_len;
+    uint8_t *auth_key;
+} CryptoSymSessionInfo;
+
+typedef struct CryptoSymOpInfo {
+    uint64_t session_id;
+    uint8_t op_type; /* cipher or algo chainning */
+    uint8_t *src;
+    uint8_t *dst;
+    uint8_t *iv;
+    uint8_t *aad_data; /* additional auth data */
+    uint32_t aad_len;
+    uint32_t iv_len;
+    uint32_t src_len;
+    /* the dst_len is equal to src_len + hash_result_len
+     * if hash alg configured */
+    uint32_t dst_len;
+    uint8_t data[0];
+} CryptoSymOpInfo;
+
 typedef void (CryptoPoll)(CryptoClientState *, bool);
 typedef void (CryptoCleanup) (CryptoClientState *);
 typedef void (CryptoClientDestructor)(CryptoClientState *);
 typedef void (CryptoHWStatusChanged)(CryptoClientState *);
+typedef int (CryptoCreateSymSession)(CryptoClientState *,
+                              CryptoSymSessionInfo *, uint64_t *);
+typedef int (CryptoCloseSession)(CryptoClientState *, uint64_t);
+typedef int (CryptoDoSymOp)(CryptoClientState *, CryptoSymOpInfo *);
 
 typedef struct CryptoClientInfo {
     CryptoClientOptionsKind type;
@@ -45,6 +85,9 @@ typedef struct CryptoClientInfo {
     CryptoCleanup *cleanup;
     CryptoPoll *poll;
     CryptoHWStatusChanged *hw_status_changed;
+    CryptoCreateSymSession *create_session;
+    CryptoCloseSession *close_session;
+    CryptoDoSymOp *do_sym_op;
 } CryptoClientInfo;
 
 struct CryptoClientState {
@@ -57,6 +100,21 @@ struct CryptoClientState {
     char info_str[256];
     CryptoQueue *incoming_queue;
     unsigned int queue_index;
+
+    /* Supported service mask */
+    uint32_t crypto_services;
+
+    /* Detailed algorithms mask */
+    uint32_t cipher_algo_l;
+    uint32_t cipher_algo_h;
+    uint32_t hash_algo;
+    uint32_t mac_algo_l;
+    uint32_t mac_algo_h;
+    uint32_t asym_algo;
+    uint32_t kdf_algo;
+    uint32_t aead_algo;
+    uint32_t primitive_algo;
+
     CryptoClientDestructor *destructor;
 };
 
@@ -69,6 +127,20 @@ typedef struct CryptoLegacyHWPeers {
 
 typedef struct CryptoLegacyHWConf {
     CryptoLegacyHWPeers peers;
+
+    /* Supported service mask */
+    uint32_t crypto_services;
+
+    /* Detailed algorithms mask */
+    uint32_t cipher_algo_l;
+    uint32_t cipher_algo_h;
+    uint32_t hash_algo;
+    uint32_t mac_algo_l;
+    uint32_t mac_algo_h;
+    uint32_t asym_algo;
+    uint32_t kdf_algo;
+    uint32_t aead_algo;
+    uint32_t primitive_algo;
 } CryptoLegacyHWConf;
 
 typedef struct CryptoLegacyHWState {
@@ -104,4 +176,17 @@ void qemu_del_crypto_legacy_hw(CryptoLegacyHWState *crypto);
 CryptoClientState *
 qemu_get_crypto_subqueue(CryptoLegacyHWState *crypto, int queue_index);
 
+CryptoLegacyHWState *qemu_get_crypto_legacy_hw(CryptoClientState *cc);
+
+void *qemu_get_crypto_legacy_hw_opaque(CryptoClientState *cc);
+
+int qemu_find_crypto_clients_except(const char *id, CryptoClientState **ccs,
+                                 CryptoClientOptionsKind type, int max);
+
+int qemu_crypto_create_session(CryptoClientState *cc,
+                               CryptoSymSessionInfo *info,
+                               uint64_t *session_id);
+int qemu_crypto_close_session(CryptoClientState *cc,
+                               uint64_t session_id);
+
 #endif /* QCRYPTO_CRYPTO_H__ */
-- 
1.7.12.4

  parent reply	other threads:[~2016-09-13  3:56 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13  3:52 [Qemu-devel] [PATCH v2 00/15] virtio-crypto: introduce framework and device emulation Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 01/15] crypto: introduce cryptodev backend and crypto legacy hardware Gonglei
2016-09-13  9:13   ` Daniel P. Berrange
2016-09-13  9:55     ` Gonglei (Arei)
2016-09-13  9:59       ` Daniel P. Berrange
2016-09-13 10:06         ` Gonglei (Arei)
2016-09-13 10:50     ` Paolo Bonzini
2016-09-13 11:04       ` Daniel P. Berrange
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 02/15] crypto: introduce crypto queue handler Gonglei
2016-09-13  9:20   ` Daniel P. Berrange
2016-09-13  9:58     ` Gonglei (Arei)
2016-09-13 10:58     ` Paolo Bonzini
2016-09-13 11:52       ` [Qemu-devel] [virtio-dev] " Ola Liljedahl
2016-09-14  1:07         ` Gonglei (Arei)
2016-09-14  8:24           ` Ola Liljedahl
2016-09-14  1:03       ` Gonglei (Arei)
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff Gonglei
2016-09-13  9:22   ` Daniel P. Berrange
2016-09-13 10:05     ` Gonglei (Arei)
2016-09-13 10:08       ` Daniel P. Berrange
2016-09-13 10:14         ` Gonglei (Arei)
2016-09-13  3:52 ` Gonglei [this message]
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 05/15] crypto: add cryptodev-linux as a cryptodev backend Gonglei
2016-09-13  9:23   ` Daniel P. Berrange
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 06/15] crypto: add internal handle logic layer Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 07/15] virtio-crypto: introduce virtio-crypto.h Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 08/15] virtio-crypto-pci: add virtio crypto pci support Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 09/15] virtio-crypto: add virtio crypto realization Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 10/15] virtio-crypto: set capacity of crypto legacy hardware Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 11/15] virtio-crypto: add control queue handler Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 12/15] virtio-crypto: add destroy session logic Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 13/15] virtio-crypto: get correct input data address for each request Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 14/15] virtio-crypto: add data virtqueue processing handler Gonglei
2016-09-13  3:52 ` [Qemu-devel] [PATCH v2 15/15] virtio-crypto: support scatter gather list Gonglei
2016-09-13  8:57 ` [Qemu-devel] [PATCH v2 00/15] virtio-crypto: introduce framework and device emulation Daniel P. Berrange
2016-09-13  9:45   ` Gonglei (Arei)
2016-09-13  9:54     ` Daniel P. Berrange
2016-09-13 10:08       ` Gonglei (Arei)
2016-09-13 10:58       ` Paolo Bonzini
2016-09-13 11:07         ` Daniel P. Berrange

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=1473738741-220600-5-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=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=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.