[PATCH RFC 2/7] crypto/compress: introduce sychronuous compression API

2016-01-03 Thread Joonsoo Kim
This introduces new compression APIs. Major change is that APIs are
stateless. Instead of previous implementation, tfm objects doesn't
embedded any context so we can de/compress concurrently with one tfm
object. Instead, thsi de/compression context is coupled with the request.
This architecture change will make APIs more flexible.

Signed-off-by: Joonsoo Kim 
---
 crypto/Kconfig|   5 ++
 crypto/Makefile   |   1 +
 crypto/scompress.c| 114 ++
 include/crypto/compress.h |  76 +++
 include/linux/crypto.h|   1 +
 5 files changed, 197 insertions(+)
 create mode 100644 crypto/scompress.c
 create mode 100644 include/crypto/compress.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index c80d34f..7159520 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -84,6 +84,10 @@ config CRYPTO_RNG_DEFAULT
tristate
select CRYPTO_DRBG_MENU
 
+config CRYPTO_SCOMPRESS
+   tristate
+   select CRYPTO_ALGAPI2
+
 config CRYPTO_AKCIPHER2
tristate
select CRYPTO_ALGAPI2
@@ -1499,6 +1503,7 @@ config CRYPTO_LZO
select CRYPTO_ALGAPI
select LZO_COMPRESS
select LZO_DECOMPRESS
+   select SCOMPRESS
help
  This is the LZO algorithm.
 
diff --git a/crypto/Makefile b/crypto/Makefile
index ffe18c9..16ef796 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -28,6 +28,7 @@ crypto_hash-y += ahash.o
 crypto_hash-y += shash.o
 obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
 
+obj-$(CONFIG_CRYPTO_SCOMPRESS) += scompress.o
 obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o
 
 $(obj)/rsapubkey-asn1.o: $(obj)/rsapubkey-asn1.c $(obj)/rsapubkey-asn1.h
diff --git a/crypto/scompress.c b/crypto/scompress.c
new file mode 100644
index 000..7c9955b
--- /dev/null
+++ b/crypto/scompress.c
@@ -0,0 +1,114 @@
+/*
+ * Cryptographic API.
+ *
+ * Synchronous compression operations.
+ *
+ * Copyright 2015 LG Electronics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "internal.h"
+
+
+static int crypto_scomp_init(struct crypto_tfm *tfm, u32 type, u32 mask)
+{
+   return 0;
+}
+
+static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
+{
+   return 0;
+}
+
+#ifdef CONFIG_NET
+static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+   struct crypto_report_comp rcomp;
+
+   strncpy(rcomp.type, "scomp", sizeof(rcomp.type));
+   if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
+   sizeof(struct crypto_report_comp), ))
+   goto nla_put_failure;
+   return 0;
+
+nla_put_failure:
+   return -EMSGSIZE;
+}
+#else
+static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+   return -ENOSYS;
+}
+#endif
+
+static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
+   __attribute__ ((unused));
+static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
+{
+   seq_puts(m, "type : scomp\n");
+}
+
+static const struct crypto_type crypto_scomp_type = {
+   .extsize= crypto_alg_extsize,
+   .init   = crypto_scomp_init,
+   .init_tfm   = crypto_scomp_init_tfm,
+#ifdef CONFIG_PROC_FS
+   .show   = crypto_scomp_show,
+#endif
+   .report = crypto_scomp_report,
+   .maskclear  = ~CRYPTO_ALG_TYPE_MASK,
+   .maskset= CRYPTO_ALG_TYPE_MASK,
+   .type   = CRYPTO_ALG_TYPE_SCOMPRESS,
+   .tfmsize= offsetof(struct crypto_scomp, base),
+};
+
+struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type,
+   u32 mask)
+{
+   return crypto_alloc_tfm(alg_name, _scomp_type, type, mask);
+}
+EXPORT_SYMBOL_GPL(crypto_alloc_scomp);
+
+int crypto_register_scomp(struct scomp_alg *alg)
+{
+   struct crypto_alg *base = >base;
+
+   base->cra_type = _scomp_type;
+   base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
+   base->cra_flags |= CRYPTO_ALG_TYPE_SCOMPRESS;
+
+   return crypto_register_alg(base);
+}
+EXPORT_SYMBOL_GPL(crypto_register_scomp);
+
+int crypto_unregister_scomp(struct scomp_alg *alg)
+{
+   return crypto_unregister_alg(>base);
+}
+EXPORT_SYMBOL_GPL(crypto_unregister_scomp);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Synchronous compression 

[PATCH RFC 2/7] crypto/compress: introduce sychronuous compression API

2016-01-03 Thread Joonsoo Kim
This introduces new compression APIs. Major change is that APIs are
stateless. Instead of previous implementation, tfm objects doesn't
embedded any context so we can de/compress concurrently with one tfm
object. Instead, thsi de/compression context is coupled with the request.
This architecture change will make APIs more flexible.

Signed-off-by: Joonsoo Kim 
---
 crypto/Kconfig|   5 ++
 crypto/Makefile   |   1 +
 crypto/scompress.c| 114 ++
 include/crypto/compress.h |  76 +++
 include/linux/crypto.h|   1 +
 5 files changed, 197 insertions(+)
 create mode 100644 crypto/scompress.c
 create mode 100644 include/crypto/compress.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index c80d34f..7159520 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -84,6 +84,10 @@ config CRYPTO_RNG_DEFAULT
tristate
select CRYPTO_DRBG_MENU
 
+config CRYPTO_SCOMPRESS
+   tristate
+   select CRYPTO_ALGAPI2
+
 config CRYPTO_AKCIPHER2
tristate
select CRYPTO_ALGAPI2
@@ -1499,6 +1503,7 @@ config CRYPTO_LZO
select CRYPTO_ALGAPI
select LZO_COMPRESS
select LZO_DECOMPRESS
+   select SCOMPRESS
help
  This is the LZO algorithm.
 
diff --git a/crypto/Makefile b/crypto/Makefile
index ffe18c9..16ef796 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -28,6 +28,7 @@ crypto_hash-y += ahash.o
 crypto_hash-y += shash.o
 obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
 
+obj-$(CONFIG_CRYPTO_SCOMPRESS) += scompress.o
 obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o
 
 $(obj)/rsapubkey-asn1.o: $(obj)/rsapubkey-asn1.c $(obj)/rsapubkey-asn1.h
diff --git a/crypto/scompress.c b/crypto/scompress.c
new file mode 100644
index 000..7c9955b
--- /dev/null
+++ b/crypto/scompress.c
@@ -0,0 +1,114 @@
+/*
+ * Cryptographic API.
+ *
+ * Synchronous compression operations.
+ *
+ * Copyright 2015 LG Electronics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
+ * If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "internal.h"
+
+
+static int crypto_scomp_init(struct crypto_tfm *tfm, u32 type, u32 mask)
+{
+   return 0;
+}
+
+static int crypto_scomp_init_tfm(struct crypto_tfm *tfm)
+{
+   return 0;
+}
+
+#ifdef CONFIG_NET
+static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+   struct crypto_report_comp rcomp;
+
+   strncpy(rcomp.type, "scomp", sizeof(rcomp.type));
+   if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
+   sizeof(struct crypto_report_comp), ))
+   goto nla_put_failure;
+   return 0;
+
+nla_put_failure:
+   return -EMSGSIZE;
+}
+#else
+static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
+{
+   return -ENOSYS;
+}
+#endif
+
+static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
+   __attribute__ ((unused));
+static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg)
+{
+   seq_puts(m, "type : scomp\n");
+}
+
+static const struct crypto_type crypto_scomp_type = {
+   .extsize= crypto_alg_extsize,
+   .init   = crypto_scomp_init,
+   .init_tfm   = crypto_scomp_init_tfm,
+#ifdef CONFIG_PROC_FS
+   .show   = crypto_scomp_show,
+#endif
+   .report = crypto_scomp_report,
+   .maskclear  = ~CRYPTO_ALG_TYPE_MASK,
+   .maskset= CRYPTO_ALG_TYPE_MASK,
+   .type   = CRYPTO_ALG_TYPE_SCOMPRESS,
+   .tfmsize= offsetof(struct crypto_scomp, base),
+};
+
+struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type,
+   u32 mask)
+{
+   return crypto_alloc_tfm(alg_name, _scomp_type, type, mask);
+}
+EXPORT_SYMBOL_GPL(crypto_alloc_scomp);
+
+int crypto_register_scomp(struct scomp_alg *alg)
+{
+   struct crypto_alg *base = >base;
+
+   base->cra_type = _scomp_type;
+   base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
+   base->cra_flags |= CRYPTO_ALG_TYPE_SCOMPRESS;
+
+   return crypto_register_alg(base);
+}
+EXPORT_SYMBOL_GPL(crypto_register_scomp);
+
+int crypto_unregister_scomp(struct scomp_alg *alg)
+{
+   return crypto_unregister_alg(>base);
+}
+EXPORT_SYMBOL_GPL(crypto_unregister_scomp);
+
+MODULE_LICENSE("GPL");