Skip to contentSkip to conversation

crypto: introduce some common functions for af_alg backend

PATCH Superseded Longpeng(Mike) 2 participants 2 messages Apr 10, 2017 Crypto API

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 13/19 crypto: introduce some common functions for af_alg backend

This patch introduces some common functions for af_alg backend, they would be used in af_alg-backend cipher/hash/hmac latter.

---
 crypto/Makefile.objs        |  1 +
 crypto/afalg-comm.c         | 71 +++++++++++++++++++++++++++++++++++++++++++++
 include/crypto/afalg-comm.h | 61 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 crypto/afalg-comm.c
 create mode 100644 include/crypto/afalg-comm.h
crypto/Makefile.objs +1 -0
index 1f749f2..6f244a3 100644
@@ -10,6 +10,7 @@ crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT_HMAC),n,y)) += hmac-glib
 crypto-obj-y += aes.o
 crypto-obj-y += desrfb.o
 crypto-obj-y += cipher.o
+crypto-obj-$(CONFIG_AF_ALG) += afalg-comm.o
 crypto-obj-y += tlscreds.o
 crypto-obj-y += tlscredsanon.o
 crypto-obj-y += tlscredsx509.o
crypto/afalg-comm.c new file +71 -0

71 lines not on this page · raw message

include/crypto/afalg-comm.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

crypto/afalg-comm.c

Quoted 29 lines · Longpeng(Mike)

This patch introduces some common functions for af_alg backend, they would be used in af_alg-backend cipher/hash/hmac latter.

---
 crypto/Makefile.objs        |  1 +
 crypto/afalg-comm.c         | 71 +++++++++++++++++++++++++++++++++++++++++++++
 include/crypto/afalg-comm.h | 61 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 crypto/afalg-comm.c
 create mode 100644 include/crypto/afalg-comm.h
crypto/Makefile.objs +1 -0
index 1f749f2..6f244a3 100644
@@ -10,6 +10,7 @@ crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT_HMAC),n,y)) += hmac-glib
 crypto-obj-y += aes.o
 crypto-obj-y += desrfb.o
 crypto-obj-y += cipher.o
+crypto-obj-$(CONFIG_AF_ALG) += afalg-comm.o
 crypto-obj-y += tlscreds.o
 crypto-obj-y += tlscredsanon.o
 crypto-obj-y += tlscredsx509.o
crypto/afalg-comm.c new file +0 -0
new file mode 100644
index 0000000..27bc88c

Just calls this crypto/afalg.c

crypto/afalg-comm.c line 24

Quoted 6 lines
crypto/afalg-comm.c new file +6 -0
+void afalg_comm_format_type(AfalgSocketAddress *afalg,
+                            const char *type)
+{
+    afalg->type = (char *)g_new0(int8_t, SALG_TYPE_LEN_MAX);
+    pstrcpy(afalg->type, SALG_TYPE_LEN_MAX, type);
+}

Needs an 'Error **errp' for reporting if 'type' is too long

Quoted 16 lines
include/crypto/afalg-comm.h new file +10 -0
new file mode 100644
index 0000000..b6b9464
@@ -0,0 +1,61 @@
+/*
+ * QEMU Crypto af_alg support
+ *
+ * Copyright (c) 2017 HUAWEI TECHNOLOGIES CO., LTD.
+ *
+ * Authors:
+ *    Longpeng(Mike) <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the

include/crypto/afalg-comm.h line 20

Quoted 10 lines
include/crypto/afalg-comm.h new file +10 -0
+ * top-level directory.
+ */
+#ifndef QCRYPTO_AFALG_H
+#define QCRYPTO_AFALG_H
+
+#include "qapi-types.h"
+
+#ifndef SOL_ALG
+#define SOL_ALG 279
+#endif

This can be in the .c file as I don't se it used elsewhere.

include/crypto/afalg-comm.h line 23

Quoted 3 lines
include/crypto/afalg-comm.h new file +3 -0
+
+typedef struct QCryptoAfalg QCryptoAfalg;
+struct QCryptoAfalg {

Name it 'QCryptoAFAlg' since the letters 'af' are an abbreviation.

Quoted 28 lines
include/crypto/afalg-comm.h new file +28 -0
+    int tfmfd;
+    int opfd;
+    struct msghdr *msg;
+    struct cmsghdr *cmsg;
+};
+
+
+/**
+ * afalg_comm_format_type:
+ * @afalg: the AfalgSocketAddress object
+ * @type: the type of crypto alg.
+ *
+ * Set the type field of the @afalg according to @type.
+ */
+void afalg_comm_format_type(AfalgSocketAddress *afalg,
+                            const char *type);
+
+/**
+ * afalg_comm_alloc:
+ * @saddr: the SocketAddress object
+ *
+ * Allocate a QCryptoAfalg object and bind itself to
+ * a AF_ALG socket.
+ *
+ * Returns:
+ *  a new QCryptoAfalg object, or NULL in error.
+ */
+QCryptoAfalg *afalg_comm_alloc(SocketAddress *saddr);

include/crypto/afalg-comm.h line 61

Quoted 10 lines
include/crypto/afalg-comm.h new file +10 -0
+
+/**
+ * afalg_comm_free:
+ * @afalg: the QCryptoAfalg object
+ *
+ * Free the @afalg.
+ */
+void afalg_comm_free(QCryptoAfalg *afalg);
+
+#endif

This is all for internal use by the crypto/ code, so should be in a header crypto/afalgpriv.h

Quoted 4 lines
Signature · 1 line
1.8.3.1

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|