diff mbox

[v2,06/15] crypto: add internal handle logic layer

Message ID 1473738741-220600-7-git-send-email-arei.gonglei@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gonglei (Arei) Sept. 13, 2016, 3:52 a.m. UTC
This patch add some transfering layer or functions,
such as session creation, closing etc, which will be
used by subsequent virtio crypto device patches.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 crypto/crypto.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
diff mbox

Patch

diff --git a/crypto/crypto.c b/crypto/crypto.c
index 1d3d1d3..184f837 100644
--- a/crypto/crypto.c
+++ b/crypto/crypto.c
@@ -291,3 +291,71 @@  void qemu_del_crypto_legacy_hw(CryptoLegacyHWState *crypto)
 
     g_free(crypto);
 }
+
+CryptoLegacyHWState *qemu_get_crypto_legacy_hw(CryptoClientState *cc)
+{
+    CryptoClientState *cc0 = cc - cc->queue_index;
+
+    return (CryptoLegacyHWState *)((void *)cc0 - cc->info->size);
+}
+
+void *qemu_get_crypto_legacy_hw_opaque(CryptoClientState *cc)
+{
+    CryptoLegacyHWState *crypto = qemu_get_crypto_legacy_hw(cc);
+
+    return crypto->opaque;
+}
+
+int qemu_find_crypto_clients_except(const char *id, CryptoClientState **ccs,
+                                 CryptoClientOptionsKind type, int max)
+{
+    CryptoClientState *cc;
+    int ret = 0;
+
+    QTAILQ_FOREACH(cc, &crypto_clients, next) {
+        if (cc->info->type == type) {
+            continue;
+        }
+        if (!id || !strcmp(cc->name, id)) {
+            if (ret < max) {
+                ccs[ret] = cc;
+            }
+            ret++;
+        }
+    }
+
+    return ret;
+}
+
+int qemu_crypto_create_session(CryptoClientState *cc,
+                               CryptoSymSessionInfo *info,
+                               uint64_t *session_id)
+{
+    int ret = -1;
+    CryptoClientState *peer = cc->peer;
+
+    if (!peer || !peer->ready) {
+        return ret;
+    }
+
+    if (peer->info->create_session) {
+        ret = peer->info->create_session(peer, info, session_id);
+    }
+    return ret;
+}
+
+int qemu_crypto_close_session(CryptoClientState *cc,
+                               uint64_t session_id)
+{
+    int ret = -1;
+    CryptoClientState *peer = cc->peer;
+
+    if (!peer || !peer->ready) {
+        return ret;
+    }
+
+    if (peer->info->close_session) {
+        ret = peer->info->close_session(peer, session_id);
+    }
+    return ret;
+}