backports: add crypto/ccm backport
authorJohannes Berg <johannes.berg@intel.com>
Thu, 27 Feb 2014 17:37:49 +0000 (18:37 +0100)
committerLuis R. Rodriguez <mcgrof@do-not-panic.com>
Wed, 9 Apr 2014 01:16:20 +0000 (18:16 -0700)
This seems to commonly be missing in the random kernels
people use, so just provide a backport.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
backport/compat/Kconfig
backport/compat/Makefile
backport/compat/backports.h
backport/compat/main.c
patches/backport-adjustments/crypto-ccm.patch [new file with mode: 0644]

index 28aef6cb0e57a81f97695c1f4210c6cd36006501..1cec8ada08d339506c724b0ba70ce4fc15897139 100644 (file)
@@ -175,3 +175,12 @@ config BACKPORT_USERSEL_BUILD_ALL
 
          It's only really useful for compat testing, so
          you probably shouldn't enable it.
+
+config BACKPORT_CRYPTO_CCM
+       bool
+
+config BACKPORT_BUILD_CRYPTO_CCM
+       bool
+       default n if CRYPTO_CCM
+       default y if BACKPORT_CRYPTO_CCM
+       #c-file crypto/ccm.c
index e2da341367818119bc02bd3caa3dc0eecf987d89..3c46a1bae6b86df42dc99a8d2aadbc628327e424 100644 (file)
@@ -32,6 +32,7 @@ compat-$(CPTCFG_BACKPORT_KERNEL_3_13) += backport-3.13.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_14) += backport-3.14.o
 compat-$(CPTCFG_BACKPORT_KERNEL_3_15) += backport-3.15.o
 
+compat-$(CPTCFG_BACKPORT_BUILD_CRYPTO_CCM) += crypto-ccm.o
 compat-$(CPTCFG_BACKPORT_BUILD_KFIFO) += kfifo.o
 compat-$(CPTCFG_BACKPORT_BUILD_GENERIC_ATOMIC64) += compat_atomic.o
 compat-$(CPTCFG_BACKPORT_BUILD_DMA_SHARED_HELPERS) += dma-shared-helpers.o
index b6090583617dbebffb44b6550d7d06dadf3e727a..9d76c950dc0e8460a6a51a24628a8aa42e12e705 100644 (file)
@@ -11,4 +11,14 @@ static inline int __init dma_buf_init(void) { return 0; }
 static inline void __exit dma_buf_deinit(void) { }
 #endif
 
+#ifdef CPTCFG_BACKPORT_BUILD_CRYPTO_CCM
+int crypto_ccm_module_init(void);
+void crypto_ccm_module_exit(void);
+#else
+static inline int crypto_ccm_module_init(void)
+{ return 0; }
+static inline void crypto_ccm_module_exit(void)
+{}
+#endif
+
 #endif /* LINUX_BACKPORTS_PRIVATE_H */
index 9a82f72df8ba1618b40d83092425bd572a76acd5..07efc8c0e8e9446aadadd3911d9514fad950ae68 100644 (file)
@@ -54,6 +54,10 @@ EXPORT_SYMBOL_GPL(backport_dependency_symbol);
 
 static int __init backport_init(void)
 {
+       int ret = crypto_ccm_module_init();
+       if (ret)
+               return ret;
+
        backport_system_workqueue_create();
        backport_init_mmc_pm_flags();
        dma_buf_init();
@@ -76,8 +80,6 @@ subsys_initcall(backport_init);
 static void __exit backport_exit(void)
 {
        backport_system_workqueue_destroy();
-
-        return;
+       crypto_ccm_module_exit();
 }
 module_exit(backport_exit);
-
diff --git a/patches/backport-adjustments/crypto-ccm.patch b/patches/backport-adjustments/crypto-ccm.patch
new file mode 100644 (file)
index 0000000..51479ee
--- /dev/null
@@ -0,0 +1,76 @@
+--- a/compat/crypto-ccm.c
++++ b/compat/crypto-ccm.c
+@@ -13,13 +13,44 @@
+ #include <crypto/internal/aead.h>
+ #include <crypto/internal/skcipher.h>
+ #include <crypto/scatterwalk.h>
++#include <crypto/algapi.h>
+ #include <linux/err.h>
+ #include <linux/init.h>
+ #include <linux/kernel.h>
+ #include <linux/module.h>
+ #include <linux/slab.h>
++#include <linux/version.h>
+-#include "internal.h"
++#if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
++/* consider properly backporting this? */
++static int crypto_memneq(const void *a, const void *b, size_t size)
++{
++      unsigned long neq = 0;
++
++#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
++      while (size >= sizeof(unsigned long)) {
++              neq |= *(unsigned long *)a ^ *(unsigned long *)b;
++              /* OPTIMIZER_HIDE_VAR(neq); */
++              barrier();
++              a += sizeof(unsigned long);
++              b += sizeof(unsigned long);
++              size -= sizeof(unsigned long);
++      }
++#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */
++      while (size > 0) {
++              neq |= *(unsigned char *)a ^ *(unsigned char *)b;
++              /* OPTIMIZER_HIDE_VAR(neq); */
++              barrier();
++              a += 1;
++              b += 1;
++              size -= 1;
++      }
++      return neq != 0UL ? 1 : 0;
++}
++#endif
++
++/* from internal.h */
++struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask);
+ struct ccm_instance_ctx {
+       struct crypto_skcipher_spawn ctr;
+@@ -841,7 +872,7 @@ static struct crypto_template crypto_rfc
+       .module = THIS_MODULE,
+ };
+-static int __init crypto_ccm_module_init(void)
++int __init crypto_ccm_module_init(void)
+ {
+       int err;
+@@ -867,17 +898,9 @@ out_undo_base:
+       goto out;
+ }
+-static void __exit crypto_ccm_module_exit(void)
++void __exit crypto_ccm_module_exit(void)
+ {
+       crypto_unregister_template(&crypto_rfc4309_tmpl);
+       crypto_unregister_template(&crypto_ccm_tmpl);
+       crypto_unregister_template(&crypto_ccm_base_tmpl);
+ }
+-
+-module_init(crypto_ccm_module_init);
+-module_exit(crypto_ccm_module_exit);
+-
+-MODULE_LICENSE("GPL");
+-MODULE_DESCRIPTION("Counter with CBC MAC");
+-MODULE_ALIAS("ccm_base");
+-MODULE_ALIAS("rfc4309");