Work around bugs in jmap revoke processing and in the cleaner
[ext4-patch-queue.git] / move-halfmd4-to-ext4
blob15bdda03a3c6b8927f28de8046fad8b680c41f32
1 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 ext4: move halfmd4 into hash.c directly
5 The "half md4" transform should not be used by any new code. And
6 fortunately, it's only used now by ext4. Since ext4 supports several
7 hashing methods, at some point it might be desirable to move to
8 something like SipHash. As an intermediate step, remove half md4 from
9 cryptohash.h and lib, and make it just a local function in ext4's
10 hash.c. There's precedent for doing this; the other function ext can use
11 for its hashes -- TEA -- is also implemented in the same place. Also, by
12 being a local function, this might allow gcc to perform some additional
13 optimizations.
15 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
16 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
17 Cc: Theodore Ts'o <tytso@mit.edu>
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
19 ---
20 v1->v2:
21   - Two blank lines were added for style.
22   - Andreas provided his Reviewed-by line.
24  fs/ext4/hash.c             | 71 +++++++++++++++++++++++++++++++++++++++++++++-
25  include/linux/cryptohash.h |  2 --
26  lib/Makefile               |  2 +-
27  lib/halfmd4.c              | 67 -------------------------------------------
28  4 files changed, 71 insertions(+), 71 deletions(-)
29  delete mode 100644 lib/halfmd4.c
31 diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
32 index e026aa941fd5..38b8a96eb97c 100644
33 --- a/fs/ext4/hash.c
34 +++ b/fs/ext4/hash.c
35 @@ -10,7 +10,8 @@
36   */
38  #include <linux/fs.h>
39 -#include <linux/cryptohash.h>
40 +#include <linux/compiler.h>
41 +#include <linux/bitops.h>
42  #include "ext4.h"
44  #define DELTA 0x9E3779B9
45 @@ -32,6 +33,74 @@ static void TEA_transform(__u32 buf[4], __u32 const in[])
46         buf[1] += b1;
47  }
49 +/* F, G and H are basic MD4 functions: selection, majority, parity */
50 +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
51 +#define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z)))
52 +#define H(x, y, z) ((x) ^ (y) ^ (z))
54 +/*
55 + * The generic round function.  The application is so specific that
56 + * we don't bother protecting all the arguments with parens, as is generally
57 + * good macro practice, in favor of extra legibility.
58 + * Rotation is separate from addition to prevent recomputation
59 + */
60 +#define ROUND(f, a, b, c, d, x, s)     \
61 +       (a += f(b, c, d) + x, a = rol32(a, s))
62 +#define K1 0
63 +#define K2 013240474631UL
64 +#define K3 015666365641UL
66 +/*
67 + * Basic cut-down MD4 transform.  Returns only 32 bits of result.
68 + */
69 +static __u32 half_md4_transform(__u32 buf[4], __u32 const in[8])
71 +       __u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
73 +       /* Round 1 */
74 +       ROUND(F, a, b, c, d, in[0] + K1,  3);
75 +       ROUND(F, d, a, b, c, in[1] + K1,  7);
76 +       ROUND(F, c, d, a, b, in[2] + K1, 11);
77 +       ROUND(F, b, c, d, a, in[3] + K1, 19);
78 +       ROUND(F, a, b, c, d, in[4] + K1,  3);
79 +       ROUND(F, d, a, b, c, in[5] + K1,  7);
80 +       ROUND(F, c, d, a, b, in[6] + K1, 11);
81 +       ROUND(F, b, c, d, a, in[7] + K1, 19);
83 +       /* Round 2 */
84 +       ROUND(G, a, b, c, d, in[1] + K2,  3);
85 +       ROUND(G, d, a, b, c, in[3] + K2,  5);
86 +       ROUND(G, c, d, a, b, in[5] + K2,  9);
87 +       ROUND(G, b, c, d, a, in[7] + K2, 13);
88 +       ROUND(G, a, b, c, d, in[0] + K2,  3);
89 +       ROUND(G, d, a, b, c, in[2] + K2,  5);
90 +       ROUND(G, c, d, a, b, in[4] + K2,  9);
91 +       ROUND(G, b, c, d, a, in[6] + K2, 13);
93 +       /* Round 3 */
94 +       ROUND(H, a, b, c, d, in[3] + K3,  3);
95 +       ROUND(H, d, a, b, c, in[7] + K3,  9);
96 +       ROUND(H, c, d, a, b, in[2] + K3, 11);
97 +       ROUND(H, b, c, d, a, in[6] + K3, 15);
98 +       ROUND(H, a, b, c, d, in[1] + K3,  3);
99 +       ROUND(H, d, a, b, c, in[5] + K3,  9);
100 +       ROUND(H, c, d, a, b, in[0] + K3, 11);
101 +       ROUND(H, b, c, d, a, in[4] + K3, 15);
103 +       buf[0] += a;
104 +       buf[1] += b;
105 +       buf[2] += c;
106 +       buf[3] += d;
108 +       return buf[1]; /* "most hashed" word */
110 +#undef ROUND
111 +#undef K1
112 +#undef K2
113 +#undef K3
114 +#undef F
115 +#undef G
116 +#undef H
118  /* The old legacy hash */
119  static __u32 dx_hack_hash_unsigned(const char *name, int len)
120 diff --git a/include/linux/cryptohash.h b/include/linux/cryptohash.h
121 index f4754282c9c2..3252799832cf 100644
122 --- a/include/linux/cryptohash.h
123 +++ b/include/linux/cryptohash.h
124 @@ -15,6 +15,4 @@ void sha_transform(__u32 *digest, const char *data, __u32 *W);
126  void md5_transform(__u32 *hash, __u32 const *in);
128 -__u32 half_md4_transform(__u32 buf[4], __u32 const in[8]);
130  #endif
131 diff --git a/lib/Makefile b/lib/Makefile
132 index bc4073a8cd08..19ea76149a37 100644
133 --- a/lib/Makefile
134 +++ b/lib/Makefile
135 @@ -31,7 +31,7 @@ lib-$(CONFIG_HAS_DMA) += dma-noop.o
136  lib-y  += kobject.o klist.o
137  obj-y  += lockref.o
139 -obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
140 +obj-y += bcd.o div64.o sort.o parser.o debug_locks.o random32.o \
141          bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \
142          gcd.o lcm.o list_sort.o uuid.o flex_array.o iov_iter.o clz_ctz.o \
143          bsearch.o find_bit.o llist.o memweight.o kfifo.o \
144 diff --git a/lib/halfmd4.c b/lib/halfmd4.c
145 deleted file mode 100644
146 index 137e861d9690..000000000000
147 --- a/lib/halfmd4.c
148 +++ /dev/null
149 @@ -1,67 +0,0 @@
150 -#include <linux/compiler.h>
151 -#include <linux/export.h>
152 -#include <linux/cryptohash.h>
153 -#include <linux/bitops.h>
155 -/* F, G and H are basic MD4 functions: selection, majority, parity */
156 -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
157 -#define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z)))
158 -#define H(x, y, z) ((x) ^ (y) ^ (z))
161 - * The generic round function.  The application is so specific that
162 - * we don't bother protecting all the arguments with parens, as is generally
163 - * good macro practice, in favor of extra legibility.
164 - * Rotation is separate from addition to prevent recomputation
165 - */
166 -#define ROUND(f, a, b, c, d, x, s)     \
167 -       (a += f(b, c, d) + x, a = rol32(a, s))
168 -#define K1 0
169 -#define K2 013240474631UL
170 -#define K3 015666365641UL
173 - * Basic cut-down MD4 transform.  Returns only 32 bits of result.
174 - */
175 -__u32 half_md4_transform(__u32 buf[4], __u32 const in[8])
177 -       __u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
179 -       /* Round 1 */
180 -       ROUND(F, a, b, c, d, in[0] + K1,  3);
181 -       ROUND(F, d, a, b, c, in[1] + K1,  7);
182 -       ROUND(F, c, d, a, b, in[2] + K1, 11);
183 -       ROUND(F, b, c, d, a, in[3] + K1, 19);
184 -       ROUND(F, a, b, c, d, in[4] + K1,  3);
185 -       ROUND(F, d, a, b, c, in[5] + K1,  7);
186 -       ROUND(F, c, d, a, b, in[6] + K1, 11);
187 -       ROUND(F, b, c, d, a, in[7] + K1, 19);
189 -       /* Round 2 */
190 -       ROUND(G, a, b, c, d, in[1] + K2,  3);
191 -       ROUND(G, d, a, b, c, in[3] + K2,  5);
192 -       ROUND(G, c, d, a, b, in[5] + K2,  9);
193 -       ROUND(G, b, c, d, a, in[7] + K2, 13);
194 -       ROUND(G, a, b, c, d, in[0] + K2,  3);
195 -       ROUND(G, d, a, b, c, in[2] + K2,  5);
196 -       ROUND(G, c, d, a, b, in[4] + K2,  9);
197 -       ROUND(G, b, c, d, a, in[6] + K2, 13);
199 -       /* Round 3 */
200 -       ROUND(H, a, b, c, d, in[3] + K3,  3);
201 -       ROUND(H, d, a, b, c, in[7] + K3,  9);
202 -       ROUND(H, c, d, a, b, in[2] + K3, 11);
203 -       ROUND(H, b, c, d, a, in[6] + K3, 15);
204 -       ROUND(H, a, b, c, d, in[1] + K3,  3);
205 -       ROUND(H, d, a, b, c, in[5] + K3,  9);
206 -       ROUND(H, c, d, a, b, in[0] + K3, 11);
207 -       ROUND(H, b, c, d, a, in[4] + K3, 15);
209 -       buf[0] += a;
210 -       buf[1] += b;
211 -       buf[2] += c;
212 -       buf[3] += d;
214 -       return buf[1]; /* "most hashed" word */
216 -EXPORT_SYMBOL(half_md4_transform);
217 -- 
218 2.11.0