25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/string.h>
28 #include <linux/types.h>
29 #include <asm/byteorder.h>
31 #define MD4_DIGEST_SIZE 16
32 #define MD4_HMAC_BLOCK_SIZE 64
33 #define MD4_BLOCK_WORDS 16
34 #define MD4_HASH_WORDS 4
42 static inline u32 lshift(
u32 x,
unsigned int s)
45 return ((x << s) & 0xFFFFFFFF) | (x >> (32 -
s));
50 return (x & y) | ((~x) & z);
55 return (x & y) | (x & z) | (y & z);
63 #define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s))
64 #define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (u32)0x5A827999,s))
65 #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (u32)0x6ED9EBA1,s))
68 static inline void le32_to_cpu_array(
u32 *
buf,
unsigned int words)
76 static inline void cpu_to_le32_array(
u32 *
buf,
unsigned int words)
93 ROUND1(a, b, c, d, in[0], 3);
94 ROUND1(d, a, b, c, in[1], 7);
95 ROUND1(c, d, a, b, in[2], 11);
96 ROUND1(b, c, d, a, in[3], 19);
97 ROUND1(a, b, c, d, in[4], 3);
98 ROUND1(d, a, b, c, in[5], 7);
99 ROUND1(c, d, a, b, in[6], 11);
100 ROUND1(b, c, d, a, in[7], 19);
101 ROUND1(a, b, c, d, in[8], 3);
102 ROUND1(d, a, b, c, in[9], 7);
103 ROUND1(c, d, a, b, in[10], 11);
104 ROUND1(b, c, d, a, in[11], 19);
105 ROUND1(a, b, c, d, in[12], 3);
106 ROUND1(d, a, b, c, in[13], 7);
107 ROUND1(c, d, a, b, in[14], 11);
108 ROUND1(b, c, d, a, in[15], 19);
110 ROUND2(a, b, c, d,in[ 0], 3);
111 ROUND2(d, a, b, c, in[4], 5);
112 ROUND2(c, d, a, b, in[8], 9);
113 ROUND2(b, c, d, a, in[12], 13);
114 ROUND2(a, b, c, d, in[1], 3);
115 ROUND2(d, a, b, c, in[5], 5);
116 ROUND2(c, d, a, b, in[9], 9);
117 ROUND2(b, c, d, a, in[13], 13);
118 ROUND2(a, b, c, d, in[2], 3);
119 ROUND2(d, a, b, c, in[6], 5);
120 ROUND2(c, d, a, b, in[10], 9);
121 ROUND2(b, c, d, a, in[14], 13);
122 ROUND2(a, b, c, d, in[3], 3);
123 ROUND2(d, a, b, c, in[7], 5);
124 ROUND2(c, d, a, b, in[11], 9);
125 ROUND2(b, c, d, a, in[15], 13);
127 ROUND3(a, b, c, d,in[ 0], 3);
128 ROUND3(d, a, b, c, in[8], 9);
129 ROUND3(c, d, a, b, in[4], 11);
130 ROUND3(b, c, d, a, in[12], 15);
131 ROUND3(a, b, c, d, in[2], 3);
132 ROUND3(d, a, b, c, in[10], 9);
133 ROUND3(c, d, a, b, in[6], 11);
134 ROUND3(b, c, d, a, in[14], 15);
135 ROUND3(a, b, c, d, in[1], 3);
136 ROUND3(d, a, b, c, in[9], 9);
137 ROUND3(c, d, a, b, in[5], 11);
138 ROUND3(b, c, d, a, in[13], 15);
139 ROUND3(a, b, c, d, in[3], 3);
140 ROUND3(d, a, b, c, in[11], 9);
141 ROUND3(c, d, a, b, in[7], 11);
142 ROUND3(b, c, d, a, in[15], 15);
150 static inline void md4_transform_helper(
struct md4_ctx *
ctx)
158 struct md4_ctx *mctx = shash_desc_ctx(desc);
160 mctx->
hash[0] = 0x67452301;
161 mctx->
hash[1] = 0xefcdab89;
162 mctx->
hash[2] = 0x98badcfe;
163 mctx->
hash[3] = 0x10325476;
171 struct md4_ctx *mctx = shash_desc_ctx(desc);
185 md4_transform_helper(mctx);
189 while (len >=
sizeof(mctx->
block)) {
191 md4_transform_helper(mctx);
192 data +=
sizeof(mctx->
block);
193 len -=
sizeof(mctx->
block);
203 struct md4_ctx *mctx = shash_desc_ctx(desc);
205 char *
p = (
char *)mctx->
block + offset;
206 int padding = 56 - (offset + 1);
211 md4_transform_helper(mctx);
212 p = (
char *)mctx->
block;
219 le32_to_cpu_array(mctx->
block, (
sizeof(mctx->
block) -
220 sizeof(
u64)) /
sizeof(
u32));
224 memset(mctx, 0,
sizeof(*mctx));
232 .update = md4_update,
234 .descsize =
sizeof(
struct md4_ctx),
243 static int __init md4_mod_init(
void)
248 static void __exit md4_mod_fini(
void)