summaryrefslogtreecommitdiff
path: root/patches/crypto-ccm.patch
blob: 2136689eca91cacbbc8ab3ec73db32b65ca4a03b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
--- a/compat/crypto-ccm.c
+++ b/compat/crypto-ccm.c
@@ -14,13 +14,44 @@
 #include <crypto/internal/hash.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_IS_LESS(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;
@@ -1001,7 +1032,7 @@ static struct crypto_template crypto_cbc
 	.module = THIS_MODULE,
 };
 
-static int __init crypto_ccm_module_init(void)
+int __init crypto_ccm_module_init(void)
 {
 	int err;
 
@@ -1033,19 +1064,10 @@ out_undo_cbcmac:
 	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);
 	crypto_unregister_template(&crypto_cbcmac_tmpl);
 }
-
-module_init(crypto_ccm_module_init);
-module_exit(crypto_ccm_module_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Counter with CBC MAC");
-MODULE_ALIAS_CRYPTO("ccm_base");
-MODULE_ALIAS_CRYPTO("rfc4309");
-MODULE_ALIAS_CRYPTO("ccm");